Skip to content

Commit

Permalink
Refactor solution
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Dec 9, 2024
1 parent d513202 commit afe910c
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/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": "o0r7dTMBgRTsatqWC09DllWt7iKawEfT+UEYJyPvpjw=",
"shasum": "dWCQ3BjoAmv1KlzbrNPRa4QlB3qSHQKL6ONaV0mo7b0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/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": "+nueF506YIHiz6om1Qozd92BRpO3qs17joFO+0sUr/Y=",
"shasum": "dqWYaxXKggEChwefUCTvipvNzQ+0KbaT6x8vRDW0miw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
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": "w8ZPchwG+LqlFzbmkqVQ5nDqt5GDFkZsU8dUm1b5NXo=",
"shasum": "lyy+HECzOFQzuzjyD1nas6GPc4kMt340ChbqQZl7uEo=",
"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": "tkxfxAjBgF7nF6SvHC4M7Q0srVnLsPuk23aJoh/dsFI=",
"shasum": "k7NYoT8jI2E4u785PN5PoruwtjF18KNOSagNY9fS44U=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/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": "CEewtsiFdgFdhRMjCUJX6/1q+AW3EEHIg+KsCDGe++U=",
"shasum": "8bB9qcVDzKQyefr78Cm03aTbojKKg5jQ4nkzZUccKhs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/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": "/EeoYCNi7wEoA/1FrpL1FIi/qyYmgUNMKSj1kVbVgQk=",
"shasum": "uZhYG9+3b1yA/94e0QhCJycqrPA96cBQyP+2plF0SEg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/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": "nDlAQQY2l0vn9krd3F0EMJWpgKtUGrA7OPcLdXLd1iA=",
"shasum": "uVLwzYliwDATW6CiqATb1FyPgyagNs+3ini7QA+0okc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/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": "U+a7ZNEVnChJYWtX9A2s92XLDL4fIGfz+HWTTjDpM+E=",
"shasum": "1jPm8koZvt+Tme7DCtogqKfS+fR4SJnPU7N8r85ku1Y=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/images/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": "/FySWBXQTwZgrpkIHPWb/0Q+k3fBWmKL41u0dZaV5O0=",
"shasum": "PWtPR8sJIxj/6B8eLRvGjndi5udmdlWu6eKP4QWFOXg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
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": "RptJSWpO9h8t3X7kxCq7spXzP2xWqw6ype4+StKyZNQ=",
"shasum": "QPxHqRPygXB1Z6M4XreZtw/im8wCEBJgEtLdkOtwob8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
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": "f9c70KMplhX7bQunGJ9fom0KVBUePVz+B2v+AkdImRc=",
"shasum": "W7760+wNYB7ikWVHQeEx5IRAt+Q07Cq4zaYwmfCEqr8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
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": "G1B2zhWBAKG5KuzKgWcyPEYlAd1KSdD5ydBjiQq2NSg=",
"shasum": "FxEMWKtdMuijdmu4neAmXosp1zIiuvwzngv7U6t9eC4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
19 changes: 19 additions & 0 deletions packages/snaps-sdk/src/jsx/components/form/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,23 @@ describe('Button', () => {
key: null,
});
});

it('returns a button element with a variant and loading state', () => {
const result = (
<Button type="button" variant="primary" loading={true}>
foo
</Button>
);

expect(result).toStrictEqual({
type: 'Button',
props: {
children: 'foo',
type: 'button',
variant: 'primary',
loading: true,
},
key: null,
});
});
});
4 changes: 3 additions & 1 deletion packages/snaps-sdk/src/jsx/components/form/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import type { ImageElement } from '../Image';
* @property variant - The variant of the button, i.e., `'primary'` or
* `'destructive'`. Defaults to `'primary'`.
* @property disabled - Whether the button is disabled. Defaults to `false`.
* @property loading - Whether the button is in loading state. Defaults to `false`.
* @property form - The name of the form component to associate the button with.
*/
export type ButtonProps = {
children: SnapsChildren<StringElement | IconElement | ImageElement>;
name?: string | undefined;
type?: 'button' | 'submit' | undefined;
variant?: 'primary' | 'destructive' | 'loading' | undefined;
variant?: 'primary' | 'destructive' | undefined;
disabled?: boolean | undefined;
loading?: boolean | undefined;
form?: string | undefined;
};

Expand Down
4 changes: 3 additions & 1 deletion packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ describe('ButtonStruct', () => {
<Button name="foo">bar</Button>,
<Button type="submit">foo</Button>,
<Button variant="destructive">foo</Button>,
<Button variant="loading">foo</Button>,
<Button disabled={true}>foo</Button>,
<Button variant="primary" loading={true}>
foo
</Button>,
<Button key="button">foo</Button>,
<Button>
<Icon name="wifi" />
Expand Down
5 changes: 2 additions & 3 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,9 @@ export const ButtonStruct: Describe<ButtonElement> = element('Button', {
children: children([StringElementStruct, ImageStruct, IconStruct]),
name: optional(string()),
type: optional(nullUnion([literal('button'), literal('submit')])),
variant: optional(
nullUnion([literal('primary'), literal('destructive'), literal('loading')]),
),
variant: optional(nullUnion([literal('primary'), literal('destructive')])),
disabled: optional(boolean()),
loading: optional(boolean()),
form: optional(string()),
});

Expand Down
2 changes: 0 additions & 2 deletions packages/snaps-sdk/src/ui/components/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { LiteralStruct, NodeType } from '../nodes';
export enum ButtonVariant {
Primary = 'primary',
Secondary = 'secondary',
Loading = 'loading',
}

export enum ButtonType {
Expand All @@ -32,7 +31,6 @@ export const ButtonStruct = assign(
union([
enumValue(ButtonVariant.Primary),
enumValue(ButtonVariant.Secondary),
enumValue(ButtonVariant.Loading),
]),
),
buttonType: optional(
Expand Down
6 changes: 1 addition & 5 deletions packages/snaps-utils/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ const ALLOWED_PROTOCOLS = ['https:', 'mailto:', 'metamask:'];
* @param variant - The legacy button component variant.
* @returns The button variant.
*/
function getButtonVariant(
variant?: 'primary' | 'secondary' | 'loading' | undefined,
) {
function getButtonVariant(variant?: 'primary' | 'secondary' | undefined) {
switch (variant) {
case 'primary':
return 'primary';
case 'secondary':
return 'destructive';
case 'loading':
return 'loading';
default:
return undefined;
}
Expand Down

0 comments on commit afe910c

Please sign in to comment.