Skip to content

Commit

Permalink
don't show search result twice
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Jan 7, 2025
1 parent ee8c797 commit aa6c9c5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ const TokenList = (props: Props) => {
if (
props.selectedToken &&
props.selectedToken!.chain === props.selectedChainConfig.key &&
!tokenSet.has(props.selectedToken.key)
!tokenSet.has(props.selectedToken.address.toString())
) {
tokenSet.add(props.selectedToken.key);
tokenSet.add(props.selectedToken.address.toString());
tokens.push(props.selectedToken);
}

Expand All @@ -108,8 +108,8 @@ const TokenList = (props: Props) => {
const searchResult = props.tokenList?.find(
(t) => t.address.toString().toLowerCase() === searchQuery.toLowerCase(),
);
if (searchResult) {
tokenSet.add(searchResult.key);
if (searchResult && !tokenSet.has(searchResult.address.toString())) {
tokenSet.add(searchResult.address.toString());
tokens.push(searchResult);
}

Expand Down Expand Up @@ -147,20 +147,23 @@ const TokenList = (props: Props) => {
// Third: Add the native gas token
if (
nativeToken &&
nativeToken.key !== props.selectedToken?.key &&
!tokenSet.has(nativeToken.key)
nativeToken.address.toString() !==
props.selectedToken?.address.toString() &&
!tokenSet.has(nativeToken.address.toString())
) {
tokenSet.add(nativeToken.key);
tokenSet.add(nativeToken.address.toString());
tokens.push(nativeToken);
}

// Fourth: Add tokens with a balances in the connected wallet
Object.entries(balances).forEach(([key, val]) => {
if (val?.balance && sdkAmount.units(val.balance) > 0n) {
const tokenConfig = props.tokenList?.find((t) => t.key === key);
const tokenConfig = props.tokenList?.find(
(t) => t.address.toString() === key,
);

if (tokenConfig && !tokenSet.has(tokenConfig.key)) {
tokenSet.add(tokenConfig.key);
if (tokenConfig && !tokenSet.has(tokenConfig.address.toString())) {
tokenSet.add(tokenConfig.address.toString());
tokens.push(tokenConfig);
}
}
Expand All @@ -171,7 +174,7 @@ const TokenList = (props: Props) => {
if (!props.isSource || !props.wallet?.address) {
props.tokenList?.forEach((t) => {
// Check if previously added
if (tokenSet.has(t.key)) {
if (tokenSet.has(t.address.toString())) {
return;
}

Expand All @@ -189,7 +192,7 @@ const TokenList = (props: Props) => {
return;
}

tokenSet.add(t.key);
tokenSet.add(t.address.toString());
tokens.push(t);
});
}
Expand Down

0 comments on commit aa6c9c5

Please sign in to comment.