From dd37354099b49b47740977ab54a505d38d3eac52 Mon Sep 17 00:00:00 2001 From: Lucas Jiang Date: Mon, 22 Apr 2024 15:14:07 +0800 Subject: [PATCH] use utils in chain-registry to get check if native asset or not --- .../asset-list/utils/local-chain-registry.ts | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/examples/asset-list/utils/local-chain-registry.ts b/examples/asset-list/utils/local-chain-registry.ts index 6b5931fad..2425c94cd 100644 --- a/examples/asset-list/utils/local-chain-registry.ts +++ b/examples/asset-list/utils/local-chain-registry.ts @@ -1,6 +1,6 @@ import { assets, chains, ibc } from 'chain-registry/mainnet' import { Asset, AssetList } from '@chain-registry/types' -import { getChainNameByDenom } from '@chain-registry/utils' +import { getNativeAssetLists } from '@chain-registry/utils' export { assets, chains, ibc } @@ -9,30 +9,7 @@ export const getAssetsByChainName = (chainName: string) => { } export const isNativeAsset = (targetAsset: Asset, chainName: string) => { - const assetsByChain = assets.filter(a => a.chain_name === chainName) - const chain_name = getChainNameByDenom(assetsByChain, targetAsset.base) - switch (true) { - case targetAsset.base.startsWith('factory/'): - return false; - - case targetAsset.base.startsWith('ft') && chain_name === 'bitsong': - return false; - - case targetAsset.base.startsWith('erc20/'): - return true; - - case targetAsset.base.startsWith('ibc/'): - return false; - - case targetAsset.base.startsWith('cw20:'): - return true; - - default: - if (!targetAsset.traces || !targetAsset.traces.length) { - // asset.type_asset = 'sdk.coin' - return true; - } - return false; - } + const nativeAssetList: AssetList[] = getNativeAssetLists(chainName, ibc, assets) + return !!nativeAssetList.flatMap(al => al.assets).find(a => a.base === targetAsset.base) }