-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathuseERC20Tokens.ts
More file actions
28 lines (23 loc) · 1.02 KB
/
useERC20Tokens.ts
File metadata and controls
28 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { NameType } from '../../UI/Name/Name.types';
import { UseDisplayNameRequest } from './useDisplayName';
import { Hex } from '@metamask/utils';
import { useTokensData } from '../useTokensData/useTokensData';
import { buildEvmCaip19AssetId } from '../../../util/multichain/buildEvmCaip19AssetId';
export function useERC20Tokens(requests: UseDisplayNameRequest[]) {
const assetIds = requests
.filter(({ type, value }) => type === NameType.EthereumAddress && value)
.map(({ value, variation }) =>
buildEvmCaip19AssetId(value as string, variation as Hex),
);
const tokensByAssetId = useTokensData(assetIds);
return requests.map(({ preferContractSymbol, type, value, variation }) => {
if (type !== NameType.EthereumAddress || !value) {
return undefined;
}
const token =
tokensByAssetId[buildEvmCaip19AssetId(value as string, variation as Hex)];
const name =
preferContractSymbol && token?.symbol ? token.symbol : token?.name;
return { name, image: token?.iconUrl };
});
}