diff --git a/packages/snaps-controllers/coverage.json b/packages/snaps-controllers/coverage.json index 495584a15f..dfab807b4a 100644 --- a/packages/snaps-controllers/coverage.json +++ b/packages/snaps-controllers/coverage.json @@ -1,5 +1,5 @@ { - "branches": 93.38, + "branches": 93.41, "functions": 97.38, "lines": 98.34, "statements": 98.07 diff --git a/packages/snaps-controllers/src/multichain/MultichainRouter.test.ts b/packages/snaps-controllers/src/multichain/MultichainRouter.test.ts index f2fb279fcf..ec3d155d89 100644 --- a/packages/snaps-controllers/src/multichain/MultichainRouter.test.ts +++ b/packages/snaps-controllers/src/multichain/MultichainRouter.test.ts @@ -399,6 +399,15 @@ describe('MultichainRouter', () => { withSnapKeyring, }); + rootMessenger.registerActionHandler('SnapController:getAll', () => { + return [getTruncatedSnap()]; + }); + + rootMessenger.registerActionHandler( + 'PermissionController:getPermissions', + () => ({}), + ); + rootMessenger.registerActionHandler( 'AccountsController:listMultichainAccounts', () => MOCK_SOLANA_ACCOUNTS, @@ -409,7 +418,37 @@ describe('MultichainRouter', () => { ).toBe(true); }); - it('returns false if no account Snap is found', async () => { + it('returns true if a protocol Snap exists', async () => { + const rootMessenger = getRootMultichainRouterMessenger(); + const messenger = getRestrictedMultichainRouterMessenger(rootMessenger); + const withSnapKeyring = getMockWithSnapKeyring(); + + /* eslint-disable-next-line no-new */ + new MultichainRouter({ + messenger, + withSnapKeyring, + }); + + rootMessenger.registerActionHandler('SnapController:getAll', () => { + return [getTruncatedSnap()]; + }); + + rootMessenger.registerActionHandler( + 'PermissionController:getPermissions', + () => MOCK_SOLANA_SNAP_PERMISSIONS, + ); + + rootMessenger.registerActionHandler( + 'AccountsController:listMultichainAccounts', + () => [], + ); + + expect( + messenger.call('MultichainRouter:isSupportedScope', SOLANA_CAIP2), + ).toBe(true); + }); + + it('returns false if no Snap is found', async () => { const rootMessenger = getRootMultichainRouterMessenger(); const messenger = getRestrictedMultichainRouterMessenger(rootMessenger); const withSnapKeyring = getMockWithSnapKeyring(); @@ -420,6 +459,10 @@ describe('MultichainRouter', () => { withSnapKeyring, }); + rootMessenger.registerActionHandler('SnapController:getAll', () => { + return []; + }); + rootMessenger.registerActionHandler( 'AccountsController:listMultichainAccounts', () => [], diff --git a/packages/snaps-controllers/src/multichain/MultichainRouter.ts b/packages/snaps-controllers/src/multichain/MultichainRouter.ts index cd3136f71c..16b24210fa 100644 --- a/packages/snaps-controllers/src/multichain/MultichainRouter.ts +++ b/packages/snaps-controllers/src/multichain/MultichainRouter.ts @@ -397,9 +397,10 @@ export class MultichainRouter { * @returns True if the router can service the scope, otherwise false. */ isSupportedScope(scope: CaipChainId): boolean { - // We currently assume here that if one Snap exists that service the scope, we can service the scope generally. - return this.#messenger + const hasAccountSnap = this.#messenger .call('AccountsController:listMultichainAccounts', scope) .some((account: InternalAccount) => account.metadata.snap?.enabled); + // We currently assume here that if one Snap exists that service the scope, we can service the scope generally. + return hasAccountSnap || this.#getProtocolSnaps(scope).length > 0; } }