Skip to content

Commit d63fc21

Browse files
fix: Consider protocol Snaps when determining isSupportedScope
1 parent eb408a3 commit d63fc21

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

packages/snaps-controllers/coverage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"branches": 93.34,
2+
"branches": 93.36,
33
"functions": 97.37,
44
"lines": 98.33,
55
"statements": 98.07

packages/snaps-controllers/src/multichain/MultichainRouter.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ describe('MultichainRouter', () => {
399399
withSnapKeyring,
400400
});
401401

402+
rootMessenger.registerActionHandler('SnapController:getAll', () => {
403+
return [getTruncatedSnap()];
404+
});
405+
406+
rootMessenger.registerActionHandler(
407+
'PermissionController:getPermissions',
408+
() => ({}),
409+
);
410+
402411
rootMessenger.registerActionHandler(
403412
'AccountsController:listMultichainAccounts',
404413
() => MOCK_SOLANA_ACCOUNTS,
@@ -409,7 +418,37 @@ describe('MultichainRouter', () => {
409418
).toBe(true);
410419
});
411420

412-
it('returns false if no account Snap is found', async () => {
421+
it('returns true if a protocol Snap exists', async () => {
422+
const rootMessenger = getRootMultichainRouterMessenger();
423+
const messenger = getRestrictedMultichainRouterMessenger(rootMessenger);
424+
const withSnapKeyring = getMockWithSnapKeyring();
425+
426+
/* eslint-disable-next-line no-new */
427+
new MultichainRouter({
428+
messenger,
429+
withSnapKeyring,
430+
});
431+
432+
rootMessenger.registerActionHandler('SnapController:getAll', () => {
433+
return [getTruncatedSnap()];
434+
});
435+
436+
rootMessenger.registerActionHandler(
437+
'PermissionController:getPermissions',
438+
() => MOCK_SOLANA_SNAP_PERMISSIONS,
439+
);
440+
441+
rootMessenger.registerActionHandler(
442+
'AccountsController:listMultichainAccounts',
443+
() => [],
444+
);
445+
446+
expect(
447+
messenger.call('MultichainRouter:isSupportedScope', SOLANA_CAIP2),
448+
).toBe(true);
449+
});
450+
451+
it('returns false if no Snap is found', async () => {
413452
const rootMessenger = getRootMultichainRouterMessenger();
414453
const messenger = getRestrictedMultichainRouterMessenger(rootMessenger);
415454
const withSnapKeyring = getMockWithSnapKeyring();
@@ -420,6 +459,10 @@ describe('MultichainRouter', () => {
420459
withSnapKeyring,
421460
});
422461

462+
rootMessenger.registerActionHandler('SnapController:getAll', () => {
463+
return [];
464+
});
465+
423466
rootMessenger.registerActionHandler(
424467
'AccountsController:listMultichainAccounts',
425468
() => [],

packages/snaps-controllers/src/multichain/MultichainRouter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,11 @@ export class MultichainRouter {
397397
* @returns True if the router can service the scope, otherwise false.
398398
*/
399399
isSupportedScope(scope: CaipChainId): boolean {
400-
// We currently assume here that if one Snap exists that service the scope, we can service the scope generally.
401-
return this.#messenger
400+
const hasAccountSnap = this.#messenger
402401
.call('AccountsController:listMultichainAccounts', scope)
403402
.some((account: InternalAccount) => account.metadata.snap?.enabled);
403+
const hasProtocolSnap = this.#getProtocolSnaps(scope).length > 0;
404+
// We currently assume here that if one Snap exists that service the scope, we can service the scope generally.
405+
return hasAccountSnap || hasProtocolSnap;
404406
}
405407
}

0 commit comments

Comments
 (0)