Skip to content

Commit

Permalink
fix: dev token prices should all be non zero (#473)
Browse files Browse the repository at this point in the history
* fix: allow STK and TKN to be considered devTokens

* fix: allow devToken price to be shown when CoinGecko data is undefined
  • Loading branch information
dib542 authored Oct 18, 2023
1 parent d2748c7 commit 6de0f01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/lib/tokenPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions src/lib/web3/hooks/useTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type TokenList = Array<Token>;

// 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: [
Expand All @@ -60,7 +60,7 @@ export const dualityMainToken: Token = {
};

export const dualityStakeToken: Token = {
chain: dualityChain,
chain: devChain,
description: 'SDK default token',
address: 'stake',
denom_units: [
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -159,12 +160,14 @@ function getTokens(condition: (chain: Chain) => boolean) {
return assetList.reduce<TokenList>((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<Token, 'chain'> => !!asset.address)
// and append chain information to them (if devChain not already set)
.map((asset) => ({ chain, ...asset }))
)
: result;
}, []);
}
Expand Down

0 comments on commit 6de0f01

Please sign in to comment.