Skip to content

Commit eafe1b2

Browse files
Adjust JSX documentation and related tutorials (#1500)
* Adjust JSX documentation and related tutorials Closes #1499, #1498, #1495. * typo * Update snaps/features/custom-ui/with-jsx.md --------- Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>
1 parent ae0233a commit eafe1b2

File tree

2 files changed

+17
-37
lines changed

2 files changed

+17
-37
lines changed

snaps/features/custom-ui/with-jsx.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ await snap.request({
120120
content: (
121121
<Box>
122122
<Heading>Are you sure you want to send tokens to this address?</Heading>
123-
<Address>0x000000000000000000000000000000000000dEaD</Address>
123+
<Address address="0x000000000000000000000000000000000000dEaD" />
124124
</Box>
125125
),
126126
},
@@ -254,6 +254,11 @@ await snap.request({
254254

255255
Outputs a read-only text field with a copy-to-clipboard shortcut.
256256

257+
#### Props
258+
259+
- `value`: `string` - The value to copy when the user clicks on the copyable element.
260+
- `sensitive`: `boolean` - (Optional) Indicates whether the value is sensitive. If `true`, the value will be hidden when the user is not interacting with the copyable element.
261+
257262
#### Example
258263

259264
```javascript title="index.jsx"
@@ -266,7 +271,7 @@ await snap.request({
266271
content: (
267272
<Box>
268273
<Text>Your address:</Text>
269-
<Copyable>0x000000000000000000000000000000000000dEaD</Copyable>
274+
<Copyable value="0x000000000000000000000000000000000000dEaD" />
270275
</Box>
271276
),
272277
},
@@ -587,7 +592,7 @@ Outputs a clickable link.
587592

588593
#### Props
589594

590-
- `href`: `string` - The URL to point to.
595+
- `href`: `string` - The URL to point to. This must be an HTTPS URL.
591596
- `children`: `Array<string | Bold | Italic>` - The link text.
592597

593598
#### Example
@@ -640,7 +645,7 @@ await snap.request({
640645
content: (
641646
<Box>
642647
<Row label="Address">
643-
<Address>0x000000000000000000000000000000000000dEaD</Address>
648+
<Address address="0x000000000000000000000000000000000000dEaD" />
644649
</Row>
645650
<Row label="Balance">
646651
<Text>1.78 ETH</Text>

snaps/learn/tutorials/gas-estimation.md

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ gas-estimation-snap/
100100
| | | |- gas.svg
101101
| | ├─ src/
102102
| | | |- index.test.ts
103-
| | | |- index.ts
103+
| | | |- index.tsx
104104
| | ├─ snap.manifest.json
105105
| | ├─ package.json
106106
| | |- ... (Snap content)
@@ -186,27 +186,27 @@ permission in `packages/snap/snap.manifest.json`:
186186

187187
### 4. Fetch gas fee estimates
188188

189-
Open `packages/snap/src/index.ts`.
189+
Open `packages/snap/src/index.tsx`.
190190
This is the main code file for your Snap.
191191
To get a gas fee estimate, use the public API endpoint provided by
192192
[Open Source Ethereum Explorer](https://beaconcha.in/).
193-
Add the following `getFees()` function to the beginning of the `/packages/snap/src/index.ts` file:
193+
Add the following `getFees()` function to the beginning of the `/packages/snap/src/index.tsx` file:
194194

195195
```typescript title="index.ts"
196196
import type { OnRpcRequestHandler } from "@metamask/snaps-sdk"
197-
import { panel, text } from "@metamask/snaps-sdk"
197+
import { Box, Text } from "@metamask/snaps-sdk/jsx"
198198

199199
async function getFees() {
200200
const response = await fetch("https://beaconcha.in/api/v1/execution/gasnow")
201201
return response.text()
202202
}
203203
```
204204
205-
Next, add the `copyable` component to the second import of the file:
205+
Next, add the `Copyable` component to the second import of the file:
206206
207207
```typescript title="index.ts"
208208
import type { OnRpcRequestHandler } from "@metamask/snaps-sdk"
209-
import { panel, text, copyable } from "@metamask/snaps-sdk"
209+
import { Box, Text, Copyable } from "@metamask/snaps-sdk/jsx"
210210
```
211211
212212
Modify the Snap RPC message handler that displays the dialog.
@@ -217,9 +217,6 @@ dialog, and passes some static strings.
217217
218218
Update the `hello` method with the following code:
219219
220-
<Tabs>
221-
<TabItem value="JSX">
222-
223220
```tsx title="index.tsx"
224221
case "hello":
225222
const fees = await getFees();
@@ -231,36 +228,14 @@ case "hello":
231228
<Box>
232229
<Text>Hello, <Bold>{origin}</Bold>!</Text>
233230
<Text>Current gas fee estimates:</Text>
234-
<Copyable>{fees}</Copyable>
231+
<Copyable value={fees} />
235232
</Box>
236233
),
237234
}
238235
});
239236
```
240237
241-
</TabItem>
242-
<TabItem value="Functions" deprecated>
243-
244-
```typescript title="index.ts"
245-
case "hello":
246-
const fees = await getFees();
247-
return snap.request({
248-
method: "snap_dialog",
249-
params: {
250-
type: "alert",
251-
content: panel([
252-
text(`Hello, **${origin}**!`),
253-
text("Current gas fee estimates:"),
254-
copyable(fees),
255-
]),
256-
}
257-
});
258-
```
259-
260-
</TabItem>
261-
</Tabs>
262-
263-
### 5. Build and test your Snap
238+
### 5. Build and test the Snap
264239
265240
Complete the following steps to build and test your Snap:
266241

0 commit comments

Comments
 (0)