diff --git a/snaps/features/custom-ui/with-jsx.md b/snaps/features/custom-ui/with-jsx.md index 1a89dc5b3af..432f84313ab 100644 --- a/snaps/features/custom-ui/with-jsx.md +++ b/snaps/features/custom-ui/with-jsx.md @@ -120,7 +120,7 @@ await snap.request({ content: ( Are you sure you want to send tokens to this address? -
0x000000000000000000000000000000000000dEaD
+
), }, @@ -254,6 +254,11 @@ await snap.request({ Outputs a read-only text field with a copy-to-clipboard shortcut. +#### Props + +- `value`: `string` - The value to copy when the user clicks on the copyable element. +- `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. + #### Example ```javascript title="index.jsx" @@ -266,7 +271,7 @@ await snap.request({ content: ( Your address: - 0x000000000000000000000000000000000000dEaD + ), }, @@ -587,7 +592,7 @@ Outputs a clickable link. #### Props -- `href`: `string` - The URL to point to. +- `href`: `string` - The URL to point to. This must be an HTTPS URL. - `children`: `Array` - The link text. #### Example @@ -640,7 +645,7 @@ await snap.request({ content: ( -
0x000000000000000000000000000000000000dEaD
+
1.78 ETH diff --git a/snaps/learn/tutorials/gas-estimation.md b/snaps/learn/tutorials/gas-estimation.md index 874bef40ac3..c82dfb215e4 100644 --- a/snaps/learn/tutorials/gas-estimation.md +++ b/snaps/learn/tutorials/gas-estimation.md @@ -100,7 +100,7 @@ gas-estimation-snap/ | | | |- gas.svg | | ├─ src/ | | | |- index.test.ts -| | | |- index.ts +| | | |- index.tsx | | ├─ snap.manifest.json | | ├─ package.json | | |- ... (Snap content) @@ -186,15 +186,15 @@ permission in `packages/snap/snap.manifest.json`: ### 4. Fetch gas fee estimates -Open `packages/snap/src/index.ts`. +Open `packages/snap/src/index.tsx`. This is the main code file for your Snap. To get a gas fee estimate, use the public API endpoint provided by [Open Source Ethereum Explorer](https://beaconcha.in/). -Add the following `getFees()` function to the beginning of the `/packages/snap/src/index.ts` file: +Add the following `getFees()` function to the beginning of the `/packages/snap/src/index.tsx` file: ```typescript title="index.ts" import type { OnRpcRequestHandler } from "@metamask/snaps-sdk" -import { panel, text } from "@metamask/snaps-sdk" +import { Box, Text } from "@metamask/snaps-sdk/jsx" async function getFees() { const response = await fetch("https://beaconcha.in/api/v1/execution/gasnow") @@ -202,11 +202,11 @@ async function getFees() { } ``` -Next, add the `copyable` component to the second import of the file: +Next, add the `Copyable` component to the second import of the file: ```typescript title="index.ts" import type { OnRpcRequestHandler } from "@metamask/snaps-sdk" -import { panel, text, copyable } from "@metamask/snaps-sdk" +import { Box, Text, Copyable } from "@metamask/snaps-sdk/jsx" ``` Modify the Snap RPC message handler that displays the dialog. @@ -217,9 +217,6 @@ dialog, and passes some static strings. Update the `hello` method with the following code: - - - ```tsx title="index.tsx" case "hello": const fees = await getFees(); @@ -231,36 +228,14 @@ case "hello": Hello, {origin}! Current gas fee estimates: - {fees} + ), } }); ``` - - - -```typescript title="index.ts" -case "hello": - const fees = await getFees(); - return snap.request({ - method: "snap_dialog", - params: { - type: "alert", - content: panel([ - text(`Hello, **${origin}**!`), - text("Current gas fee estimates:"), - copyable(fees), - ]), - } - }); -``` - - - - -### 5. Build and test your Snap +### 5. Build and test the Snap Complete the following steps to build and test your Snap: