-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chore: stop using tokensChainsCache in confirmations #27611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
34be656
6c6fca7
f18535e
8276fcf
9712024
4d112f6
5abccf0
9737e04
7104f8a
8bd4182
49ca151
ca108e7
4d2eace
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,31 @@ | ||
| import { NameType } from '../../UI/Name/Name.types'; | ||
| import { UseDisplayNameRequest } from './useDisplayName'; | ||
| import { selectERC20TokensByChain } from '../../../selectors/tokenListController'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { Hex } from '@metamask/utils'; | ||
| import { useTokensData } from '../useTokensData/useTokensData'; | ||
|
|
||
| function buildAssetId(value: string, variation: Hex): string { | ||
| return `eip155:${parseInt(variation, 16)}/erc20:${value.toLowerCase()}`; | ||
| } | ||
|
|
||
| export function useERC20Tokens(requests: UseDisplayNameRequest[]) { | ||
| const erc20TokensByChain = useSelector(selectERC20TokensByChain); | ||
| const assetIds = requests | ||
| .filter(({ type, value }) => type === NameType.EthereumAddress && value) | ||
| .map(({ value, variation }) => | ||
| buildAssetId(value as string, variation as Hex), | ||
|
Check warning on line 14 in app/components/hooks/DisplayName/useERC20Tokens.ts
|
||
| ); | ||
|
|
||
| const tokensByAssetId = useTokensData(assetIds); | ||
|
|
||
| return requests.map(({ preferContractSymbol, type, value, variation }) => { | ||
| if (type !== NameType.EthereumAddress || !value) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const contractAddress = value.toLowerCase(); | ||
| const chainId = variation as Hex; | ||
|
|
||
| const { | ||
| name: tokenName, | ||
| symbol, | ||
| iconUrl: image, | ||
| } = erc20TokensByChain[chainId]?.data?.[contractAddress] ?? {}; | ||
|
|
||
| const name = preferContractSymbol && symbol ? symbol : tokenName; | ||
| const token = | ||
| tokensByAssetId[buildAssetId(value as string, variation as Hex)]; | ||
|
Check warning on line 25 in app/components/hooks/DisplayName/useERC20Tokens.ts
|
||
| const name = | ||
| preferContractSymbol && token?.symbol ? token.symbol : token?.name; | ||
|
|
||
| return { name, image }; | ||
| return { name, image: token?.iconUrl }; | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.