Skip to content

Commit

Permalink
Revert AccountSelector (#2794)
Browse files Browse the repository at this point in the history
This PR reverts the work on the `AccountSelector` component.
  • Loading branch information
GuillaumeRx authored Oct 7, 2024
1 parent 4506049 commit 249fb25
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "BbaKbj8YVe957H1cnhBBv8X4ITiFjgmmor7/Rp9b/Yc=",
"shasum": "4a1znWfS1zEU7F+KvELAq39Q31sOaFMrxy40yNz4B0s=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "j5111I9EFtd21hrAQ1CIU41NgKleyEr7AiW4Gj3yHLg=",
"shasum": "t0meIgWvqOjHA02oXh9UmcfDmGoiklTgVud+eqyKbRE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"branches": 92.64,
"branches": 92.6,
"functions": 96.65,
"lines": 97.97,
"statements": 97.67
Expand Down
77 changes: 0 additions & 77 deletions packages/snaps-controllers/src/interface/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Selector,
Card,
SelectorOption,
AccountSelector,
} from '@metamask/snaps-sdk/jsx';

import { assertNameIsUnique, constructState, getJsxInterface } from './utils';
Expand Down Expand Up @@ -548,82 +547,6 @@ describe('constructState', () => {
});
});

it('sets default value for root level Account selector', () => {
const element = (
<Box>
<AccountSelector
name="foo"
title="Choose an account"
chainId="eip155:1"
selectedAddress="0x1234567890123456789012345678901234567890"
/>
</Box>
);

const result = constructState({}, element);
expect(result).toStrictEqual({
foo: '0x1234567890123456789012345678901234567890',
});
});

it('supports root level Account selector', () => {
const element = (
<Box>
<AccountSelector
name="foo"
title="Choose an account"
chainId="eip155:1"
selectedAddress="0x1234567890123456789012345678901234567890"
/>
</Box>
);

const result = constructState({}, element);
expect(result).toStrictEqual({
foo: '0x1234567890123456789012345678901234567890',
});
});

it('sets default value for Account selector in form', () => {
const element = (
<Box>
<Form name="form">
<AccountSelector
name="foo"
title="Choose an account"
chainId="eip155:1"
selectedAddress="0x1234567890123456789012345678901234567890"
/>
</Form>
</Box>
);

const result = constructState({}, element);
expect(result).toStrictEqual({
form: { foo: '0x1234567890123456789012345678901234567890' },
});
});

it('supports Account selector in form', () => {
const element = (
<Box>
<Form name="form">
<AccountSelector
name="foo"
title="Choose an account"
chainId="eip155:1"
selectedAddress="0x1234567890123456789012345678901234567890"
/>
</Form>
</Box>
);

const result = constructState({}, element);
expect(result).toStrictEqual({
form: { foo: '0x1234567890123456789012345678901234567890' },
});
});

