Skip to content

Commit

Permalink
refactor: streamline token item methods and add isVerified property
Browse files Browse the repository at this point in the history
  • Loading branch information
trungbach committed Dec 21, 2024
1 parent 08fb28c commit 1037bdf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
36 changes: 10 additions & 26 deletions packages/common/src/token-items/token-items.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) => {
Expand All @@ -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,
Expand All @@ -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() {
Expand All @@ -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)
);
}

Expand All @@ -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
);
}
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/token-items/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export type TokenItemType = {
feeCurrencies?: FeeCurrency[];
icon: string;
iconLight?: string;
isVerified?: boolean;
};

0 comments on commit 1037bdf

Please sign in to comment.