Skip to content

Commit 2fcfd55

Browse files
authored
Merge pull request #164 from MetaMask/fix/remove-endowment-lifecycle-hooks
Remove endowment lifecycle hooks
2 parents 6a1fa93 + 5f997f1 commit 2fcfd55

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const manifest: SnapManifest = {
3333
'endowment:ethereum-provider': {},
3434
'endowment:network-access': {},
3535
snap_dialog: {},
36-
'endowment:lifecycle-hooks': {},
3736
snap_getPreferences: {},
3837
},
3938
platformVersion: '8.1.0',

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

Lines changed: 0 additions & 29 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,
@@ -225,30 +223,3 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
225223
*/
226224
export const onUserInput: OnUserInputHandler =
227225
userEventDispatcher.createUserInputEventHandler();
228-
229-
export const onInstall: OnInstallHandler = async () => {
230-
/**
231-
* Local Development Only
232-
*
233-
* The message signing snap must be installed and the gator permissions snap must
234-
* have permission to communicate with the message signing snap, or the request is rejected.
235-
*
236-
* Since the message signing snap is preinstalled in production, and has
237-
* initialConnections configured to automatically connect to the gator snap, this is not needed in production.
238-
*/
239-
// eslint-disable-next-line no-restricted-globals
240-
if (snapEnv === 'local' && isStorePermissionsFeatureEnabled) {
241-
const installedSnaps = (await snap.request({
242-
method: 'wallet_getSnaps',
243-
})) as unknown as GetSnapsResponse;
244-
if (!installedSnaps[messageSigningSnapId]) {
245-
logger.debug('Installing local message signing snap');
246-
await snap.request({
247-
method: 'wallet_requestSnaps',
248-
params: {
249-
[messageSigningSnapId]: {},
250-
},
251-
});
252-
}
253-
}
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)