Skip to content

Commit 8eae484

Browse files
grod220turbocrime
authored andcommitted
Use compat flag for noble
1 parent a88436f commit 8eae484

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const ChainSelector = () => {
4444
<SelectContent className='left-[-17px]'>
4545
{chains.data?.map((i, index) => (
4646
<SelectItem
47-
disabled={i.chainId === 'noble-1'}
4847
key={index}
4948
value={i.displayName}
5049
className={cn(

apps/minifront/src/state/ibc-in/index.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { currentTimePlusTwoDaysRounded } from '../ibc-out';
2020
import { EncodeObject } from '@cosmjs/proto-signing';
2121
import { MsgTransfer } from 'osmo-query/ibc/applications/transfer/v1/tx';
2222
import { parseRevisionNumberFromChainId } from './parse-revision-number-from-chain-id';
23+
import { bech32ChainIds } from '../shared.ts';
2324

2425
export interface IbcInSlice {
2526
selectedChain?: ChainInfo;
@@ -64,7 +65,7 @@ export const createIbcInSlice = (): SliceCreator<IbcInSlice> => (set, get) => {
6465
address: undefined,
6566
setAddress: async () => {
6667
const { selectedChain, account } = get().ibcIn;
67-
const penumbraAddress = await getPenumbraAddress(account, selectedChain?.chainName);
68+
const penumbraAddress = await getPenumbraAddress(account, selectedChain?.chainId);
6869
if (penumbraAddress) {
6970
set(state => {
7071
state.ibcIn.address = penumbraAddress;
@@ -132,25 +133,19 @@ const getExplorerPage = (txHash: string, chainId?: string) => {
132133
return txPage.replace('${txHash}', txHash);
133134
};
134135

135-
/**
136-
* For Noble specifically we need to use a Bech32 encoding rather than Bech32m,
137-
* because Noble currently has a middleware that decodes as Bech32.
138-
* Noble plans to change this at some point in the future but until then we need
139-
* to use a special encoding just for Noble specifically.
140-
*/
141-
const bech32Chains = ['noble', 'nobletestnet'];
142-
const getCompatibleBech32 = (chainName: string, address: Address): string => {
143-
return bech32Chains.includes(chainName) ? bech32CompatAddress(address) : bech32mAddress(address);
136+
const getCompatibleBech32 = (chainId: string, address: Address): string => {
137+
return bech32ChainIds.includes(chainId) ? bech32CompatAddress(address) : bech32mAddress(address);
144138
};
139+
145140
export const getPenumbraAddress = async (
146141
account: number,
147-
chainName?: string,
142+
chainId?: string,
148143
): Promise<string | undefined> => {
149-
if (!chainName) {
144+
if (!chainId) {
150145
return undefined;
151146
}
152147
const receiverAddress = await getAddrByIndex(account, true);
153-
return getCompatibleBech32(chainName, receiverAddress);
148+
return getCompatibleBech32(chainId, receiverAddress);
154149
};
155150

156151
const estimateFee = async ({
@@ -201,7 +196,7 @@ async function execute(
201196
throw new Error('Penumbra chain id could not be retrieved');
202197
}
203198

204-
const penumbraAddress = await getPenumbraAddress(account, selectedChain.chainName);
199+
const penumbraAddress = await getPenumbraAddress(account, selectedChain.chainId);
205200
if (!penumbraAddress) {
206201
throw new Error('Penumbra address not available');
207202
}

apps/minifront/src/state/ibc-out.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Chain } from '@penumbra-labs/registry';
2323
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb.js';
2424
import { Channel } from '@buf/cosmos_ibc.bufbuild_es/ibc/core/channel/v1/channel_pb.js';
2525
import { BLOCKS_PER_HOUR } from './constants';
26-
import { ZQueryState, createZQuery } from '@penumbra-zone/zquery';
26+
import { createZQuery, ZQueryState } from '@penumbra-zone/zquery';
2727
import { getChains } from '../fetchers/registry';
2828

2929
export const { chains, useChains } = createZQuery({
@@ -211,6 +211,8 @@ const getPlanRequest = async ({
211211
timeoutHeight,
212212
timeoutTime,
213213
sourceChannel: chain.channelId,
214+
// TODO: after updating bufbuild types, uncomment this
215+
// useCompatAddress: bech32ChainIds.includes(chain.chainId),
214216
},
215217
],
216218
source: addressIndex,

apps/minifront/src/state/shared.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ import { getAllAssets } from '../fetchers/assets';
99
import { getBalances } from '../fetchers/balances';
1010
import { getStakingTokenMetadata } from '../fetchers/registry';
1111

12+
/**
13+
* For Noble specifically we need to use a Bech32 encoding rather than Bech32m,
14+
* because Noble currently has a middleware that decodes as Bech32.
15+
* Noble plans to change this at some point in the future but until then we need
16+
* to use a special encoding just for Noble specifically.
17+
*/
18+
export const bech32ChainIds = [
19+
'noble-1', // noble mainnet
20+
'grand-1', // noble testnet
21+
];
22+
1223
export const { stakingTokenMetadata, useStakingTokenMetadata } = createZQuery({
1324
name: 'stakingTokenMetadata',
1425
fetch: getStakingTokenMetadata,

0 commit comments

Comments
 (0)