Skip to content

Commit 9d7db6a

Browse files
committed
chore: fix onboarding permissions
1 parent 179e645 commit 9d7db6a

File tree

4 files changed

+76
-64
lines changed

4 files changed

+76
-64
lines changed

packages/site/src/pages/index.tsx

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';
22
import { KeyringSnapRpcClient } from '@metamask/keyring-api';
3+
import { Select, MenuItem } from '@mui/material';
34
import Grid from '@mui/material/Grid';
45
import React, { useContext, useEffect, useState } from 'react';
56

@@ -21,8 +22,6 @@ import { InputType } from '../types';
2122
import type { KeyringState } from '../utils';
2223
import { connectSnap, getSnap } from '../utils';
2324

24-
const snapId = defaultSnapOrigin;
25-
2625
const initialState: {
2726
pendingRequests: KeyringRequest[];
2827
accounts: KeyringAccount[];
@@ -51,6 +50,8 @@ const Index = () => {
5150
'signed',
5251
);
5352

53+
const [snapId, setSnapId] = useState<string>(defaultSnapOrigin);
54+
5455
// const [accountPayload, setAccountPayload] =
5556
// useState<Pick<KeyringAccount, 'name' | 'options'>>();
5657
const client = new KeyringSnapRpcClient(snapId, window.ethereum);
@@ -94,7 +95,7 @@ const Index = () => {
9495
const params = {
9596
method: 'wallet_invokeSnap',
9697
params: {
97-
snapId: 'local:http://localhost:8080',
98+
snapId,
9899
request: {
99100
method: 'authentication.onboard',
100101
params: {
@@ -130,8 +131,8 @@ const Index = () => {
130131

131132
const handleConnectClick = async () => {
132133
try {
133-
await connectSnap();
134-
const installedSnap = await getSnap();
134+
await connectSnap(snapId);
135+
const installedSnap = await getSnap(snapId);
135136

136137
dispatch({
137138
type: MetamaskActions.SetInstalled,
@@ -168,8 +169,11 @@ const Index = () => {
168169
action: {
169170
callback: async () =>
170171
await injectToken(
171-
'https://neptune-custody.dev.metamask-institutional.io/eth',
172-
'https://neptune-custody.dev.metamask-institutional.io/oauth/token',
172+
'https://neptune-custody.metamask-institutional.io/eth',
173+
'https://neptune-custody.metamask-institutional.io/oauth/token',
174+
'ECA3',
175+
'Neptune Custody',
176+
'neptune-custody-prod',
173177
),
174178
label: 'Inject Token',
175179
},
@@ -236,7 +240,7 @@ const Index = () => {
236240
},
237241
{
238242
name: 'List accounts',
239-
description: 'List all account managed by the SSK',
243+
description: 'List all accounts managed by the snap',
240244
action: {
241245
disabled: false,
242246
callback: async () => {
@@ -378,7 +382,7 @@ const Index = () => {
378382
const params = {
379383
method: 'wallet_invokeSnap',
380384
params: {
381-
snapId: 'local:http://localhost:8080',
385+
snapId,
382386
request: {
383387
method: 'snap.internal.clearAllRequests',
384388
params: {},
@@ -606,6 +610,27 @@ const Index = () => {
606610
)}
607611
</CardContainer>
608612

613+
<CardContainer>
614+
<Card
615+
content={{
616+
title: 'Snap ID',
617+
description: 'Choose the Snap ID to connect with',
618+
button: (
619+
<Select
620+
value={snapId}
621+
onChange={(e) => setSnapId(e.target.value)}
622+
fullWidth
623+
>
624+
<MenuItem value={defaultSnapOrigin}>Local Development</MenuItem>
625+
<MenuItem value="npm:@metamask/institutional-wallet-snap">
626+
NPM Package
627+
</MenuItem>
628+
</Select>
629+
),
630+
}}
631+
/>
632+
</CardContainer>
633+
609634
<StyledBox sx={{ flexGrow: 1 }}>
610635
<Grid container spacing={4} columns={[1, 2, 3]}>
611636
<Grid item xs={8} sm={4} md={2}>

packages/site/src/utils/snap.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ export const connectSnap = async (
3636
/**
3737
* Get the snap from MetaMask.
3838
*
39+
* @param snapId - The ID of the snap to get.
3940
* @param version - The version of the snap to install (optional).
4041
* @returns The snap object returned by the extension.
4142
*/
42-
export const getSnap = async (version?: string): Promise<Snap | undefined> => {
43+
export const getSnap = async (
44+
snapId: string,
45+
version?: string,
46+
): Promise<Snap | undefined> => {
4347
try {
4448
const snaps = await getSnaps();
4549

4650
return Object.values(snaps).find(
47-
(snap) =>
48-
snap.id === defaultSnapOrigin && (!version || snap.version === version),
51+
(snap) => snap.id === snapId && (!version || snap.version === version),
4952
);
5053
} catch (error) {
5154
console.log('Failed to obtain installed snap', error);

packages/snap/snap.manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "git+https://github.com/MetaMask/snap-institutional-wallet.git"
88
},
99
"source": {
10-
"shasum": "MbS8Z5/p1S5Q1X4ciJXDOEL1GXYPO1Sh850lBt4MlHY=",
10+
"shasum": "eInmwJ5KS6yb+VtEpPAkSzgs8VJEwVNUPXy4UMdXMRI=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/lib/custodian-types/custodianMetadata.ts

+35-51
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,47 @@ export type CustodianMetadata = {
1515
allowedOnboardingDomains?: string[];
1616
};
1717

18-
export const custodianMetadata: CustodianMetadata[] = [
18+
// Enforce custodianPublishesTransaction to be true or false for ECA3 but true for everything else
19+
20+
type ECA3CustodianMetadata = CustodianMetadata & {
21+
apiVersion: CustodianType.ECA3;
22+
custodianPublishesTransaction: true | false;
23+
};
24+
25+
type ECA1CustodianMetadata = CustodianMetadata & {
26+
apiVersion: CustodianType.ECA1;
27+
custodianPublishesTransaction: true;
28+
};
29+
30+
type BitGoCustodianMetadata = CustodianMetadata & {
31+
apiVersion: CustodianType.BitGo;
32+
custodianPublishesTransaction: true;
33+
};
34+
35+
type CactusCustodianMetadata = CustodianMetadata & {
36+
apiVersion: CustodianType.Cactus;
37+
custodianPublishesTransaction: true;
38+
};
39+
40+
export const custodianMetadata: (
41+
| ECA3CustodianMetadata
42+
| ECA1CustodianMetadata
43+
| BitGoCustodianMetadata
44+
| CactusCustodianMetadata
45+
)[] = [
1946
{
2047
refreshTokenUrl: null,
2148
name: 'bitgo-test',
2249
displayName: 'BitGo Test',
2350
enabled: false,
2451
apiBaseUrl: 'https://app.bitgo-test.com/defi/v2',
2552
apiVersion: CustodianType.BitGo,
26-
custodianPublishesTransaction: false,
53+
custodianPublishesTransaction: true,
2754
iconUrl:
2855
'https://dashboard.metamask-institutional.io/custodian-icons/bitgo-icon.svg',
2956
isManualTokenInputSupported: false,
3057
onboardingUrl: 'https://app.bitgo-test.com',
31-
allowedOnboardingDomains: ['app.bitgo-test.com'], // @audit - remove dev/test domains
58+
allowedOnboardingDomains: ['app.bitgo-test.com'],
3259
},
3360
{
3461
refreshTokenUrl: null,
@@ -183,15 +210,15 @@ export const custodianMetadata: CustodianMetadata[] = [
183210
iconUrl: 'https://zodia.io/wp-content/uploads/2023/01/cropped-ico.png',
184211
isManualTokenInputSupported: false,
185212
onboardingUrl: 'https://zodia.io',
186-
allowedOnboardingDomains: ['zodia.io'],
213+
allowedOnboardingDomains: ['ui-preprod-v2.uat.zodia.io'],
187214
},
188215
{
189216
refreshTokenUrl: 'https://mmi.fireblocks.io/v1/auth/access',
190217
name: 'fireblocks-prod',
191218
displayName: 'Fireblocks',
192219
enabled: true,
193220
apiBaseUrl: 'https://mmi.fireblocks.io',
194-
apiVersion: CustodianType.ECA3,
221+
apiVersion: CustodianType.ECA1,
195222
custodianPublishesTransaction: true,
196223
iconUrl:
197224
'https://metamask-institutional.io/custodian-icons/fireblocks-icon.svg',
@@ -210,7 +237,7 @@ export const custodianMetadata: CustodianMetadata[] = [
210237
iconUrl: 'https://zodia.io/wp-content/uploads/2023/01/cropped-ico.png',
211238
isManualTokenInputSupported: false,
212239
onboardingUrl: 'https://zodia.io',
213-
allowedOnboardingDomains: ['zodia.io'],
240+
allowedOnboardingDomains: ['zodia.io', 'v2.custody.zodia.io'],
214241
},
215242
{
216243
refreshTokenUrl: 'https://api.sit.zodia.io/oauth/token',
@@ -223,24 +250,7 @@ export const custodianMetadata: CustodianMetadata[] = [
223250
iconUrl: 'https://zodia.io/wp-content/uploads/2023/01/cropped-ico.png',
224251
isManualTokenInputSupported: false,
225252
onboardingUrl: 'https://zodia.io',
226-
allowedOnboardingDomains: ['sit.zodia.io'], // @audit dev host
227-
},
228-
{
229-
refreshTokenUrl:
230-
'https://saturn-custody.dev.metamask-institutional.io/oauth/token',
231-
name: 'saturn-dev',
232-
displayName: 'Saturn Custody',
233-
enabled: false,
234-
apiBaseUrl: 'https://saturn-custody.dev.metamask-institutional.io/eth',
235-
apiVersion: CustodianType.ECA1,
236-
custodianPublishesTransaction: false,
237-
iconUrl:
238-
'https://saturn-custody-ui.dev.metamask-institutional.io/saturn.svg',
239-
isManualTokenInputSupported: false,
240-
onboardingUrl: 'https://saturn-custody-ui.dev.metamask-institutional.io',
241-
allowedOnboardingDomains: [
242-
'saturn-custody-ui.dev.metamask-institutional.io',
243-
],
253+
allowedOnboardingDomains: ['sit.zodia.io', 'ui-v2.sit.zodia.io'],
244254
},
245255
{
246256
refreshTokenUrl: 'https://api-qa.qa.zodia.io/oauth/token',
@@ -253,7 +263,7 @@ export const custodianMetadata: CustodianMetadata[] = [
253263
iconUrl: 'https://zodia.io/wp-content/uploads/2023/01/cropped-ico.png',
254264
isManualTokenInputSupported: false,
255265
onboardingUrl: 'https://zodia.io',
256-
allowedOnboardingDomains: ['qa.zodia.io'],
266+
allowedOnboardingDomains: ['qa.zodia.io', 'ui-v2.qa.zodia.io'],
257267
},
258268
{
259269
refreshTokenUrl: 'http://localhost:8090/oauth/token',
@@ -308,20 +318,6 @@ export const custodianMetadata: CustodianMetadata[] = [
308318
isManualTokenInputSupported: true,
309319
allowedOnboardingDomains: [], // Cubist does not support onboarding via a web page
310320
},
311-
{
312-
refreshTokenUrl: 'http://localhost:3009/oauth/token',
313-
name: 'neptune-custody-local',
314-
displayName: 'Neptune Custody Local',
315-
enabled: true,
316-
apiBaseUrl: 'http://localhost:3009/eth',
317-
apiVersion: CustodianType.ECA3,
318-
custodianPublishesTransaction: false,
319-
iconUrl:
320-
'https://dev.metamask-institutional.io/custodian-icons/neptune-icon.svg',
321-
isManualTokenInputSupported: false,
322-
onboardingUrl: 'http://localhost:3005',
323-
allowedOnboardingDomains: ['localhost:3005'],
324-
},
325321
{
326322
refreshTokenUrl: 'http://localhost:3330/oauth/token',
327323
apiBaseUrl: 'http://localhost:3330',
@@ -335,16 +331,4 @@ export const custodianMetadata: CustodianMetadata[] = [
335331
isManualTokenInputSupported: true,
336332
allowedOnboardingDomains: ['localhost:8000', 'http://localhost:8000'],
337333
},
338-
{
339-
refreshTokenUrl: 'http://localhost:3330/oauth/token',
340-
apiBaseUrl: 'http://localhost:3330',
341-
apiVersion: CustodianType.ECA3,
342-
custodianPublishesTransaction: false,
343-
name: 'local-dev',
344-
displayName: 'Local Dev',
345-
enabled: false,
346-
iconUrl:
347-
'https://dev.metamask-institutional.io/custodian-icons/neptune-icon.svg',
348-
isManualTokenInputSupported: true,
349-
},
350334
];

0 commit comments

Comments
 (0)