From b4c1cb80a6aefc62bde0cfbb8cf74420da3ef447 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Sun, 28 Jan 2024 15:32:03 -0800 Subject: [PATCH 1/3] . --- app/scripts/controllers/detect-tokens.js | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js index d5a230765431..6d3c0508a82c 100644 --- a/app/scripts/controllers/detect-tokens.js +++ b/app/scripts/controllers/detect-tokens.js @@ -169,29 +169,38 @@ export default class DetectTokensController extends StaticIntervalPollingControl const tokensToDetect = []; for (const tokenAddress in tokenListUsed) { if ( - !this.tokenAddresses.find((address) => + !this.tokensController.state.allTokens?.[chainIdAgainstWhichToDetect]?.[ + addressAgainstWhichToDetect + ]?.find(({ address }) => isEqualCaseInsensitive(address, tokenAddress), ) && - !this.hiddenTokens.find((address) => + !this.tokensController.state.allIgnoredTokens?.[ + chainIdAgainstWhichToDetect + ]?.[addressAgainstWhichToDetect]?.find((address) => isEqualCaseInsensitive(address, tokenAddress), ) && - !this.detectedTokens.find(({ address }) => + !this.tokensController.state.allDetectedTokens?.[ + chainIdAgainstWhichToDetect + ]?.[addressAgainstWhichToDetect]?.find(({ address }) => isEqualCaseInsensitive(address, tokenAddress), ) ) { tokensToDetect.push(tokenAddress); } } - const sliceOfTokensToDetect = [ - tokensToDetect.slice(0, 1000), - tokensToDetect.slice(1000, tokensToDetect.length - 1), - ]; + const sliceOfTokensToDetect = []; + for (let i = 0, size = 1000; i < tokensToDetect.length; i += size) { + sliceOfTokensToDetect.push(tokensToDetect.slice(i, i + size)); + } for (const tokensSlice of sliceOfTokensToDetect) { let result; try { result = await this.assetsContractController.getBalancesInSingleCall( addressAgainstWhichToDetect, tokensSlice, + this.network.findNetworkClientIdByChainId( + chainIdAgainstWhichToDetect, + ), ); } catch (error) { warn( @@ -247,7 +256,8 @@ export default class DetectTokensController extends StaticIntervalPollingControl */ restartTokenDetection({ selectedAddress, chainId } = {}) { const addressAgainstWhichToDetect = selectedAddress ?? this.selectedAddress; - const chainIdAgainstWhichToDetect = chainId ?? this.chainId; + const chainIdAgainstWhichToDetect = + chainId ?? this.getChainIdFromNetworkStore(); if (!(this.isActive && addressAgainstWhichToDetect)) { return; } From 6550633c2b63d8cd097390536d9a431875210fac Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Mon, 5 Feb 2024 08:08:08 -0800 Subject: [PATCH 2/3] undo batching change --- app/scripts/controllers/detect-tokens.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js index 6d3c0508a82c..34dc58aaf715 100644 --- a/app/scripts/controllers/detect-tokens.js +++ b/app/scripts/controllers/detect-tokens.js @@ -188,10 +188,10 @@ export default class DetectTokensController extends StaticIntervalPollingControl tokensToDetect.push(tokenAddress); } } - const sliceOfTokensToDetect = []; - for (let i = 0, size = 1000; i < tokensToDetect.length; i += size) { - sliceOfTokensToDetect.push(tokensToDetect.slice(i, i + size)); - } + const sliceOfTokensToDetect = [ + tokensToDetect.slice(0, 1000), + tokensToDetect.slice(1000, tokensToDetect.length - 1), + ]; for (const tokensSlice of sliceOfTokensToDetect) { let result; try { From 5e6b428bb59ceb7fd2fc0359238b6fbdf97689b8 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Thu, 8 Feb 2024 11:08:27 -0800 Subject: [PATCH 3/3] removed unused code --- app/scripts/controllers/detect-tokens.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js index 34dc58aaf715..203541df338f 100644 --- a/app/scripts/controllers/detect-tokens.js +++ b/app/scripts/controllers/detect-tokens.js @@ -65,12 +65,7 @@ export default class DetectTokensController extends StaticIntervalPollingControl this.useTokenDetection = this.preferences?.store.getState().useTokenDetection; this.selectedAddress = getCurrentSelectedAccount().address; - this.tokenAddresses = this.tokensController?.state.tokens.map((token) => { - return token.address; - }); this.setIntervalLength(interval); - this.hiddenTokens = this.tokensController?.state.ignoredTokens; - this.detectedTokens = this.tokensController?.state.detectedTokens; this.chainId = this.getChainIdFromNetworkStore(); this._trackMetaMetricsEvent = trackMetaMetricsEvent; @@ -101,15 +96,6 @@ export default class DetectTokensController extends StaticIntervalPollingControl } }); - tokensController?.subscribe( - ({ tokens = [], ignoredTokens = [], detectedTokens = [] }) => { - this.tokenAddresses = tokens.map((token) => { - return token.address; - }); - this.hiddenTokens = ignoredTokens; - this.detectedTokens = detectedTokens; - }, - ); messenger.subscribe('NetworkController:stateChange', () => { if (this.chainId !== this.getChainIdFromNetworkStore()) { const chainId = this.getChainIdFromNetworkStore();