Skip to content

Commit

Permalink
Use IBC assets for token info. (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso authored Jul 15, 2023
1 parent f5b5951 commit 61a5d87
Showing 1 changed file with 6 additions and 41 deletions.
47 changes: 6 additions & 41 deletions packages/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,50 +211,15 @@ export const getTokenForChainIdAndDenom = (

const key = `${chainId}:${denom}`
if (!cachedTokens[key]) {
// If Juno mainnet, check IBC assets.
if (chainId === ChainId.JunoMainnet) {
const ibcAsset = getIbcAssets().find(
({ denomOrAddress }) => denomOrAddress === denom
)

if (ibcAsset) {
cachedTokens[key] = ibcAsset
return ibcAsset
}
}

// Otherwise, check asset list.
const chain = getChainForChainId(chainId)

const assetList =
assets.find(({ chain_name }) => chain_name === chain.chain_name)
?.assets ?? []
const asset = assetList.find(({ base }) => base === denom)
if (!asset) {
// Try IBC assets.
const ibcAsset = getIbcAssets().find(
({ denomOrAddress }) => denomOrAddress === denom
)
if (!ibcAsset) {
throw new Error(`Chain ${chainId} has no asset for token ${denom}`)
}

cachedTokens[key] = Object.freeze({
chainId,
type: TokenType.Native,
denomOrAddress: denom,
symbol: asset.symbol,
decimals:
asset.denom_units.find(({ denom }) => denom === asset.display)
?.exponent ??
asset.denom_units.find(({ exponent }) => exponent > 0)?.exponent ??
asset.denom_units[0]?.exponent ??
0,
// Use local Juno image for ujuno token prefix.
imageUrl: denom.startsWith('ujuno')
? '/juno.png'
: // Use asset images.
asset.logo_URIs?.svg ??
asset.logo_URIs?.png ??
asset.logo_URIs?.jpeg ??
// Fallback.
getFallbackImage(denom),
})
cachedTokens[key] = ibcAsset
}

return cachedTokens[key]!
Expand Down

3 comments on commit 61a5d87

@vercel
Copy link

@vercel vercel bot commented on 61a5d87 Jul 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 61a5d87 Jul 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 61a5d87 Jul 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.