Skip to content

Commit

Permalink
addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Feb 19, 2024
1 parent 6fdee42 commit ecb5e72
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
4 changes: 1 addition & 3 deletions packages/selected-network-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -77,6 +76,11 @@ export type SelectedNetworkControllerSetNetworkClientIdForDomainAction = {
handler: SelectedNetworkController['setNetworkClientIdForDomain'];
};

type PermissionControllerHasPermissions = {
type: `PermissionController:hasPermissions`;
handler: (domain: string) => boolean;
};

export type SelectedNetworkControllerActions =
| SelectedNetworkControllerGetSelectedNetworkStateAction
| SelectedNetworkControllerGetNetworkClientIdForDomainAction
Expand All @@ -86,7 +90,7 @@ export type SelectedNetworkControllerActions =
export type AllowedActions =
| NetworkControllerGetNetworkClientByIdAction
| NetworkControllerGetStateAction
| HasPermissions;
| PermissionControllerHasPermissions;

export type SelectedNetworkControllerEvents =
SelectedNetworkControllerStateChangeEvent;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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]) => {
Expand All @@ -240,7 +239,7 @@ export class SelectedNetworkController extends BaseController<
},
);
}
// Update the network client ID for the specified domain

this.#setNetworkClientIdForDomain(domain, networkClientId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
42 changes: 20 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit ecb5e72

Please sign in to comment.