Skip to content

Commit

Permalink
Set disabled to true by default and add enable, disable methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Dec 21, 2023
1 parent 6d020bc commit 05cf2bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<
networkClientId,
selectedAddress = '',
interval = DEFAULT_INTERVAL,
disabled = false,
disabled = true,
onPreferencesStateChange,
getBalancesInSingleCall,
addDetectedTokens,
Expand Down Expand Up @@ -212,19 +212,33 @@ 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();
}

/**
* Stop polling for detected tokens.
*/
stop() {
this.#disabled = true;
this.disable();
this.#stopPolling();
}

Expand Down

0 comments on commit 05cf2bd

Please sign in to comment.