Skip to content

Commit

Permalink
use utils in chain-registry to get check if native asset or not
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaaawscodepipelinedeploy committed Apr 22, 2024
1 parent 12e7df4 commit dd37354
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions examples/asset-list/utils/local-chain-registry.ts
Original file line number Diff line number Diff line change
@@ -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 }

Expand All @@ -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)
}

0 comments on commit dd37354

Please sign in to comment.