Skip to content

Commit

Permalink
chore: Revamp interactive UI example using JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed May 22, 2024
1 parent a85a943 commit 3fd011b
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 455 deletions.
2 changes: 1 addition & 1 deletion packages/examples/packages/interactive-ui/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
input: resolve(__dirname, 'src/index.ts'),
input: resolve(__dirname, 'src/index.tsx'),
server: {
port: 8028,
},
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": "WCcrRcQpQpNuWEmyN5TQuX1ckpHF/5JIsdkgMLCvjO0=",
"shasum": "ENUxWrgZruvIFCLM2uCYYFIjyBxp6vHYK7L1ZhiZDJA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { SnapComponent } from '@metamask/snaps-sdk/jsx';
import { Button, Box, Text, Row, Address } from '@metamask/snaps-sdk/jsx';

type InsightProps = {
from: string;
to?: string;
};

export const Insight: SnapComponent<InsightProps> = ({ from, to }) => {
return (
<Box>
<Row label="From">
<Address address={from as `0x${string}`} />
</Row>
<Row label="To">
{to ? <Address address={from as `0x${string}`} /> : <Text>None</Text>}
</Row>
<Button name="transaction-type">See transaction type</Button>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { SnapComponent } from '@metamask/snaps-sdk/jsx';
import {
Button,
Box,
Field,
Heading,
Form,
Input,
} from '@metamask/snaps-sdk/jsx';

export const InteractiveForm: SnapComponent = () => {
return (
<Box>
<Heading>Interactive UI Example Snap</Heading>
<Form name="example-form">
<Field label="Example Input">
<Input name="example-input" placeholder="Enter something..." />
</Field>
<Button type="submit" name="submit">
Submit
</Button>
</Form>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { SnapComponent } from '@metamask/snaps-sdk/jsx';
import { Heading, Button, Box, Text, Copyable } from '@metamask/snaps-sdk/jsx';

type ResultProps = {
values: Record<string, string>;
};

export const Result: SnapComponent<ResultProps> = ({ values }) => {
return (
<Box>
<Heading>Interactive UI Example Snap</Heading>
<Text>You submitted the following values:</Text>
<Box>
{Object.values(values).map((value) => (
<Copyable value={value ?? ''} />
))}
</Box>
<Button name="back">Back</Button>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { SnapComponent } from '@metamask/snaps-sdk/jsx';
import { Bold, Box, Row, Button, Text } from '@metamask/snaps-sdk/jsx';

type TransactionTypeProps = {
type: string;
};

export const TransactionType: SnapComponent<TransactionTypeProps> = ({
type,
}) => {
return (
<Box>
<Row label="Transaction Type">
<Text>
<Bold>{type}</Bold>
</Text>
</Row>
<Button name="go-back">Back</Button>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './InteractiveForm';
export * from './Insight';
export * from './Result';
export * from './TransactionType';
253 changes: 0 additions & 253 deletions packages/examples/packages/interactive-ui/src/index.test.ts

This file was deleted.

Loading

0 comments on commit 3fd011b

Please sign in to comment.