Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"branches": 93.38,
"branches": 93.41,
"functions": 97.38,
"lines": 98.34,
"statements": 98.07
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ describe('MultichainRouter', () => {
withSnapKeyring,
});

rootMessenger.registerActionHandler('SnapController:getAll', () => {
return [getTruncatedSnap()];
});

rootMessenger.registerActionHandler(
'PermissionController:getPermissions',
() => ({}),
);

rootMessenger.registerActionHandler(
'AccountsController:listMultichainAccounts',
() => MOCK_SOLANA_ACCOUNTS,
Expand All @@ -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();
Expand All @@ -420,6 +459,10 @@ describe('MultichainRouter', () => {
withSnapKeyring,
});

rootMessenger.registerActionHandler('SnapController:getAll', () => {
return [];
});

rootMessenger.registerActionHandler(
'AccountsController:listMultichainAccounts',
() => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ 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);
const hasProtocolSnap = this.#getProtocolSnaps(scope).length > 0;
// We currently assume here that if one Snap exists that service the scope, we can service the scope generally.
return hasAccountSnap || hasProtocolSnap;
}
}
Loading