|
1 | 1 | import { TransactionMeta } from '@metamask/transaction-controller'; |
2 | 2 | import { useSelector } from 'react-redux'; |
3 | 3 | import { useI18nContext } from '../../../../../../hooks/useI18nContext'; |
4 | | -import { selectERC20TokensByChain } from '../../../../../../selectors'; |
| 4 | +import { |
| 5 | + getAllTokens, |
| 6 | + selectERC20TokensByChain, |
| 7 | +} from '../../../../../../selectors'; |
| 8 | +import { Token } from '../../../../../../components/app/assets/types'; |
5 | 9 |
|
6 | 10 | export const useTokenDetails = (transactionMeta: TransactionMeta) => { |
7 | 11 | const t = useI18nContext(); |
8 | 12 | const { |
9 | 13 | chainId, |
10 | | - txParams: { to }, |
| 14 | + txParams: { to, from }, |
11 | 15 | } = transactionMeta ?? { txParams: {} }; |
12 | | - const tokenListByChain = useSelector(selectERC20TokensByChain); |
13 | | - const { iconUrl: tokenImage, symbol: tokenSymbol } = tokenListByChain[chainId] |
14 | | - ?.data?.[to?.toLowerCase() as string] ?? { |
15 | | - iconUrl: undefined, |
16 | | - symbol: t('unknown'), |
17 | | - }; |
| 16 | + const erc20TokensByChain = useSelector(selectERC20TokensByChain); |
| 17 | + const allTokens = useSelector(getAllTokens); |
| 18 | + |
| 19 | + const erc20Token = |
| 20 | + erc20TokensByChain[chainId]?.data?.[to?.toLowerCase() as string]; |
| 21 | + const tokenListToken = allTokens?.[chainId]?.[from as string].find( |
| 22 | + (token: Token) => |
| 23 | + token.address?.toLowerCase() === (to?.toLowerCase() as string), |
| 24 | + ); |
| 25 | + |
| 26 | + const tokenImage = |
| 27 | + erc20Token?.iconUrl || tokenListToken?.iconUrl || undefined; |
| 28 | + const tokenSymbol = |
| 29 | + erc20Token?.symbol || tokenListToken?.symbol || t('unknown'); |
18 | 30 |
|
19 | 31 | return { tokenImage, tokenSymbol }; |
20 | 32 | }; |
0 commit comments