Skip to content

Commit e5ac26f

Browse files
committed
Update example
1 parent 5ba5018 commit e5ac26f

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

packages/examples/packages/lifecycle-hooks/snap.manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "hTwghLmR+2f8zwjEcFujq/ojCDoMnQRcYBPMJ73IqGE=",
10+
"shasum": "/Wc+1sY2V4NwgUxQT81/nquwTBDsw2vdNEkkYd8g+0Q=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",
@@ -18,6 +18,7 @@
1818
},
1919
"initialPermissions": {
2020
"snap_dialog": {},
21+
"snap_notify": {},
2122
"endowment:lifecycle-hooks": {}
2223
},
2324
"platformVersion": "9.2.0",

packages/examples/packages/lifecycle-hooks/src/index.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
OnActiveHandler,
23
OnInstallHandler,
34
OnStartHandler,
45
OnUpdateHandler,
@@ -85,3 +86,43 @@ export const onUpdate: OnUpdateHandler = async () => {
8586
},
8687
});
8788
};
89+
90+
/**
91+
* Handle activation of the client. This handler is called when the client is
92+
* activated, and can be used to perform any initialization that is required.
93+
*
94+
* This handler is optional.
95+
*
96+
* @see https://docs.metamask.io/snaps/reference/entry-points/#onactive
97+
* @returns The JSON-RPC response.
98+
*/
99+
export const onActive: OnActiveHandler = async () => {
100+
return await snap.request({
101+
method: 'snap_notify',
102+
params: {
103+
type: 'inApp',
104+
message:
105+
'The client was activated, and the "onActive" handler was called.',
106+
},
107+
});
108+
};
109+
110+
/**
111+
* Handle deactivation of the client. This handler is called when the client
112+
* is deactivated, and can be used to perform any cleanup that is required.
113+
*
114+
* This handler is optional.
115+
*
116+
* @see https://docs.metamask.io/snaps/reference/entry-points/#oninactive
117+
* @returns The JSON-RPC response.
118+
*/
119+
export const onInactive = async () => {
120+
return await snap.request({
121+
method: 'snap_notify',
122+
params: {
123+
type: 'inApp',
124+
message:
125+
'The client was deactivated, and the "onInactive" handler was called.',
126+
},
127+
});
128+
};

0 commit comments

Comments
 (0)