From 74c6321eb4954bc344cc624a94a71d0d43b04056 Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Mon, 28 Oct 2024 21:06:15 -0400 Subject: [PATCH] use util function instead of duplicating code --- packages/utils/chain.ts | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/packages/utils/chain.ts b/packages/utils/chain.ts index 83a5fd934..cbf3e1110 100644 --- a/packages/utils/chain.ts +++ b/packages/utils/chain.ts @@ -28,7 +28,10 @@ import { bondStatusToJSON, } from '@dao-dao/types/protobuf/codegen/cosmos/staking/v1beta1/staking' -import { getChainAssets } from './assets' +import { + convertChainRegistryAssetToGenericToken, + getChainAssets, +} from './assets' import { CHAIN_ENDPOINTS, CONFIGURED_CHAINS, @@ -284,29 +287,10 @@ export const getNativeTokenForChainId = (chainId: string): GenericToken => { throw new Error(`Chain ${chainId} has no asset for fee token ${feeDenom}`) } - cachedNativeTokens[chainId] = Object.freeze({ + cachedNativeTokens[chainId] = convertChainRegistryAssetToGenericToken( chainId, - type: TokenType.Native, - denomOrAddress: feeDenom, - 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 asset images. - imageUrl: - asset.logo_URIs?.png ?? - asset.logo_URIs?.jpeg ?? - asset.logo_URIs?.svg ?? - // Fallback. - getFallbackImage(feeDenom), - source: { - chainId, - denomOrAddress: feeDenom, - }, - } as GenericToken) + asset + ) } return cachedNativeTokens[chainId]!