Skip to content

Commit

Permalink
Exclude detectedTokens already stored in tokens-controller state fr…
Browse files Browse the repository at this point in the history
…om `tokensToDetect`
  • Loading branch information
MajorLift committed Feb 6, 2024
1 parent 129c82e commit 33818aa
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,25 @@ export class TokenDetectionController extends StaticIntervalPollingController<
const tokenListUsed = isTokenDetectionInactiveInMainnet
? STATIC_MAINNET_TOKEN_LIST
: tokenList;

const { tokens, detectedTokens } = this.#getTokensState();
const tokensToDetect: string[] = [];
for (const address of Object.keys(tokenListUsed)) {
if (!tokensAddresses.includes(address)) {
tokensToDetect.push(address);

const findCaseInsensitiveMatch = (source: string[], target: string) =>
source.find((e: string) => e.toLowerCase() === target.toLowerCase());

for (const tokenAddress of Object.keys(tokenListUsed)) {
if (
!findCaseInsensitiveMatch(
tokens.map(({ address }) => address),
tokenAddress,
) &&
!findCaseInsensitiveMatch(
detectedTokens.map(({ address }) => address),
tokenAddress,
)
) {
tokensToDetect.push(tokenAddress);
}
}
const sliceOfTokensToDetect = [];
Expand Down Expand Up @@ -493,8 +508,9 @@ export class TokenDetectionController extends StaticIntervalPollingController<
);
}
const caseInsensitiveTokenKey =
Object.keys(tokenListUsed).find(
(i) => i.toLowerCase() === tokenAddress.toLowerCase(),
findCaseInsensitiveMatch(
Object.keys(tokenListUsed),
tokenAddress,
) ?? '';

if (ignored === undefined) {
Expand Down

0 comments on commit 33818aa

Please sign in to comment.