Skip to content

Commit

Permalink
Update error message and add assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Jan 29, 2025
1 parent 33cca72 commit 8202773
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 93.26,
"branches": 93.28,
"functions": 96.79,
"lines": 98.14,
"statements": 97.87
"lines": 98.15,
"statements": 97.88
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ describe('MultichainRouter', () => {
},
},
}),
).rejects.toThrow('Invalid method parameter(s)');
).rejects.toThrow('No available account found for request.');
});
});

Expand Down
9 changes: 7 additions & 2 deletions packages/snaps-controllers/src/multichain/MultichainRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
CaipChainId,
JsonRpcParams,
} from '@metamask/utils';
import { hasProperty, parseCaipAccountId } from '@metamask/utils';
import { assert, hasProperty, parseCaipAccountId } from '@metamask/utils';

import { getRunnableSnaps } from '../snaps';
import type { GetAllSnaps, HandleSnapRequest } from '../snaps';
Expand Down Expand Up @@ -225,7 +225,9 @@ export class MultichainRouter {
);

if (!selectedAccount) {
throw rpcErrors.invalidParams();
throw rpcErrors.invalidParams({
message: 'No available account found for request.',
});
}

return selectedAccount.id;
Expand Down Expand Up @@ -288,6 +290,9 @@ export class MultichainRouter {
scope: CaipChainId;
request: JsonRpcRequest;
}): Promise<unknown> {
// Explicitly block EVM scopes, just in case.
assert(!scope.startsWith('eip155') && !scope.startsWith('wallet:eip155'));

const { method, params } = request;

// If the RPC request can be serviced by an account Snap, route it there.
Expand Down

0 comments on commit 8202773

Please sign in to comment.