From 4f2d6a4255a565c5fa1de2e2c0013623ddf8810c Mon Sep 17 00:00:00 2001 From: Jongsun Suh Date: Thu, 14 Mar 2024 12:42:08 -0400 Subject: [PATCH] refactor: Replace `DetectTokensController` with core monorepo's `TokenDetectionController` (#22928) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This commit replaces [`DetectTokensController`](https://github.com/MetaMask/metamask-extension/blob/68cc610976485d0071400cb2d4c3ea18cc6b15d9/app/scripts/controllers/detect-tokens.js) with the core repo's [`TokenDetectionController`](https://github.com/MetaMask/core/blob/main/packages/assets-controllers/src/TokenDetectionController.ts). This represents the final step of Shared Libraries' initiative to a) consolidate the core repo's `TokenDetectionController`, the extension's `DetectTokensController`, and relevant mobile patches to `@metamask/assets-controllers`, with the goal of b) migrating both extension and mobile to use the consolidated controller in core. This also represents a full conversion to TypeScript for `DetectTokensController` and its unit tests. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/22928?quickstart=1) ## **Related issues** - Contributes to: - https://github.com/MetaMask/core/issues/700 - https://github.com/MetaMask/core/issues/1812 - Closes: - https://github.com/MetaMask/metamask-extension/issues/23127 - https://github.com/MetaMask/metamask-extension/issues/23322 - Blocked by: - https://github.com/MetaMask/core/issues/3916 - https://github.com/MetaMask/core/pull/3923 - https://github.com/MetaMask/core/pull/4007 (`@metamask/assets-controllers` v26) ## **Manual testing steps** - Check whether issue no. 4 in this comment https://github.com/MetaMask/metamask-extension/pull/23010#issuecomment-1975140437 can be reproed in this branch. ## Changelog ### `metamask-extension` - `MetamaskController` class: - Define a `preferencesControllerMessenger` instance which only allows the `PreferencesController:getState` action and `PreferencesController:stateChange` event. - Add a subscription to the preferences-controller observable store, with a listener that publishes a `PreferencesController:stateChange` event. - `PreferencesController`: - Add `messenger` as an optional constructor options object property. - Register a `PreferencesController:getState` action handler. - **BREAKING:** Replace all imports of `toChecksumHexAddress` from `@metamask/controller-utils` with imports from the internal `shared/modules/hexstring-utils` module. - **BREAKING:** Bump `@metamask/assets-controllers` to `^26.0.0`. - Remove patch. - **BREAKING:** Bump `@metamask/accounts-controller` to `^11.0.0`. - Remove unused diff in patch. - **BREAKING:** Bump `@metamask/keyring-controller` to `^13.0.0`. - Remove patch. - **BREAKING:** Remove `@metamask/polling-controller` as a dependency. - Required by `test-yarn-dedupe` CI run. - Bump `@metamask/controller-utils` to `^8.0.4`. ### `TokenDetectionController` (compared to `DetectTokensController`) - **BREAKING:** Inherit from `StaticIntervalPollingController` instead of `StaticIntervalPollingControllerOnly` - Constructor and class fields: - **BREAKING:** Remove `preferences`, `network`, `tokenList`, `tokensController`, `assetsContractController`, `getCurrentSelectedAccount`, `getNetworkClientById` as constructor options, and add required option `getBalancesInSingleCall`. - **BREAKING:** Remove `disableLegacyInterval` class field and constructor option. - `#restartTokenDetection` always resets polling interval to default regardless of whether legacy or new polling is being used. - **BREAKING:** Add a `#disabled` private class field, which blocks all network requests if set to true, and add `disabled` as an optional constructor option, which defaults to 'true' if omitted. - **BREAKING:** Remove `isOpen` class field, and replace by adding `enable`, `disable` public methods. - Add optional constructor option `selectedAddress`. If omitted, its value is populated by calling the `AccountsController:getSelectedAccount` action. - Messenger: - **BREAKING:** Newly subscribe to the `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`, `KeyringController:lock`, `KeyringController:unlock` events. - **BREAKING:** Newly allow messenger actions `AccountsController:getSelectedAccount`, `NetworkController:getNetworkClientById`, `NetworkController:getNetworkConfigurationByNetworkClientId`, `NetworkController:getState`, `KeyringController:getState`, `PreferencesController:getState`, `TokenListController:getState`, `TokensController:getState`, and `TokensController:addDetectedTokens`. - **BREAKING:** `detectTokens` replaces the `detectNewTokens` method. - **BREAKING:** Now expects an options object with optional properties `selectedAddress`, `networkClientId`, removing the `chainId` option. - **BREAKING:** Passes lists of full `Token` types to `TokensController:addDetectedTokens` instead of objects containing only `{ address, decimals, symbol }`. - Processes an arbitrary number of tokens in batches of 1000. - Previously, `detectTokens` was limited to two batches, with the first batch being limited to 1000 tokens. - If the `getBalancesInSingleCall` callback fails, it does not throw an error or exit early, and the method continues processing the next batch of tokens. - **BREAKING:** `#restartTokenDetection` is a private method instead of public. - **BREAKING:** Replace the `getChainIdFromNetworkStore` method with the private method `#getCorrectChainIdAndNetworkClientId`. - **BREAKING:** `#trackMetaMetricsEvents` is a private method instead of protected. - Passes string literals instead of extension shared constants into `_trackMetaMetricsEvent`. ### `TokensController` - **BREAKING:** Newly allows `NetworkController:getNetworkClientById` messenger action. - **BREAKING:** Newly subscribes to `NetworkController:networkDidChange`, `PreferencesController:stateChange`, `TokenListController:stateChange` events. - **BREAKING:** Unsubscribes from `NetworkController:stateChange` event. ## **Screenshots/Recordings** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [x] I’ve properly set the pull request status: - [x] In case it's not yet "ready for review", I've set it to "draft". - [x] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .eslintrc.js | 4 +- .mocharc.js | 1 - ...nts-controller-npm-10.0.0-247993ca9a.patch | 88 -- ...ts-controllers-npm-24.0.0-dfef136464.patch | 13 - ...ing-controller-npm-12.2.0-2b196324d1.patch | 12 - app/scripts/controllers/detect-tokens.js | 322 ------- app/scripts/controllers/detect-tokens.test.js | 901 ------------------ app/scripts/controllers/preferences.js | 11 + app/scripts/lib/setupSentry.js | 3 + .../metamask-controller.actions.test.js | 9 +- app/scripts/metamask-controller.js | 85 +- app/scripts/metamask-controller.test.js | 2 +- .../files-to-convert.json | 2 - jest.config.js | 2 - lavamoat/browserify/beta/policy.json | 143 +-- lavamoat/browserify/desktop/policy.json | 143 +-- lavamoat/browserify/flask/policy.json | 143 +-- lavamoat/browserify/main/policy.json | 143 +-- lavamoat/browserify/mmi/policy.json | 143 +-- package.json | 9 +- test/e2e/tests/metrics/swaps.spec.js | 2 +- .../account-details/account-details.test.js | 2 +- .../account-list-item/account-list-item.js | 2 +- .../account-list-item.test.js | 2 +- .../address-copy-button.js | 2 +- .../address-copy-button.test.js | 2 +- .../multichain/app-header/app-header.js | 2 +- .../import-token-link.test.js | 10 +- .../import-token-link/import-token-link.tsx | 4 +- .../menu-items/view-explorer-menu-item.js | 2 +- .../notification-detail-address.tsx | 2 +- ...otification-detail-copy-button.stories.tsx | 2 +- .../receive-modal/receive-modal.test.js | 2 +- ui/store/actions.ts | 8 +- yarn.lock | 224 ++--- 35 files changed, 398 insertions(+), 2049 deletions(-) delete mode 100644 .yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch delete mode 100644 .yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch delete mode 100644 .yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch delete mode 100644 app/scripts/controllers/detect-tokens.js delete mode 100644 app/scripts/controllers/detect-tokens.test.js diff --git a/.eslintrc.js b/.eslintrc.js index 4686585b81a9..4ca1d7064610 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -263,8 +263,7 @@ module.exports = { ], excludedFiles: [ 'app/scripts/controllers/app-state.test.js', - 'app/scripts/controllers/mmi-controller.test.ts', - 'app/scripts/controllers/detect-tokens.test.js', + 'app/scripts/controllers/mmi-controller.test.js', 'app/scripts/controllers/permissions/**/*.test.js', 'app/scripts/controllers/preferences.test.js', 'app/scripts/lib/**/*.test.js', @@ -299,7 +298,6 @@ module.exports = { 'app/scripts/controllers/permissions/**/*.test.js', 'app/scripts/controllers/preferences.test.js', 'app/scripts/lib/**/*.test.js', - 'app/scripts/controllers/detect-tokens.test.js', 'app/scripts/metamask-controller.test.js', 'app/scripts/migrations/*.test.js', 'app/scripts/platforms/*.test.js', diff --git a/.mocharc.js b/.mocharc.js index 8650b802eceb..5febd260a6cd 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -5,7 +5,6 @@ module.exports = { './app/scripts/lib/**/*.test.js', './app/scripts/migrations/*.test.js', './app/scripts/platforms/*.test.js', - './app/scripts/controllers/detect-tokens.test.js', './app/scripts/controllers/app-state.test.js', './app/scripts/controllers/permissions/**/*.test.js', './app/scripts/controllers/mmi-controller.test.ts', diff --git a/.yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch b/.yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch deleted file mode 100644 index 4d04b1c74db2..000000000000 --- a/.yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch +++ /dev/null @@ -1,88 +0,0 @@ -diff --git a/dist/utils.js b/dist/utils.js -index 810f229841ffff83f7a28191bc558862b1809e01..aa2ea845d4cccfac8e28f575d7972bd2dba8decf 100644 ---- a/dist/utils.js -+++ b/dist/utils.js -@@ -11,35 +11,40 @@ const uuid_1 = require("uuid"); - * @returns The name of the keyring type. - */ - function keyringTypeToName(keyringType) { -- switch (keyringType) { -- case keyring_controller_1.KeyringTypes.simple: { -- return 'Account'; -- } -- case keyring_controller_1.KeyringTypes.hd: { -- return 'Account'; -- } -- case keyring_controller_1.KeyringTypes.trezor: { -- return 'Trezor'; -- } -- case keyring_controller_1.KeyringTypes.ledger: { -- return 'Ledger'; -- } -- case keyring_controller_1.KeyringTypes.lattice: { -- return 'Lattice'; -- } -- case keyring_controller_1.KeyringTypes.qr: { -- return 'QR'; -- } -- case keyring_controller_1.KeyringTypes.snap: { -- return 'Snap Account'; -- } -- case keyring_controller_1.KeyringTypes.custody: { -- return 'Custody'; -- } -- default: { -- throw new Error(`Unknown keyring ${keyringType}`); -- } -+ // Custody Keyrings follow this pattern -+ if (/^Custody.*/.test(keyringType)) { -+ return "Custody"; -+ } -+ -+ switch (keyringType) { -+ case keyring_controller_1.KeyringTypes.simple: { -+ return "Account"; - } -+ case keyring_controller_1.KeyringTypes.hd: { -+ return "Account"; -+ } -+ case keyring_controller_1.KeyringTypes.trezor: { -+ return "Trezor"; -+ } -+ case keyring_controller_1.KeyringTypes.ledger: { -+ return "Ledger"; -+ } -+ case keyring_controller_1.KeyringTypes.lattice: { -+ return "Lattice"; -+ } -+ case keyring_controller_1.KeyringTypes.qr: { -+ return "QR"; -+ } -+ case keyring_controller_1.KeyringTypes.snap: { -+ return "Snap Account"; -+ } -+ case keyring_controller_1.KeyringTypes.custody: { -+ return "Custody"; -+ } -+ default: { -+ throw new Error(`Unknown keyring ${keyringType}`); -+ } -+ } - } - exports.keyringTypeToName = keyringTypeToName; - /** -@@ -48,10 +53,10 @@ exports.keyringTypeToName = keyringTypeToName; - * @returns The generated UUID. - */ - function getUUIDFromAddressOfNormalAccount(address) { -- const v4options = { -- random: (0, ethereumjs_util_1.sha256FromString)(address).slice(0, 16), -- }; -- return (0, uuid_1.v4)(v4options); -+ const v4options = { -+ random: (0, ethereumjs_util_1.sha256FromString)(address).slice(0, 16), -+ }; -+ return (0, uuid_1.v4)(v4options); - } - exports.getUUIDFromAddressOfNormalAccount = getUUIDFromAddressOfNormalAccount; - //# sourceMappingURL=utils.js.map diff --git a/.yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch b/.yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch deleted file mode 100644 index ba44b083d53b..000000000000 --- a/.yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/dist/NftDetectionController.js b/dist/NftDetectionController.js -index aad63ecf91b2037a40dfb435e0363ab588d22fa3..24373e328d3600d1168914a3dc0bbbd905b19ebe 100644 ---- a/dist/NftDetectionController.js -+++ b/dist/NftDetectionController.js -@@ -65,8 +65,6 @@ class NftDetectionController extends polling_controller_1.StaticIntervalPollingC - if (selectedAddress !== previouslySelectedAddress || - !useNftDetection !== disabled) { - this.configure({ selectedAddress, disabled: !useNftDetection }); -- } -- if (useNftDetection !== undefined) { - if (useNftDetection) { - this.start(); - } diff --git a/.yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch b/.yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch deleted file mode 100644 index 6cd55829682d..000000000000 --- a/.yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/dist/KeyringController.js b/dist/KeyringController.js -index da3fb9c0bf437e07f1927bca0bbfc94ed8454c2d..a3211dc83edb5d18daf328adc5a63fee920dd321 100644 ---- a/dist/KeyringController.js -+++ b/dist/KeyringController.js -@@ -713,7 +713,6 @@ class KeyringController extends base_controller_1.BaseController { - throw new Error('Seed phrase imported different accounts.'); - } - }); -- return seedWords; - }); - } - // QR Hardware related methods diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js deleted file mode 100644 index 57f36a3b634b..000000000000 --- a/app/scripts/controllers/detect-tokens.js +++ /dev/null @@ -1,322 +0,0 @@ -import { warn } from 'loglevel'; -import { StaticIntervalPollingControllerOnly } from '@metamask/polling-controller'; -import { MINUTE } from '../../../shared/constants/time'; -import { CHAIN_IDS } from '../../../shared/constants/network'; -import { STATIC_MAINNET_TOKEN_LIST } from '../../../shared/constants/tokens'; -import { isTokenDetectionEnabledForNetwork } from '../../../shared/modules/network.utils'; -import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; -import { - AssetType, - TokenStandard, -} from '../../../shared/constants/transaction'; -import { - MetaMetricsEventCategory, - MetaMetricsEventName, -} from '../../../shared/constants/metametrics'; - -// By default, poll every 3 minutes -const DEFAULT_INTERVAL = MINUTE * 3; - -/** - * A controller that polls for token exchange - * rates based on a user's current token list - */ -export default class DetectTokensController extends StaticIntervalPollingControllerOnly { - /** - * Creates a DetectTokensController - * - * @param {object} [config] - Options to configure controller - * @param config.interval - * @param config.preferences - * @param config.network - * @param config.tokenList - * @param config.tokensController - * @param config.assetsContractController - * @param config.trackMetaMetricsEvent - * @param config.messenger - * @param config.getCurrentSelectedAccount - * @param config.getNetworkClientById - * @param config.disableLegacyInterval - */ - constructor({ - messenger, - interval = DEFAULT_INTERVAL, - preferences, - network, - tokenList, - tokensController, - assetsContractController = null, - trackMetaMetricsEvent, - getCurrentSelectedAccount, - getNetworkClientById, - disableLegacyInterval = false, - } = {}) { - super(); - this.getNetworkClientById = getNetworkClientById; - this.messenger = messenger; - this.assetsContractController = assetsContractController; - this.tokensController = tokensController; - this.preferences = preferences; - if (!disableLegacyInterval) { - this.interval = interval; - } - this.network = network; - this.tokenList = tokenList; - this.useTokenDetection = - this.preferences?.store.getState().useTokenDetection; - this.selectedAddress = getCurrentSelectedAccount().address; - this.setIntervalLength(interval); - this.chainId = this.getChainIdFromNetworkStore(); - this._trackMetaMetricsEvent = trackMetaMetricsEvent; - - messenger.subscribe( - 'AccountsController:selectedAccountChange', - (account) => { - const useTokenDetection = - this.preferences?.store.getState().useTokenDetection; - if ( - this.selectedAddress !== account.address || - this.useTokenDetection !== useTokenDetection - ) { - this.selectedAddress = account.address; - this.useTokenDetection = useTokenDetection; - this.restartTokenDetection({ - selectedAddress: this.selectedAddress, - }); - } - }, - ); - - preferences?.store.subscribe(({ useTokenDetection }) => { - if (this.useTokenDetection !== useTokenDetection) { - this.useTokenDetection = useTokenDetection; - this.restartTokenDetection({ - selectedAddress: this.selectedAddress, - }); - } - }); - - messenger.subscribe('NetworkController:stateChange', () => { - if (this.chainId !== this.getChainIdFromNetworkStore()) { - const chainId = this.getChainIdFromNetworkStore(); - this.chainId = chainId; - this.restartTokenDetection({ chainId: this.chainId }); - } - }); - - messenger.subscribe('TokenListController:stateChange', () => { - this.restartTokenDetection(); - }); - - this.#registerKeyringHandlers(); - } - - async _executePoll(networkClientId, options) { - await this.detectNewTokens({ - ...options, - networkClientId, - }); - } - - /** - * For each token in the tokenlist provided by the TokenListController, check selectedAddress balance. - * - * @param options - * @param options.selectedAddress - the selectedAddress against which to detect for token balances - * @param options.chainId - the chainId against which to detect for token balances - * @param options.networkClientId - */ - async detectNewTokens({ selectedAddress, chainId, networkClientId } = {}) { - const addressAgainstWhichToDetect = selectedAddress ?? this.selectedAddress; - let chainIdAgainstWhichToDetect; - let networkClientIdAgainstWhichToDetect; - - if (networkClientId) { - networkClientIdAgainstWhichToDetect = networkClientId; - const networkClient = this.getNetworkClientById(networkClientId); - chainIdAgainstWhichToDetect = networkClient.configuration.chainId; - } else { - chainIdAgainstWhichToDetect = - chainId ?? this.getChainIdFromNetworkStore(); - networkClientIdAgainstWhichToDetect = - this.network.findNetworkClientIdByChainId(chainIdAgainstWhichToDetect); - } - - if (!this.isActive) { - return; - } - if (!isTokenDetectionEnabledForNetwork(chainIdAgainstWhichToDetect)) { - return; - } - if ( - !this.useTokenDetection && - chainIdAgainstWhichToDetect !== CHAIN_IDS.MAINNET - ) { - return; - } - - const isTokenDetectionInactiveInMainnet = - !this.useTokenDetection && - chainIdAgainstWhichToDetect === CHAIN_IDS.MAINNET; - const { tokenList } = this._tokenList.state; - - const tokenListUsed = isTokenDetectionInactiveInMainnet - ? STATIC_MAINNET_TOKEN_LIST - : tokenList; - - const tokensToDetect = []; - for (const tokenAddress in tokenListUsed) { - if ( - !this.tokensController.state.allTokens?.[chainIdAgainstWhichToDetect]?.[ - addressAgainstWhichToDetect - ]?.find(({ address }) => - isEqualCaseInsensitive(address, tokenAddress), - ) && - !this.tokensController.state.allIgnoredTokens?.[ - chainIdAgainstWhichToDetect - ]?.[addressAgainstWhichToDetect]?.find((address) => - isEqualCaseInsensitive(address, tokenAddress), - ) && - !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), - ]; - for (const tokensSlice of sliceOfTokensToDetect) { - let result; - try { - result = await this.assetsContractController.getBalancesInSingleCall( - addressAgainstWhichToDetect, - tokensSlice, - networkClientIdAgainstWhichToDetect, - ); - } catch (error) { - warn( - `MetaMask - DetectTokensController single call balance fetch failed`, - error, - ); - return; - } - - const tokensWithBalance = []; - const eventTokensDetails = []; - if (result) { - const nonZeroTokenAddresses = Object.keys(result); - for (const nonZeroTokenAddress of nonZeroTokenAddresses) { - const { address, symbol, decimals } = - tokenListUsed[nonZeroTokenAddress]; - - eventTokensDetails.push(`${symbol} - ${address}`); - - tokensWithBalance.push({ - address, - symbol, - decimals, - }); - } - - if (tokensWithBalance.length > 0) { - this._trackMetaMetricsEvent({ - event: MetaMetricsEventName.TokenDetected, - category: MetaMetricsEventCategory.Wallet, - properties: { - tokens: eventTokensDetails, - token_standard: TokenStandard.ERC20, - asset_type: AssetType.token, - }, - }); - await this.tokensController.addDetectedTokens(tokensWithBalance, { - selectedAddress: addressAgainstWhichToDetect, - chainId: chainIdAgainstWhichToDetect, - }); - } - } - } - } - - /** - * Restart token detection polling period and call detectNewTokens - * in case of address change or user session initialization. - * - * @param options - * @param options.selectedAddress - the selectedAddress against which to detect for token balances - * @param options.chainId - the chainId against which to detect for token balances - */ - restartTokenDetection({ selectedAddress, chainId } = {}) { - const addressAgainstWhichToDetect = selectedAddress ?? this.selectedAddress; - const chainIdAgainstWhichToDetect = - chainId ?? this.getChainIdFromNetworkStore(); - if (!(this.isActive && addressAgainstWhichToDetect)) { - return; - } - this.detectNewTokens({ - selectedAddress: addressAgainstWhichToDetect, - chainId: chainIdAgainstWhichToDetect, - }); - this.interval = DEFAULT_INTERVAL; - } - - getChainIdFromNetworkStore() { - return this.network?.state.providerConfig.chainId; - } - - /* eslint-disable accessor-pairs */ - /** - * @type {number} - */ - set interval(interval) { - this._handle && clearInterval(this._handle); - if (!interval) { - return; - } - this._handle = setInterval(() => { - this.detectNewTokens(); - }, interval); - } - - /** - * @type {object} - */ - set tokenList(tokenList) { - if (!tokenList) { - return; - } - this._tokenList = tokenList; - } - - /** - * Internal isActive state - * - * @type {object} - */ - get isActive() { - return this.isOpen && this.isUnlocked; - } - /* eslint-enable accessor-pairs */ - - /** - * Constructor helper to register listeners on the keyring - * locked state changes - */ - #registerKeyringHandlers() { - const { isUnlocked } = this.messenger.call('KeyringController:getState'); - this.isUnlocked = isUnlocked; - - this.messenger.subscribe('KeyringController:unlock', () => { - this.isUnlocked = true; - this.restartTokenDetection(); - }); - - this.messenger.subscribe('KeyringController:lock', () => { - this.isUnlocked = false; - }); - } -} diff --git a/app/scripts/controllers/detect-tokens.test.js b/app/scripts/controllers/detect-tokens.test.js deleted file mode 100644 index 87ad6ccabb1f..000000000000 --- a/app/scripts/controllers/detect-tokens.test.js +++ /dev/null @@ -1,901 +0,0 @@ -/** - * @jest-environment node - */ -import { strict as assert } from 'assert'; -import sinon from 'sinon'; -import nock from 'nock'; -import BigNumber from 'bignumber.js'; -import { ControllerMessenger } from '@metamask/base-controller'; -import { - TokenListController, - TokensController, - AssetsContractController, -} from '@metamask/assets-controllers'; -import { toHex } from '@metamask/controller-utils'; -import { EthMethod, EthAccountType } from '@metamask/keyring-api'; -import { NetworkController } from '@metamask/network-controller'; -import { AccountsController } from '@metamask/accounts-controller'; -import { NETWORK_TYPES } from '../../../shared/constants/network'; -import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils'; -import DetectTokensController from './detect-tokens'; -import PreferencesController from './preferences'; - -const flushPromises = () => { - return new Promise(jest.requireActual('timers').setImmediate); -}; - -describe('DetectTokensController', function () { - let sandbox, - interval, - assetsContractController, - network, - preferences, - provider, - tokensController, - tokenListController, - accountsController, - preferencesControllerMessenger, - getCurrentSelectedAccount, - getNetworkClientById, - messenger; - - const noop = () => undefined; - - const getRestrictedMessenger = () => { - return messenger.getRestricted({ - name: 'DetectTokensController', - allowedActions: ['KeyringController:getState'], - allowedEvents: [ - 'NetworkController:stateChange', - 'KeyringController:lock', - 'KeyringController:unlock', - 'AccountsController:selectedAccountChange', - 'TokenListController:stateChange', - ], - }); - }; - - const networkControllerProviderConfig = { - getAccounts: noop, - }; - - const infuraProjectId = 'infura-project-id'; - - beforeEach(async function () { - sandbox = sinon.createSandbox(); - // Disable all requests, even those to localhost - nock.disableNetConnect(); - nock('https://mainnet.infura.io') - .post(`/v3/${infuraProjectId}`) - .reply(200, (_uri, requestBody) => { - if (requestBody.method === 'eth_getBlockByNumber') { - return { - id: requestBody.id, - jsonrpc: '2.0', - result: { - number: '0x42', - }, - }; - } - - if (requestBody.method === 'eth_blockNumber') { - return { - id: requestBody.id, - jsonrpc: '2.0', - result: '0x42', - }; - } - - throw new Error(`(Infura) Mock not defined for ${requestBody.method}`); - }) - .persist(); - nock('https://sepolia.infura.io') - .post(`/v3/${infuraProjectId}`) - .reply(200, (_uri, requestBody) => { - if (requestBody.method === 'eth_getBlockByNumber') { - return { - id: requestBody.id, - jsonrpc: '2.0', - result: { - number: '0x42', - }, - }; - } - - if (requestBody.method === 'eth_blockNumber') { - return { - id: requestBody.id, - jsonrpc: '2.0', - result: '0x42', - }; - } - - throw new Error(`(Infura) Mock not defined for ${requestBody.method}`); - }) - .persist(); - nock('http://localhost:8545') - .post('/') - .reply(200, (_uri, requestBody) => { - if (requestBody.method === 'eth_getBlockByNumber') { - return { - id: requestBody.id, - jsonrpc: '2.0', - result: { - number: '0x42', - }, - }; - } - - if (requestBody.method === 'eth_blockNumber') { - return { - id: requestBody.id, - jsonrpc: '2.0', - result: '0x42', - }; - } - - if (requestBody.method === 'net_version') { - return { - id: requestBody.id, - jsonrpc: '2.0', - result: '1337', - }; - } - - throw new Error( - `(localhost) Mock not defined for ${requestBody.method}`, - ); - }) - .persist(); - nock('https://token-api.metaswap.codefi.network') - .get( - `/tokens/1?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`, - ) - .reply(200, [ - { - address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', - symbol: 'SNX', - decimals: 18, - occurrences: 11, - aggregators: [ - 'paraswap', - 'pmm', - 'airswapLight', - 'zeroEx', - 'bancor', - 'coinGecko', - 'zapper', - 'kleros', - 'zerion', - 'cmc', - 'oneInch', - ], - name: 'Synthetix', - iconUrl: 'https://airswap-token-images.s3.amazonaws.com/SNX.png', - }, - { - address: '0x514910771af9ca656af840dff83e8264ecf986ca', - symbol: 'LINK', - decimals: 18, - occurrences: 11, - aggregators: [ - 'paraswap', - 'pmm', - 'airswapLight', - 'zeroEx', - 'bancor', - 'coinGecko', - 'zapper', - 'kleros', - 'zerion', - 'cmc', - 'oneInch', - ], - name: 'Chainlink', - iconUrl: 'https://s3.amazonaws.com/airswap-token-images/LINK.png', - }, - { - address: '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c', - symbol: 'BNT', - decimals: 18, - occurrences: 11, - aggregators: [ - 'paraswap', - 'pmm', - 'airswapLight', - 'zeroEx', - 'bancor', - 'coinGecko', - 'zapper', - 'kleros', - 'zerion', - 'cmc', - 'oneInch', - ], - name: 'Bancor', - iconUrl: 'https://s3.amazonaws.com/airswap-token-images/BNT.png', - }, - ]) - .get(`/tokens/3`) - .reply(200, { error: 'ChainId 3 is not supported' }) - .persist(); - - jest.spyOn(ControllerMessenger.prototype, 'subscribe'); - - messenger = new ControllerMessenger(); - messenger.registerActionHandler('KeyringController:getState', () => ({ - isUnlocked: true, - })); - - const networkControllerMessenger = new ControllerMessenger(); - network = new NetworkController({ - messenger: networkControllerMessenger, - infuraProjectId, - }); - await network.initializeProvider(networkControllerProviderConfig); - provider = network.getProviderAndBlockTracker().provider; - - const tokenListMessenger = new ControllerMessenger().getRestricted({ - name: 'TokenListController', - }); - tokenListController = new TokenListController({ - chainId: toHex(1), - preventPollingOnNetworkRestart: false, - onNetworkStateChange: sinon.spy(), - onPreferencesStateChange: sinon.spy(), - messenger: tokenListMessenger, - }); - await tokenListController.start(); - - preferencesControllerMessenger = new ControllerMessenger().getRestricted({ - name: 'PreferencesController', - allowedEvents: ['AccountsController:selectedAccountChange'], - }); - - preferences = new PreferencesController({ - network, - provider, - tokenListController, - networkConfigurations: {}, - onAccountRemoved: sinon.stub(), - controllerMessenger: preferencesControllerMessenger, - onKeyringStateChange: sinon.stub(), - }); - preferences.setUseTokenDetection(true); - - const accountsControllerMessenger = new ControllerMessenger().getRestricted( - { - name: 'AccountsController', - allowedEvents: [ - 'SnapController:stateChange', - 'KeyringController:accountRemoved', - 'KeyringController:stateChange', - 'AccountsController:selectedAccountChange', - ], - }, - ); - - accountsController = new AccountsController({ - messenger: accountsControllerMessenger, - state: { - internalAccounts: { - accounts: { - 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3': { - address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', - id: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', - metadata: { - name: 'Account 1', - keyring: { - type: 'HD Key Tree', - }, - }, - options: {}, - methods: [...Object.values(EthMethod)], - type: EthAccountType.Eoa, - }, - '07c2cfec-36c9-46c4-8115-3836d3ac9047': { - address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', - id: '07c2cfec-36c9-46c4-8115-3836d3ac9047', - metadata: { - name: 'Account 2', - keyring: { - type: 'HD Key Tree', - }, - }, - options: {}, - methods: [...Object.values(EthMethod)], - type: EthAccountType.Eoa, - }, - }, - selectedAccount: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', - }, - }, - onSnapStateChange: sinon.spy(), - onKeyringStateChange: sinon.spy(), - }); - - tokensController = new TokensController({ - config: { - provider, - selectedAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', - }, - onPreferencesStateChange: (listener) => - accountsControllerMessenger.subscribe( - `AccountsController:selectedAccountChange`, - (newlySelectedInternalAccount) => { - listener({ selectedAddress: newlySelectedInternalAccount.address }); - }, - ), - onNetworkDidChange: networkControllerMessenger.subscribe.bind( - networkControllerMessenger, - 'NetworkController:stateChange', - ), - onTokenListStateChange: (listener) => - tokenListMessenger.subscribe( - `${tokenListController.name}:stateChange`, - listener, - ), - }); - - assetsContractController = new AssetsContractController({ - onPreferencesStateChange: preferences.store.subscribe.bind( - preferences.store, - ), - onNetworkDidChange: networkControllerMessenger.subscribe.bind( - networkControllerMessenger, - 'NetworkController:stateChange', - ), - }); - - getCurrentSelectedAccount = jest.fn().mockReturnValue({ - address: '0xbc86727e770de68b1060c91f6bb6945c73e10388', - }); - - getNetworkClientById = jest.fn(); - }); - - afterEach(function () { - nock.enableNetConnect('localhost'); - sandbox.restore(); - }); - - it('should poll on correct interval', async function () { - const stub = sinon.stub(global, 'setInterval'); - // eslint-disable-next-line no-new - new DetectTokensController({ - messenger: getRestrictedMessenger(), - interval: 1337, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - assert.strictEqual(stub.getCall(0).args[1], 1337); - stub.restore(); - }); - - it('should be called on every polling period', async function () { - const clock = sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.MAINNET); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - controller.isUnlocked = true; - - const stub = sandbox.stub(controller, 'detectNewTokens'); - - clock.tick(1); - sandbox.assert.notCalled(stub); - clock.tick(180000); - sandbox.assert.called(stub); - clock.tick(180000); - sandbox.assert.calledTwice(stub); - clock.tick(180000); - sandbox.assert.calledThrice(stub); - }); - - it('should not check and add tokens while on unsupported networks', async function () { - sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.SEPOLIA); - const tokenListMessengerSepolia = new ControllerMessenger().getRestricted({ - name: 'TokenListController', - }); - tokenListController = new TokenListController({ - chainId: toHex(11155111), - onNetworkStateChange: sinon.spy(), - onPreferencesStateChange: sinon.spy(), - messenger: tokenListMessengerSepolia, - }); - await tokenListController.start(); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - controller.isUnlocked = true; - - const stub = sandbox.stub( - assetsContractController, - 'getBalancesInSingleCall', - ); - - await controller.detectNewTokens(); - sandbox.assert.notCalled(stub); - }); - - it('should skip adding tokens listed in ignoredTokens array', async function () { - sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.MAINNET); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - trackMetaMetricsEvent: noop, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - controller.isUnlocked = true; - const { tokenList } = tokenListController.state; - const tokenValues = Object.values(tokenList); - - await tokensController.addDetectedTokens([ - { - address: tokenValues[0].address, - symbol: tokenValues[0].symbol, - decimals: tokenValues[0].decimals, - aggregators: undefined, - image: undefined, - isERC721: undefined, - name: undefined, - }, - ]); - - sandbox - .stub(assetsContractController, 'getBalancesInSingleCall') - .callsFake((tokensToDetect) => - tokensToDetect.map((token) => - token.address === tokenValues[1].address ? new BigNumber(10) : 0, - ), - ); - await tokensController.ignoreTokens([tokenValues[1].address]); - - await controller.detectNewTokens(); - assert.deepEqual(tokensController.state.detectedTokens, [ - { - address: toChecksumHexAddress(tokenValues[0].address), - decimals: tokenValues[0].decimals, - symbol: tokenValues[0].symbol, - aggregators: undefined, - image: undefined, - isERC721: undefined, - name: undefined, - }, - ]); - }); - - it('gets balances in single call using the networkClientId when provided', async function () { - sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.MAINNET); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - trackMetaMetricsEvent: noop, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - getNetworkClientById: () => ({ - configuration: { - chainId: '0x1', - }, - provider: {}, - blockTracker: {}, - destroy: () => { - // noop - }, - }), - }); - controller.isOpen = true; - controller.isUnlocked = true; - - const stub = sandbox.stub( - assetsContractController, - 'getBalancesInSingleCall', - ); - - await controller.detectNewTokens({ - networkClientId: 'mainnet', - }); - - sandbox.assert.calledWith( - stub, - '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', - [ - '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', - '0x514910771af9ca656af840dff83e8264ecf986ca', - '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c', - ], - 'mainnet', - ); - sandbox.assert.calledWith( - stub, - '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', - [], - 'mainnet', - ); - }); - - it('uses the resolved chainId from networkClientId over the passed in chainId arg', async function () { - sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.MAINNET); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - trackMetaMetricsEvent: noop, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - getNetworkClientById: () => ({ - configuration: { - chainId: '0x1', - }, - provider: {}, - blockTracker: {}, - destroy: () => { - // noop - }, - }), - }); - controller.isOpen = true; - controller.isUnlocked = true; - - const stub = sandbox.stub( - assetsContractController, - 'getBalancesInSingleCall', - ); - - await controller.detectNewTokens({ - // non supported chainId will cause this method to exit early if used instead of the networkClientId - chainId: '0xdeadbeef', - networkClientId: 'mainnet', - }); - - sandbox.assert.called(stub); - }); - - it('should check and add tokens while on supported networks', async function () { - sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.MAINNET); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - trackMetaMetricsEvent: noop, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - controller.isUnlocked = true; - - const { tokenList } = tokenListController.state; - const erc20ContractAddresses = Object.keys(tokenList); - - const existingTokenAddress = erc20ContractAddresses[0]; - const existingToken = tokenList[existingTokenAddress]; - - accountsController.setSelectedAccount( - 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', - ); - - await tokensController.addDetectedTokens( - [ - { - address: existingToken.address, - symbol: existingToken.symbol, - decimals: existingToken.decimals, - aggregators: undefined, - image: undefined, - isERC721: undefined, - }, - ], - { - address: existingToken.address, - symbol: existingToken.symbol, - decimals: existingToken.decimals, - aggregators: undefined, - image: undefined, - isERC721: undefined, - name: undefined, - }, - ); - const tokenAddressToAdd = erc20ContractAddresses[1]; - const tokenToAdd = tokenList[tokenAddressToAdd]; - sandbox - .stub(assetsContractController, 'getBalancesInSingleCall') - .callsFake(() => - Promise.resolve({ [tokenAddressToAdd]: new BigNumber(10) }), - ); - await controller.detectNewTokens(); - assert.deepEqual(tokensController.state.detectedTokens, [ - { - address: toChecksumHexAddress(existingTokenAddress), - decimals: existingToken.decimals, - symbol: existingToken.symbol, - aggregators: undefined, - image: undefined, - isERC721: undefined, - name: undefined, - }, - { - address: toChecksumHexAddress(tokenAddressToAdd), - decimals: tokenToAdd.decimals, - symbol: tokenToAdd.symbol, - aggregators: undefined, - image: undefined, - isERC721: undefined, - name: undefined, - }, - ]); - }); - - it('should trigger detect new tokens when change address', async function () { - sandbox.useFakeTimers(); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - controller.isUnlocked = true; - const stub = sandbox.stub(controller, 'detectNewTokens'); - messenger.publish('AccountsController:selectedAccountChange', { - id: 'mock-2', - address: '0x999', - }); - - sandbox.assert.called(stub); - }); - - it('should trigger detect new tokens when submit password', async function () { - sandbox.useFakeTimers(); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - controller.selectedAddress = '0x0'; - const stub = sandbox.stub(controller, 'detectNewTokens'); - - messenger.publish('KeyringController:unlock'); - - sandbox.assert.called(stub); - assert.equal(controller.isUnlocked, true); - }); - - it('should not be active after lock event is emitted', async function () { - sandbox.useFakeTimers(); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - - messenger.publish('KeyringController:lock'); - - assert.equal(controller.isUnlocked, false); - assert.equal(controller.isActive, false); - }); - - it('should not trigger detect new tokens when not unlocked', async function () { - const clock = sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.MAINNET); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokenList: tokenListController, - tokensController, - assetsContractController, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - controller.isOpen = true; - controller.isUnlocked = false; - const stub = sandbox.stub( - assetsContractController, - 'getBalancesInSingleCall', - ); - clock.tick(180000); - sandbox.assert.notCalled(stub); - }); - - it('should not trigger detect new tokens when not open', async function () { - const clock = sandbox.useFakeTimers(); - await network.setProviderType(NETWORK_TYPES.MAINNET); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokensController, - assetsContractController, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - }); - // trigger state update from preferences controller - accountsController.setSelectedAccount( - '07c2cfec-36c9-46c4-8115-3836d3ac9047', - ); - controller.isOpen = false; - controller.isUnlocked = true; - const stub = sandbox.stub( - assetsContractController, - 'getBalancesInSingleCall', - ); - clock.tick(180000); - sandbox.assert.notCalled(stub); - }); - - it('should poll on the correct interval by networkClientId', async function () { - jest.useFakeTimers(); - const controller = new DetectTokensController({ - messenger: getRestrictedMessenger(), - preferences, - network, - tokensController, - assetsContractController, - disableLegacyInterval: true, - interval: 1000, - getCurrentSelectedAccount: - accountsController.getSelectedAccount.bind(accountsController), - getNetworkClientById: () => ({ - configuration: { - chainId: '0x1', - }, - provider: {}, - blockTracker: {}, - destroy: () => { - // noop - }, - }), - }); - const detectNewTokensSpy = jest - .spyOn(controller, 'detectNewTokens') - .mockResolvedValue('foo'); - controller.startPollingByNetworkClientId('mainnet'); - await Promise.all([jest.advanceTimersByTime(0), flushPromises()]); - expect(detectNewTokensSpy).toHaveBeenCalledTimes(1); - await Promise.all([jest.advanceTimersByTime(1000), flushPromises()]); - expect(detectNewTokensSpy).toHaveBeenCalledTimes(2); - expect(detectNewTokensSpy.mock.calls).toStrictEqual([ - [{ networkClientId: 'mainnet' }], - [{ networkClientId: 'mainnet' }], - ]); - - detectNewTokensSpy.mockRestore(); - jest.useRealTimers(); - }); - - it('should restart token detection on selected account change', async () => { - const controller = new DetectTokensController({ - messenger, - interval, - preferences, - network, - tokensController, - assetsContractController, - getCurrentSelectedAccount, - getNetworkClientById, - }); - - jest.spyOn(controller, 'restartTokenDetection'); - - await ControllerMessenger.prototype.subscribe.mock.calls - .filter((args) => args[0] === 'AccountsController:selectedAccountChange') - .slice(-1)[0][1]({ - address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', - }); - - expect(controller.selectedAddress).toBe( - '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', - ); - expect(controller.restartTokenDetection).toHaveBeenCalledWith({ - selectedAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', - }); - }); - - it('should restart token detection on useTokenDetection change', async () => { - const controller = new DetectTokensController({ - messenger, - interval, - preferences, - network, - tokensController, - assetsContractController, - getCurrentSelectedAccount, - getNetworkClientById, - }); - - jest.spyOn(controller, 'restartTokenDetection'); - - preferences.setUseTokenDetection(false); - - expect(controller.useTokenDetection).toBe(false); - expect(controller.restartTokenDetection).toHaveBeenCalledWith({ - selectedAddress: '0xbc86727e770de68b1060c91f6bb6945c73e10388', - }); - }); - - it('should restart token detection on network state change', async () => { - const controller = new DetectTokensController({ - messenger, - interval, - preferences, - network, - tokensController, - assetsContractController, - getCurrentSelectedAccount, - getNetworkClientById, - }); - - jest.spyOn(controller, 'restartTokenDetection'); - - await ControllerMessenger.prototype.subscribe.mock.calls - .filter((args) => args[0] === 'NetworkController:stateChange') - .slice(-1)[0][1](); - - expect(controller.chainId).toBe(controller.getChainIdFromNetworkStore()); - expect(controller.restartTokenDetection).toHaveBeenCalledTimes(0); - - controller.chainId = '0xaa36a7'; - - await ControllerMessenger.prototype.subscribe.mock.calls - .filter((args) => args[0] === 'NetworkController:stateChange') - .slice(-1)[0][1](); - - expect(controller.chainId).toBe(controller.getChainIdFromNetworkStore()); - expect(controller.restartTokenDetection).toHaveBeenCalledWith({ - chainId: '0x1', - }); - }); -}); diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 7270635b24fa..0d8f8268abb5 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -24,6 +24,7 @@ export default class PreferencesController { * * @typedef {object} PreferencesController * @param {object} opts - Overrides the defaults for the initial state of this.store + * @property {object} messenger - The controller messenger * @property {object} store The stored object containing a users preferences, stored in local storage * @property {boolean} store.useBlockie The users preference for blockie identicons within the UI * @property {boolean} store.useNonceField The users preference for nonce field within the UI @@ -131,6 +132,16 @@ export default class PreferencesController { } }); + this.messagingSystem = opts.messenger; + this.messagingSystem?.registerActionHandler( + `PreferencesController:getState`, + () => this.store.getState(), + ); + this.messagingSystem?.registerInitialEventPayload({ + eventType: `PreferencesController:stateChange`, + getPayload: () => [this.store.getState(), []], + }); + global.setPreference = (key, value) => { return this.setFeatureFlag(key, value); }; diff --git a/app/scripts/lib/setupSentry.js b/app/scripts/lib/setupSentry.js index 210f266e8269..784d4471f2d3 100644 --- a/app/scripts/lib/setupSentry.js +++ b/app/scripts/lib/setupSentry.js @@ -305,6 +305,9 @@ export const SENTRY_BACKGROUND_STATE = { tradeTxId: false, }, }, + TokenDetectionController: { + [AllProperties]: false, + }, TokenListController: { preventPollingOnNetworkRestart: true, tokenList: false, diff --git a/app/scripts/metamask-controller.actions.test.js b/app/scripts/metamask-controller.actions.test.js index 268ab1f67ca5..31dcd6d5bf36 100644 --- a/app/scripts/metamask-controller.actions.test.js +++ b/app/scripts/metamask-controller.actions.test.js @@ -253,7 +253,7 @@ describe('MetaMaskController', function () { Promise.resolve({ supportsInterface: supportsInterfaceStub }), ); sinon - .stub(metamaskController.tokensController, 'getNetworkClientById') + .stub(metamaskController.controllerMessenger, 'call') .callsFake(() => ({ configuration: { chainId: '0xa', @@ -266,10 +266,9 @@ describe('MetaMaskController', function () { decimals, networkClientId: 'networkClientId1', }); - assert.strictEqual( - metamaskController.tokensController.getNetworkClientById.getCall(0) - .args[0], - 'networkClientId1', + assert.deepStrictEqual( + metamaskController.controllerMessenger.call.getCall(0).args, + ['NetworkController:getNetworkClientById', 'networkClientId1'], ); }); }); diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a72126d812ea..89905caaeffa 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -5,6 +5,7 @@ import { CurrencyRateController, NftController, NftDetectionController, + TokenDetectionController, TokenListController, TokenRatesController, TokensController, @@ -264,7 +265,6 @@ import AlertController from './controllers/alert'; import OnboardingController from './controllers/onboarding'; import Backup from './lib/backup'; import DecryptMessageController from './controllers/decrypt-message'; -import DetectTokensController from './controllers/detect-tokens'; import SwapsController from './controllers/swaps'; import MetaMetricsController from './controllers/metametrics'; import { segment } from './lib/segment'; @@ -498,9 +498,16 @@ export default class MetamaskController extends EventEmitter { state: initState.TokenListController, }); + const preferencesMessenger = this.controllerMessenger.getRestricted({ + name: 'PreferencesController', + allowedActions: ['PreferencesController:getState'], + allowedEvents: ['PreferencesController:stateChange'], + }); + this.preferencesController = new PreferencesController({ initState: initState.PreferencesController, initLangCode: opts.initLangCode, + messenger: preferencesMessenger, tokenListController: this.tokenListController, provider: this.provider, networkConfigurations: this.networkController.state.networkConfigurations, @@ -536,10 +543,15 @@ export default class MetamaskController extends EventEmitter { const tokensControllerMessenger = this.controllerMessenger.getRestricted({ name: 'TokensController', - allowedActions: ['ApprovalController:addRequest'], + allowedActions: [ + 'ApprovalController:addRequest', + 'NetworkController:getNetworkClientById', + ], allowedEvents: [ - 'NetworkController:stateChange', + 'NetworkController:networkDidChange', 'AccountsController:selectedAccountChange', + 'PreferencesController:stateChange', + 'TokenListController:stateChange', ], }); this.tokensController = new TokensController({ @@ -578,6 +590,11 @@ export default class MetamaskController extends EventEmitter { }, state: initState.TokensController, }); + // TODO: Remove once `TokensController` is upgraded to extend from `BaseControllerV2` + this.controllerMessenger.registerActionHandler( + 'TokensController:getState', + () => this.tokensController.state, + ); const nftControllerMessenger = this.controllerMessenger.getRestricted({ name: 'NftController', @@ -1391,35 +1408,39 @@ export default class MetamaskController extends EventEmitter { }); ///: END:ONLY_INCLUDE_IF - const detectTokensControllerMessenger = + const tokenDetectionControllerMessenger = this.controllerMessenger.getRestricted({ - name: 'DetectTokensController', - allowedActions: ['KeyringController:getState'], + name: 'TokenDetectionController', + allowedActions: [ + 'AccountsController:getSelectedAccount', + 'KeyringController:getState', + 'NetworkController:getNetworkClientById', + 'NetworkController:getNetworkConfigurationByNetworkClientId', + 'NetworkController:getState', + 'PreferencesController:getState', + 'TokenListController:getState', + 'TokensController:getState', + 'TokensController:addDetectedTokens', + ], allowedEvents: [ - 'NetworkController:stateChange', + 'AccountsController:selectedAccountChange', 'KeyringController:lock', 'KeyringController:unlock', - 'AccountsController:selectedAccountChange', + 'NetworkController:networkDidChange', + 'PreferencesController:stateChange', 'TokenListController:stateChange', ], }); - this.detectTokensController = new DetectTokensController({ - messenger: detectTokensControllerMessenger, - preferences: this.preferencesController, - tokensController: this.tokensController, - getCurrentSelectedAccount: - this.accountsController.getSelectedAccount.bind( - this.accountsController, + + this.tokenDetectionController = new TokenDetectionController({ + messenger: tokenDetectionControllerMessenger, + getBalancesInSingleCall: + this.assetsContractController.getBalancesInSingleCall.bind( + this.assetsContractController, ), - assetsContractController: this.assetsContractController, - network: this.networkController, - tokenList: this.tokenListController, trackMetaMetricsEvent: this.metaMetricsController.trackEvent.bind( this.metaMetricsController, ), - getNetworkClientById: this.networkController.getNetworkClientById.bind( - this.networkController, - ), }); this.addressBookController = new AddressBookController( @@ -2435,6 +2456,12 @@ export default class MetamaskController extends EventEmitter { } else { this.txController.stopIncomingTransactionPolling(); } + + // TODO: Remove once the preferences controller has been replaced with the core monorepo implementation + this.controllerMessenger.publish( + `${this.preferencesController.name}:stateChange`, + [state, []], + ); }); this.controllerMessenger.subscribe( @@ -2773,7 +2800,7 @@ export default class MetamaskController extends EventEmitter { nftController, nftDetectionController, currencyRateController, - detectTokensController, + tokenDetectionController, ensController, gasFeeController, metaMetricsController, @@ -3450,9 +3477,9 @@ export default class MetamaskController extends EventEmitter { backupUserData: backup.backupUserData.bind(backup), restoreUserData: backup.restoreUserData.bind(backup), - // DetectTokenController - detectNewTokens: detectTokensController.detectNewTokens.bind( - detectTokensController, + // TokenDetectionController + detectTokens: tokenDetectionController.detectTokens.bind( + tokenDetectionController, ), // DetectCollectibleController @@ -3681,7 +3708,7 @@ export default class MetamaskController extends EventEmitter { if (balance === '0x0') { // This account has no balance, so check for tokens - await this.detectTokensController.detectNewTokens({ + await this.tokenDetectionController.detectTokens({ selectedAddress: address, }); @@ -5579,7 +5606,11 @@ export default class MetamaskController extends EventEmitter { */ set isClientOpen(open) { this._isClientOpen = open; - this.detectTokensController.isOpen = open; + if (open) { + this.tokenDetectionController.enable(); + } else { + this.tokenDetectionController.disable(); + } } /* eslint-enable accessor-pairs */ diff --git a/app/scripts/metamask-controller.test.js b/app/scripts/metamask-controller.test.js index 67aac9ff1f66..766ea73417e0 100644 --- a/app/scripts/metamask-controller.test.js +++ b/app/scripts/metamask-controller.test.js @@ -952,7 +952,7 @@ describe('MetaMaskController', () => { it('should call keyringController.getAccounts', async () => { expect( metamaskController.keyringController.getAccounts, - ).toHaveBeenCalledTimes(2); + ).toHaveBeenCalledTimes(3); }); it('should call preferencesController.setAddresses', async () => { diff --git a/development/ts-migration-dashboard/files-to-convert.json b/development/ts-migration-dashboard/files-to-convert.json index be5e60a6a97f..9f63dc841229 100644 --- a/development/ts-migration-dashboard/files-to-convert.json +++ b/development/ts-migration-dashboard/files-to-convert.json @@ -10,8 +10,6 @@ "app/scripts/controllers/app-state.js", "app/scripts/controllers/cached-balances.js", "app/scripts/controllers/cached-balances.test.js", - "app/scripts/controllers/detect-tokens.js", - "app/scripts/controllers/detect-tokens.test.js", "app/scripts/controllers/ens/ens.js", "app/scripts/controllers/ens/index.js", "app/scripts/controllers/ens/index.test.js", diff --git a/jest.config.js b/jest.config.js index 85e9492ddb2c..b5c4d27fb59e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,7 +8,6 @@ module.exports = { '/app/scripts/controllers/transactions/EtherscanRemoteTransactionSource.ts', '/app/scripts/controllers/transactions/IncomingTransactionHelper.ts', '/app/scripts/controllers/preferences.js', - '/app/scripts/controllers/detect-tokens.test.js', '/app/scripts/flask/**/*.js', '/app/scripts/lib/**/*.(js|ts)', '/app/scripts/lib/createRPCMethodTrackingMiddleware.js', @@ -55,7 +54,6 @@ module.exports = { '/app/scripts/lib/**/*.test.(js|ts)', '/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js', '/app/scripts/metamask-controller.test.js', - '/app/scripts/controllers/detect-tokens.test.js', '/app/scripts/migrations/*.test.(js|ts)', '/app/scripts/platforms/*.test.js', '/app/scripts/translate.test.ts', diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index a5ef57f843a2..95e9412953e3 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -700,11 +700,12 @@ }, "@metamask/accounts-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/base-controller": true, "@metamask/eth-snap-keyring": true, "@metamask/keyring-api": true, "@metamask/keyring-controller": true, - "ethereumjs-util": true, "uuid": true } }, @@ -796,10 +797,12 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/abi>@ethersproject/address": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/assets-controllers>cockatiel": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, @@ -808,16 +811,27 @@ "@metamask/eth-query": true, "@metamask/metamask-eth-abis": true, "@metamask/name-controller>async-mutex": true, - "@metamask/polling-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/utils": true, - "ethereumjs-util": true, + "bn.js": true, "lodash": true, "single-call-balance-checker-abi": true, "uuid": true, "webpack>events": true } }, + "@metamask/assets-controllers>@metamask/polling-controller": { + "globals": { + "clearTimeout": true, + "console.error": true, + "setTimeout": true + }, + "packages": { + "@metamask/base-controller": true, + "@metamask/snaps-utils>fast-json-stable-stringify": true, + "uuid": true + } + }, "@metamask/assets-controllers>cockatiel": { "globals": { "AbortController": true, @@ -871,13 +885,14 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "@metamask/ethjs>@metamask/ethjs-unit": true, "@metamask/utils": true, + "bn.js": true, "browserify>buffer": true, "eslint>fast-deep-equal": true, - "eth-ens-namehash": true, - "ethereumjs-util": true + "eth-ens-namehash": true } }, "@metamask/controller-utils>@spruceid/siwe-parser": { @@ -971,37 +986,14 @@ }, "packages": { "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>@metamask/obs-store": true, "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/utils": true, "webpack>events": true } }, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": { - "globals": { - "TextEncoder": true - }, - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/scure-bip39": true, - "@metamask/utils": true, - "browserify>buffer": true - } - }, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/utils": true, - "browserify>buffer": true, - "mocha>serialize-javascript>randombytes": true - } - }, "@metamask/eth-keyring-controller>@metamask/obs-store": { "packages": { "@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, @@ -1395,26 +1387,14 @@ "setInterval": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/gas-fee-controller>@metamask/polling-controller": true, "ethereumjs-util": true, "uuid": true } }, - "@metamask/gas-fee-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/jazzicon": { "globals": { "document.createElement": true, @@ -1461,51 +1441,38 @@ }, "@metamask/keyring-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/base-controller": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": true, + "@metamask/browser-passworder": true, + "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/keyring-controller>ethereumjs-wallet": true, "@metamask/name-controller>async-mutex": true, - "@metamask/utils": true, - "ethereumjs-util": true + "@metamask/utils": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": { + "@metamask/keyring-controller>@metamask/eth-hd-keyring": { "globals": { - "console.error": true + "TextEncoder": true }, "packages": { - "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/eth-sig-util": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": true, + "@metamask/scure-bip39": true, "@metamask/utils": true, - "webpack>events": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": { - "packages": { - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true + "browserify>buffer": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": { + "@metamask/keyring-controller>@metamask/eth-simple-keyring": { "packages": { - "browserify>browser-resolve": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/eth-sig-util": true, + "@metamask/utils": true, "browserify>buffer": true, - "browserify>process": true, - "browserify>string_decoder": true, - "pumpify>inherits": true, - "readable-stream>util-deprecate": true, - "webpack>events": true + "mocha>serialize-javascript>randombytes": true } }, "@metamask/keyring-controller>ethereumjs-wallet": { @@ -1578,8 +1545,8 @@ "@metamask/controller-utils": true, "@metamask/eth-sig-util": true, "@metamask/message-manager>jsonschema": true, + "@metamask/utils": true, "browserify>buffer": true, - "ethereumjs-util": true, "uuid": true, "webpack>events": true } @@ -1718,18 +1685,6 @@ "eslint>optionator>fast-levenshtein": true } }, - "@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/ppom-validator>elliptic": { "packages": { "@metamask/ppom-validator>elliptic>brorand": true, @@ -2112,13 +2067,13 @@ "fetch": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/base-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/gas-fee-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/transaction-controller": true, - "@metamask/user-operation-controller>@metamask/polling-controller": true, "@metamask/utils": true, "ethereumjs-util": true, "lodash": true, @@ -2127,18 +2082,6 @@ "webpack>events": true } }, - "@metamask/user-operation-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/desktop/policy.json b/lavamoat/browserify/desktop/policy.json index 615f1379d1b3..f5b0c4b620b1 100644 --- a/lavamoat/browserify/desktop/policy.json +++ b/lavamoat/browserify/desktop/policy.json @@ -700,11 +700,12 @@ }, "@metamask/accounts-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/base-controller": true, "@metamask/eth-snap-keyring": true, "@metamask/keyring-api": true, "@metamask/keyring-controller": true, - "ethereumjs-util": true, "uuid": true } }, @@ -796,10 +797,12 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/abi>@ethersproject/address": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/assets-controllers>cockatiel": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, @@ -808,16 +811,27 @@ "@metamask/eth-query": true, "@metamask/metamask-eth-abis": true, "@metamask/name-controller>async-mutex": true, - "@metamask/polling-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/utils": true, - "ethereumjs-util": true, + "bn.js": true, "lodash": true, "single-call-balance-checker-abi": true, "uuid": true, "webpack>events": true } }, + "@metamask/assets-controllers>@metamask/polling-controller": { + "globals": { + "clearTimeout": true, + "console.error": true, + "setTimeout": true + }, + "packages": { + "@metamask/base-controller": true, + "@metamask/snaps-utils>fast-json-stable-stringify": true, + "uuid": true + } + }, "@metamask/assets-controllers>cockatiel": { "globals": { "AbortController": true, @@ -871,13 +885,14 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "@metamask/ethjs>@metamask/ethjs-unit": true, "@metamask/utils": true, + "bn.js": true, "browserify>buffer": true, "eslint>fast-deep-equal": true, - "eth-ens-namehash": true, - "ethereumjs-util": true + "eth-ens-namehash": true } }, "@metamask/controller-utils>@spruceid/siwe-parser": { @@ -1048,37 +1063,14 @@ }, "packages": { "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>@metamask/obs-store": true, "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/utils": true, "webpack>events": true } }, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": { - "globals": { - "TextEncoder": true - }, - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/scure-bip39": true, - "@metamask/utils": true, - "browserify>buffer": true - } - }, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/utils": true, - "browserify>buffer": true, - "mocha>serialize-javascript>randombytes": true - } - }, "@metamask/eth-keyring-controller>@metamask/obs-store": { "packages": { "@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, @@ -1472,26 +1464,14 @@ "setInterval": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/gas-fee-controller>@metamask/polling-controller": true, "ethereumjs-util": true, "uuid": true } }, - "@metamask/gas-fee-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/jazzicon": { "globals": { "document.createElement": true, @@ -1538,51 +1518,38 @@ }, "@metamask/keyring-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/base-controller": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": true, + "@metamask/browser-passworder": true, + "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/keyring-controller>ethereumjs-wallet": true, "@metamask/name-controller>async-mutex": true, - "@metamask/utils": true, - "ethereumjs-util": true + "@metamask/utils": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": { + "@metamask/keyring-controller>@metamask/eth-hd-keyring": { "globals": { - "console.error": true + "TextEncoder": true }, "packages": { - "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/eth-sig-util": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": true, + "@metamask/scure-bip39": true, "@metamask/utils": true, - "webpack>events": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": { - "packages": { - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true + "browserify>buffer": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": { + "@metamask/keyring-controller>@metamask/eth-simple-keyring": { "packages": { - "browserify>browser-resolve": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/eth-sig-util": true, + "@metamask/utils": true, "browserify>buffer": true, - "browserify>process": true, - "browserify>string_decoder": true, - "pumpify>inherits": true, - "readable-stream>util-deprecate": true, - "webpack>events": true + "mocha>serialize-javascript>randombytes": true } }, "@metamask/keyring-controller>ethereumjs-wallet": { @@ -1655,8 +1622,8 @@ "@metamask/controller-utils": true, "@metamask/eth-sig-util": true, "@metamask/message-manager>jsonschema": true, + "@metamask/utils": true, "browserify>buffer": true, - "ethereumjs-util": true, "uuid": true, "webpack>events": true } @@ -1822,18 +1789,6 @@ "eslint>optionator>fast-levenshtein": true } }, - "@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/post-message-stream": { "globals": { "MessageEvent.prototype": true, @@ -2392,13 +2347,13 @@ "fetch": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/base-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/gas-fee-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/transaction-controller": true, - "@metamask/user-operation-controller>@metamask/polling-controller": true, "@metamask/utils": true, "ethereumjs-util": true, "lodash": true, @@ -2407,18 +2362,6 @@ "webpack>events": true } }, - "@metamask/user-operation-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index f4e628f2abc8..abf158b069f9 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -700,11 +700,12 @@ }, "@metamask/accounts-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/base-controller": true, "@metamask/eth-snap-keyring": true, "@metamask/keyring-api": true, "@metamask/keyring-controller": true, - "ethereumjs-util": true, "uuid": true } }, @@ -796,10 +797,12 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/abi>@ethersproject/address": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/assets-controllers>cockatiel": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, @@ -808,16 +811,27 @@ "@metamask/eth-query": true, "@metamask/metamask-eth-abis": true, "@metamask/name-controller>async-mutex": true, - "@metamask/polling-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/utils": true, - "ethereumjs-util": true, + "bn.js": true, "lodash": true, "single-call-balance-checker-abi": true, "uuid": true, "webpack>events": true } }, + "@metamask/assets-controllers>@metamask/polling-controller": { + "globals": { + "clearTimeout": true, + "console.error": true, + "setTimeout": true + }, + "packages": { + "@metamask/base-controller": true, + "@metamask/snaps-utils>fast-json-stable-stringify": true, + "uuid": true + } + }, "@metamask/assets-controllers>cockatiel": { "globals": { "AbortController": true, @@ -871,13 +885,14 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "@metamask/ethjs>@metamask/ethjs-unit": true, "@metamask/utils": true, + "bn.js": true, "browserify>buffer": true, "eslint>fast-deep-equal": true, - "eth-ens-namehash": true, - "ethereumjs-util": true + "eth-ens-namehash": true } }, "@metamask/controller-utils>@spruceid/siwe-parser": { @@ -1048,37 +1063,14 @@ }, "packages": { "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>@metamask/obs-store": true, "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/utils": true, "webpack>events": true } }, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": { - "globals": { - "TextEncoder": true - }, - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/scure-bip39": true, - "@metamask/utils": true, - "browserify>buffer": true - } - }, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/utils": true, - "browserify>buffer": true, - "mocha>serialize-javascript>randombytes": true - } - }, "@metamask/eth-keyring-controller>@metamask/obs-store": { "packages": { "@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, @@ -1472,26 +1464,14 @@ "setInterval": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/gas-fee-controller>@metamask/polling-controller": true, "ethereumjs-util": true, "uuid": true } }, - "@metamask/gas-fee-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/jazzicon": { "globals": { "document.createElement": true, @@ -1538,51 +1518,38 @@ }, "@metamask/keyring-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/base-controller": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": true, + "@metamask/browser-passworder": true, + "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/keyring-controller>ethereumjs-wallet": true, "@metamask/name-controller>async-mutex": true, - "@metamask/utils": true, - "ethereumjs-util": true + "@metamask/utils": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": { + "@metamask/keyring-controller>@metamask/eth-hd-keyring": { "globals": { - "console.error": true + "TextEncoder": true }, "packages": { - "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/eth-sig-util": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": true, + "@metamask/scure-bip39": true, "@metamask/utils": true, - "webpack>events": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": { - "packages": { - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true + "browserify>buffer": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": { + "@metamask/keyring-controller>@metamask/eth-simple-keyring": { "packages": { - "browserify>browser-resolve": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/eth-sig-util": true, + "@metamask/utils": true, "browserify>buffer": true, - "browserify>process": true, - "browserify>string_decoder": true, - "pumpify>inherits": true, - "readable-stream>util-deprecate": true, - "webpack>events": true + "mocha>serialize-javascript>randombytes": true } }, "@metamask/keyring-controller>ethereumjs-wallet": { @@ -1655,8 +1622,8 @@ "@metamask/controller-utils": true, "@metamask/eth-sig-util": true, "@metamask/message-manager>jsonschema": true, + "@metamask/utils": true, "browserify>buffer": true, - "ethereumjs-util": true, "uuid": true, "webpack>events": true } @@ -1822,18 +1789,6 @@ "eslint>optionator>fast-levenshtein": true } }, - "@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/post-message-stream": { "globals": { "MessageEvent.prototype": true, @@ -2426,13 +2381,13 @@ "fetch": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/base-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/gas-fee-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/transaction-controller": true, - "@metamask/user-operation-controller>@metamask/polling-controller": true, "@metamask/utils": true, "ethereumjs-util": true, "lodash": true, @@ -2441,18 +2396,6 @@ "webpack>events": true } }, - "@metamask/user-operation-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index ad57d9baa681..72cfe4e6fa71 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -700,11 +700,12 @@ }, "@metamask/accounts-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/base-controller": true, "@metamask/eth-snap-keyring": true, "@metamask/keyring-api": true, "@metamask/keyring-controller": true, - "ethereumjs-util": true, "uuid": true } }, @@ -796,10 +797,12 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/abi>@ethersproject/address": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/assets-controllers>cockatiel": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, @@ -808,16 +811,27 @@ "@metamask/eth-query": true, "@metamask/metamask-eth-abis": true, "@metamask/name-controller>async-mutex": true, - "@metamask/polling-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/utils": true, - "ethereumjs-util": true, + "bn.js": true, "lodash": true, "single-call-balance-checker-abi": true, "uuid": true, "webpack>events": true } }, + "@metamask/assets-controllers>@metamask/polling-controller": { + "globals": { + "clearTimeout": true, + "console.error": true, + "setTimeout": true + }, + "packages": { + "@metamask/base-controller": true, + "@metamask/snaps-utils>fast-json-stable-stringify": true, + "uuid": true + } + }, "@metamask/assets-controllers>cockatiel": { "globals": { "AbortController": true, @@ -871,13 +885,14 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "@metamask/ethjs>@metamask/ethjs-unit": true, "@metamask/utils": true, + "bn.js": true, "browserify>buffer": true, "eslint>fast-deep-equal": true, - "eth-ens-namehash": true, - "ethereumjs-util": true + "eth-ens-namehash": true } }, "@metamask/controller-utils>@spruceid/siwe-parser": { @@ -971,37 +986,14 @@ }, "packages": { "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>@metamask/obs-store": true, "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/utils": true, "webpack>events": true } }, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": { - "globals": { - "TextEncoder": true - }, - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/scure-bip39": true, - "@metamask/utils": true, - "browserify>buffer": true - } - }, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/utils": true, - "browserify>buffer": true, - "mocha>serialize-javascript>randombytes": true - } - }, "@metamask/eth-keyring-controller>@metamask/obs-store": { "packages": { "@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, @@ -1395,26 +1387,14 @@ "setInterval": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/gas-fee-controller>@metamask/polling-controller": true, "ethereumjs-util": true, "uuid": true } }, - "@metamask/gas-fee-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/jazzicon": { "globals": { "document.createElement": true, @@ -1461,51 +1441,38 @@ }, "@metamask/keyring-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/base-controller": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": true, + "@metamask/browser-passworder": true, + "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/keyring-controller>ethereumjs-wallet": true, "@metamask/name-controller>async-mutex": true, - "@metamask/utils": true, - "ethereumjs-util": true + "@metamask/utils": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": { + "@metamask/keyring-controller>@metamask/eth-hd-keyring": { "globals": { - "console.error": true + "TextEncoder": true }, "packages": { - "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/eth-sig-util": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": true, + "@metamask/scure-bip39": true, "@metamask/utils": true, - "webpack>events": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": { - "packages": { - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true + "browserify>buffer": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": { + "@metamask/keyring-controller>@metamask/eth-simple-keyring": { "packages": { - "browserify>browser-resolve": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/eth-sig-util": true, + "@metamask/utils": true, "browserify>buffer": true, - "browserify>process": true, - "browserify>string_decoder": true, - "pumpify>inherits": true, - "readable-stream>util-deprecate": true, - "webpack>events": true + "mocha>serialize-javascript>randombytes": true } }, "@metamask/keyring-controller>ethereumjs-wallet": { @@ -1578,8 +1545,8 @@ "@metamask/controller-utils": true, "@metamask/eth-sig-util": true, "@metamask/message-manager>jsonschema": true, + "@metamask/utils": true, "browserify>buffer": true, - "ethereumjs-util": true, "uuid": true, "webpack>events": true } @@ -1745,18 +1712,6 @@ "eslint>optionator>fast-levenshtein": true } }, - "@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/post-message-stream": { "globals": { "MessageEvent.prototype": true, @@ -2349,13 +2304,13 @@ "fetch": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/base-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/gas-fee-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/transaction-controller": true, - "@metamask/user-operation-controller>@metamask/polling-controller": true, "@metamask/utils": true, "ethereumjs-util": true, "lodash": true, @@ -2364,18 +2319,6 @@ "webpack>events": true } }, - "@metamask/user-operation-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index 165a4ac21eca..0422d27c3ae7 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -832,11 +832,12 @@ }, "@metamask/accounts-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/base-controller": true, "@metamask/eth-snap-keyring": true, "@metamask/keyring-api": true, "@metamask/keyring-controller": true, - "ethereumjs-util": true, "uuid": true } }, @@ -928,10 +929,12 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/abi>@ethersproject/address": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/assets-controllers>cockatiel": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, @@ -940,16 +943,27 @@ "@metamask/eth-query": true, "@metamask/metamask-eth-abis": true, "@metamask/name-controller>async-mutex": true, - "@metamask/polling-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/utils": true, - "ethereumjs-util": true, + "bn.js": true, "lodash": true, "single-call-balance-checker-abi": true, "uuid": true, "webpack>events": true } }, + "@metamask/assets-controllers>@metamask/polling-controller": { + "globals": { + "clearTimeout": true, + "console.error": true, + "setTimeout": true + }, + "packages": { + "@metamask/base-controller": true, + "@metamask/snaps-utils>fast-json-stable-stringify": true, + "uuid": true + } + }, "@metamask/assets-controllers>cockatiel": { "globals": { "AbortController": true, @@ -1003,13 +1017,14 @@ "setTimeout": true }, "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "@metamask/ethjs>@metamask/ethjs-unit": true, "@metamask/utils": true, + "bn.js": true, "browserify>buffer": true, "eslint>fast-deep-equal": true, - "eth-ens-namehash": true, - "ethereumjs-util": true + "eth-ens-namehash": true } }, "@metamask/controller-utils>@spruceid/siwe-parser": { @@ -1103,37 +1118,14 @@ }, "packages": { "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>@metamask/obs-store": true, "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/utils": true, "webpack>events": true } }, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": { - "globals": { - "TextEncoder": true - }, - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/scure-bip39": true, - "@metamask/utils": true, - "browserify>buffer": true - } - }, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@ethereumjs/tx>ethereum-cryptography": true, - "@metamask/eth-sig-util": true, - "@metamask/utils": true, - "browserify>buffer": true, - "mocha>serialize-javascript>randombytes": true - } - }, "@metamask/eth-keyring-controller>@metamask/obs-store": { "packages": { "@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, @@ -1527,26 +1519,14 @@ "setInterval": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/gas-fee-controller>@metamask/polling-controller": true, "ethereumjs-util": true, "uuid": true } }, - "@metamask/gas-fee-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/jazzicon": { "globals": { "document.createElement": true, @@ -1593,51 +1573,38 @@ }, "@metamask/keyring-controller": { "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/base-controller": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": true, + "@metamask/browser-passworder": true, + "@metamask/eth-sig-util": true, + "@metamask/keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/keyring-controller>ethereumjs-wallet": true, "@metamask/name-controller>async-mutex": true, - "@metamask/utils": true, - "ethereumjs-util": true + "@metamask/utils": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller": { + "@metamask/keyring-controller>@metamask/eth-hd-keyring": { "globals": { - "console.error": true + "TextEncoder": true }, "packages": { - "@metamask/browser-passworder": true, - "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, - "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, "@metamask/eth-sig-util": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": true, + "@metamask/scure-bip39": true, "@metamask/utils": true, - "webpack>events": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store": { - "packages": { - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": true, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": true - } - }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>@metamask/safe-event-emitter": { - "globals": { - "setTimeout": true - }, - "packages": { - "webpack>events": true + "browserify>buffer": true } }, - "@metamask/keyring-controller>@metamask/eth-keyring-controller>@metamask/obs-store>readable-stream": { + "@metamask/keyring-controller>@metamask/eth-simple-keyring": { "packages": { - "browserify>browser-resolve": true, + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/eth-sig-util": true, + "@metamask/utils": true, "browserify>buffer": true, - "browserify>process": true, - "browserify>string_decoder": true, - "pumpify>inherits": true, - "readable-stream>util-deprecate": true, - "webpack>events": true + "mocha>serialize-javascript>randombytes": true } }, "@metamask/keyring-controller>ethereumjs-wallet": { @@ -1710,8 +1677,8 @@ "@metamask/controller-utils": true, "@metamask/eth-sig-util": true, "@metamask/message-manager>jsonschema": true, + "@metamask/utils": true, "browserify>buffer": true, - "ethereumjs-util": true, "uuid": true, "webpack>events": true } @@ -1877,18 +1844,6 @@ "eslint>optionator>fast-levenshtein": true } }, - "@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/post-message-stream": { "globals": { "MessageEvent.prototype": true, @@ -2447,13 +2402,13 @@ "fetch": true }, "packages": { + "@metamask/assets-controllers>@metamask/polling-controller": true, "@metamask/base-controller": true, "@metamask/controller-utils": true, "@metamask/eth-query": true, "@metamask/gas-fee-controller": true, "@metamask/providers>@metamask/rpc-errors": true, "@metamask/transaction-controller": true, - "@metamask/user-operation-controller>@metamask/polling-controller": true, "@metamask/utils": true, "ethereumjs-util": true, "lodash": true, @@ -2462,18 +2417,6 @@ "webpack>events": true } }, - "@metamask/user-operation-controller>@metamask/polling-controller": { - "globals": { - "clearTimeout": true, - "console.error": true, - "setTimeout": true - }, - "packages": { - "@metamask/base-controller": true, - "@metamask/snaps-utils>fast-json-stable-stringify": true, - "uuid": true - } - }, "@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/package.json b/package.json index 696eb9e9cb4d..4bd7ee543f8c 100644 --- a/package.json +++ b/package.json @@ -241,15 +241,15 @@ "@metamask-institutional/sdk": "^0.1.23", "@metamask-institutional/transaction-update": "^0.1.32", "@metamask/abi-utils": "^2.0.2", - "@metamask/accounts-controller": "patch:@metamask/accounts-controller@npm%3A10.0.0#~/.yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch", + "@metamask/accounts-controller": "^11.0.0", "@metamask/address-book-controller": "^3.0.0", "@metamask/announcement-controller": "^5.0.1", "@metamask/approval-controller": "^5.1.2", - "@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A24.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch", + "@metamask/assets-controllers": "^26.0.0", "@metamask/base-controller": "^4.1.0", "@metamask/browser-passworder": "^4.3.0", "@metamask/contract-metadata": "^2.3.1", - "@metamask/controller-utils": "^8.0.1", + "@metamask/controller-utils": "^8.0.4", "@metamask/design-tokens": "^2.1.1", "@metamask/desktop": "^0.3.0", "@metamask/ens-controller": "^9.0.0", @@ -269,7 +269,7 @@ "@metamask/gas-fee-controller": "^13.0.0", "@metamask/jazzicon": "^2.0.0", "@metamask/keyring-api": "^3.0.0", - "@metamask/keyring-controller": "patch:@metamask/keyring-controller@npm%3A12.2.0#~/.yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch", + "@metamask/keyring-controller": "^13.0.0", "@metamask/logging-controller": "^2.0.2", "@metamask/logo": "^3.1.2", "@metamask/message-manager": "^7.3.0", @@ -281,7 +281,6 @@ "@metamask/permission-controller": "^8.0.0", "@metamask/permission-log-controller": "^1.0.0", "@metamask/phishing-controller": "^8.0.0", - "@metamask/polling-controller": "^4.0.0", "@metamask/post-message-stream": "^8.0.0", "@metamask/ppom-validator": "^0.27.0", "@metamask/providers": "^14.0.2", diff --git a/test/e2e/tests/metrics/swaps.spec.js b/test/e2e/tests/metrics/swaps.spec.js index 594c23d5ea2d..0102d2cd6d6b 100644 --- a/test/e2e/tests/metrics/swaps.spec.js +++ b/test/e2e/tests/metrics/swaps.spec.js @@ -170,7 +170,7 @@ async function getQuoteAndSwapTokens(driver) { async function assertReqsNumAndFilterMetrics(driver, mockedEndpoints) { const events = await getEventPayloads(driver, mockedEndpoints); - const numberOfMetaswapRequests = 8; + const numberOfMetaswapRequests = 7; assert.equal( events.length, numberOfSegmentRequests + numberOfMetaswapRequests, diff --git a/ui/components/multichain/account-details/account-details.test.js b/ui/components/multichain/account-details/account-details.test.js index a4ac6e1284b3..3d017160e00b 100644 --- a/ui/components/multichain/account-details/account-details.test.js +++ b/ui/components/multichain/account-details/account-details.test.js @@ -1,5 +1,4 @@ import { LavaDomeDebug } from '@lavamoat/lavadome-core'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { fireEvent, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; @@ -14,6 +13,7 @@ import { setAccountDetailsAddress, } from '../../../store/actions'; import configureStore from '../../../store/store'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { AccountDetailsKey } from './account-details-key'; import { AccountDetails } from '.'; diff --git a/ui/components/multichain/account-list-item/account-list-item.js b/ui/components/multichain/account-list-item/account-list-item.js index d6734091486e..e3b03a4259b7 100644 --- a/ui/components/multichain/account-list-item/account-list-item.js +++ b/ui/components/multichain/account-list-item/account-list-item.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import { useSelector } from 'react-redux'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { shortenAddress } from '../../../helpers/utils/util'; @@ -58,6 +57,7 @@ import { import { useAccountTotalFiatBalance } from '../../../hooks/useAccountTotalFiatBalance'; import { TEST_NETWORKS } from '../../../../shared/constants/network'; import { ConnectedStatus } from '../connected-status/connected-status'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { AccountListItemMenuTypes } from './account-list-item.types'; const MAXIMUM_CURRENCY_DECIMALS = 3; diff --git a/ui/components/multichain/account-list-item/account-list-item.test.js b/ui/components/multichain/account-list-item/account-list-item.test.js index 925acc34c338..3b99ea931ce7 100644 --- a/ui/components/multichain/account-list-item/account-list-item.test.js +++ b/ui/components/multichain/account-list-item/account-list-item.test.js @@ -1,11 +1,11 @@ /* eslint-disable jest/require-top-level-describe */ import React from 'react'; import { fireEvent, screen } from '@testing-library/react'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { renderWithProvider } from '../../../../test/jest'; import configureStore from '../../../store/store'; import mockState from '../../../../test/data/mock-state.json'; import { shortenAddress } from '../../../helpers/utils/util'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { AccountListItem, AccountListItemMenuTypes } from '.'; const account = { diff --git a/ui/components/multichain/address-copy-button/address-copy-button.js b/ui/components/multichain/address-copy-button/address-copy-button.js index 9ae846d1fafd..1e632d9206d7 100644 --- a/ui/components/multichain/address-copy-button/address-copy-button.js +++ b/ui/components/multichain/address-copy-button/address-copy-button.js @@ -1,7 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) import { useSelector } from 'react-redux'; import { getSelectedInternalAccount } from '../../../selectors'; @@ -26,6 +25,7 @@ import { shortenAddress } from '../../../helpers/utils/util'; import Tooltip from '../../ui/tooltip/tooltip'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { MINUTE } from '../../../../shared/constants/time'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; export const AddressCopyButton = ({ address, diff --git a/ui/components/multichain/address-copy-button/address-copy-button.test.js b/ui/components/multichain/address-copy-button/address-copy-button.test.js index bf9ffdc135e6..2de16d491c0d 100644 --- a/ui/components/multichain/address-copy-button/address-copy-button.test.js +++ b/ui/components/multichain/address-copy-button/address-copy-button.test.js @@ -2,7 +2,6 @@ import React from 'react'; import configureMockStore from 'redux-mock-store'; import copyToClipboard from 'copy-to-clipboard'; import { fireEvent } from '@testing-library/react'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { renderWithProvider } from '../../../../test/lib/render-helpers'; import mockState from '../../../../test/data/mock-state.json'; import { COPY_OPTIONS } from '../../../../shared/constants/copy'; @@ -11,6 +10,7 @@ import { getIsCustodianSupportedChain, getCustodianIconForAddress, } from '../../../selectors/institutional/selectors'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { AddressCopyButton } from '.'; jest.mock('copy-to-clipboard'); diff --git a/ui/components/multichain/app-header/app-header.js b/ui/components/multichain/app-header/app-header.js index 8da8f544ed12..ab1a3adc0ed9 100644 --- a/ui/components/multichain/app-header/app-header.js +++ b/ui/components/multichain/app-header/app-header.js @@ -4,7 +4,6 @@ import PropTypes from 'prop-types'; import browser from 'webextension-polyfill'; import { useDispatch, useSelector } from 'react-redux'; import { matchPath, useHistory } from 'react-router-dom'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { MetaMetricsEventCategory, @@ -77,6 +76,7 @@ import Tooltip from '../../ui/tooltip'; import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard'; import { MINUTE } from '../../../../shared/constants/time'; import { getURLHost, shortenAddress } from '../../../helpers/utils/util'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; export const AppHeader = ({ location }) => { const trackEvent = useContext(MetaMetricsContext); diff --git a/ui/components/multichain/import-token-link/import-token-link.test.js b/ui/components/multichain/import-token-link/import-token-link.test.js index 49cbdc42e869..e15b4ed09aa4 100644 --- a/ui/components/multichain/import-token-link/import-token-link.test.js +++ b/ui/components/multichain/import-token-link/import-token-link.test.js @@ -1,7 +1,7 @@ import React from 'react'; import configureMockStore from 'redux-mock-store'; import { fireEvent, screen } from '@testing-library/react'; -import { detectNewTokens } from '../../../store/actions'; +import { detectTokens } from '../../../store/actions'; import { renderWithProvider } from '../../../../test/lib/render-helpers'; import { CHAIN_IDS } from '../../../../shared/constants/network'; import { ImportTokenLink } from '.'; @@ -20,9 +20,7 @@ jest.mock('react-router-dom', () => { }); jest.mock('../../../store/actions.ts', () => ({ - detectNewTokens: jest - .fn() - .mockImplementation(() => ({ type: 'DETECT_TOKENS' })), + detectTokens: jest.fn().mockImplementation(() => ({ type: 'DETECT_TOKENS' })), showImportTokensModal: jest .fn() .mockImplementation(() => ({ type: 'UI_IMPORT_TOKENS_POPOVER_OPEN' })), @@ -61,7 +59,7 @@ describe('Import Token Link', () => { expect(container).toMatchSnapshot(); }); - it('should detectNewTokens when clicking refresh', () => { + it('should detectTokens when clicking refresh', () => { const mockState = { metamask: { providerConfig: { @@ -77,7 +75,7 @@ describe('Import Token Link', () => { const refreshList = screen.getByTestId('refresh-list-button'); fireEvent.click(refreshList); - expect(detectNewTokens).toHaveBeenCalled(); + expect(detectTokens).toHaveBeenCalled(); }); it('should push import token route', () => { diff --git a/ui/components/multichain/import-token-link/import-token-link.tsx b/ui/components/multichain/import-token-link/import-token-link.tsx index 91319b82097d..6c7c9b6a8e6b 100644 --- a/ui/components/multichain/import-token-link/import-token-link.tsx +++ b/ui/components/multichain/import-token-link/import-token-link.tsx @@ -9,7 +9,7 @@ import { } from '../../component-library'; import { AlignItems, Display } from '../../../helpers/constants/design-system'; import { useI18nContext } from '../../../hooks/useI18nContext'; -import { detectNewTokens, showImportTokensModal } from '../../../store/actions'; +import { detectTokens, showImportTokensModal } from '../../../store/actions'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { MetaMetricsEventCategory, @@ -71,7 +71,7 @@ export const ImportTokenLink: React.FC = ({ size={ButtonLinkSize.Md} startIconName={IconName.Refresh} data-testid="refresh-list-button" - onClick={() => dispatch(detectNewTokens())} + onClick={() => dispatch(detectTokens())} > {t('refreshList')} diff --git a/ui/components/multichain/menu-items/view-explorer-menu-item.js b/ui/components/multichain/menu-items/view-explorer-menu-item.js index b4953cc0e5bc..302ccb5e372a 100644 --- a/ui/components/multichain/menu-items/view-explorer-menu-item.js +++ b/ui/components/multichain/menu-items/view-explorer-menu-item.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { useHistory } from 'react-router-dom'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { getAccountLink } from '@metamask/etherscan-link'; import { MenuItem } from '../../ui/menu'; @@ -22,6 +21,7 @@ import { } from '../../../selectors'; import { getURLHostName } from '../../../helpers/utils/util'; import { NETWORKS_ROUTE } from '../../../helpers/constants/routes'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; export const ViewExplorerMenuItem = ({ metricsLocation, diff --git a/ui/components/multichain/notification-detail-address/notification-detail-address.tsx b/ui/components/multichain/notification-detail-address/notification-detail-address.tsx index c4c79869d021..fb22bc927181 100644 --- a/ui/components/multichain/notification-detail-address/notification-detail-address.tsx +++ b/ui/components/multichain/notification-detail-address/notification-detail-address.tsx @@ -1,6 +1,5 @@ import React from 'react'; import type { FC } from 'react'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { NotificationDetail } from '../notification-detail'; import { NotificationDetailCopyButton } from '../notification-detail-copy-button'; import { AvatarAccount, Text } from '../../component-library'; @@ -9,6 +8,7 @@ import { TextVariant, } from '../../../helpers/constants/design-system'; import { shortenAddress } from '../../../helpers/utils/util'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; export interface NotificationDetailAddressProps { side: string; diff --git a/ui/components/multichain/notification-detail-copy-button/notification-detail-copy-button.stories.tsx b/ui/components/multichain/notification-detail-copy-button/notification-detail-copy-button.stories.tsx index bc0647fdc6e5..e51edece841e 100644 --- a/ui/components/multichain/notification-detail-copy-button/notification-detail-copy-button.stories.tsx +++ b/ui/components/multichain/notification-detail-copy-button/notification-detail-copy-button.stories.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Meta } from '@storybook/react'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import { shortenAddress } from '../../../helpers/utils/util'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { NotificationDetailCopyButton, NotificationDetailCopyButtonProps, diff --git a/ui/components/multichain/receive-modal/receive-modal.test.js b/ui/components/multichain/receive-modal/receive-modal.test.js index 0650757accac..48bafe095e3e 100644 --- a/ui/components/multichain/receive-modal/receive-modal.test.js +++ b/ui/components/multichain/receive-modal/receive-modal.test.js @@ -1,9 +1,9 @@ import React from 'react'; import { screen } from '@testing-library/react'; -import { toChecksumHexAddress } from '@metamask/controller-utils'; import mockState from '../../../../test/data/mock-state.json'; import { renderWithProvider } from '../../../../test/jest'; import configureStore from '../../../store/store'; +import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { ReceiveModal } from '.'; describe('ReceiveModal', () => { diff --git a/ui/store/actions.ts b/ui/store/actions.ts index 1fa371531216..a19154880305 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -3256,8 +3256,8 @@ export function setUseCurrencyRateCheck( }; } -// DetectTokenController -export function detectNewTokens(): ThunkAction< +// TokenDetectionController +export function detectTokens(): ThunkAction< void, MetaMaskReduxState, unknown, @@ -3265,8 +3265,8 @@ export function detectNewTokens(): ThunkAction< > { return async (dispatch: MetaMaskReduxDispatch) => { dispatch(showLoadingIndication()); - log.debug(`background.detectNewTokens`); - await submitRequestToBackground('detectNewTokens'); + log.debug(`background.detectTokens`); + await submitRequestToBackground('detectTokens'); dispatch(hideLoadingIndication()); await forceUpdateMetamaskState(dispatch); }; diff --git a/yarn.lock b/yarn.lock index 776c39160416..c8057b5b449f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3839,31 +3839,11 @@ __metadata: languageName: node linkType: hard -"@metamask/accounts-controller@npm:10.0.0": - version: 10.0.0 - resolution: "@metamask/accounts-controller@npm:10.0.0" - dependencies: - "@metamask/base-controller": "npm:^4.1.1" - "@metamask/eth-snap-keyring": "npm:^2.1.1" - "@metamask/keyring-api": "npm:^3.0.0" - "@metamask/snaps-sdk": "npm:^1.3.2" - "@metamask/snaps-utils": "npm:^5.1.2" - "@metamask/utils": "npm:^8.3.0" - deepmerge: "npm:^4.2.2" - ethereumjs-util: "npm:^7.0.10" - immer: "npm:^9.0.6" - uuid: "npm:^8.3.2" - peerDependencies: - "@metamask/keyring-controller": ^12.2.0 - "@metamask/snaps-controllers": ^4.0.0 - checksum: 67bde84bd7d4215635ac1e5121fefca43a111743e922d6b8c050b136571a7887119bd8d1c08e41c5806292260309b27853fe959ff593731434bcbdbb7a22b076 - languageName: node - linkType: hard - -"@metamask/accounts-controller@patch:@metamask/accounts-controller@npm%3A10.0.0#~/.yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch": - version: 10.0.0 - resolution: "@metamask/accounts-controller@patch:@metamask/accounts-controller@npm%3A10.0.0#~/.yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch::version=10.0.0&hash=0a18f3" +"@metamask/accounts-controller@npm:^11.0.0": + version: 11.0.0 + resolution: "@metamask/accounts-controller@npm:11.0.0" dependencies: + "@ethereumjs/util": "npm:^8.1.0" "@metamask/base-controller": "npm:^4.1.1" "@metamask/eth-snap-keyring": "npm:^2.1.1" "@metamask/keyring-api": "npm:^3.0.0" @@ -3871,13 +3851,13 @@ __metadata: "@metamask/snaps-utils": "npm:^5.1.2" "@metamask/utils": "npm:^8.3.0" deepmerge: "npm:^4.2.2" - ethereumjs-util: "npm:^7.0.10" + ethereum-cryptography: "npm:^2.1.2" immer: "npm:^9.0.6" uuid: "npm:^8.3.2" peerDependencies: - "@metamask/keyring-controller": ^12.2.0 + "@metamask/keyring-controller": ^13.0.0 "@metamask/snaps-controllers": ^4.0.0 - checksum: 809c1a3bfe0982b6113c7c76c43576fc9a454c66ec5403b839e10468ec753d742027cb7674045c9005de32ca7822dcd2bc0a19f68be37e1184486652c7befba3 + checksum: 3d57f8763a0553ca22b492534cbb6b3ee40f61f434386f567965127382e2049919e9a5101eb97eb5e00d81f4b8e691c7a7f7ab0c177aee879a3e4da9cef3e8c1 languageName: node linkType: hard @@ -3913,75 +3893,45 @@ __metadata: languageName: node linkType: hard -"@metamask/assets-controllers@npm:24.0.0": - version: 24.0.0 - resolution: "@metamask/assets-controllers@npm:24.0.0" - dependencies: - "@ethersproject/address": "npm:^5.7.0" - "@ethersproject/bignumber": "npm:^5.7.0" - "@ethersproject/contracts": "npm:^5.7.0" - "@ethersproject/providers": "npm:^5.7.0" - "@metamask/abi-utils": "npm:^2.0.2" - "@metamask/approval-controller": "npm:^5.1.1" - "@metamask/base-controller": "npm:^4.0.1" - "@metamask/contract-metadata": "npm:^2.4.0" - "@metamask/controller-utils": "npm:^8.0.1" - "@metamask/eth-query": "npm:^4.0.0" - "@metamask/metamask-eth-abis": "npm:3.0.0" - "@metamask/network-controller": "npm:^17.1.0" - "@metamask/polling-controller": "npm:^4.0.0" - "@metamask/preferences-controller": "npm:^6.0.0" - "@metamask/rpc-errors": "npm:^6.1.0" - "@metamask/utils": "npm:^8.2.0" - "@types/uuid": "npm:^8.3.0" - async-mutex: "npm:^0.2.6" - cockatiel: "npm:^3.1.2" - ethereumjs-util: "npm:^7.0.10" - lodash: "npm:^4.17.21" - multiformats: "npm:^9.5.2" - single-call-balance-checker-abi: "npm:^1.0.0" - uuid: "npm:^8.3.2" - peerDependencies: - "@metamask/approval-controller": ^5.1.1 - "@metamask/network-controller": ^17.1.0 - "@metamask/preferences-controller": ^6.0.0 - checksum: f9c857e26e04ca8463421434fad3096161d24e776da85c136689ac93a402f9cdafc175c8bd11b64a93d0d38d54109a541fedfee0d93b9e7eb1e1372904b68694 - languageName: node - linkType: hard - -"@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A24.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch": - version: 24.0.0 - resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A24.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch::version=24.0.0&hash=f321cb" +"@metamask/assets-controllers@npm:^26.0.0": + version: 26.0.0 + resolution: "@metamask/assets-controllers@npm:26.0.0" dependencies: + "@ethereumjs/util": "npm:^8.1.0" "@ethersproject/address": "npm:^5.7.0" "@ethersproject/bignumber": "npm:^5.7.0" "@ethersproject/contracts": "npm:^5.7.0" "@ethersproject/providers": "npm:^5.7.0" "@metamask/abi-utils": "npm:^2.0.2" - "@metamask/approval-controller": "npm:^5.1.1" - "@metamask/base-controller": "npm:^4.0.1" + "@metamask/accounts-controller": "npm:^11.0.0" + "@metamask/approval-controller": "npm:^5.1.3" + "@metamask/base-controller": "npm:^4.1.1" "@metamask/contract-metadata": "npm:^2.4.0" - "@metamask/controller-utils": "npm:^8.0.1" + "@metamask/controller-utils": "npm:^8.0.4" "@metamask/eth-query": "npm:^4.0.0" + "@metamask/keyring-controller": "npm:^13.0.0" "@metamask/metamask-eth-abis": "npm:3.0.0" - "@metamask/network-controller": "npm:^17.1.0" - "@metamask/polling-controller": "npm:^4.0.0" - "@metamask/preferences-controller": "npm:^6.0.0" - "@metamask/rpc-errors": "npm:^6.1.0" - "@metamask/utils": "npm:^8.2.0" + "@metamask/network-controller": "npm:^17.2.1" + "@metamask/polling-controller": "npm:^5.0.1" + "@metamask/preferences-controller": "npm:^8.0.0" + "@metamask/rpc-errors": "npm:^6.2.1" + "@metamask/utils": "npm:^8.3.0" + "@types/bn.js": "npm:^5.1.5" "@types/uuid": "npm:^8.3.0" async-mutex: "npm:^0.2.6" + bn.js: "npm:^5.2.1" cockatiel: "npm:^3.1.2" - ethereumjs-util: "npm:^7.0.10" lodash: "npm:^4.17.21" multiformats: "npm:^9.5.2" single-call-balance-checker-abi: "npm:^1.0.0" uuid: "npm:^8.3.2" peerDependencies: - "@metamask/approval-controller": ^5.1.1 - "@metamask/network-controller": ^17.1.0 - "@metamask/preferences-controller": ^6.0.0 - checksum: fd23afac75f432daf108b3ae8aed915466bd1d91d3c306580b262cb2886ac0e3874bc367a24f21a3179d720610ce6b2e8ff9d1b34ddcdd9179d65679c1ced6fd + "@metamask/accounts-controller": ^11.0.0 + "@metamask/approval-controller": ^5.1.2 + "@metamask/keyring-controller": ^13.0.0 + "@metamask/network-controller": ^17.2.0 + "@metamask/preferences-controller": ^8.0.0 + checksum: ef59cf79ed9f69bce485d690df5eea6ce0ffc5ec021396a439f0e8467af6978d140709e95d1edfca394a679968d4eebb9a96e222961d16166f7eaf0ae2fb8774 languageName: node linkType: hard @@ -4076,18 +4026,18 @@ __metadata: languageName: node linkType: hard -"@metamask/controller-utils@npm:^8.0.1, @metamask/controller-utils@npm:^8.0.2, @metamask/controller-utils@npm:^8.0.3": - version: 8.0.3 - resolution: "@metamask/controller-utils@npm:8.0.3" +"@metamask/controller-utils@npm:^8.0.1, @metamask/controller-utils@npm:^8.0.2, @metamask/controller-utils@npm:^8.0.3, @metamask/controller-utils@npm:^8.0.4": + version: 8.0.4 + resolution: "@metamask/controller-utils@npm:8.0.4" dependencies: + "@ethereumjs/util": "npm:^8.1.0" "@metamask/eth-query": "npm:^4.0.0" "@metamask/ethjs-unit": "npm:^0.3.0" "@metamask/utils": "npm:^8.3.0" "@spruceid/siwe-parser": "npm:1.1.3" eth-ens-namehash: "npm:^2.0.8" - ethereumjs-util: "npm:^7.0.10" fast-deep-equal: "npm:^3.1.3" - checksum: 01c0fbddc3d1fbc56b72b9ea234104e81394efbb4487f60cf0a8316e1a3b79e2d0e6ccf071ea8e4d35a84a34004a4e654f3007e3c4151ac3dbe69dd280969af4 + checksum: 112a07614eec28cff270c99aa0695bec34cd29461d0c4cb83eb913a5bc37b3b72e4f33dad59a0ab23da5d1b091372ee5207657349bfdb814098c5a51d6570554 languageName: node linkType: hard @@ -4637,7 +4587,7 @@ __metadata: languageName: node linkType: hard -"@metamask/keyring-controller@npm:12.2.0, @metamask/keyring-controller@npm:^12.2.0": +"@metamask/keyring-controller@npm:^12.2.0": version: 12.2.0 resolution: "@metamask/keyring-controller@npm:12.2.0" dependencies: @@ -4655,21 +4605,24 @@ __metadata: languageName: node linkType: hard -"@metamask/keyring-controller@patch:@metamask/keyring-controller@npm%3A12.2.0#~/.yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch": - version: 12.2.0 - resolution: "@metamask/keyring-controller@patch:@metamask/keyring-controller@npm%3A12.2.0#~/.yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch::version=12.2.0&hash=8ab884" +"@metamask/keyring-controller@npm:^13.0.0": + version: 13.0.0 + resolution: "@metamask/keyring-controller@npm:13.0.0" dependencies: + "@ethereumjs/util": "npm:^8.1.0" "@keystonehq/metamask-airgapped-keyring": "npm:^0.13.1" "@metamask/base-controller": "npm:^4.1.1" - "@metamask/eth-keyring-controller": "npm:^17.0.1" + "@metamask/browser-passworder": "npm:^4.3.0" + "@metamask/eth-hd-keyring": "npm:^7.0.1" + "@metamask/eth-sig-util": "npm:^7.0.1" + "@metamask/eth-simple-keyring": "npm:^6.0.1" "@metamask/keyring-api": "npm:^3.0.0" - "@metamask/message-manager": "npm:^7.3.8" + "@metamask/message-manager": "npm:^7.3.9" "@metamask/utils": "npm:^8.3.0" async-mutex: "npm:^0.2.6" - ethereumjs-util: "npm:^7.0.10" ethereumjs-wallet: "npm:^1.0.1" immer: "npm:^9.0.6" - checksum: 7874fe2645d3c4ed08155825b1f5d10dec3cc6eb05e75e94664dda59056c8e625cfdf394678b6b9dbecf93ab20dcdf5b920a3a77701cd1854ab9668116eecdff + checksum: 477b6d7b9104370f562a862a11406013a744109f8d49e34eacedef8c9a1101e9f02f101aca3ea3af2b32b77b17535443c02d771c384ef436718b5d2fc28cbbb7 languageName: node linkType: hard @@ -4694,19 +4647,18 @@ __metadata: languageName: node linkType: hard -"@metamask/message-manager@npm:^7.3.0, @metamask/message-manager@npm:^7.3.8": - version: 7.3.8 - resolution: "@metamask/message-manager@npm:7.3.8" +"@metamask/message-manager@npm:^7.3.0, @metamask/message-manager@npm:^7.3.8, @metamask/message-manager@npm:^7.3.9": + version: 7.3.9 + resolution: "@metamask/message-manager@npm:7.3.9" dependencies: "@metamask/base-controller": "npm:^4.1.1" - "@metamask/controller-utils": "npm:^8.0.2" + "@metamask/controller-utils": "npm:^8.0.4" "@metamask/eth-sig-util": "npm:^7.0.1" "@metamask/utils": "npm:^8.3.0" "@types/uuid": "npm:^8.3.0" - ethereumjs-util: "npm:^7.0.10" jsonschema: "npm:^1.2.4" uuid: "npm:^8.3.2" - checksum: 0aa94422751e405b542af1f2b6a6f89aa61c991a9a9312b2a4d5a2bbb007aae84bda2dae2e084206003bbfe75f06bd170820d88c9a39492a0f8f0e9edcb4afe3 + checksum: 6df95c053b08b0a12fab994d4f47b07582a9d31a37c550d6a812b96e90365f46fb8d1077c0b4281ac4409731aeaee91a072bc69cc2b7bf6852144df1ab3dfe38 languageName: node linkType: hard @@ -4750,25 +4702,25 @@ __metadata: languageName: node linkType: hard -"@metamask/network-controller@npm:^17.0.0, @metamask/network-controller@npm:^17.1.0, @metamask/network-controller@npm:^17.2.0": - version: 17.2.0 - resolution: "@metamask/network-controller@npm:17.2.0" +"@metamask/network-controller@npm:^17.0.0, @metamask/network-controller@npm:^17.2.0, @metamask/network-controller@npm:^17.2.1": + version: 17.2.1 + resolution: "@metamask/network-controller@npm:17.2.1" dependencies: "@metamask/base-controller": "npm:^4.1.1" - "@metamask/controller-utils": "npm:^8.0.2" + "@metamask/controller-utils": "npm:^8.0.4" "@metamask/eth-json-rpc-infura": "npm:^9.0.0" - "@metamask/eth-json-rpc-middleware": "npm:^12.0.1" + "@metamask/eth-json-rpc-middleware": "npm:^12.1.0" "@metamask/eth-json-rpc-provider": "npm:^2.3.2" "@metamask/eth-query": "npm:^4.0.0" - "@metamask/json-rpc-engine": "npm:^7.3.2" - "@metamask/rpc-errors": "npm:^6.1.0" + "@metamask/json-rpc-engine": "npm:^7.3.3" + "@metamask/rpc-errors": "npm:^6.2.1" "@metamask/swappable-obj-proxy": "npm:^2.2.0" "@metamask/utils": "npm:^8.3.0" async-mutex: "npm:^0.2.6" eth-block-tracker: "npm:^8.0.0" immer: "npm:^9.0.6" uuid: "npm:^8.3.2" - checksum: 0fa7cf92cdcde5dba68e4d35d0f23c060d43f8da8062922aa2b468a9ab7bbd51a600b93c9f80091bbe0fbc760f263b7d8ddd3e5130662b55fc6d9b4974654285 + checksum: be3f6549756229033dafd5ac9c746607c757d5702d1ba76beb818ec7cb85805f975c38be822934694ddc6e285f9b28a1caadf2cbf88469b00262beedbff2b8e8 languageName: node linkType: hard @@ -4923,37 +4875,20 @@ __metadata: languageName: node linkType: hard -"@metamask/polling-controller@npm:^4.0.0": - version: 4.0.0 - resolution: "@metamask/polling-controller@npm:4.0.0" - dependencies: - "@metamask/base-controller": "npm:^4.0.1" - "@metamask/controller-utils": "npm:^8.0.1" - "@metamask/network-controller": "npm:^17.1.0" - "@metamask/utils": "npm:^8.2.0" - "@types/uuid": "npm:^8.3.0" - fast-json-stable-stringify: "npm:^2.1.0" - uuid: "npm:^8.3.2" - peerDependencies: - "@metamask/network-controller": ^17.1.0 - checksum: b309b3ea131b854f162f831ea48f87afee6787960ce44febbeefc980c5dcd84138d7b412ac317d8c65bf3e4bae7a2e8f2b70839185a9baf88d3b7d010c2ffe42 - languageName: node - linkType: hard - -"@metamask/polling-controller@npm:^5.0.0": - version: 5.0.0 - resolution: "@metamask/polling-controller@npm:5.0.0" +"@metamask/polling-controller@npm:^5.0.0, @metamask/polling-controller@npm:^5.0.1": + version: 5.0.1 + resolution: "@metamask/polling-controller@npm:5.0.1" dependencies: "@metamask/base-controller": "npm:^4.1.1" - "@metamask/controller-utils": "npm:^8.0.2" - "@metamask/network-controller": "npm:^17.2.0" + "@metamask/controller-utils": "npm:^8.0.4" + "@metamask/network-controller": "npm:^17.2.1" "@metamask/utils": "npm:^8.3.0" "@types/uuid": "npm:^8.3.0" fast-json-stable-stringify: "npm:^2.1.0" uuid: "npm:^8.3.2" peerDependencies: "@metamask/network-controller": ^17.2.0 - checksum: 78655074916c445594787e8573e10a992933477cf702aa458c28396b49dbcd13a60bfb1fac46f680819139f918eacff1f4c1e6386f5d74ceaa3715f8ee48d79f + checksum: 3b2a0bcc2aa83758f973364746aaf291fef3db1b1ef188813e522b7dd41967a57888d5d8150fe0fb0226d5d85631b5df4d72f4c879f9132948800753a91b752c languageName: node linkType: hard @@ -4994,13 +4929,15 @@ __metadata: languageName: node linkType: hard -"@metamask/preferences-controller@npm:^6.0.0": - version: 6.0.0 - resolution: "@metamask/preferences-controller@npm:6.0.0" +"@metamask/preferences-controller@npm:^8.0.0": + version: 8.0.0 + resolution: "@metamask/preferences-controller@npm:8.0.0" dependencies: - "@metamask/base-controller": "npm:^4.0.1" - "@metamask/controller-utils": "npm:^8.0.1" - checksum: 963df49ff9f79204586ee38873823d11d4c75587212e0a9c8c835f9fbdbbaeadebe34fe635d36b3e9cb3d3cf9f4ecf3ddc0fec6ec366284294b01b2420cde895 + "@metamask/base-controller": "npm:^4.1.1" + "@metamask/controller-utils": "npm:^8.0.4" + peerDependencies: + "@metamask/keyring-controller": ^13.0.0 + checksum: 40b5efc1c3ad2b5d6662a1989b9bf60c62bb9a6a681bf7dd9b3033f4a55b7cd03ce709110691843d70c6d03c220ab459562209c304c45b11ee581359e4cf1281 languageName: node linkType: hard @@ -8941,12 +8878,12 @@ __metadata: languageName: node linkType: hard -"@types/bn.js@npm:^5.1.0": - version: 5.1.1 - resolution: "@types/bn.js@npm:5.1.1" +"@types/bn.js@npm:^5.1.0, @types/bn.js@npm:^5.1.5": + version: 5.1.5 + resolution: "@types/bn.js@npm:5.1.5" dependencies: "@types/node": "npm:*" - checksum: cf2c45833e67ecfc45e5336151965a47857431640b61708b6e4dc81d88ed53585c9b30be59abbbee609cdf7a63828e5b8a58c1a27eb4306e5cb7ddd9bad46650 + checksum: 9719330c86aeae0a6a447c974cf0f853ba3660ede20de61f435b03d699e30e6d8b35bf71a8dc9fdc8317784438e83177644ba068ed653d0ae0106e1ecbfe289e languageName: node linkType: hard @@ -24725,17 +24662,17 @@ __metadata: "@metamask-institutional/sdk": "npm:^0.1.23" "@metamask-institutional/transaction-update": "npm:^0.1.32" "@metamask/abi-utils": "npm:^2.0.2" - "@metamask/accounts-controller": "patch:@metamask/accounts-controller@npm%3A10.0.0#~/.yarn/patches/@metamask-accounts-controller-npm-10.0.0-247993ca9a.patch" + "@metamask/accounts-controller": "npm:^11.0.0" "@metamask/address-book-controller": "npm:^3.0.0" "@metamask/announcement-controller": "npm:^5.0.1" "@metamask/approval-controller": "npm:^5.1.2" - "@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A24.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-24.0.0-dfef136464.patch" + "@metamask/assets-controllers": "npm:^26.0.0" "@metamask/auto-changelog": "npm:^2.1.0" "@metamask/base-controller": "npm:^4.1.0" "@metamask/browser-passworder": "npm:^4.3.0" "@metamask/build-utils": "npm:^1.0.0" "@metamask/contract-metadata": "npm:^2.3.1" - "@metamask/controller-utils": "npm:^8.0.1" + "@metamask/controller-utils": "npm:^8.0.4" "@metamask/design-tokens": "npm:^2.1.1" "@metamask/desktop": "npm:^0.3.0" "@metamask/ens-controller": "npm:^9.0.0" @@ -24761,7 +24698,7 @@ __metadata: "@metamask/gas-fee-controller": "npm:^13.0.0" "@metamask/jazzicon": "npm:^2.0.0" "@metamask/keyring-api": "npm:^3.0.0" - "@metamask/keyring-controller": "patch:@metamask/keyring-controller@npm%3A12.2.0#~/.yarn/patches/@metamask-keyring-controller-npm-12.2.0-2b196324d1.patch" + "@metamask/keyring-controller": "npm:^13.0.0" "@metamask/logging-controller": "npm:^2.0.2" "@metamask/logo": "npm:^3.1.2" "@metamask/message-manager": "npm:^7.3.0" @@ -24774,7 +24711,6 @@ __metadata: "@metamask/permission-log-controller": "npm:^1.0.0" "@metamask/phishing-controller": "npm:^8.0.0" "@metamask/phishing-warning": "npm:^3.0.3" - "@metamask/polling-controller": "npm:^4.0.0" "@metamask/post-message-stream": "npm:^8.0.0" "@metamask/ppom-validator": "npm:^0.27.0" "@metamask/providers": "npm:^14.0.2"