From 56da4f7fa59217a62eae54acc241fc87358c5731 Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Fri, 2 Aug 2024 10:03:25 +0200 Subject: [PATCH] Use compat flag for noble --- .../components/ibc/ibc-out/chain-selector.tsx | 1 - apps/minifront/src/state/ibc-in/index.tsx | 23 ++++++++----------- apps/minifront/src/state/ibc-out.ts | 4 +++- apps/minifront/src/state/shared.ts | 13 ++++++++++- 4 files changed, 24 insertions(+), 17 deletions(-) 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..f3ae742659 100644 --- a/apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx +++ b/apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx @@ -44,7 +44,6 @@ 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,