Skip to content

Commit 6ba98de

Browse files
committed
Exclude detectedTokens already stored in tokens-controller state from tokensToDetect
1 parent 32465fd commit 6ba98de

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

packages/assets-controllers/src/TokenDetectionController.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,25 @@ export class TokenDetectionController extends StaticIntervalPollingController<
452452
const tokenListUsed = isTokenDetectionInactiveInMainnet
453453
? STATIC_MAINNET_TOKEN_LIST
454454
: tokenList;
455+
456+
const { tokens, detectedTokens } = this.#getTokensState();
455457
const tokensToDetect: string[] = [];
456-
for (const address of Object.keys(tokenListUsed)) {
457-
if (!tokensAddresses.includes(address)) {
458-
tokensToDetect.push(address);
458+
459+
const findCaseInsensitiveMatch = (source: string[], target: string) =>
460+
source.find((e: string) => e.toLowerCase() === target.toLowerCase());
461+
462+
for (const tokenAddress of Object.keys(tokenListUsed)) {
463+
if (
464+
!findCaseInsensitiveMatch(
465+
tokens.map(({ address }) => address),
466+
tokenAddress,
467+
) &&
468+
!findCaseInsensitiveMatch(
469+
detectedTokens.map(({ address }) => address),
470+
tokenAddress,
471+
)
472+
) {
473+
tokensToDetect.push(tokenAddress);
459474
}
460475
}
461476
const sliceOfTokensToDetect = [];
@@ -493,8 +508,9 @@ export class TokenDetectionController extends StaticIntervalPollingController<
493508
);
494509
}
495510
const caseInsensitiveTokenKey =
496-
Object.keys(tokenListUsed).find(
497-
(i) => i.toLowerCase() === tokenAddress.toLowerCase(),
511+
findCaseInsensitiveMatch(
512+
Object.keys(tokenListUsed),
513+
tokenAddress,
498514
) ?? '';
499515

500516
if (ignored === undefined) {

0 commit comments

Comments
 (0)