Skip to content

Commit 5f997f1

Browse files
committed
feat: remove local development hooks and add InstallButton component
1 parent df0e3ef commit 5f997f1

File tree

4 files changed

+44
-47
lines changed

4 files changed

+44
-47
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
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;
87

98
const manifest: SnapManifest = {
109
version: '0.2.1',
@@ -40,11 +39,6 @@ const manifest: SnapManifest = {
4039
manifestVersion: '0.1',
4140
};
4241

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

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-restricted-globals */
2-
import type { GetSnapsResponse } from '@metamask/7715-permissions-shared/types';
32
import { logger } from '@metamask/7715-permissions-shared/utils';
43
import {
54
AuthType,
@@ -8,7 +7,6 @@ import {
87
UserStorage,
98
} from '@metamask/profile-sync-controller/sdk';
109
import {
11-
type OnInstallHandler,
1210
type Json,
1311
type JsonRpcParams,
1412
type OnRpcRequestHandler,
@@ -219,36 +217,3 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
219217
*/
220218
export const onUserInput: OnUserInputHandler =
221219
userEventDispatcher.createUserInputEventHandler();
222-
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-
}
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-
}

packages/site/src/components/Buttons.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ export const ConnectButton = (
9494
);
9595
};
9696

97+
export const InstallButton = (
98+
props: ComponentProps<typeof Button> & { $isInstalled?: boolean },
99+
) => {
100+
return (
101+
<Button {...props}>
102+
<FlaskFox />
103+
<ButtonText>{props.$isInstalled ? 'Installed' : 'Install'}</ButtonText>
104+
</Button>
105+
);
106+
};
107+
97108
export const CustomMessageButton = (
98109
props: ComponentProps<typeof Button> & { $text?: string },
99110
) => {

packages/site/src/pages/index.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as chains from 'viem/chains';
1818

1919
import {
2020
ConnectButton,
21+
InstallButton,
2122
InstallFlaskButton,
2223
CustomMessageButton,
2324
Card,
@@ -29,6 +30,11 @@ import {
2930
NativeTokenPeriodicForm,
3031
ERC20TokenPeriodicForm,
3132
} from '../components/permissions';
33+
import {
34+
kernelSnapOrigin,
35+
gatorSnapOrigin,
36+
messageSigningSnapOrigin,
37+
} from '../config';
3238
import {
3339
Container,
3440
Heading,
@@ -41,7 +47,6 @@ import {
4147
ResponseContainer,
4248
CopyButton,
4349
} from '../styles';
44-
import { kernelSnapOrigin, gatorSnapOrigin } from '../config';
4550
import {
4651
useMetaMask,
4752
useMetaMaskContext,
@@ -97,6 +102,8 @@ const Index = () => {
97102
const { isFlask, snapsDetected, installedSnaps, provider } = useMetaMask();
98103
const requestKernelSnap = useRequestSnap(kernelSnapOrigin);
99104
const requestPermissionSnap = useRequestSnap(gatorSnapOrigin);
105+
const requestMessageSigningSnap = useRequestSnap(messageSigningSnapOrigin);
106+
100107
const { delegateAccount } = useDelegateAccount({ chain: selectedChain });
101108
const { bundlerClient, getFeePerGas } = useBundlerClient({
102109
chain: selectedChain,
@@ -124,6 +131,9 @@ const Index = () => {
124131

125132
const isKernelSnapReady = Boolean(installedSnaps[kernelSnapOrigin]);
126133
const isGatorSnapReady = Boolean(installedSnaps[gatorSnapOrigin]);
134+
const isMessageSigningSnapReady = Boolean(
135+
installedSnaps[messageSigningSnapOrigin],
136+
);
127137

128138
const chainId = selectedChain.id;
129139
const [permissionType, setPermissionType] = useState('native-token-stream');
@@ -175,13 +185,13 @@ const Index = () => {
175185
if (!delegateAccount) {
176186
throw new Error('Delegate account not found');
177187
}
178-
188+
179189
// Generate a unique identifier for this redemption request
180190
const requestId = `redeem-${Date.now()}-${Math.random()}`;
181-
191+
182192
// Add this request to pending requests
183193
setPendingPermissionRequests(prev => new Set(prev).add(requestId));
184-
194+
185195
setReceipt(null);
186196
setPermissionResponseError(null);
187197

@@ -267,10 +277,10 @@ const Index = () => {
267277

268278
// Generate a unique identifier for this permission request
269279
const requestId = `${type}-${Date.now()}-${Math.random()}`;
270-
280+
271281
// Add this request to pending requests
272282
setPendingPermissionRequests(prev => new Set(prev).add(requestId));
273-
283+
274284
setPermissionResponse(null);
275285
setReceipt(null);
276286
setPermissionResponseError(null);
@@ -497,6 +507,23 @@ const Index = () => {
497507
/>
498508
)}
499509

510+
<Card
511+
content={{
512+
title: 'Message Signing Snap',
513+
description:
514+
'Set up by installing and authorizing the message signing snap.',
515+
button: (
516+
<InstallButton
517+
onClick={requestMessageSigningSnap}
518+
disabled={!isMetaMaskReady || isMessageSigningSnapReady}
519+
$isInstalled={isMessageSigningSnapReady}
520+
/>
521+
),
522+
}}
523+
fullWidth
524+
disabled={!isMetaMaskReady}
525+
/>
526+
500527
<Card
501528
content={{
502529
title: `${isKernelSnapReady ? 'Reconnect' : 'Connect'}(kernel)`,

0 commit comments

Comments
 (0)