Skip to content

Commit

Permalink
[token-detection-controller] Consolidate with `DetectTokensController…
Browse files Browse the repository at this point in the history
…` from extension (#3775)

## Explanation

Merges the core `TokenDetectionController` with `DetectTokensController`
from the extension and patches for this controller from mobile.

- Aims to replace the extension and mobile versions of this controller
and implement a unified interface that consolidates the functionality of
all three iterations.
- Generally assumes `DetectTokensController` to be more up-to-date, and
prioritizes preserving extension and mobile behavior to minimize
disruption.

Significant API changes: see
[Changelog](https://github.com/MetaMask/core/pull/3775/files#diff-ee47d03d53776b8dd530799a8047f5e32e36e35765620aeb50b294adc3339fab)
for details.

## References

- Closes #3626
- See #1813 

## Changelog

###
[`@metamask/assets-controllers`](https://github.com/MetaMask/core/pull/3775/files#diff-ee47d03d53776b8dd530799a8047f5e32e36e35765620aeb50b294adc3339fab)
### Added

- **BREAKING:** Adds `@metamask/accounts-controller` ^8.0.0 and
`@metamask/keyring-controller` ^12.0.0 as dependencies and peer
dependencies. ([#3775](#3775)).
- **BREAKING:** `TokenDetectionController` newly subscribes to the
`PreferencesController:stateChange`,
`AccountsController:selectedAccountChange`, `KeyringController:lock`,
`KeyringController:unlock` events, and allows the
`PreferencesController:getState` messenger action.
([#3775](#3775))

### Changed

- **BREAKING:** `TokenDetectionController` is merged with
`DetectTokensController` from the `metamask-extension` repo.
([#3775](#3775))
- **BREAKING:** `TokenDetectionController` now resets its polling
interval to the default value of 3 minutes when token detection is
triggered by external controller events `KeyringController:unlock`,
`TokenListController:stateChange`, `PreferencesController:stateChange`,
`AccountsController:selectedAccountChange`.
- **BREAKING:** `TokenDetectionController` now refetches tokens on
`NetworkController:networkDidChange` if the `networkClientId` is changed
instead of `chainId`.
- **BREAKING:** `TokenDetectionController` cannot initiate polling or
token detection if `KeyringController` state is locked.
- **BREAKING:** The `detectTokens` method now excludes tokens that are
already included in the `TokensController`'s `detectedTokens` list from
the batch of incoming tokens it sends to the `TokensController`
`addDetectedTokens` method.
- **BREAKING:** The constructor for `TokenDetectionController` expects a
new required proprerty `trackMetaMetricsEvent`, which defines the
callback that is called in the `detectTokens` method.
- **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).

### Removed

- **BREAKING:** `TokenDetectionController` constructor no longer accepts
options `onPreferencesStateChange`, `getPreferencesState`.
([#3775](#3775))
- **BREAKING:** `TokenDetectionController` no longer allows the
`NetworkController:stateChange` event. The
`NetworkController:networkDidChange` event can be used instead.
([#3775](#3775))

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
  • Loading branch information
MajorLift and mcmire authored Feb 8, 2024
1 parent 065fd91 commit 00e4a9c
Show file tree
Hide file tree
Showing 8 changed files with 435 additions and 115 deletions.
20 changes: 20 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **BREAKING:** Adds `@metamask/accounts-controller` ^8.0.0 and `@metamask/keyring-controller` ^12.0.0 as dependencies and peer dependencies. ([#3775](https://github.com/MetaMask/core/pull/3775/)).
- **BREAKING:** `TokenDetectionController` newly subscribes to the `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`, `KeyringController:lock`, `KeyringController:unlock` events, and allows the `PreferencesController:getState` messenger action. ([#3775](https://github.com/MetaMask/core/pull/3775/))

### Changed

- **BREAKING:** `TokenDetectionController` is merged with `DetectTokensController` from the `metamask-extension` repo. ([#3775](https://github.com/MetaMask/core/pull/3775/))
- **BREAKING:** `TokenDetectionController` now resets its polling interval to the default value of 3 minutes when token detection is triggered by external controller events `KeyringController:unlock`, `TokenListController:stateChange`, `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`.
- **BREAKING:** `TokenDetectionController` now refetches tokens on `NetworkController:networkDidChange` if the `networkClientId` is changed instead of `chainId`.
- **BREAKING:** `TokenDetectionController` cannot initiate polling or token detection if `KeyringController` state is locked.
- **BREAKING:** The `detectTokens` method now excludes tokens that are already included in the `TokensController`'s `detectedTokens` list from the batch of incoming tokens it sends to the `TokensController` `addDetectedTokens` method.
- **BREAKING:** The constructor for `TokenDetectionController` expects a new required proprerty `trackMetaMetricsEvent`, which defines the callback that is called in the `detectTokens` method.
- **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).

### Removed

- **BREAKING:** `TokenDetectionController` constructor no longer accepts options `onPreferencesStateChange`, `getPreferencesState`. ([#3775](https://github.com/MetaMask/core/pull/3775/))
- **BREAKING:** `TokenDetectionController` no longer allows the `NetworkController:stateChange` event. The `NetworkController:networkDidChange` event can be used instead. ([#3775](https://github.com/MetaMask/core/pull/3775/))

## [25.0.0]

### Added
Expand Down
8 changes: 4 additions & 4 deletions packages/assets-controllers/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ module.exports = merge(baseConfig, {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 88.36,
functions: 97.08,
lines: 97.23,
statements: 97.28,
branches: 88.3,
functions: 95.32,
lines: 96.69,
statements: 96.7,
},
},

Expand Down
5 changes: 5 additions & 0 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@metamask/abi-utils": "^2.0.2",
"@metamask/accounts-controller": "^10.0.0",
"@metamask/approval-controller": "^5.1.2",
"@metamask/base-controller": "^4.1.1",
"@metamask/contract-metadata": "^2.4.0",
"@metamask/controller-utils": "^8.0.2",
"@metamask/eth-query": "^4.0.0",
"@metamask/keyring-controller": "^12.2.0",
"@metamask/metamask-eth-abis": "3.0.0",
"@metamask/network-controller": "^17.2.0",
"@metamask/polling-controller": "^5.0.0",
Expand All @@ -59,6 +61,7 @@
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/ethjs-provider-http": "^0.3.0",
"@metamask/keyring-api": "^3.0.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
"@types/node": "^16.18.54",
Expand All @@ -73,7 +76,9 @@
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/accounts-controller": "^10.0.0",
"@metamask/approval-controller": "^5.1.2",
"@metamask/keyring-controller": "^12.2.0",
"@metamask/network-controller": "^17.2.0",
"@metamask/preferences-controller": "^7.0.0"
},
Expand Down
Loading

0 comments on commit 00e4a9c

Please sign in to comment.