Skip to content

Commit ea11bfa

Browse files
authored
Allow multiple chain ID in AccountSelector (#2768)
This PR changes the `chainId` prop of the `AccountSelector` to `chainIds` that is an array of CAIP-2 chain IDs.
1 parent d4e1403 commit ea11bfa

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

packages/examples/packages/browserify-plugin/snap.manifest.json

+1-1
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": "zGgTjLWTEn796eXGvv66p8tGxZSa82yEEGnRtyVutEc=",
10+
"shasum": "hU2i377FhKzvwrx4y28hc5XFO3KccCUq7bAJdsQ2CD0=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/browserify/snap.manifest.json

+1-1
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": "qfkidJLew8JNN2Enx4pDUgWNgLPqBkG0k3mGQRR1oaY=",
10+
"shasum": "VCd6NkT2lPRvH5tKtzCqtW4dO8zEA3/zagYxhhv1mBI=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snaps-sdk/src/jsx/components/form/AccountSelector.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('AccountSelector', () => {
66
<AccountSelector
77
name="account"
88
title="From account"
9-
chainId="bip122:p2wpkh"
9+
chainIds={['bip122:p2wpkh']}
1010
selectedAddress="bc1qc8dwyqua9elc3mzcxk93c70kjz8tcc92x0a8a6"
1111
/>
1212
);
@@ -16,7 +16,7 @@ describe('AccountSelector', () => {
1616
props: {
1717
name: 'account',
1818
title: 'From account',
19-
chainId: 'bip122:p2wpkh',
19+
chainIds: ['bip122:p2wpkh'],
2020
selectedAddress: 'bc1qc8dwyqua9elc3mzcxk93c70kjz8tcc92x0a8a6',
2121
},
2222
key: null,

packages/snaps-sdk/src/jsx/components/form/AccountSelector.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { createSnapComponent } from '../../component';
88
* @property name - The name of the account selector. This is used to identify the
99
* state in the form data.
1010
* @property title - The title of the account selector. This is displayed in the UI.
11-
* @property chainId - The chain ID of the account selector. This should be a valid CAIP-2 chain ID.
11+
* @property chainIds - The chain IDs of the account selector. This should be a valid CAIP-2 chain ID array.
1212
* @property selectedAddress - The default selected address of the account selector. This should be a
1313
* valid CAIP-10 account address.
1414
*/
1515
export type AccountSelectorProps = {
1616
name: string;
1717
title: string;
18-
chainId: CaipChainId;
18+
chainIds: CaipChainId[];
1919
selectedAddress: CaipAccountAddress;
2020
};
2121

@@ -30,14 +30,14 @@ const TYPE = 'AccountSelector';
3030
* @param props.name - The name of the account selector field. This is used to identify the
3131
* state in the form data.
3232
* @param props.title - The title of the account selector field. This is displayed in the UI.
33-
* @param props.chainId - The chain ID of the account selector. This should be a valid CAIP-2 chain ID.
33+
* @param props.chainIds - The chain IDs of the account selector. This should be a valid CAIP-2 chain ID array.
3434
* @param props.selectedAddress - The selected address of the account selector. This should be a
3535
* valid CAIP-10 account address.
3636
* @returns An account selector element.
3737
* @example
38-
* <AccountSelector name="account" title="From account" chainId="eip155:1" selectedAddress="0x1234567890123456789012345678901234567890" />
38+
* <AccountSelector name="account" title="From account" chainIds={["eip155:1"]} selectedAddress="0x1234567890123456789012345678901234567890" />
3939
* @example
40-
* <AccountSelector name="account" title="From account" chainId="bip122:000000000019d6689c085ae165831e93" selectedAddress="128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6" />
40+
* <AccountSelector name="account" title="From account" chainIds={["bip122:000000000019d6689c085ae165831e93"]} selectedAddress="128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6" />
4141
*/
4242
export const AccountSelector = createSnapComponent<
4343
AccountSelectorProps,

packages/snaps-sdk/src/jsx/validation.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -963,13 +963,13 @@ describe('AccountSelectorStruct', () => {
963963
<AccountSelector
964964
name="account"
965965
title="From Account"
966-
chainId="bip122:000000000019d6689c085ae165831e93"
966+
chainIds={['bip122:000000000019d6689c085ae165831e93']}
967967
selectedAddress="128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6"
968968
/>,
969969
<AccountSelector
970970
name="account"
971971
title="From Account"
972-
chainId="eip155:1"
972+
chainIds={['eip155:1']}
973973
selectedAddress="0x1234567890123456789012345678901234567890"
974974
/>,
975975
])('validates an account picker element', (value) => {
@@ -994,19 +994,19 @@ describe('AccountSelectorStruct', () => {
994994
// @ts-expect-error - Invalid props.
995995
<AccountSelector title="From Account" />,
996996
// @ts-expect-error - Invalid props.
997-
<AccountSelector chainId="bip122:000000000019d6689c085ae165831e93" />,
997+
<AccountSelector chainIds={['bip122:000000000019d6689c085ae165831e93']} />,
998998
// @ts-expect-error - Invalid props.
999999
<AccountSelector selectedAddress="128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6" />,
10001000
<AccountSelector
10011001
name="account"
10021002
title="From Account"
1003-
chainId="foo:bar"
1003+
chainIds={['foo:bar']}
10041004
selectedAddress="0x1234567890123456789012345678901234567890"
10051005
/>,
10061006
<AccountSelector
10071007
name="account"
10081008
title="From Account"
1009-
chainId="eip155:1"
1009+
chainIds={['eip155:1']}
10101010
selectedAddress="0x123"
10111011
/>,
10121012
<Text>foo</Text>,

packages/snaps-sdk/src/jsx/validation.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,12 @@ export const AccountSelectorStruct: Describe<AccountSelectorElement> = element(
342342
{
343343
name: string(),
344344
title: string(),
345-
chainId: CaipChainIdStruct as unknown as Struct<
346-
Infer<typeof CaipChainIdStruct>,
347-
Infer<typeof CaipChainIdStruct>
348-
>,
345+
chainIds: array(
346+
CaipChainIdStruct as unknown as Struct<
347+
Infer<typeof CaipChainIdStruct>,
348+
Infer<typeof CaipChainIdStruct>
349+
>,
350+
),
349351
selectedAddress: CaipAccountAddressStruct,
350352
},
351353
);

0 commit comments

Comments
 (0)