diff --git a/apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx b/apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx index 6b65e98363..3e6e49e45a 100644 --- a/apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx +++ b/apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx @@ -11,6 +11,7 @@ import { AllSlices } from '../../../state'; import { Chain } from '@penumbra-labs/registry'; import { useStoreShallow } from '../../../utils/use-store-shallow'; import { useChains } from '../../../state/ibc-out'; +import { bech32ChainIds } from '../../../state/shared.ts'; const chainSelectorSelector = (state: AllSlices) => ({ chain: state.ibcOut.chain, @@ -44,7 +45,7 @@ export const ChainSelector = () => { {chains.data?.map((i, index) => ( => (set, get) => { address: undefined, setAddress: async () => { const { selectedChain, account } = get().ibcIn; - const penumbraAddress = await getPenumbraAddress(account, selectedChain?.chainName); + const penumbraAddress = await getPenumbraAddress(account, selectedChain?.chainId); if (penumbraAddress) { set(state => { state.ibcIn.address = penumbraAddress; @@ -132,25 +133,19 @@ const getExplorerPage = (txHash: string, chainId?: string) => { return txPage.replace('${txHash}', txHash); }; -/** - * For Noble specifically we need to use a Bech32 encoding rather than Bech32m, - * because Noble currently has a middleware that decodes as Bech32. - * Noble plans to change this at some point in the future but until then we need - * to use a special encoding just for Noble specifically. - */ -const bech32Chains = ['noble', 'nobletestnet']; -const getCompatibleBech32 = (chainName: string, address: Address): string => { - return bech32Chains.includes(chainName) ? bech32CompatAddress(address) : bech32mAddress(address); +const getCompatibleBech32 = (chainId: string, address: Address): string => { + return bech32ChainIds.includes(chainId) ? bech32CompatAddress(address) : bech32mAddress(address); }; + export const getPenumbraAddress = async ( account: number, - chainName?: string, + chainId?: string, ): Promise => { - if (!chainName) { + if (!chainId) { return undefined; } const receiverAddress = await getAddrByIndex(account, true); - return getCompatibleBech32(chainName, receiverAddress); + return getCompatibleBech32(chainId, receiverAddress); }; const estimateFee = async ({ @@ -201,7 +196,7 @@ async function execute( throw new Error('Penumbra chain id could not be retrieved'); } - const penumbraAddress = await getPenumbraAddress(account, selectedChain.chainName); + const penumbraAddress = await getPenumbraAddress(account, selectedChain.chainId); if (!penumbraAddress) { throw new Error('Penumbra address not available'); } diff --git a/apps/minifront/src/state/ibc-out.ts b/apps/minifront/src/state/ibc-out.ts index 8d934608fa..3ff594eed0 100644 --- a/apps/minifront/src/state/ibc-out.ts +++ b/apps/minifront/src/state/ibc-out.ts @@ -23,7 +23,7 @@ import { Chain } from '@penumbra-labs/registry'; import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb.js'; import { Channel } from '@buf/cosmos_ibc.bufbuild_es/ibc/core/channel/v1/channel_pb.js'; import { BLOCKS_PER_HOUR } from './constants'; -import { ZQueryState, createZQuery } from '@penumbra-zone/zquery'; +import { createZQuery, ZQueryState } from '@penumbra-zone/zquery'; import { getChains } from '../fetchers/registry'; export const { chains, useChains } = createZQuery({ @@ -211,6 +211,8 @@ const getPlanRequest = async ({ timeoutHeight, timeoutTime, sourceChannel: chain.channelId, + // TODO: after updating bufbuild types, uncomment this + // useCompatAddress: bech32ChainIds.includes(chain.chainId), }, ], source: addressIndex, diff --git a/apps/minifront/src/state/shared.ts b/apps/minifront/src/state/shared.ts index 276e2403fd..38f894f1b6 100644 --- a/apps/minifront/src/state/shared.ts +++ b/apps/minifront/src/state/shared.ts @@ -1,4 +1,4 @@ -import { ZQueryState, createZQuery } from '@penumbra-zone/zquery'; +import { createZQuery, ZQueryState } from '@penumbra-zone/zquery'; import { SliceCreator, useStore } from '.'; import { getStakingTokenMetadata } from '../fetchers/registry'; import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb.js'; @@ -9,6 +9,17 @@ import { Address } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/k import { getAddress, getAddressIndex } from '@penumbra-zone/getters/address-view'; import { AbridgedZQueryState } from '@penumbra-zone/zquery/src/types'; +/** + * For Noble specifically we need to use a Bech32 encoding rather than Bech32m, + * because Noble currently has a middleware that decodes as Bech32. + * Noble plans to change this at some point in the future but until then we need + * to use a special encoding just for Noble specifically. + */ +export const bech32ChainIds = [ + 'noble-1', // noble mainnet + 'grand-1', // noble testnet +]; + export const { stakingTokenMetadata, useStakingTokenMetadata } = createZQuery({ name: 'stakingTokenMetadata', fetch: getStakingTokenMetadata,