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 all commits
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 @@ -231,8 +231,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 @@ -56,8 +56,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 @@ -96,7 +96,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 @@ -112,14 +111,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 @@ -638,36 +633,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 @@ -173,7 +173,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 @@ -440,14 +440,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
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.linkssssss',
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 @@ -148,7 +148,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 @@ -752,7 +752,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
20 changes: 20 additions & 0 deletions ui/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,24 @@ describe('Selectors', () => {
mockState.metamask.snapsInstallPrivacyWarningShown = null;
expect(selectors.getSnapsInstallPrivacyWarningShown(mockState)).toBe(false);
});

it('#getInfuraBlocked', () => {
let isInfuraBlocked = selectors.getInfuraBlocked(mockState);
expect(isInfuraBlocked).toBe(false);

const modifiedMockState = {
...mockState,
metamask: {
...mockState.metamask,
networksMetadata: {
...mockState.metamask.networksMetadata,
goerli: {
status: 'blocked',
},
},
},
};
isInfuraBlocked = selectors.getInfuraBlocked(modifiedMockState);
expect(isInfuraBlocked).toBe(true);
});
});
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3029,12 +3029,12 @@ __metadata:
linkType: hard

"@jest/expect@npm:^29.1.2":
version: 29.6.2
resolution: "@jest/expect@npm:29.6.2"
version: 29.1.2
resolution: "@jest/expect@npm:29.1.2"
dependencies:
expect: "npm:^29.6.2"
jest-snapshot: "npm:^29.6.2"
checksum: 2beed96e3d24945a72aa2ae4843c99f4c631564569258fdde6746fae3efcbfbff96dbf92ed28d6531299bd12b2766075bacaaae88ebf84b99316e77151b43a9f
expect: "npm:^29.1.2"
jest-snapshot: "npm:^29.1.2"
checksum: 7bb80bf176f39becdbd2ef54be615c3e7010f3230ccc419f22c97fa5b66e0fa14bb6b05019840d01cd1892e42be8158bea4c94487f05da1dd2b85a4ac097dd15
languageName: node
linkType: hard

Expand Down Expand Up @@ -16720,7 +16720,7 @@ __metadata:
languageName: node
linkType: hard

"expect@npm:^29.0.0, expect@npm:^29.6.2":
"expect@npm:^29.0.0, expect@npm:^29.1.2, expect@npm:^29.6.2":
version: 29.6.2
resolution: "expect@npm:29.6.2"
dependencies:
Expand Down Expand Up @@ -21807,7 +21807,7 @@ __metadata:
languageName: node
linkType: hard

"jest-snapshot@npm:^29.1.2, jest-snapshot@npm:^29.6.2":
"jest-snapshot@npm:^29.1.2":
version: 29.6.2
resolution: "jest-snapshot@npm:29.6.2"
dependencies:
Expand Down
Loading