Skip to content

fix(checkout): Exclude non-Squid tokens from Add Tokens Widget #2630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ export function TokenDrawerMenu({
}),
[
addTokensState.allowedTokens,
addTokensState.tokens,
handleTokenChange,
isSelected,
defaultTokenImage,
searchValue,
],
);
Expand All @@ -126,7 +122,7 @@ export function TokenDrawerMenu({
}, [setVisible, setSearchValue]);

useEffect(() => {
if (!checkout || addTokensState.tokens != null) return;
if (!checkout || addTokensState.allowedTokens || !addTokensState.tokens) return;

(async () => {
try {
Expand All @@ -136,18 +132,31 @@ export function TokenDrawerMenu({
});

if (tokenResponse?.tokens.length > 0) {
const updatedTokens = tokenResponse.tokens.map((token) => {
const updatedTokens = tokenResponse.tokens.reduce((acc, token) => {
if (!addTokensState.tokens) throw new Error('Squid tokens not loaded');

if (isNativeToken(token.address)) {
return {
acc.push({
...token,
icon: getTokenImageByAddress(
checkout.config.environment as Environment,
token.symbol,
),
};
});
return acc;
}
return token;
});

const squidToken = addTokensState.tokens.find((x) =>
x.address.toLowerCase() === token.address?.toLowerCase());

if (squidToken) {
acc.push(token);
return acc;
}

return acc;
}, new Array<TokenInfo>());

updatedTokens.sort((a, b) => {
const aIndex = TOKEN_PRIORITY_ORDER.findIndex(
(token) => token === a.symbol,
Expand Down
Loading