Skip to content

Commit ded13d2

Browse files
committed
fix(cms): remove duplicates from the token list
1 parent f861fe6 commit ded13d2

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cms/src/app/(api)/tokenlist/route.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,24 @@ export const GET = async (request: Request) => {
175175
underlyingTokens = foundUnderlyingTokens;
176176
}
177177

178-
// Combine all tokens
179-
const allTokens = [...tokens, ...underlyingTokens];
178+
// Combine all tokens and deduplicate by composite ID (chainId:address)
179+
const tokenMap = new Map<string, Token>();
180+
181+
// Add initial tokens
182+
for (const token of tokens) {
183+
const key = `${token.chainId}:${token.address.toLowerCase()}`;
184+
tokenMap.set(key, token);
185+
}
186+
187+
// Add underlying tokens (will not overwrite existing ones)
188+
for (const token of underlyingTokens) {
189+
const key = `${token.chainId}:${token.address.toLowerCase()}`;
190+
if (!tokenMap.has(key)) {
191+
tokenMap.set(key, token);
192+
}
193+
}
194+
195+
const allTokens = Array.from(tokenMap.values());
180196

181197
// Get testnet chain IDs programmatically from Superfluid metadata
182198
const testnetChainIds = new Set(superfluidMetadata.testnets.map((network) => network.chainId));

0 commit comments

Comments
 (0)