Skip to content

Commit 192d42c

Browse files
authored
fix: Allow AccountSelector in Field and add disabled prop. (#3430)
This PR fixes the missing type in the `Field` for `AccountSelector` and adds the `disabled` prop to it.
1 parent 59964cf commit 192d42c

6 files changed

Lines changed: 49 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,27 @@ describe('AccountSelector', () => {
7979
});
8080
});
8181

82+
it('returns an account selector element with a disabled prop', () => {
83+
const result = <AccountSelector name="account" disabled={true} />;
84+
85+
expect(result).toStrictEqual({
86+
type: 'AccountSelector',
87+
props: {
88+
name: 'account',
89+
disabled: true,
90+
},
91+
key: null,
92+
});
93+
});
94+
8295
it('returns an account selector element with all props', () => {
8396
const result = (
8497
<AccountSelector
8598
name="account"
8699
chainIds={['bip122:000000000019d6689c085ae165831e93']}
87100
hideExternalAccounts={true}
88101
switchGlobalAccount={true}
102+
disabled={true}
89103
value="bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6"
90104
/>
91105
);
@@ -97,6 +111,7 @@ describe('AccountSelector', () => {
97111
chainIds: ['bip122:000000000019d6689c085ae165831e93'],
98112
hideExternalAccounts: true,
99113
switchGlobalAccount: true,
114+
disabled: true,
100115
value:
101116
'bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6',
102117
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createSnapComponent } from '../../component';
1010
* @property hideExternalAccounts - Whether to hide accounts that don't belong to the snap.
1111
* @property chainIds - The chain IDs to filter the accounts to show.
1212
* @property switchGlobalAccount - Whether to switch the selected account in the client.
13+
* @property disabled - Whether the account selector is disabled.
1314
* @property value - The selected address.
1415
*/
1516
export type AccountSelectorProps = {
@@ -18,6 +19,7 @@ export type AccountSelectorProps = {
1819
chainIds?: CaipChainId[] | undefined;
1920
switchGlobalAccount?: boolean | undefined;
2021
value?: CaipAccountId | undefined;
22+
disabled?: boolean | undefined;
2123
};
2224

2325
const TYPE = 'AccountSelector';
@@ -32,6 +34,7 @@ const TYPE = 'AccountSelector';
3234
* @param props.chainIds - The chain IDs to filter the accounts to show.
3335
* @param props.switchGlobalAccount - Whether to switch the selected account in the client.
3436
* @param props.value - The selected address.
37+
* @param props.disabled - Whether the account selector is disabled.
3538
* @returns An account selector element.
3639
* @example
3740
* <AccountSelector name="account-selector" />

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AccountSelector } from './AccountSelector';
12
import { AddressInput } from './AddressInput';
23
import { Button } from './Button';
34
import { Dropdown } from './Dropdown';
@@ -348,6 +349,29 @@ describe('Field', () => {
348349
});
349350
});
350351

352+
it('renders a field with an account selector', () => {
353+
const result = (
354+
<Field label="Select Account">
355+
<AccountSelector name="account" />
356+
</Field>
357+
);
358+
359+
expect(result).toStrictEqual({
360+
type: 'Field',
361+
key: null,
362+
props: {
363+
label: 'Select Account',
364+
children: {
365+
type: 'AccountSelector',
366+
key: null,
367+
props: {
368+
name: 'account',
369+
},
370+
},
371+
},
372+
});
373+
});
374+
351375
it('renders a field with a conditional', () => {
352376
const result = (
353377
<Field>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { AccountSelectorElement } from './AccountSelector';
12
import type { AddressInputElement } from './AddressInput';
23
import type { AssetSelectorElement } from './AssetSelector';
34
import type { CheckboxElement } from './Checkbox';
@@ -30,7 +31,8 @@ export type FieldProps = {
3031
| CheckboxElement
3132
| SelectorElement
3233
| AssetSelectorElement
33-
| AddressInputElement;
34+
| AddressInputElement
35+
| AccountSelectorElement;
3436
};
3537

3638
const TYPE = 'Field';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ describe('AccountSelectorStruct', () => {
658658
switchGlobalAccount
659659
value="eip155:1:0x1234567890abcdef1234567890abcdef12345678"
660660
/>,
661+
<AccountSelector name="account" disabled={true} />,
661662
])('validates an account picker element', (value) => {
662663
expect(is(value, AccountSelectorStruct)).toBe(true);
663664
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ export const AccountSelectorStruct: Describe<AccountSelectorElement> = element(
409409
>,
410410
switchGlobalAccount: optional(boolean()),
411411
value: optional(CaipAccountIdStruct),
412+
disabled: optional(boolean()),
412413
},
413414
);
414415

@@ -595,7 +596,8 @@ const FieldChildStruct = selectiveUnion((value) => {
595596
| CheckboxElement
596597
| SelectorElement
597598
| AssetSelectorElement
598-
| AddressInputElement,
599+
| AddressInputElement
600+
| AccountSelectorElement,
599601
null
600602
>;
601603

0 commit comments

Comments
 (0)