-
Notifications
You must be signed in to change notification settings - Fork 542
/
index.js
38 lines (38 loc) · 1.08 KB
/
index.js
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
31
32
33
34
35
36
37
38
/**
* Handle incoming JSON-RPC requests, sent through `wallet_invokeSnap`.
*
* @param {object} args - The request handler args as object.
* @param {string} args.origin - The origin of the request, e.g., the website
* that invoked the snap.
* @param {JsonRpcRequest<unknown[] | Record<string, unknown>>} args.request - A
* validated JSON-RPC request object.
* @returns {boolean} `null` if the request succeeded.
* @throws If the request method is not valid for this snap.
* @throws If the `snap_notify` call failed.
*/
module.exports.onRpcRequest = async ({ origin, request }) => {
switch (request.method) {
case 'inApp':
return snaps.request({
method: 'snap_notify',
params: [
{
type: 'inApp',
message: `Hello, ${origin}!`,
},
],
});
case 'native':
return snaps.request({
method: 'snap_notify',
params: [
{
type: 'native',
message: `Hello, ${origin}!`,
},
],
});
default:
throw new Error('Method not found.');
}
};