Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get infuraBlocked from network state #20822

Merged
merged 20 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
692f461
remove infuraBlocked from preferences controller and infer from netwo…
jiexi Sep 11, 2023
baefdb0
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 18, 2023
bdca488
lavamoat
jiexi Sep 18, 2023
3f5fb87
Dedupe. Lavamoat
jiexi Sep 18, 2023
f9064cb
Lint
jiexi Sep 18, 2023
f0e8e6e
Update LavaMoat policies
metamaskbot Sep 18, 2023
cd7d8e6
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 19, 2023
ff6ede4
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 20, 2023
2d13a1d
add getInfuraBlocked selector spec
jiexi Sep 20, 2023
5158d01
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 21, 2023
d9a9103
Bring in networkcontroller bump
jiexi Sep 21, 2023
f6a8325
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 21, 2023
888a247
Update LavaMoat policies
metamaskbot Sep 21, 2023
3b998b6
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 21, 2023
dc5436a
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 21, 2023
0b5aaf7
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 22, 2023
647694d
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 22, 2023
623a52e
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 22, 2023
aef5ebb
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 22, 2023
14a02e1
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
jiexi Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,6 @@ const state = {
lostIdentities: {},
forgottenPassword: false,
ipfsGateway: 'dweb.link',
infuraBlocked: false,
migratedPrivacyMode: false,
selectedAddress: '0x9d0ba4ddac06032527b140912ec808ab9451b788',
metaMetricsId:
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/controllers/detect-tokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ describe('DetectTokensController', function () {
network,
provider,
tokenListController,
onInfuraIsBlocked: sinon.stub(),
onInfuraIsUnblocked: sinon.stub(),
networkConfigurations: {},
onAccountRemoved: sinon.stub(),
});
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/controllers/mmi-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ describe('MMIController', function () {
}),
preferencesController: new PreferencesController({
initState: {},
onInfuraIsBlocked: jest.fn(),
onInfuraIsUnblocked: jest.fn(),
onAccountRemoved: jest.fn(),
provider: {},
networkConfigurations: {},
Expand Down
35 changes: 0 additions & 35 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));

Expand Down Expand Up @@ -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
*/
Expand Down
6 changes: 0 additions & 6 deletions app/scripts/controllers/preferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -120,8 +118,6 @@ describe('preferences controller', () => {
preferencesController = new PreferencesController({
initLangCode: 'en_US',
tokenListController,
onInfuraIsBlocked: jest.fn(),
onInfuraIsUnblocked: jest.fn(),
initState: {
identities: {
[testAddress]: {
Expand Down Expand Up @@ -150,8 +146,6 @@ describe('preferences controller', () => {
preferencesController = new PreferencesController({
initLangCode: 'en_US',
tokenListController,
onInfuraIsBlocked: jest.fn(),
onInfuraIsUnblocked: jest.fn(),
initState: {
identities: {
'0x7e57e2': {
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/backup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ const jsonData = JSON.stringify({
useNativeCurrencyAsPrimaryCurrency: true,
},
ipfsGateway: 'dweb.link',
infuraBlocked: false,
ledgerTransportType: 'webhid',
theme: 'light',
customNetworkListEnabled: false,
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export const SENTRY_BACKGROUND_STATE = {
forgottenPassword: true,
identities: false,
incomingTransactionsPreferences: true,
infuraBlocked: true,
ipfsGateway: false,
isLineaMainnetReleased: true,
knownMethodData: false,
Expand Down
8 changes: 0 additions & 8 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"audit": "yarn npm audit --recursive --environment production --severity moderate"
},
"resolutions": {
"@metamask/network-controller@^12.0.0": "npm:@metamask-previews/[email protected]",
jiexi marked this conversation as resolved.
Show resolved Hide resolved
"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",
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ function defaultFixture() {
name: 'Account 1',
},
},
infuraBlocked: false,
ipfsGateway: 'dweb.link',
knownMethodData: {},
ledgerTransportType: 'webhid',
Expand Down Expand Up @@ -382,7 +381,6 @@ function onboardingFixture() {
featureFlags: {},
forgottenPassword: false,
identities: {},
infuraBlocked: false,
ipfsGateway: 'dweb.link',
knownMethodData: {},
ledgerTransportType: 'webhid',
Expand Down
1 change: 0 additions & 1 deletion test/e2e/restore/MetaMaskUserData.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"ticker": "ETH"
}
],
"infuraBlocked": false,
"ipfsGateway": "dweb.link",
"knownMethodData": {},
"ledgerTransportType": "webhid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
},
"ipfsGateway": "string",
"useAddressBarEnsResolution": true,
"infuraBlocked": false,
"ledgerTransportType": "webhid",
"snapRegistryList": "object",
"transactionSecurityCheckEnabled": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"forgottenPassword": false,
"ipfsGateway": "string",
"useAddressBarEnsResolution": true,
"infuraBlocked": false,
"ledgerTransportType": "webhid",
"snapRegistryList": "object",
"transactionSecurityCheckEnabled": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"featureFlags": {},
"forgottenPassword": false,
"identities": "object",
"infuraBlocked": false,
"ipfsGateway": "string",
"knownMethodData": "object",
"ledgerTransportType": "webhid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"featureFlags": {},
"forgottenPassword": false,
"identities": "object",
"infuraBlocked": false,
"ipfsGateway": "string",
"knownMethodData": "object",
"ledgerTransportType": "webhid",
Expand Down
5 changes: 4 additions & 1 deletion ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
jiexi marked this conversation as resolved.
Show resolved Hide resolved
);
}

export function getUSDConversionRate(state) {
Expand Down
59 changes: 38 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
Loading