Skip to content

Commit 81e64cd

Browse files
committed
Update tests
1 parent ce11e57 commit 81e64cd

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import { TransactionMeta } from '@metamask/transaction-controller';
22
import { useSelector } from 'react-redux';
33
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';
59

610
export const useTokenDetails = (transactionMeta: TransactionMeta) => {
711
const t = useI18nContext();
812
const {
913
chainId,
10-
txParams: { to },
14+
txParams: { to, from },
1115
} = 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');
1830

1931
return { tokenImage, tokenSymbol };
2032
};

0 commit comments

Comments
 (0)