From 1037bdfeb13f24fccfc98c79681ec1a90366d502 Mon Sep 17 00:00:00 2001 From: trungbach Date: Sat, 21 Dec 2024 16:31:34 +0700 Subject: [PATCH] refactor: streamline token item methods and add isVerified property --- .../common/src/token-items/token-items.ts | 36 ++++++------------- packages/common/src/token-items/types.ts | 1 + 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/packages/common/src/token-items/token-items.ts b/packages/common/src/token-items/token-items.ts index 107db0a..356ef82 100644 --- a/packages/common/src/token-items/token-items.ts +++ b/packages/common/src/token-items/token-items.ts @@ -1,9 +1,5 @@ import { flatten, uniqBy } from "lodash"; -import { - BridgeAppCurrency, - ChainInfoReader, - CustomChainInfo -} from "../chain-infos"; +import { BridgeAppCurrency, ChainInfoReader, CustomChainInfo } from "../chain-infos"; import { COSMOS_CHAIN_IDS } from "../constants/chain-ids"; import { IBC_DENOMS } from "../constants/denoms"; import { NETWORK_TYPES } from "../constants/network"; @@ -39,9 +35,7 @@ export class TokenItemsImpl implements TokenItems { return tokenItems; } - private getTokensFromNetwork = ( - network: CustomChainInfo - ): TokenItemType[] => { + private getTokensFromNetwork = (network: CustomChainInfo): TokenItemType[] => { if (!network) return []; return network.currencies.map((currency) => { @@ -50,8 +44,7 @@ export class TokenItemsImpl implements TokenItems { org: network.chainName, coinType: network.bip44.coinType, contractAddress: currency.contractAddress, - prefix: - currency?.prefixToken ?? network.bech32Config?.bech32PrefixAccAddr, + prefix: currency?.prefixToken ?? network.bech32Config?.bech32PrefixAccAddr, coinGeckoId: currency.coinGeckoId, denom: currency.coinMinimalDenom, bridgeNetworkIdentifier: currency.bridgeNetworkIdentifier, @@ -66,15 +59,14 @@ export class TokenItemsImpl implements TokenItems { feeCurrencies: network.feeCurrencies, evmDenoms: evmDenomsMap[currency.coinMinimalDenom], icon: currency.coinImageUrl, - iconLight: currency.coinImageUrl + iconLight: currency.coinImageUrl, + isVerified: true }; }); }; getSpecificChainTokens(chainId: string) { - return this.getTokensFromNetwork( - this.chainInfos.find((chain) => chain.chainId === chainId) - ); + return this.getTokensFromNetwork(this.chainInfos.find((chain) => chain.chainId === chainId)); } get otherChainTokens() { @@ -87,9 +79,7 @@ export class TokenItemsImpl implements TokenItems { get oraichainTokens() { return this.getTokensFromNetwork( - this.chainInfos.find( - (chain) => chain.chainId === COSMOS_CHAIN_IDS.ORAICHAIN - ) + this.chainInfos.find((chain) => chain.chainId === COSMOS_CHAIN_IDS.ORAICHAIN) ); } @@ -106,16 +96,12 @@ export class TokenItemsImpl implements TokenItems { } get assetInfoMap() { - return Object.fromEntries( - this.flattenTokens.map((c) => [c.contractAddress || c.denom, c]) - ); + return Object.fromEntries(this.flattenTokens.map((c) => [c.contractAddress || c.denom, c])); } get cosmosTokens() { return uniqBy( - this.flattenTokens.filter( - (token) => token.denom && token.cosmosBased && token.coinGeckoId - ), + this.flattenTokens.filter((token) => token.denom && token.cosmosBased && token.coinGeckoId), (c) => c.denom ); } @@ -131,9 +117,7 @@ export class TokenItemsImpl implements TokenItems { } get cw20TokenMap() { - return Object.fromEntries( - this.cw20Tokens.map((c) => [c.contractAddress, c]) - ); + return Object.fromEntries(this.cw20Tokens.map((c) => [c.contractAddress, c])); } get evmTokens() { diff --git a/packages/common/src/token-items/types.ts b/packages/common/src/token-items/types.ts index 7ebc122..6a80ff8 100644 --- a/packages/common/src/token-items/types.ts +++ b/packages/common/src/token-items/types.ts @@ -25,4 +25,5 @@ export type TokenItemType = { feeCurrencies?: FeeCurrency[]; icon: string; iconLight?: string; + isVerified?: boolean; };