Skip to content

Commit 494e065

Browse files
authored
fix: fix new ibc tokens not showing (#2012)
1 parent 09a320f commit 494e065

File tree

8 files changed

+52
-36
lines changed

8 files changed

+52
-36
lines changed

apps/namadillo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@chain-registry/client": "^1.53.5",
1111
"@cosmjs/encoding": "^0.32.3",
1212
"@keplr-wallet/types": "^0.12.136",
13-
"@namada/chain-registry": "^1.0.0",
13+
"@namada/chain-registry": "^1.2.0",
1414
"@namada/indexer-client": "2.5.4",
1515
"@tailwindcss/container-queries": "^0.1.1",
1616
"@tanstack/query-core": "^5.40.0",

apps/namadillo/src/App/Transfer/TransferModule.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
LedgerAccountInfo,
2323
WalletProvider,
2424
} from "types";
25-
import { filterAvailableAsssetsWithBalance } from "utils/assets";
25+
import { filterAvailableAssetsWithBalance } from "utils/assets";
2626
import { checkKeychainCompatibleWithMasp } from "utils/compatibility";
2727
import { getDisplayGasFee } from "utils/gas";
2828
import {
@@ -184,15 +184,15 @@ export const TransferModule = ({
184184
const [memo, setMemo] = useState<undefined | string>();
185185
const keychainVersion = useKeychainVersion();
186186
const chainAssetsMap = useAtomValue(chainAssetsMapAtom);
187-
const allUsersAssets = Object.values(chainAssetsMap) ?? [];
187+
const chainAssets = Object.values(chainAssetsMap) ?? [];
188188
const gasConfig = gasConfigProp ?? feeProps?.gasConfig;
189189

190190
const displayGasFee = useMemo(() => {
191191
return gasConfig ? getDisplayGasFee(gasConfig, chainAssetsMap) : undefined;
192192
}, [gasConfig]);
193193

194194
const availableAssets: AddressWithAssetAndAmountMap = useMemo(() => {
195-
return filterAvailableAsssetsWithBalance(source.availableAssets);
195+
return filterAvailableAssetsWithBalance(source.availableAssets);
196196
}, [source.availableAssets]);
197197

198198
const selectedAsset = mapUndefined(
@@ -348,32 +348,32 @@ export const TransferModule = ({
348348
return assetDisplayAmount.gt(feeDisplayAmount);
349349
}
350350

351-
const chainAcceptedAssets = useMemo(() => {
351+
const filteredAvailableAssets = useMemo(() => {
352352
// Get available assets that are accepted by the chain
353353
return Object.values(availableAssets).filter(({ asset }) => {
354354
if (!source.chain) return true;
355-
return allUsersAssets.some(
355+
return chainAssets.some(
356356
(chainAsset) =>
357357
chainAsset?.symbol.toLowerCase() === asset?.symbol.toLowerCase()
358358
);
359359
});
360-
}, [availableAssets, source.chain, allUsersAssets]);
360+
}, [availableAssets, source.chain, chainAssets]);
361361

362362
const sortedAssets = useMemo(() => {
363-
if (!chainAcceptedAssets.length) {
363+
if (!filteredAvailableAssets.length) {
364364
return [];
365365
}
366366

367367
// Sort filtered assets by amount
368-
return [...chainAcceptedAssets].sort(
368+
return [...filteredAvailableAssets].sort(
369369
(
370370
asset1: AddressWithAssetAndAmount,
371371
asset2: AddressWithAssetAndAmount
372372
) => {
373373
return asset1.amount.gt(asset2.amount) ? -1 : 1;
374374
}
375375
);
376-
}, [chainAcceptedAssets]);
376+
}, [filteredAvailableAssets]);
377377

378378
const getButtonTextError = (
379379
id: ValidationResult,

apps/namadillo/src/atoms/chain/atoms.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from "atoms/settings";
1111
import { queryDependentFn } from "atoms/utils";
1212
import BigNumber from "bignumber.js";
13-
import * as osmosis from "chain-registry/mainnet/osmosis";
1413
import { atom } from "jotai";
1514
import { atomWithQuery } from "jotai-tanstack-query";
1615
import {
@@ -86,20 +85,16 @@ export const chainAssetsMapAtom = atom<Record<Address, Asset | undefined>>(
8685
const nativeTokenAddress = get(nativeTokenAddressAtom);
8786
const chainTokensQuery = get(chainTokensAtom);
8887

88+
// TODO we should get this dynamically from the Github like how we do for chains
89+
const assets = namadaAssets.assets as Asset[];
90+
8991
const chainAssetsMap: Record<Address, Asset> = {};
9092
if (nativeTokenAddress.data) {
9193
// the first asset is the native token asset
92-
chainAssetsMap[nativeTokenAddress.data] = namadaAssets.assets[0];
94+
chainAssetsMap[nativeTokenAddress.data] = assets[0];
9395
}
94-
// TODO
95-
// while we don't have all assets listed on namada-chain-registry,
96-
// merge the osmosis assets to guarantee the most common ones to be available
97-
const assetList: Asset[] = [
98-
...namadaAssets.assets,
99-
...osmosis.assets.assets,
100-
];
10196
chainTokensQuery.data?.forEach((token) => {
102-
const asset = findAssetByToken(token, assetList);
97+
const asset = findAssetByToken(token, assets);
10398
if (asset) {
10499
chainAssetsMap[token.address] = asset;
105100
}

apps/namadillo/src/atoms/integrations/atoms.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ export const availableChainsAtom = atom((get) => {
122122
return getKnownChains(settings.advancedMode).map(({ chain }) => chain);
123123
});
124124

125-
// Lists only the available assets list
126-
export const availableAssetsAtom = atom((get) => {
127-
const settings = get(settingsAtom);
128-
return getKnownChains(settings.advancedMode).map(({ assets }) => assets);
129-
});
130-
131125
export const ibcRateLimitAtom = atomWithQuery((get) => {
132126
const chainTokens = get(chainTokensAtom);
133127
return {
@@ -159,7 +153,12 @@ export const enabledIbcAssetsDenomFamily = atomFamily((ibcChannel?: string) => {
159153
const ibcRateLimit = ibcRateLimits.data?.find(
160154
(rateLimit) => rateLimit.tokenAddress === token.address
161155
);
162-
if (ibcRateLimit && BigNumber(ibcRateLimit.throughputLimit).gt(0)) {
156+
if (
157+
// if we don't have a rate limit defined on the indexer, believe that the sky is the limit
158+
!ibcRateLimit ||
159+
// otherwise, check if the limit is greater than zero
160+
(ibcRateLimit && BigNumber(ibcRateLimit.throughputLimit).gt(0))
161+
) {
163162
if ("trace" in token) {
164163
availableTokens.push(getDenomFromIbcTrace(token.trace));
165164
}

apps/namadillo/src/atoms/integrations/functions.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { mapUndefined } from "@namada/utils";
66
import BigNumber from "bignumber.js";
77
import * as celestia from "chain-registry/mainnet/celestia";
88
import * as cosmos from "chain-registry/mainnet/cosmoshub";
9+
import * as neutron from "chain-registry/mainnet/neutron";
10+
import * as noble from "chain-registry/mainnet/noble";
11+
import * as nyx from "chain-registry/mainnet/nyx";
912
import * as osmosis from "chain-registry/mainnet/osmosis";
1013
import * as stride from "chain-registry/mainnet/stride";
1114
import * as celestiaTestnet from "chain-registry/testnet/celestiatestnet3";
@@ -56,7 +59,16 @@ registry.assets.push(
5659
namadaAssets
5760
);
5861

59-
const mainnetChains: ChainRegistryEntry[] = [celestia, cosmos, osmosis, stride];
62+
// This is the array we must update to add new chains and assets
63+
const mainnetChains: ChainRegistryEntry[] = [
64+
celestia,
65+
cosmos,
66+
osmosis,
67+
stride,
68+
neutron,
69+
noble,
70+
nyx,
71+
];
6072
const testnetChains: ChainRegistryEntry[] = [
6173
cosmosTestnet,
6274
celestiaTestnet,

apps/namadillo/src/utils/assets.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export const findAssetByToken = (
1717
token: NativeToken | IbcToken,
1818
assets: Asset[]
1919
): Asset | undefined => {
20+
// first, search by the address
21+
const asset = assets.find((a) => a.address === token.address);
22+
if (asset) {
23+
return asset;
24+
}
25+
26+
// then, search by trace
2027
if ("trace" in token) {
2128
const traceDenom = token.trace.split("/").at(-1);
2229
if (traceDenom) {
@@ -36,7 +43,7 @@ export const findAssetByToken = (
3643
return undefined;
3744
};
3845

39-
export const filterAvailableAsssetsWithBalance = (
46+
export const filterAvailableAssetsWithBalance = (
4047
availableAssets?: AddressWithAssetAndAmountMap
4148
): AddressWithAssetAndAmountMap => {
4249
if (!availableAssets) return {};

apps/namadillo/src/utils/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ export const namadaAsset = (): Asset => {
8383
const config = store.get(localnetConfigAtom);
8484

8585
const configTokenAddress = config.data?.tokenAddress;
86-
const registryAsset = namadaAssets.assets[0];
86+
87+
// TODO we should get this dynamically from the Github like how we do for chains
88+
const assets = namadaAssets.assets as Asset[];
89+
const registryAsset = assets[0];
8790
const asset =
8891
configTokenAddress ?
8992
{
@@ -92,7 +95,7 @@ export const namadaAsset = (): Asset => {
9295
}
9396
: registryAsset;
9497

95-
return asset satisfies Asset;
98+
return asset;
9699
};
97100

98101
export const isNamadaAsset = (asset?: Asset): boolean =>

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,10 +3557,10 @@ __metadata:
35573557
languageName: node
35583558
linkType: hard
35593559

3560-
"@namada/chain-registry@npm:^1.0.0":
3561-
version: 1.1.0
3562-
resolution: "@namada/chain-registry@npm:1.1.0"
3563-
checksum: 10c0/5a9d94c1963cf6d9269281fba77a13fa2b3e3a1d8181b02ce628bae14e004a4ebb0ecf6fa901597d7f3e16b7136303d71447fa11ce19d1583d9208e43afd1ed4
3560+
"@namada/chain-registry@npm:^1.2.0":
3561+
version: 1.2.0
3562+
resolution: "@namada/chain-registry@npm:1.2.0"
3563+
checksum: 10c0/23f571f9d5358cad747024df262ac0ef3d8c6fd1fa3d3d6ef145801883173b7b48e6f25acf32a4876b682d7138afa6db71971100fe2a9fc6c73c53b2e1da9232
35643564
languageName: node
35653565
linkType: hard
35663566

@@ -3826,7 +3826,7 @@ __metadata:
38263826
"@cosmjs/encoding": "npm:^0.32.3"
38273827
"@eslint/js": "npm:^9.9.1"
38283828
"@keplr-wallet/types": "npm:^0.12.136"
3829-
"@namada/chain-registry": "npm:^1.0.0"
3829+
"@namada/chain-registry": "npm:^1.2.0"
38303830
"@namada/indexer-client": "npm:2.5.4"
38313831
"@playwright/test": "npm:^1.24.1"
38323832
"@svgr/webpack": "npm:^6.5.1"

0 commit comments

Comments
 (0)