-
Notifications
You must be signed in to change notification settings - Fork 542
/
index.ts
30 lines (29 loc) · 924 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { OnRpcRequestHandler } from '@metamask/snaps-types';
import { getMessage } from './message';
/**
* Handle incoming JSON-RPC requests, sent through `wallet_invokeSnap`.
*
* @param args - The request handler args as object.
* @param args.origin - The origin of the request, e.g., the website that
* invoked the snap.
* @param args.request - A validated JSON-RPC request object.
* @returns `null` if the request succeeded.
* @throws If the request method is not valid for this snap.
* @throws If the `snap_notify` call failed.
*/
export const onRpcRequest: OnRpcRequestHandler = ({ origin, request }) => {
switch (request.method) {
case 'hello':
return snaps.request({
method: 'snap_notify',
params: [
{
type: 'inapp',
message: getMessage(origin),
},
],
});
default:
throw new Error('Method not found.');
}
};