1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

fix issue where duplicate tokens without icons appear in swap-to token list dropdown (#12148)

This commit is contained in:
Alex Donesky 2021-09-22 10:31:36 -05:00 committed by GitHub
parent 1cc45774dc
commit 1ca02cb633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,7 +66,8 @@ export function getRenderableTokenData(
const usedIconUrl = const usedIconUrl =
iconUrl || iconUrl ||
(tokenList[tokenAddress] && (tokenList[tokenAddress] &&
`images/contract/${tokenList[tokenAddress].iconUrl}`); `images/contract/${tokenList[tokenAddress].iconUrl}`) ||
token?.image;
return { return {
...token, ...token,
primaryLabel: symbol, primaryLabel: symbol,
@ -127,7 +128,7 @@ export function useTokensToSearch({
const memoizedTokensToSearch = useEqualityCheck(tokensToSearch); const memoizedTokensToSearch = useEqualityCheck(tokensToSearch);
return useMemo(() => { return useMemo(() => {
const usersTokensAddressMap = memoizedUsersToken.reduce( const usersTokensAddressMap = memoizedUsersToken.reduce(
(acc, token) => ({ ...acc, [token.address]: token }), (acc, token) => ({ ...acc, [token.address.toLowerCase()]: token }),
{}, {},
); );
@ -139,12 +140,12 @@ export function useTokensToSearch({
const memoizedSwapsAndUserTokensWithoutDuplicities = uniqBy( const memoizedSwapsAndUserTokensWithoutDuplicities = uniqBy(
[...memoizedTokensToSearch, ...memoizedUsersToken], [...memoizedTokensToSearch, ...memoizedUsersToken],
'address', (token) => token.address.toLowerCase(),
); );
memoizedSwapsAndUserTokensWithoutDuplicities.forEach((token) => { memoizedSwapsAndUserTokensWithoutDuplicities.forEach((token) => {
const renderableDataToken = getRenderableTokenData( const renderableDataToken = getRenderableTokenData(
{ ...usersTokensAddressMap[token.address], ...token }, { ...usersTokensAddressMap[token.address.toLowerCase()], ...token },
tokenConversionRates, tokenConversionRates,
conversionRate, conversionRate,
currentCurrency, currentCurrency,
@ -154,12 +155,12 @@ export function useTokensToSearch({
); );
if ( if (
isSwapsDefaultTokenSymbol(renderableDataToken.symbol, chainId) || isSwapsDefaultTokenSymbol(renderableDataToken.symbol, chainId) ||
usersTokensAddressMap[token.address] usersTokensAddressMap[token.address.toLowerCase()]
) { ) {
tokensToSearchBuckets.owned.push(renderableDataToken); tokensToSearchBuckets.owned.push(renderableDataToken);
} else if (memoizedTopTokens[token.address]) { } else if (memoizedTopTokens[token.address.toLowerCase()]) {
tokensToSearchBuckets.top[ tokensToSearchBuckets.top[
memoizedTopTokens[token.address].index memoizedTopTokens[token.address.toLowerCase()].index
] = renderableDataToken; ] = renderableDataToken;
} else { } else {
tokensToSearchBuckets.others.push(renderableDataToken); tokensToSearchBuckets.others.push(renderableDataToken);