From c7108fd60404066fa0a46f0066a512e3a39626ab Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Fri, 29 Nov 2024 20:42:13 +0100 Subject: [PATCH 1/2] chore: bump @metamsk/network-controller to 21.0.1 --- .storybook/main.js | 13 +++++++ ...ork-controller-npm-21.0.0-559aa8e395.patch | 33 ---------------- ...ork-controller-npm-21.0.1-55b6d471c0.patch | 35 +++++++++++++++++ package.json | 8 ++-- ui/__mocks__/eth-block-tracker.js | 6 +++ ui/__mocks__/eth-json-rpc-infura.js | 6 +++ ui/__mocks__/eth-json-rpc-middleware.js | 6 +++ ui/__mocks__/swappable-obj-proxy.js | 6 +++ yarn.lock | 38 +++++++++---------- 9 files changed, 95 insertions(+), 56 deletions(-) delete mode 100644 .yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch create mode 100644 .yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch create mode 100644 ui/__mocks__/eth-block-tracker.js create mode 100644 ui/__mocks__/eth-json-rpc-infura.js create mode 100644 ui/__mocks__/eth-json-rpc-middleware.js create mode 100644 ui/__mocks__/swappable-obj-proxy.js diff --git a/.storybook/main.js b/.storybook/main.js index 2b4384250c9c..76c498a05959 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -62,6 +62,19 @@ module.exports = { config.resolve.alias['./useNftCollectionsMetadata'] = require.resolve( '../ui/__mocks__/useNftCollectionsMetadata.js', ); + // Import within network-controller crashes storybook. + config.resolve.alias['@metamask/eth-block-tracker'] = require.resolve( + '../ui/__mocks__/eth-block-tracker.js', + ); + config.resolve.alias['@metamask/eth-json-rpc-infura'] = require.resolve( + '../ui/__mocks__/eth-json-rpc-infura.js', + ); + config.resolve.alias['@metamask/eth-json-rpc-middleware'] = require.resolve( + '../ui/__mocks__/eth-json-rpc-middleware.js', + ); + config.resolve.alias['@metamask/swappable-obj-proxy'] = require.resolve( + '../ui/__mocks__/swappable-obj-proxy.js', + ); config.resolve.fallback = { child_process: false, constants: false, diff --git a/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch b/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch deleted file mode 100644 index 5719ae0284f7..000000000000 --- a/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch +++ /dev/null @@ -1,33 +0,0 @@ -diff --git a/PATCH.txt b/PATCH.txt -new file mode 100644 -index 0000000000000000000000000000000000000000..78b9156dc2b0bf7c33dadf325cb3ec0bfae71ccb ---- /dev/null -+++ b/PATCH.txt -@@ -0,0 +1,3 @@ -+We remove `lookupNetwork` from `initializeProvider` in the network controller to prevent network requests before user onboarding is completed. -+The network lookup is done after onboarding is completed, and when the extension reloads if onboarding has been completed. -+This patch is part of a temporary fix that will be reverted soon to make way for a more permanent solution. https://github.com/MetaMask/metamask-extension/pull/23005 -diff --git a/dist/chunk-BV3ZGWII.mjs b/dist/chunk-BV3ZGWII.mjs -index 0d1bf3b6348ad4ec7a799083fcadf36f9fc74851..48a09c6e474da9c18115bec88130a88888337044 100644 ---- a/dist/chunk-BV3ZGWII.mjs -+++ b/dist/chunk-BV3ZGWII.mjs -@@ -468,7 +468,6 @@ var NetworkController = class extends BaseController { - */ - async initializeProvider() { - __privateMethod(this, _applyNetworkSelection, applyNetworkSelection_fn).call(this, this.state.selectedNetworkClientId); -- await this.lookupNetwork(); - } - /** - * Refreshes the network meta with EIP-1559 support and the network status -diff --git a/dist/chunk-YOHMQPGM.js b/dist/chunk-YOHMQPGM.js -index ff15cd78ef90b35f86aae9dc64d17d1d2efe352d..14a8bba39c204585164dfb252d0a183844a58d63 100644 ---- a/dist/chunk-YOHMQPGM.js -+++ b/dist/chunk-YOHMQPGM.js -@@ -468,7 +468,6 @@ var NetworkController = class extends _basecontroller.BaseController { - */ - async initializeProvider() { - _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _applyNetworkSelection, applyNetworkSelection_fn).call(this, this.state.selectedNetworkClientId); -- await this.lookupNetwork(); - } - /** - * Refreshes the network meta with EIP-1559 support and the network status diff --git a/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch b/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch new file mode 100644 index 000000000000..bebf56fe73dd --- /dev/null +++ b/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch @@ -0,0 +1,35 @@ +diff --git a/PATCH.txt b/PATCH.txt +new file mode 100644 +index 0000000000000000000000000000000000000000..ce3b18534f055ee00aa5821793f855fd300fb72c +--- /dev/null ++++ b/PATCH.txt +@@ -0,0 +1,4 @@ ++We remove lookupNetwork from initializeProvider in the network controller to prevent network requests before user onboarding is completed. ++The network lookup is done after onboarding is completed, and when the extension reloads if onboarding has been completed. ++This patch is part of a temporary fix that will be reverted soon to make way for a more permanent solution. https://github.com/MetaMask/metamask-extension/pull/23005 ++You can see the changes before compilation on this branch: https://github.com/MetaMask/core/compare/pnf/ext-23622-review?expand=1 +\ No newline at end of file +diff --git a/dist/NetworkController.cjs b/dist/NetworkController.cjs +index b85de6f29620feecf6f1e395f3d25c96fb10f204..68c894de3975ab917e8320b5937b19a9b3ddd4ca 100644 +--- a/dist/NetworkController.cjs ++++ b/dist/NetworkController.cjs +@@ -408,7 +408,6 @@ class NetworkController extends base_controller_1.BaseController { + */ + async initializeProvider() { + __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, this.state.selectedNetworkClientId); +- await this.lookupNetwork(); + } + /** + * Refreshes the network meta with EIP-1559 support and the network status +diff --git a/dist/NetworkController.mjs b/dist/NetworkController.mjs +index 966da694324513857dc6766590a4c965dedc2e3d..eb2fe95f9d77fa781d2bce97b7007d4676a3bede 100644 +--- a/dist/NetworkController.mjs ++++ b/dist/NetworkController.mjs +@@ -383,7 +383,6 @@ export class NetworkController extends BaseController { + */ + async initializeProvider() { + __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, this.state.selectedNetworkClientId); +- await this.lookupNetwork(); + } + /** + * Refreshes the network meta with EIP-1559 support and the network status diff --git a/package.json b/package.json index 803853059703..d7d50d87e675 100644 --- a/package.json +++ b/package.json @@ -241,9 +241,9 @@ "@expo/config-plugins/glob": "^10.3.10", "@solana/web3.js/rpc-websockets": "^8.0.1", "@metamask/nonce-tracker@npm:^5.0.0": "patch:@metamask/nonce-tracker@npm%3A5.0.0#~/.yarn/patches/@metamask-nonce-tracker-npm-5.0.0-d81478218e.patch", - "@metamask/network-controller@npm:^17.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", - "@metamask/network-controller@npm:^19.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", - "@metamask/network-controller@npm:^20.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", + "@metamask/network-controller@npm:^17.0.0": "patch:@metamask/network-controller@npm%3A21.0.1#~/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch", + "@metamask/network-controller@npm:^19.0.0": "patch:@metamask/network-controller@npm%3A21.0.1#~/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch", + "@metamask/network-controller@npm:^20.0.0": "patch:@metamask/network-controller@npm%3A21.0.1#~/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch", "path-to-regexp": "1.9.0", "@ledgerhq/cryptoassets-evm-signatures/axios": "^0.28.0", "@ledgerhq/domain-service/axios": "^0.28.0", @@ -320,7 +320,7 @@ "@metamask/message-signing-snap": "^0.4.0", "@metamask/metamask-eth-abis": "^3.1.1", "@metamask/name-controller": "^8.0.0", - "@metamask/network-controller": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", + "@metamask/network-controller": "patch:@metamask/network-controller@npm%3A21.0.1#~/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch", "@metamask/notification-services-controller": "^0.14.0", "@metamask/object-multiplex": "^2.0.0", "@metamask/obs-store": "^9.0.0", diff --git a/ui/__mocks__/eth-block-tracker.js b/ui/__mocks__/eth-block-tracker.js new file mode 100644 index 000000000000..3a85f921310d --- /dev/null +++ b/ui/__mocks__/eth-block-tracker.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line import/no-extraneous-dependencies, node/no-extraneous-require +const ethBlockTracker = require('@metamask/eth-block-tracker'); + +module.exports = { + ...ethBlockTracker, +}; diff --git a/ui/__mocks__/eth-json-rpc-infura.js b/ui/__mocks__/eth-json-rpc-infura.js new file mode 100644 index 000000000000..f396c6a9d9c2 --- /dev/null +++ b/ui/__mocks__/eth-json-rpc-infura.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line import/no-extraneous-dependencies, node/no-extraneous-require +const ethJsonRpcInfura = require('@metamask/eth-json-rpc-infura'); + +module.exports = { + ...ethJsonRpcInfura, +}; diff --git a/ui/__mocks__/eth-json-rpc-middleware.js b/ui/__mocks__/eth-json-rpc-middleware.js new file mode 100644 index 000000000000..590e08751720 --- /dev/null +++ b/ui/__mocks__/eth-json-rpc-middleware.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line import/no-extraneous-dependencies, node/no-extraneous-require +const ethJsonRpcMiddleware = require('@metamask/eth-json-rpc-middleware'); + +module.exports = { + ...ethJsonRpcMiddleware, +}; diff --git a/ui/__mocks__/swappable-obj-proxy.js b/ui/__mocks__/swappable-obj-proxy.js new file mode 100644 index 000000000000..665dd132829a --- /dev/null +++ b/ui/__mocks__/swappable-obj-proxy.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line import/no-extraneous-dependencies, node/no-extraneous-require +const swappablObjProxy = require('@metamask/swappable-obj-proxy'); + +module.exports = { + ...swappablObjProxy, +}; diff --git a/yarn.lock b/yarn.lock index c88156929c17..e60633459aca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5299,7 +5299,7 @@ __metadata: languageName: node linkType: hard -"@metamask/eth-json-rpc-provider@npm:^4.0.0, @metamask/eth-json-rpc-provider@npm:^4.1.3, @metamask/eth-json-rpc-provider@npm:^4.1.5, @metamask/eth-json-rpc-provider@npm:^4.1.6": +"@metamask/eth-json-rpc-provider@npm:^4.0.0, @metamask/eth-json-rpc-provider@npm:^4.1.4, @metamask/eth-json-rpc-provider@npm:^4.1.5, @metamask/eth-json-rpc-provider@npm:^4.1.6": version: 4.1.6 resolution: "@metamask/eth-json-rpc-provider@npm:4.1.6" dependencies: @@ -5612,7 +5612,7 @@ __metadata: languageName: node linkType: hard -"@metamask/json-rpc-engine@npm:^9.0.0, @metamask/json-rpc-engine@npm:^9.0.2, @metamask/json-rpc-engine@npm:^9.0.3": +"@metamask/json-rpc-engine@npm:^9.0.0, @metamask/json-rpc-engine@npm:^9.0.3": version: 9.0.3 resolution: "@metamask/json-rpc-engine@npm:9.0.3" dependencies: @@ -5789,18 +5789,18 @@ __metadata: languageName: node linkType: hard -"@metamask/network-controller@npm:21.0.0": - version: 21.0.0 - resolution: "@metamask/network-controller@npm:21.0.0" +"@metamask/network-controller@npm:21.0.1": + version: 21.0.1 + resolution: "@metamask/network-controller@npm:21.0.1" dependencies: - "@metamask/base-controller": "npm:^7.0.0" - "@metamask/controller-utils": "npm:^11.2.0" + "@metamask/base-controller": "npm:^7.0.1" + "@metamask/controller-utils": "npm:^11.3.0" "@metamask/eth-block-tracker": "npm:^10.0.0" "@metamask/eth-json-rpc-infura": "npm:^9.1.0" "@metamask/eth-json-rpc-middleware": "npm:^13.0.0" - "@metamask/eth-json-rpc-provider": "npm:^4.1.3" + "@metamask/eth-json-rpc-provider": "npm:^4.1.4" "@metamask/eth-query": "npm:^4.0.0" - "@metamask/json-rpc-engine": "npm:^9.0.2" + "@metamask/json-rpc-engine": "npm:^9.0.3" "@metamask/rpc-errors": "npm:^6.3.1" "@metamask/swappable-obj-proxy": "npm:^2.2.0" "@metamask/utils": "npm:^9.1.0" @@ -5810,7 +5810,7 @@ __metadata: reselect: "npm:^5.1.1" uri-js: "npm:^4.4.1" uuid: "npm:^8.3.2" - checksum: 10/b44804720a7338a89edfc4e82c5652d429f6e3589de4fe1ebbba921d1d9af6c82a78c79591c0c8a6cb9b4439dbd77ede5b6aa8a72d24996ccedd8a7854fc7d46 + checksum: 10/cff5359167d902226e6dc4bdde3ee751a641ef2c4d82f0c3b04378057d5eb03f75295116875613d4bd9448bd29d21984c73b69350401b9062b25f0b1a46cfdb8 languageName: node linkType: hard @@ -5839,18 +5839,18 @@ __metadata: languageName: node linkType: hard -"@metamask/network-controller@patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch": - version: 21.0.0 - resolution: "@metamask/network-controller@patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch::version=21.0.0&hash=1a5039" +"@metamask/network-controller@patch:@metamask/network-controller@npm%3A21.0.1#~/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch": + version: 21.0.1 + resolution: "@metamask/network-controller@patch:@metamask/network-controller@npm%3A21.0.1#~/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch::version=21.0.1&hash=5eb093" dependencies: - "@metamask/base-controller": "npm:^7.0.0" - "@metamask/controller-utils": "npm:^11.2.0" + "@metamask/base-controller": "npm:^7.0.1" + "@metamask/controller-utils": "npm:^11.3.0" "@metamask/eth-block-tracker": "npm:^10.0.0" "@metamask/eth-json-rpc-infura": "npm:^9.1.0" "@metamask/eth-json-rpc-middleware": "npm:^13.0.0" - "@metamask/eth-json-rpc-provider": "npm:^4.1.3" + "@metamask/eth-json-rpc-provider": "npm:^4.1.4" "@metamask/eth-query": "npm:^4.0.0" - "@metamask/json-rpc-engine": "npm:^9.0.2" + "@metamask/json-rpc-engine": "npm:^9.0.3" "@metamask/rpc-errors": "npm:^6.3.1" "@metamask/swappable-obj-proxy": "npm:^2.2.0" "@metamask/utils": "npm:^9.1.0" @@ -5860,7 +5860,7 @@ __metadata: reselect: "npm:^5.1.1" uri-js: "npm:^4.4.1" uuid: "npm:^8.3.2" - checksum: 10/6c3fdf78360df8bf39a0045f7d5e6d0b7fd8984eaee7a3348bd688ee2740669c654803790dbf2429f8559b69d88101de0add0cc76e5c42661cf2eec14b263cb0 + checksum: 10/9b2cae1c5d3f78d4795b9dce9ec57d9cb332a5b3d2fff3a087deccef39366158b7ce54fa74cfa5486a76df54aa3465402f389f47173ffdfb3f596b44d04d61c1 languageName: node linkType: hard @@ -26535,7 +26535,7 @@ __metadata: "@metamask/message-signing-snap": "npm:^0.4.0" "@metamask/metamask-eth-abis": "npm:^3.1.1" "@metamask/name-controller": "npm:^8.0.0" - "@metamask/network-controller": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch" + "@metamask/network-controller": "patch:@metamask/network-controller@npm%3A21.0.1#~/.yarn/patches/@metamask-network-controller-npm-21.0.1-55b6d471c0.patch" "@metamask/notification-services-controller": "npm:^0.14.0" "@metamask/object-multiplex": "npm:^2.0.0" "@metamask/obs-store": "npm:^9.0.0" From ec5cd0bac505c41b3c39413b51c4a8fb9f048bf8 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Fri, 29 Nov 2024 20:54:37 +0100 Subject: [PATCH 2/2] fix: add storybook only packages to depcheckrc.yml --- .depcheckrc.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.depcheckrc.yml b/.depcheckrc.yml index 5260be984692..28b9e0c99c3b 100644 --- a/.depcheckrc.yml +++ b/.depcheckrc.yml @@ -82,6 +82,10 @@ ignores: - '@testing-library/dom' - 'mini-css-extract-plugin' - 'webpack-cli' + # Used only in storybook (ui/__mocks__/) + - '@metamask/eth-block-tracker' + - '@metamask/eth-json-rpc-infura' + - '@metamask/swappable-obj-proxy' # files depcheck should not parse ignorePatterns: