From 6de0f015b9eca0cda36aad27757a509505191c37 Mon Sep 17 00:00:00 2001 From: David Uhlmann Date: Wed, 18 Oct 2023 22:11:55 +1000 Subject: [PATCH] fix: dev token prices should all be non zero (#473) * fix: allow STK and TKN to be considered devTokens * fix: allow devToken price to be shown when CoinGecko data is undefined --- src/lib/tokenPrices.ts | 4 ++-- src/lib/web3/hooks/useTokens.ts | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/lib/tokenPrices.ts b/src/lib/tokenPrices.ts index b5e738558..9b0f19724 100644 --- a/src/lib/tokenPrices.ts +++ b/src/lib/tokenPrices.ts @@ -170,9 +170,9 @@ export function useSimplePrice( const cachedResults = useMemo(() => { // return found results as numbers return tokens.map((token) => - data && token?.coingecko_id + token?.coingecko_id ? // if the information is fetchable, return fetched (number) or not yet fetched (undefined) - (data[token.coingecko_id]?.[currencyID] as number | undefined) + (data?.[token.coingecko_id]?.[currencyID] as number | undefined) : // if the information is not fetchable, return a dev token price or 0 (unpriced) isDevToken(token) ? 1 diff --git a/src/lib/web3/hooks/useTokens.ts b/src/lib/web3/hooks/useTokens.ts index 4cbcbdc1d..e954e4d9c 100644 --- a/src/lib/web3/hooks/useTokens.ts +++ b/src/lib/web3/hooks/useTokens.ts @@ -35,7 +35,7 @@ type TokenList = Array; // create an alternate chain to identify dev assets on the Duality chain export const dualityMainToken: Token = { - chain: dualityChain, + chain: devChain, description: 'SDK default token', address: 'token', denom_units: [ @@ -60,7 +60,7 @@ export const dualityMainToken: Token = { }; export const dualityStakeToken: Token = { - chain: dualityChain, + chain: devChain, description: 'SDK default token', address: 'stake', denom_units: [ @@ -88,7 +88,7 @@ export const dualityAssets: AssetList | undefined = REACT_APP__CHAIN_ASSETS ? (JSON.parse(REACT_APP__CHAIN_ASSETS) as AssetList) : isTestnet ? { - chain_name: dualityChain.chain_name, + chain_name: devChain.chain_name, assets: [dualityStakeToken, dualityMainToken], } : undefined; @@ -115,6 +115,7 @@ export const devAssets: AssetList | undefined = REACT_APP__DEV_ASSET_MAP return foundAsset ? { ...foundAsset, + chain: devChain, // fix: remove clashing TypeScript types traces: undefined, // overwrite address for token matching @@ -159,12 +160,14 @@ function getTokens(condition: (chain: Chain) => boolean) { return assetList.reduce((result, { chain_name, assets }) => { // add each asset with the parent chain details const chain = chainList.find((chain) => chain.chain_name === chain_name); - // only show assets that have a known address - const knownAssets = assets.filter( - (asset): asset is Token => !!asset.address - ); return chain && condition(chain) - ? result.concat(knownAssets.map((asset) => ({ ...asset, chain }))) + ? result.concat( + // add assets that have a known address + assets + .filter((asset): asset is Omit => !!asset.address) + // and append chain information to them (if devChain not already set) + .map((asset) => ({ chain, ...asset })) + ) : result; }, []); }