Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/hooks/useTokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface UseTokenListParams {
selectedChainConfig: ChainConfig;
selectedToken?: Token;
sourceToken?: Token;
destToken?: Token;
wallet: WalletData;
balances: Balances;
isSourceList?: boolean; // true for source tokens, false for destination tokens
Expand All @@ -30,6 +31,7 @@ export const useTokenList = ({
selectedChainConfig,
selectedToken,
sourceToken,
destToken,
wallet,
balances,
isSourceList = false,
Expand All @@ -42,12 +44,17 @@ export const useTokenList = ({
// Apply search input - find tokens with exact match of address, or partial match of symbol
let tokens = applyTokenSearch(tokenList, searchQuery, selectedChainConfig);

// For bidirectional symbol matching: use opposite side's token
// Source list shows tokens matching dest token's symbol at top
// Dest list shows tokens matching source token's symbol at top
const oppositeToken = isSourceList ? destToken : sourceToken;

tokens = sortTokensByPreference(
tokens,
selectedToken,
balances,
getTokenPrice,
sourceToken,
oppositeToken,
);

// Apply token whitelist filtering if configured
Expand Down Expand Up @@ -75,5 +82,6 @@ export const useTokenList = ({
lastTokenPriceUpdate,
isSourceList,
sourceToken,
destToken,
]);
};
16 changes: 8 additions & 8 deletions src/utils/tokenListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import type { Balances } from './wallet/types';
export const getTokenPreferenceScore = (
token: Token,
selectedToken?: Token,
sourceToken?: Token,
oppositeToken?: Token,
): number => {
// Currently selected token should be shown first
if (selectedToken && isSameToken(selectedToken, token)) {
return 5;
}
// For destination picker: prioritize tokens with same symbol as source token
// Only prioritize native (non-wrapped) destination tokens
// Prioritize tokens with same symbol as the opposite side's token
// Exclude Wormhole-wrapped tokens from this preference
if (
sourceToken &&
token.symbol === sourceToken.symbol &&
oppositeToken &&
token.symbol === oppositeToken.symbol &&
!token.isTokenBridgeWrappedToken
) {
return 4;
Expand Down Expand Up @@ -100,11 +100,11 @@ export const sortTokensByPreference = (
selectedToken: Token | undefined,
balances: Balances,
getTokenPrice: (token: Token) => number | undefined,
sourceToken?: Token,
oppositeToken?: Token,
): Token[] => {
return tokens.sort((a, b) => {
const scoreA = getTokenPreferenceScore(a, selectedToken, sourceToken);
const scoreB = getTokenPreferenceScore(b, selectedToken, sourceToken);
const scoreA = getTokenPreferenceScore(a, selectedToken, oppositeToken);
const scoreB = getTokenPreferenceScore(b, selectedToken, oppositeToken);
if (scoreA > scoreB) return -1;
if (scoreB > scoreA) return 1;

Expand Down
2 changes: 2 additions & 0 deletions src/views/v3/Bridge/AssetPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Props = {
chainList: Array<ChainConfig>;
token?: Token;
sourceToken?: Token;
destToken?: Token;
tokenList?: Array<Token> | undefined;
isFetchingQuotes?: boolean;
isFetchingTokens?: boolean;
Expand Down Expand Up @@ -87,6 +88,7 @@ function AssetPicker(props: Props) {
selectedChainConfig: props.chain ? config.chains[props.chain] : ({} as any),
selectedToken: props.token,
sourceToken: props.sourceToken,
destToken: props.destToken,
wallet: props.wallet,
balances: props.balances,
isSourceList: props.isSource, // true for source, false for destination
Expand Down
1 change: 1 addition & 0 deletions src/views/v3/Bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ function Bridge(props: BridgeProps) {
chain={sourceChain}
chainList={supportedSourceChains}
token={sourceToken}
destToken={destToken}
tokenList={sourceTokens}
setChain={handleSourceChainChange}
setToken={handleSourceTokenChange}
Expand Down
Loading