diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index 4a4b7a1e1eb..1466f922e52 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **BREAKING:** In Mainnet, even if the `PreferenceController`'s `useTokenDetection` option is set to false, automatic token detection is performed on the legacy token list (token data from the contract-metadata repo). - **BREAKING:** The `TokensState` type is now defined as a type alias rather than an interface. ([#3690](https://github.com/MetaMask/core/pull/3690/)) - `TokensState` now extends the `Record` types, and it has an index signature of `string`, making it compatible with the `BaseControllerV2` state object constraint of `Record<string, Json>`. + - The `detectTokens` method can now process an arbitrary number of tokens in batches of 1000. ### Removed diff --git a/packages/assets-controllers/src/TokenDetectionController.ts b/packages/assets-controllers/src/TokenDetectionController.ts index 5dadfeaa742..161efcfb2bd 100644 --- a/packages/assets-controllers/src/TokenDetectionController.ts +++ b/packages/assets-controllers/src/TokenDetectionController.ts @@ -566,11 +566,9 @@ export class TokenDetectionController extends StaticIntervalPollingController< } const slicesOfTokensToDetect = []; - slicesOfTokensToDetect[0] = tokensToDetect.slice(0, 1000); - slicesOfTokensToDetect[1] = tokensToDetect.slice( - 1000, - tokensToDetect.length - 1, - ); + for (let i = 0, size = 1000; i < tokensToDetect.length; i += size) { + slicesOfTokensToDetect.push(tokensToDetect.slice(i, i + size)); + } return slicesOfTokensToDetect; }