it('supports nested fields', () => {
const element = (
<Box>
Expand Down
19 changes: 5 additions & 14 deletions packages/snaps-controllers/src/interface/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
RadioElement,
SelectorElement,
SelectorOptionElement,
AccountSelectorElement,
} from '@metamask/snaps-sdk/jsx';
import { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';
import {
Expand Down Expand Up @@ -71,8 +70,7 @@ function constructComponentSpecificDefaultState(
| DropdownElement
| RadioGroupElement
| CheckboxElement
| SelectorElement
| AccountSelectorElement,
| SelectorElement,
) {
switch (element.type) {
case 'Dropdown': {
Expand Down Expand Up @@ -113,16 +111,12 @@ function getComponentStateValue(
| DropdownElement
| RadioGroupElement
| CheckboxElement
| SelectorElement
| AccountSelectorElement,
| SelectorElement,
) {
switch (element.type) {
case 'Checkbox':
return element.props.checked;

case 'AccountSelector':
return element.props.selectedAddress;

default:
return element.props.value;
}
Expand All @@ -144,8 +138,7 @@ function constructInputState(
| RadioGroupElement
| FileInputElement
| CheckboxElement
| SelectorElement
| AccountSelectorElement,
| SelectorElement,
form?: string,
) {
const oldStateUnwrapped = form ? (oldState[form] as FormState) : oldState;
Expand Down Expand Up @@ -203,8 +196,7 @@ export function constructState(
component.type === 'RadioGroup' ||
component.type === 'FileInput' ||
component.type === 'Checkbox' ||
component.type === 'Selector' ||
component.type === 'AccountSelector')
component.type === 'Selector')
) {
const formState = newState[currentForm.name] as FormState;
assertNameIsUnique(formState, component.props.name);
Expand All @@ -223,8 +215,7 @@ export function constructState(
component.type === 'RadioGroup' ||
component.type === 'FileInput' ||
component.type === 'Checkbox' ||
component.type === 'Selector' ||
component.type === 'AccountSelector'
component.type === 'Selector'
) {
assertNameIsUnique(newState, component.props.name);
newState[component.props.name] = constructInputState(oldState, component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('snap_createInterface', () => {
error: {
code: -32602,
message:
'Invalid params: At path: ui -- Expected type to be one of: "AccountSelector", "Address", "Bold", "Box", "Button", "Copyable", "Divider", "Dropdown", "RadioGroup", "FileInput", "Form", "Heading", "Input", "Image", "Italic", "Link", "Row", "Spinner", "Text", "Tooltip", "Checkbox", "Card", "Icon", "Selector", "Section", "Container", but received: undefined.',
'Invalid params: At path: ui -- Expected type to be one of: "Address", "Bold", "Box", "Button", "Copyable", "Divider", "Dropdown", "RadioGroup", "FileInput", "Form", "Heading", "Input", "Image", "Italic", "Link", "Row", "Spinner", "Text", "Tooltip", "Checkbox", "Card", "Icon", "Selector", "Section", "Container", but received: undefined.',
stack: expect.any(String),
},
id: 1,
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('snap_createInterface', () => {
error: {
code: -32602,
message:
'Invalid params: At path: ui.props.children -- Expected type to be one of: "AccountSelector", "Address", "Bold", "Box", "Button", "Copyable", "Divider", "Dropdown", "RadioGroup", "FileInput", "Form", "Heading", "Input", "Image", "Italic", "Link", "Row", "Spinner", "Text", "Tooltip", "Checkbox", "Card", "Icon", "Selector", "Section", but received: "Field".',
'Invalid params: At path: ui.props.children -- Expected type to be one of: "Address", "Bold", "Box", "Button", "Copyable", "Divider", "Dropdown", "RadioGroup", "FileInput", "Form", "Heading", "Input", "Image", "Italic", "Link", "Row", "Spinner", "Text", "Tooltip", "Checkbox", "Card", "Icon", "Selector", "Section", but received: "Field".',
stack: expect.any(String),
},
id: 1,
Expand Down

This file was deleted.

49 changes: 0 additions & 49 deletions packages/snaps-sdk/src/jsx/components/form/AccountSelector.ts

This file was deleted.

4 changes: 1 addition & 3 deletions packages/snaps-sdk/src/jsx/components/form/Field.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { GenericSnapChildren } from '../../component';
import { createSnapComponent } from '../../component';
import type { AccountSelectorElement } from './AccountSelector';
import type { CheckboxElement } from './Checkbox';
import type { DropdownElement } from './Dropdown';
import type { FileInputElement } from './FileInput';
Expand All @@ -27,8 +26,7 @@ export type FieldProps = {
| FileInputElement
| InputElement
| CheckboxElement
| SelectorElement
| AccountSelectorElement;
| SelectorElement;
};

const TYPE = 'Field';
Expand Down
3 changes: 0 additions & 3 deletions packages/snaps-sdk/src/jsx/components/form/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AccountSelectorElement } from './AccountSelector';
import type { ButtonElement } from './Button';
import type { CheckboxElement } from './Checkbox';
import type { DropdownElement } from './Dropdown';
Expand All @@ -12,7 +11,6 @@ import type { RadioGroupElement } from './RadioGroup';
import type { SelectorElement } from './Selector';
import type { SelectorOptionElement } from './SelectorOption';

export * from './AccountSelector';
export * from './Button';
export * from './Checkbox';
export * from './Dropdown';
Expand All @@ -27,7 +25,6 @@ export * from './Selector';
export * from './SelectorOption';

export type StandardFormElement =
| AccountSelectorElement
| ButtonElement
| CheckboxElement
| FormElement
Expand Down
Loading

0 comments on commit 249fb25

Please sign in to comment.