Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ export class SelectedNetworkController extends BaseController<
);
}

// Snaps should be excluded from the domain state
// npm and local are currently the only valid prefixes for snap domains
// https://github.com/MetaMask/snaps/blob/2beee7803bfe9e540788a3558b546b9f55dc3cb4/packages/snaps-utils/src/types.ts#L120
if (domain.startsWith('npm:') || domain.startsWith('local:')) {
return;
}

if (!this.#domainHasPermissions(domain)) {
throw new Error(
'NetworkClientId for domain cannot be called with a domain that has not yet been granted permissions',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,34 @@ describe('SelectedNetworkController', () => {
});

describe('when the useRequestQueue is true', () => {
describe('when the requesting domain is a snap (starts with "npm:" or "local:"', () => {
it('skips setting the networkClientId for the passed in domain', () => {
const { controller, mockHasPermissions } = setup({
state: { domains: {} },
useRequestQueuePreference: true,
});
mockHasPermissions.mockReturnValue(true);
const snapDomainOne = 'npm:@metamask/bip32-example-snap';
const snapDomainTwo = 'local:@metamask/bip32-example-snap';
const nonSnapDomain = 'example.com';
const networkClientId = 'network1';
controller.setNetworkClientIdForDomain(
nonSnapDomain,
networkClientId,
);
controller.setNetworkClientIdForDomain(
snapDomainOne,
networkClientId,
);
controller.setNetworkClientIdForDomain(
snapDomainTwo,
networkClientId,
);
expect(controller.state.domains).toStrictEqual({
[nonSnapDomain]: networkClientId,
});
});
});
describe('when the requesting domain has existing permissions', () => {
it('sets the networkClientId for the passed in domain', () => {
const { controller, mockHasPermissions } = setup({
Expand Down