diff --git a/packages/selected-network-controller/package.json b/packages/selected-network-controller/package.json index c3a305d8fb..e2473295ac 100644 --- a/packages/selected-network-controller/package.json +++ b/packages/selected-network-controller/package.json @@ -34,7 +34,6 @@ "@metamask/base-controller": "^4.1.1", "@metamask/json-rpc-engine": "^7.3.2", "@metamask/network-controller": "^17.2.0", - "@metamask/permission-controller": "^8.0.0", "@metamask/swappable-obj-proxy": "^2.2.0", "@metamask/utils": "^8.3.0" }, @@ -53,8 +52,7 @@ "typescript": "~4.8.4" }, "peerDependencies": { - "@metamask/network-controller": "^17.2.0", - "@metamask/permission-controller": "^8.0.0" + "@metamask/network-controller": "^17.2.0" }, "engines": { "node": ">=16.0.0" diff --git a/packages/selected-network-controller/src/SelectedNetworkController.ts b/packages/selected-network-controller/src/SelectedNetworkController.ts index d8cabe0539..047265b75d 100644 --- a/packages/selected-network-controller/src/SelectedNetworkController.ts +++ b/packages/selected-network-controller/src/SelectedNetworkController.ts @@ -8,7 +8,6 @@ import type { NetworkControllerStateChangeEvent, ProviderProxy, } from '@metamask/network-controller'; -import type { HasPermissions } from '@metamask/permission-controller'; import { createEventEmitterProxy } from '@metamask/swappable-obj-proxy'; import type { Patch } from 'immer'; @@ -77,6 +76,11 @@ export type SelectedNetworkControllerSetNetworkClientIdForDomainAction = { handler: SelectedNetworkController['setNetworkClientIdForDomain']; }; +type PermissionControllerHasPermissions = { + type: `PermissionController:hasPermissions`; + handler: (domain: string) => boolean; +}; + export type SelectedNetworkControllerActions = | SelectedNetworkControllerGetSelectedNetworkStateAction | SelectedNetworkControllerGetNetworkClientIdForDomainAction @@ -86,7 +90,7 @@ export type SelectedNetworkControllerActions = export type AllowedActions = | NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction - | HasPermissions; + | PermissionControllerHasPermissions; export type SelectedNetworkControllerEvents = SelectedNetworkControllerStateChangeEvent; @@ -145,10 +149,7 @@ export class SelectedNetworkController extends BaseController< const { selectedNetworkClientId } = this.messagingSystem.call( 'NetworkController:getState', ); - this.setNetworkClientIdForDomain( - METAMASK_DOMAIN, - selectedNetworkClientId, - ); + this.setNetworkClientIdForMetamask(selectedNetworkClientId); } this.messagingSystem.subscribe( @@ -217,17 +218,15 @@ export class SelectedNetworkController extends BaseController< domain: Domain, networkClientId: NetworkClientId, ) { - // Early return if perDomainNetwork is disabled and the domain is not Metamask, unless it's setting for Metamask specifically if (domain !== METAMASK_DOMAIN && !this.state.perDomainNetwork) { return; } - // Check and, if not a metamask request, return early if the domain lacks permissions if (domain !== METAMASK_DOMAIN && !this.#domainHasPermissions(domain)) { return; } - // If setting for Metamask and perDomainNetwork is disabled, update all domains to the Metamask networkClientId + // If setting for Metamask and perDomainNetwork is disabled, update all domains to the Metamask networkClientId in order to keep the proxies in sync if (domain === METAMASK_DOMAIN && !this.state.perDomainNetwork) { Object.entries(this.state.domains).forEach( ([entryDomain, networkClientIdForDomain]) => { @@ -240,7 +239,7 @@ export class SelectedNetworkController extends BaseController< }, ); } - // Update the network client ID for the specified domain + this.#setNetworkClientIdForDomain(domain, networkClientId); } diff --git a/packages/selected-network-controller/tests/SelectedNetworkMiddleware.test.ts b/packages/selected-network-controller/tests/SelectedNetworkMiddleware.test.ts index efcdd64813..ece981ffa1 100644 --- a/packages/selected-network-controller/tests/SelectedNetworkMiddleware.test.ts +++ b/packages/selected-network-controller/tests/SelectedNetworkMiddleware.test.ts @@ -58,7 +58,7 @@ describe('createSelectedNetworkMiddleware', () => { expect(req.networkClientId).toBe('mockNetworkClientId'); }); - it('puts metamask selected networkClientId on request if requesting origin does not have one set', async () => { + it('puts metamask selected networkClientId on the request object if the requesting origin does not have one set', async () => { const messenger = buildMessenger(); const middleware = createSelectedNetworkMiddleware(messenger); diff --git a/yarn.lock b/yarn.lock index cb8dfe9747..fcc17862f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2412,7 +2412,26 @@ __metadata: languageName: node linkType: hard -"@metamask/permission-controller@^8.0.0, @metamask/permission-controller@workspace:packages/permission-controller": +"@metamask/permission-controller@npm:^7.0.0, @metamask/permission-controller@npm:^7.1.0": + version: 7.1.0 + resolution: "@metamask/permission-controller@npm:7.1.0" + dependencies: + "@metamask/base-controller": ^4.0.1 + "@metamask/controller-utils": ^8.0.1 + "@metamask/json-rpc-engine": ^7.3.1 + "@metamask/rpc-errors": ^6.1.0 + "@metamask/utils": ^8.2.0 + "@types/deep-freeze-strict": ^1.1.0 + deep-freeze-strict: ^1.1.1 + immer: ^9.0.6 + nanoid: ^3.1.31 + peerDependencies: + "@metamask/approval-controller": ^5.1.1 + checksum: 889213cca32cbf5b32b7e71c70ded0aeea32eae169ec67fb0d0bc8dcaa183b222f9d5417f657e331d7fb21ecb71f250cf1c932110d4b1e2167972b30bd012098 + languageName: node + linkType: hard + +"@metamask/permission-controller@workspace:packages/permission-controller": version: 0.0.0-use.local resolution: "@metamask/permission-controller@workspace:packages/permission-controller" dependencies: @@ -2439,25 +2458,6 @@ __metadata: languageName: unknown linkType: soft -"@metamask/permission-controller@npm:^7.0.0, @metamask/permission-controller@npm:^7.1.0": - version: 7.1.0 - resolution: "@metamask/permission-controller@npm:7.1.0" - dependencies: - "@metamask/base-controller": ^4.0.1 - "@metamask/controller-utils": ^8.0.1 - "@metamask/json-rpc-engine": ^7.3.1 - "@metamask/rpc-errors": ^6.1.0 - "@metamask/utils": ^8.2.0 - "@types/deep-freeze-strict": ^1.1.0 - deep-freeze-strict: ^1.1.1 - immer: ^9.0.6 - nanoid: ^3.1.31 - peerDependencies: - "@metamask/approval-controller": ^5.1.1 - checksum: 889213cca32cbf5b32b7e71c70ded0aeea32eae169ec67fb0d0bc8dcaa183b222f9d5417f657e331d7fb21ecb71f250cf1c932110d4b1e2167972b30bd012098 - languageName: node - linkType: hard - "@metamask/permission-log-controller@workspace:packages/permission-log-controller": version: 0.0.0-use.local resolution: "@metamask/permission-log-controller@workspace:packages/permission-log-controller" @@ -2668,7 +2668,6 @@ __metadata: "@metamask/base-controller": ^4.1.1 "@metamask/json-rpc-engine": ^7.3.2 "@metamask/network-controller": ^17.2.0 - "@metamask/permission-controller": ^8.0.0 "@metamask/swappable-obj-proxy": ^2.2.0 "@metamask/utils": ^8.3.0 "@types/jest": ^27.4.1 @@ -2684,7 +2683,6 @@ __metadata: typescript: ~4.8.4 peerDependencies: "@metamask/network-controller": ^17.2.0 - "@metamask/permission-controller": ^8.0.0 languageName: unknown linkType: soft