-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Revamp interactive UI example using JSX (#2427)
Revamps the interactive UI example, rewriting most of the UI logic in JSX and removing the `getState` functionality. This will let us more easily test different types of inputs once added as well, e.g. `Dropdown`. This also uses the new `context` property and lets us remove the usage of `manageState` entirely from the Snap.
- Loading branch information
1 parent
aecf71d
commit 6633bab
Showing
14 changed files
with
281 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/examples/packages/interactive-ui/src/components/Insight.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/examples/packages/interactive-ui/src/components/InteractiveForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/examples/packages/interactive-ui/src/components/Result.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/examples/packages/interactive-ui/src/components/TransactionType.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/examples/packages/interactive-ui/src/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
253
packages/examples/packages/interactive-ui/src/index.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.