Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert AccountSelector #2794

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading