Skip to content

Commit

Permalink
fix: display token in URL first if it exists in selected chain
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelae committed Jan 10, 2025
1 parent eabc52f commit 616fdf5
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions ui/hooks/bridge/useTokensWithFiltering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useSelector } from 'react-redux';
import { isEqual } from 'lodash';
import { ChainId } from '@metamask/controller-utils';
import { Hex } from '@metamask/utils';
import { useParams } from 'react-router-dom';
import { zeroAddress } from 'ethereumjs-util';
import {
getAllDetectedTokensForSelectedAddress,
Expand Down Expand Up @@ -41,17 +40,15 @@ type FilterPredicate = (

/**
* Returns a token list generator that filters and sorts tokens in this order
* - matches URL token parameter
* - matches search query
* - highest balance in selected currency
* - detected tokens (with balance)
* - tokens with highest to lowest balance in selected currency
* - detected tokens (without balance)
* - popularity
* - all other tokens
*
* @param chainId - the selected src/dest chainId
*/
export const useTokensWithFiltering = (chainId?: ChainId | Hex) => {
const { token: tokenAddressFromUrl } = useParams();
const allDetectedTokens: Record<string, Token[]> = useSelector(
getAllDetectedTokensForSelectedAddress,
);
Expand Down Expand Up @@ -140,22 +137,6 @@ export const useTokensWithFiltering = (chainId?: ChainId | Hex) => {
return;
}

// If a token address is in the URL (e.g. from a deep link), yield that token first
if (tokenAddressFromUrl) {
const token =
tokenList[tokenAddressFromUrl] ??
tokenList[tokenAddressFromUrl.toLowerCase()];
if (
token &&
shouldAddToken(token.symbol, token.address ?? undefined, chainId)
) {
const tokenWithData = buildTokenData(token);
if (tokenWithData) {
yield tokenWithData;
}
}
}

// Yield multichain tokens with balances and are not blocked
for (const token of multichainTokensWithBalance) {
if (
Expand Down Expand Up @@ -250,7 +231,6 @@ export const useTokensWithFiltering = (chainId?: ChainId | Hex) => {
currentCurrency,
chainId,
tokenList,
tokenAddressFromUrl,
allDetectedTokens,
],
);
Expand Down

0 comments on commit 616fdf5

Please sign in to comment.