@@ -100,7 +100,7 @@ gas-estimation-snap/
100
100
| | | |- gas.svg
101
101
| | ├─ src/
102
102
| | | |- index.test.ts
103
- | | | |- index.ts
103
+ | | | |- index.tsx
104
104
| | ├─ snap.manifest.json
105
105
| | ├─ package.json
106
106
| | |- ... (Snap content)
@@ -186,27 +186,27 @@ permission in `packages/snap/snap.manifest.json`:
186
186
187
187
### 4. Fetch gas fee estimates
188
188
189
- Open ` packages/snap/src/index.ts ` .
189
+ Open ` packages/snap/src/index.tsx ` .
190
190
This is the main code file for your Snap .
191
191
To get a gas fee estimate , use the public API endpoint provided by
192
192
[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:
194
194
195
195
```typescript title="index.ts"
196
196
import type { OnRpcRequestHandler } from " @metamask/snaps-sdk"
197
- import { panel , text } from " @metamask/snaps-sdk"
197
+ import { Box , Text } from " @metamask/snaps-sdk/jsx "
198
198
199
199
async function getFees() {
200
200
const response = await fetch (" https://beaconcha.in/api/v1/execution/gasnow" )
201
201
return response .text ()
202
202
}
203
203
` ` `
204
204
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:
206
206
207
207
` ` ` typescript title = " index.ts"
208
208
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 "
210
210
` ` `
211
211
212
212
Modify the Snap RPC message handler that displays the dialog.
@@ -217,9 +217,6 @@ dialog, and passes some static strings.
217
217
218
218
Update the ` hello ` method with the following code:
219
219
220
- <Tabs>
221
- <TabItem value="JSX">
222
-
223
220
` ` ` tsx title = " index.tsx"
224
221
case " hello" :
225
222
const fees = await getFees ();
@@ -231,36 +228,14 @@ case "hello":
231
228
<Box >
232
229
<Text >Hello , <Bold >{origin }< / Bold > ! < / Text >
233
230
<Text >Current gas fee estimates : </Text >
234
- <Copyable > {fees }< / Copyable >
231
+ < Copyable value = {fees } / >
235
232
< / Box >
236
233
),
237
234
}
238
235
});
239
236
` ` `
240
237
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
264
239
265
240
Complete the following steps to build and test your Snap:
266
241
0 commit comments