diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index a7cb1a9b91..5580dfa631 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -8,11 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `TokenListController` now exports a `TokenListControllerMessenger` type ([#3609](https://github.com/MetaMask/core/pull/3609)). - `TokenDetectionController` exports types `TokenDetectionControllerMessenger`, `TokenDetectionControllerActions`, `TokenDetectionControllerGetStateAction`, `TokenDetectionControllerEvents`, `TokenDetectionControllerStateChangeEvent` ([#3609](https://github.com/MetaMask/core/pull/3609)). +- Add `enable` and `disable` methods to `TokenDetectionController`, which control whether the controller is able to make polling requests or all of its network calls are blocked ([#3609](https://github.com/MetaMask/core/pull/3609)). ### Changed - **BREAKING:** `TokenDetectionController` is upgraded to extend `BaseControllerV2` and `StaticIntervalPollingController` ([#3609](https://github.com/MetaMask/core/pull/3609)). - - The constructor now expects an options object as its only argument, with required properties `messenger`, `networkClientId`, required callbacks `onPreferencesStateChange`, `getBalancesInSingleCall`, `getPreferencesState`, and optional properties `interval`, `selectedAddress`. Note that the `config` object is no longer used by the constructor. - - Polling can only be initiated by calling `start` or `startPollingByNetworkClientId` from a controller client. There is no longer an option to automatically start polling when the controller is instantiated. + - The constructor now expects an options object as its only argument, with required properties `messenger`, `networkClientId`, required callbacks `onPreferencesStateChange`, `getBalancesInSingleCall`, `addDetectedTokens`, `getTokenState`, `getPreferencesState`, and optional properties `disabled`, `interval`, `selectedAddress`. Note that the `config` object is no longer used by the constructor. ## [22.0.0] ### Changed diff --git a/packages/assets-controllers/src/TokenDetectionController.ts b/packages/assets-controllers/src/TokenDetectionController.ts index e17f9b7fb2..19c4d90871 100644 --- a/packages/assets-controllers/src/TokenDetectionController.ts +++ b/packages/assets-controllers/src/TokenDetectionController.ts @@ -117,7 +117,7 @@ export class TokenDetectionController extends StaticIntervalPollingController< networkClientId, selectedAddress = '', interval = DEFAULT_INTERVAL, - disabled = false, + disabled = true, onPreferencesStateChange, getBalancesInSingleCall, addDetectedTokens, @@ -212,11 +212,25 @@ export class TokenDetectionController extends StaticIntervalPollingController< ); } + /** + * Allows controller to make active and passive polling requests + */ + enable() { + this.#disabled = false; + } + + /** + * Blocks controller from making network calls + */ + disable() { + this.#disabled = true; + } + /** * Start polling for detected tokens. */ async start() { - this.#disabled = false; + this.enable(); await this.#startPolling(); } @@ -224,7 +238,7 @@ export class TokenDetectionController extends StaticIntervalPollingController< * Stop polling for detected tokens. */ stop() { - this.#disabled = true; + this.disable(); this.#stopPolling(); }