From 692f46115b15f2636353bcccd252c4aea8bc4834 Mon Sep 17 00:00:00 2001 From: Jiexi Luan Date: Mon, 11 Sep 2023 13:43:58 -0700 Subject: [PATCH] remove infuraBlocked from preferences controller and infer from network state instead --- .storybook/test-data.js | 1 - app/scripts/controllers/detect-tokens.test.js | 2 - .../controllers/mmi-controller.test.js | 2 - app/scripts/controllers/preferences.js | 35 ----------- app/scripts/controllers/preferences.test.js | 6 -- app/scripts/lib/backup.test.js | 1 - app/scripts/lib/setupSentry.js | 1 - app/scripts/metamask-controller.js | 8 --- package.json | 1 + test/e2e/fixture-builder.js | 2 - test/e2e/restore/MetaMaskUserData.json | 1 - ...rs-after-init-opt-in-background-state.json | 1 - .../errors-after-init-opt-in-ui-state.json | 1 - ...s-before-init-opt-in-background-state.json | 1 - .../errors-before-init-opt-in-ui-state.json | 1 - ui/selectors/selectors.js | 5 +- yarn.lock | 59 ++++++++++++------- 17 files changed, 43 insertions(+), 85 deletions(-) diff --git a/.storybook/test-data.js b/.storybook/test-data.js index 7acce27bc431..353064992c42 100644 --- a/.storybook/test-data.js +++ b/.storybook/test-data.js @@ -1137,7 +1137,6 @@ const state = { lostIdentities: {}, forgottenPassword: false, ipfsGateway: 'dweb.link', - infuraBlocked: false, migratedPrivacyMode: false, selectedAddress: '0x9d0ba4ddac06032527b140912ec808ab9451b788', metaMetricsId: diff --git a/app/scripts/controllers/detect-tokens.test.js b/app/scripts/controllers/detect-tokens.test.js index 8d1c182c249e..ba2e49b183d7 100644 --- a/app/scripts/controllers/detect-tokens.test.js +++ b/app/scripts/controllers/detect-tokens.test.js @@ -223,8 +223,6 @@ describe('DetectTokensController', function () { network, provider, tokenListController, - onInfuraIsBlocked: sinon.stub(), - onInfuraIsUnblocked: sinon.stub(), networkConfigurations: {}, onAccountRemoved: sinon.stub(), }); diff --git a/app/scripts/controllers/mmi-controller.test.js b/app/scripts/controllers/mmi-controller.test.js index e4b26dd62f5b..605af0d5bb57 100644 --- a/app/scripts/controllers/mmi-controller.test.js +++ b/app/scripts/controllers/mmi-controller.test.js @@ -50,8 +50,6 @@ describe('MMIController', function () { }), preferencesController: new PreferencesController({ initState: {}, - onInfuraIsBlocked: jest.fn(), - onInfuraIsUnblocked: jest.fn(), onAccountRemoved: jest.fn(), provider: {}, networkConfigurations: {}, diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 5c1f169834ab..3b6edebc9372 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -93,7 +93,6 @@ export default class PreferencesController { // ENS decentralized website resolution ipfsGateway: IPFS_DEFAULT_GATEWAY_URL, useAddressBarEnsResolution: true, - infuraBlocked: null, ledgerTransportType: window.navigator.hid ? LedgerTransportTypes.webhid : LedgerTransportTypes.u2f, @@ -109,14 +108,10 @@ export default class PreferencesController { this.network = opts.network; - this._onInfuraIsBlocked = opts.onInfuraIsBlocked; - this._onInfuraIsUnblocked = opts.onInfuraIsUnblocked; this.store = new ObservableStore(initState); this.store.setMaxListeners(13); this.tokenListController = opts.tokenListController; - this._subscribeToInfuraAvailability(); - // subscribe to account removal opts.onAccountRemoved((address) => this.removeAddress(address)); @@ -621,36 +616,6 @@ export default class PreferencesController { ///: END:ONLY_INCLUDE_IN - // - // PRIVATE METHODS - // - - _subscribeToInfuraAvailability() { - this._onInfuraIsBlocked(() => { - this._setInfuraBlocked(true); - }); - - this._onInfuraIsUnblocked(() => { - this._setInfuraBlocked(false); - }); - } - - /** - * - * A setter for the `infuraBlocked` property - * - * @param {boolean} isBlocked - Bool indicating whether Infura is blocked - */ - _setInfuraBlocked(isBlocked) { - const { infuraBlocked } = this.store.getState(); - - if (infuraBlocked === isBlocked) { - return; - } - - this.store.updateState({ infuraBlocked: isBlocked }); - } - /** * A method to check is the linea mainnet network should be displayed */ diff --git a/app/scripts/controllers/preferences.test.js b/app/scripts/controllers/preferences.test.js index de312b7e0fa3..0ae29fba084a 100644 --- a/app/scripts/controllers/preferences.test.js +++ b/app/scripts/controllers/preferences.test.js @@ -40,8 +40,6 @@ describe('preferences controller', () => { preferencesController = new PreferencesController({ initLangCode: 'en_US', tokenListController, - onInfuraIsBlocked: jest.fn(), - onInfuraIsUnblocked: jest.fn(), onAccountRemoved: jest.fn(), networkConfigurations: NETWORK_CONFIGURATION_DATA, }); @@ -120,8 +118,6 @@ describe('preferences controller', () => { preferencesController = new PreferencesController({ initLangCode: 'en_US', tokenListController, - onInfuraIsBlocked: jest.fn(), - onInfuraIsUnblocked: jest.fn(), initState: { identities: { [testAddress]: { @@ -150,8 +146,6 @@ describe('preferences controller', () => { preferencesController = new PreferencesController({ initLangCode: 'en_US', tokenListController, - onInfuraIsBlocked: jest.fn(), - onInfuraIsUnblocked: jest.fn(), initState: { identities: { '0x7e57e2': { diff --git a/app/scripts/lib/backup.test.js b/app/scripts/lib/backup.test.js index 93aee74bddd7..f2d2336d792f 100644 --- a/app/scripts/lib/backup.test.js +++ b/app/scripts/lib/backup.test.js @@ -142,7 +142,6 @@ const jsonData = JSON.stringify({ useNativeCurrencyAsPrimaryCurrency: true, }, ipfsGateway: 'dweb.link', - infuraBlocked: false, ledgerTransportType: 'webhid', theme: 'light', customNetworkListEnabled: false, diff --git a/app/scripts/lib/setupSentry.js b/app/scripts/lib/setupSentry.js index edc7925e2220..b7f475d50913 100644 --- a/app/scripts/lib/setupSentry.js +++ b/app/scripts/lib/setupSentry.js @@ -170,7 +170,6 @@ export const SENTRY_BACKGROUND_STATE = { forgottenPassword: true, identities: false, incomingTransactionsPreferences: true, - infuraBlocked: true, ipfsGateway: false, isLineaMainnetReleased: true, knownMethodData: false, diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 52fc263aa53e..ca299993d70f 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -404,14 +404,6 @@ export default class MetamaskController extends EventEmitter { this.preferencesController = new PreferencesController({ initState: initState.PreferencesController, initLangCode: opts.initLangCode, - onInfuraIsBlocked: networkControllerMessenger.subscribe.bind( - networkControllerMessenger, - 'NetworkController:infuraIsBlocked', - ), - onInfuraIsUnblocked: networkControllerMessenger.subscribe.bind( - networkControllerMessenger, - 'NetworkController:infuraIsUnblocked', - ), onAccountRemoved: this.controllerMessenger.subscribe.bind( this.controllerMessenger, 'KeyringController:accountRemoved', diff --git a/package.json b/package.json index 604b5a03e123..56c0762ad134 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,7 @@ "audit": "yarn npm audit --recursive --environment production --severity moderate" }, "resolutions": { + "@metamask/network-controller@^12.0.0": "npm:@metamask-previews/network-controller@12.1.2-preview.0f6a2fb", "simple-update-notifier@^1.0.0": "^2.0.0", "@babel/core": "patch:@babel/core@npm%3A7.21.5#./.yarn/patches/@babel-core-npm-7.21.5-c72c337956.patch", "@babel/runtime": "patch:@babel/runtime@npm%3A7.18.9#./.yarn/patches/@babel-runtime-npm-7.18.9-28ca6b5f61.patch", diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index 61db5bfc3e2e..1d6b8bb2f356 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -259,7 +259,6 @@ function defaultFixture() { name: 'Account 1', }, }, - infuraBlocked: false, ipfsGateway: 'dweb.link', knownMethodData: {}, ledgerTransportType: 'webhid', @@ -382,7 +381,6 @@ function onboardingFixture() { featureFlags: {}, forgottenPassword: false, identities: {}, - infuraBlocked: false, ipfsGateway: 'dweb.link', knownMethodData: {}, ledgerTransportType: 'webhid', diff --git a/test/e2e/restore/MetaMaskUserData.json b/test/e2e/restore/MetaMaskUserData.json index 5215b9620011..250b3cb3e852 100644 --- a/test/e2e/restore/MetaMaskUserData.json +++ b/test/e2e/restore/MetaMaskUserData.json @@ -27,7 +27,6 @@ "ticker": "ETH" } ], - "infuraBlocked": false, "ipfsGateway": "dweb.link", "knownMethodData": {}, "ledgerTransportType": "webhid", diff --git a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json index a522a1b11f93..a30d484914a3 100644 --- a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json @@ -145,7 +145,6 @@ }, "ipfsGateway": "string", "useAddressBarEnsResolution": true, - "infuraBlocked": false, "ledgerTransportType": "webhid", "snapRegistryList": "object", "transactionSecurityCheckEnabled": false, diff --git a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json index aad4be321658..960f57c2bbea 100644 --- a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -96,7 +96,6 @@ "forgottenPassword": false, "ipfsGateway": "string", "useAddressBarEnsResolution": true, - "infuraBlocked": false, "ledgerTransportType": "webhid", "snapRegistryList": "object", "transactionSecurityCheckEnabled": false, diff --git a/test/e2e/tests/state-snapshots/errors-before-init-opt-in-background-state.json b/test/e2e/tests/state-snapshots/errors-before-init-opt-in-background-state.json index 98f21ebd506a..75bd62d27908 100644 --- a/test/e2e/tests/state-snapshots/errors-before-init-opt-in-background-state.json +++ b/test/e2e/tests/state-snapshots/errors-before-init-opt-in-background-state.json @@ -80,7 +80,6 @@ "featureFlags": {}, "forgottenPassword": false, "identities": "object", - "infuraBlocked": false, "ipfsGateway": "string", "knownMethodData": "object", "ledgerTransportType": "webhid", diff --git a/test/e2e/tests/state-snapshots/errors-before-init-opt-in-ui-state.json b/test/e2e/tests/state-snapshots/errors-before-init-opt-in-ui-state.json index bf25106ca50b..5fa13c429985 100644 --- a/test/e2e/tests/state-snapshots/errors-before-init-opt-in-ui-state.json +++ b/test/e2e/tests/state-snapshots/errors-before-init-opt-in-ui-state.json @@ -80,7 +80,6 @@ "featureFlags": {}, "forgottenPassword": false, "identities": "object", - "infuraBlocked": false, "ipfsGateway": "string", "knownMethodData": "object", "ledgerTransportType": "webhid", diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 4d77bcec8858..be6b565a79b2 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -750,7 +750,10 @@ export function getIpfsGateway(state) { } export function getInfuraBlocked(state) { - return Boolean(state.metamask.infuraBlocked); + return ( + state.metamask.networksMetadata[getSelectedNetworkClientId(state)].status === + NetworkStatus.Blocked + ); } export function getUSDConversionRate(state) { diff --git a/yarn.lock b/yarn.lock index 90c1ddcaa2fb..1d78eca4f486 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3894,7 +3894,7 @@ __metadata: languageName: node linkType: hard -"@metamask/controller-utils@npm:^4.0.0, @metamask/controller-utils@npm:^4.0.1, @metamask/controller-utils@npm:^4.1.0, @metamask/controller-utils@npm:^4.2.0, @metamask/controller-utils@npm:^4.3.0, @metamask/controller-utils@npm:^4.3.1, @metamask/controller-utils@npm:^4.3.2": +"@metamask/controller-utils@npm:^4.0.0, @metamask/controller-utils@npm:^4.0.1, @metamask/controller-utils@npm:^4.1.0, @metamask/controller-utils@npm:^4.2.0, @metamask/controller-utils@npm:^4.3.0, @metamask/controller-utils@npm:^4.3.2": version: 4.3.2 resolution: "@metamask/controller-utils@npm:4.3.2" dependencies: @@ -4037,6 +4037,23 @@ __metadata: languageName: node linkType: hard +"@metamask/eth-json-rpc-middleware@npm:^11.0.2": + version: 11.0.2 + resolution: "@metamask/eth-json-rpc-middleware@npm:11.0.2" + dependencies: + "@metamask/eth-json-rpc-provider": "npm:^1.0.0" + "@metamask/eth-sig-util": "npm:^6.0.0" + "@metamask/utils": "npm:^5.0.1" + clone: "npm:^2.1.1" + eth-block-tracker: "npm:^7.0.1" + eth-rpc-errors: "npm:^4.0.3" + json-rpc-engine: "npm:^6.1.0" + pify: "npm:^3.0.0" + safe-stable-stringify: "npm:^2.3.2" + checksum: 188d98dce78f85fc6364ea78b6f7e14a95cdcf0791a187177a1da8e79b8588d1b08141110b570239d92afeb021c08432d5f10948f4bba983acd1665a013b8a2c + languageName: node + linkType: hard + "@metamask/eth-json-rpc-provider@npm:^1.0.0": version: 1.0.0 resolution: "@metamask/eth-json-rpc-provider@npm:1.0.0" @@ -4358,48 +4375,48 @@ __metadata: languageName: node linkType: hard -"@metamask/network-controller@npm:^10.2.0, @metamask/network-controller@npm:^10.3.0": - version: 10.3.1 - resolution: "@metamask/network-controller@npm:10.3.1" +"@metamask/network-controller@npm:@metamask-previews/network-controller@12.1.2-preview.0f6a2fb": + version: 12.1.2-preview.0f6a2fb + resolution: "@metamask-previews/network-controller@npm:12.1.2-preview.0f6a2fb" dependencies: - "@metamask/base-controller": "npm:^3.1.0" - "@metamask/controller-utils": "npm:^4.2.0" - "@metamask/eth-json-rpc-infura": "npm:^8.1.0" - "@metamask/eth-json-rpc-middleware": "npm:^11.0.0" + "@metamask/base-controller": "npm:^3.2.1" + "@metamask/controller-utils": "npm:^4.3.2" + "@metamask/eth-json-rpc-infura": "npm:^8.1.1" + "@metamask/eth-json-rpc-middleware": "npm:^11.0.2" "@metamask/eth-json-rpc-provider": "npm:^1.0.0" + "@metamask/eth-query": "npm:^3.0.1" "@metamask/swappable-obj-proxy": "npm:^2.1.0" - "@metamask/utils": "npm:^5.0.2" + "@metamask/utils": "npm:^6.2.0" async-mutex: "npm:^0.2.6" - babel-runtime: "npm:^6.26.0" eth-block-tracker: "npm:^7.0.1" - eth-query: "npm:^2.1.2" eth-rpc-errors: "npm:^4.0.2" immer: "npm:^9.0.6" json-rpc-engine: "npm:^6.1.0" uuid: "npm:^8.3.2" - checksum: 48b30bee12f90ca5e818dd99d3e164b4330368498e6388cc1044141be2f70eea28b2a85310bacb176d1c12027e2d8c996effa3902238aff75e6c20e31351740d + checksum: 94148d653df2ce9ba7467a074db029e559efca0cb701f674a511550fdd2f4c67cc2cb074d364bf6504ee7808459404a56cec023ca4cdfe04237b90a355d5cfeb languageName: node linkType: hard -"@metamask/network-controller@npm:^12.0.0": - version: 12.0.0 - resolution: "@metamask/network-controller@npm:12.0.0" +"@metamask/network-controller@npm:^10.2.0, @metamask/network-controller@npm:^10.3.0": + version: 10.3.1 + resolution: "@metamask/network-controller@npm:10.3.1" dependencies: - "@metamask/base-controller": "npm:^3.2.0" - "@metamask/controller-utils": "npm:^4.3.1" - "@metamask/eth-json-rpc-infura": "npm:^8.1.1" + "@metamask/base-controller": "npm:^3.1.0" + "@metamask/controller-utils": "npm:^4.2.0" + "@metamask/eth-json-rpc-infura": "npm:^8.1.0" "@metamask/eth-json-rpc-middleware": "npm:^11.0.0" "@metamask/eth-json-rpc-provider": "npm:^1.0.0" - "@metamask/eth-query": "npm:^3.0.1" "@metamask/swappable-obj-proxy": "npm:^2.1.0" - "@metamask/utils": "npm:^6.2.0" + "@metamask/utils": "npm:^5.0.2" async-mutex: "npm:^0.2.6" + babel-runtime: "npm:^6.26.0" eth-block-tracker: "npm:^7.0.1" + eth-query: "npm:^2.1.2" eth-rpc-errors: "npm:^4.0.2" immer: "npm:^9.0.6" json-rpc-engine: "npm:^6.1.0" uuid: "npm:^8.3.2" - checksum: ea7c8010f1ca80c448050c7cf618598a1dabe82969fe1ff4a4952b85b3e4db677adab88d99a146cb11461d899628d3914f71e1b22d4249ccc5787a0281839afd + checksum: 48b30bee12f90ca5e818dd99d3e164b4330368498e6388cc1044141be2f70eea28b2a85310bacb176d1c12027e2d8c996effa3902238aff75e6c20e31351740d languageName: node linkType: hard