Skip to content

Commit df0e3ef

Browse files
committed
feat: add lifecycle hooks permission for local development and refactor onInstall handler
1 parent e34723f commit df0e3ef

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

packages/gator-permissions-snap/snap.manifest.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import type { SnapManifest } from '@metamask/7715-permissions-shared/types';
55

66
const kernelSnapId = process.env.KERNEL_SNAP_ID;
7+
const snapEnv = process.env.SNAP_ENV;
78

89
const manifest: SnapManifest = {
910
version: '0.2.1',
@@ -33,13 +34,17 @@ const manifest: SnapManifest = {
3334
'endowment:ethereum-provider': {},
3435
'endowment:network-access': {},
3536
snap_dialog: {},
36-
'endowment:lifecycle-hooks': {},
3737
snap_getPreferences: {},
3838
},
3939
platformVersion: '8.1.0',
4040
manifestVersion: '0.1',
4141
};
4242

43+
// Only include lifecycle hooks permission in local development
44+
if (snapEnv === 'local') {
45+
manifest.initialPermissions['endowment:lifecycle-hooks'] = {};
46+
}
47+
4348
if (kernelSnapId) {
4449
manifest.initialConnections = {
4550
[kernelSnapId]: {},

packages/gator-permissions-snap/src/index.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,29 +220,35 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
220220
export const onUserInput: OnUserInputHandler =
221221
userEventDispatcher.createUserInputEventHandler();
222222

223-
export const onInstall: OnInstallHandler = async () => {
224-
/**
225-
* Local Development Only
226-
*
227-
* The message signing snap must be installed and the gator permissions snap must
228-
* have permission to communicate with the message signing snap, or the request is rejected.
229-
*
230-
* Since the message signing snap is preinstalled in production, and has
231-
* initialConnections configured to automatically connect to the gator snap, this is not needed in production.
232-
*/
233-
// eslint-disable-next-line no-restricted-globals
234-
if (snapEnv === 'local' && isStorePermissionsFeatureEnabled) {
235-
const installedSnaps = (await snap.request({
236-
method: 'wallet_getSnaps',
237-
})) as unknown as GetSnapsResponse;
238-
if (!installedSnaps[messageSigningSnapId]) {
239-
logger.debug('Installing local message signing snap');
240-
await snap.request({
241-
method: 'wallet_requestSnaps',
242-
params: {
243-
[messageSigningSnapId]: {},
244-
},
245-
});
223+
/**
224+
* Local Development Only
225+
*
226+
* The message signing snap must be installed and the gator permissions snap must
227+
* have permission to communicate with the message signing snap, or the request is rejected.
228+
*
229+
* Since the message signing snap is preinstalled in production, and has
230+
* initialConnections configured to automatically connect to the gator snap, this is not needed in production.
231+
*/
232+
// eslint-disable-next-line no-restricted-globals
233+
if (snapEnv === 'local') {
234+
const installHandler: OnInstallHandler = async () => {
235+
if (isStorePermissionsFeatureEnabled) {
236+
const installedSnaps = (await snap.request({
237+
method: 'wallet_getSnaps',
238+
})) as unknown as GetSnapsResponse;
239+
if (!installedSnaps[messageSigningSnapId]) {
240+
logger.debug('Installing local message signing snap');
241+
await snap.request({
242+
method: 'wallet_requestSnaps',
243+
params: {
244+
[messageSigningSnapId]: {},
245+
},
246+
});
247+
}
246248
}
247-
}
248-
};
249+
};
250+
251+
// Export onInstall for local development only
252+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
253+
(globalThis as any).onInstall = installHandler;
254+
}

0 commit comments

Comments
 (0)