Skip to content

Commit 1d89629

Browse files
committed
frontend: add issupportederc20 helper function
So that amount component does not have to maintain an extra list
1 parent 1ea71ad commit 1d89629

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

frontends/web/src/api/erc20.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ export const supportedERC20Tokens: Readonly<TERC20Token[]> = [
2121
{ code: 'eth-erc20-paxg', name: 'Pax Gold', unit: 'PAXG' },
2222
{ code: 'eth-erc20-dai0x6b17', name: 'Dai', unit: 'DAI' },
2323
];
24+
25+
const supportedERC20Units = new Set(
26+
supportedERC20Tokens.map(({ unit }) => unit)
27+
);
28+
29+
export const isSupportedERC20Unit = (
30+
unit: string,
31+
): unit is ERC20TokenUnit => (
32+
supportedERC20Units.has(unit as ERC20TokenUnit)
33+
);

frontends/web/src/components/amount/amount.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useContext } from 'react';
44
import type { CoinUnit, ConversionUnit } from '@/api/account';
5+
import { isSupportedERC20Unit } from '@/api/erc20';
56
import { AppContext } from '@/contexts/AppContext';
67
import { LocalizationContext } from '@/contexts/localization-context';
78
import { useMediaQuery } from '@/hooks/mediaquery';
@@ -207,15 +208,9 @@ export const FormattedAmount = ({
207208
case 'ETH':
208209
case 'SEPETH':
209210
return formatEth(displayedAmount, group, decimal, maxDecimals);
210-
case 'USDT':
211-
case 'USDC':
212-
case 'LINK':
213-
case 'BAT':
214-
case 'MKR':
215-
case 'ZRX':
216-
case 'WBTC':
217-
case 'PAXG':
218-
case 'DAI':
211+
}
212+
213+
if (isSupportedERC20Unit(unit)) {
219214
return formatEth(displayedAmount, group, decimal, maxDecimals);
220215
}
221216

0 commit comments

Comments
 (0)