Skip to content

Commit a90976a

Browse files
m4sterbunnyalexandratranjoaniekube
authored
docs(1367): tidy up for tutorials (#1401)
* docs(1367): tidy up for tutorials * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * completes the separation of paths for yarn etc * reverts tabs in favor of dropping support for npm/npx Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * makes step 2 optional and extends it to point that all clicks make sense Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * improves numbering, rmvs 6 (not a step), aligns 5 with new flow Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * attempts to allow both tutorials to function as hello world && to direct devs toward deeper understanding Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * final proofs Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * final proofs Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * final proofs? Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * final proofs? Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * aligns both per proofs Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * proofs and toc4 Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * proofs Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * proofs Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md rmv toc4 * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md works Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/gas-estimation.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md rmv toc4 * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof- nice catch Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof -- nice catch Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * Update snaps/learn/tutorials/transaction-insights.md proof Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> * proposes solution for fragements * docs: Reverts tabbed full code and applies proofs * fixes code sample and alt method to disable button * Add closing tag * edits * minor fix * Update snaps/learn/tutorials/transaction-insights.md logic fixed * Apply suggestions from code review --------- Signed-off-by: m4sterbunny <harrie.bickle@consensys.net> Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> Co-authored-by: Alexandra Tran <alexandratran@protonmail.com> Co-authored-by: Joan E <153745173+joaniefromtheblock@users.noreply.github.com>
1 parent b09c614 commit a90976a

File tree

2 files changed

+305
-147
lines changed

2 files changed

+305
-147
lines changed

snaps/learn/tutorials/gas-estimation.md

Lines changed: 110 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,58 @@ starter kit by running:
3131
yarn create @metamask/snap gas-estimation-snap
3232
```
3333

34-
or
35-
36-
```bash
37-
npx @metamask/create-snap gas-estimation-snap
38-
```
39-
40-
or
41-
42-
```bash
43-
npm create @metamask/snap gas-estimation-snap
44-
```
45-
4634
Next, `cd` into the `gas-estimation-snap` project directory and run:
4735

4836
```bash
4937
yarn install
5038
```
5139

52-
This initializes your development environment with the required dependencies.
53-
You may get a warning similar to the following:
40+
This initializes your development environment with the required dependencies.
41+
42+
<details>
43+
<summary>Did you get a warning?</summary>
44+
<div>
45+
You may get a warning such as:
5446

5547
```bash
5648
@lavamoat/allow-scripts has detected dependencies without configuration. explicit configuration required.
5749
run "allow-scripts auto" to automatically populate the configuration.
5850
```
59-
60-
You can resolve this error by running the following command:
61-
51+
You can resolve this error by running:
52+
6253
```bash
6354
yarn run allow-scripts auto
6455
```
56+
</div>
57+
</details>
58+
59+
60+
### 2. (Optional) Customize your Snap's UX
61+
62+
This Snap is generated from a TypeScript template Snap. We recommend customizing your
63+
Snap to improve its UX, but this is optional for testing. If you don't wish to customize your Snap,
64+
skip to [Step 3](#3-enable-network-access).
6565

66-
### 2. Add a custom icon
66+
#### 2.1. Provide an icon
6767

68-
Your Snap must [display an icon](../best-practices/design-guidelines.md#optimize-your-metadata) in MetaMask.
69-
To add an icon, create a new folder `images` in the Snap package `packages/snap/`:
68+
[Optimize your metadata](../best-practices/design-guidelines.md#optimize-your-metadata) and display an icon for your Snap in MetaMask.
69+
70+
Create a new folder `images` in the Snap package `packages/snap/`:
7071

7172
```bash
7273
mkdir packages/snap/images
7374
```
7475

7576
Download
7677
[this `gas.svg` icon file](https://raw.githubusercontent.com/Montoya/gas-fee-snap/main/packages/snap/images/gas.svg)
77-
into the `ìmages` folder you just created.
78-
This is a free icon, "Gas" by Mello from
79-
[Noun Project](https://thenounproject.com/browse/icons/term/gas/).
78+
into that `ìmages` folder.
79+
80+
<details>
81+
<summary>Icon attribution</summary>
82+
<div>
83+
This is a free icon, "Gas" by Mello from the [Noun Project](https://thenounproject.com/browse/icons/term/gas/).
84+
</div>
85+
</details>
8086

8187
Your file structure should look like this:
8288

@@ -102,10 +108,9 @@ gas-estimation-snap/
102108
├─ ... (other stuff)
103109
```
104110

105-
Open `packages/snap/snap.manifest.json` in a text editor.
106-
This file contains the main configuration details for your Snap.
107-
Edit the `npm` object, within the `location` object,
108-
and add `iconPath` with the value `"images/gas.svg"` to point to your new icon:
111+
Open `packages/snap/snap.manifest.json` in a text editor. This file contains the main configuration
112+
details for your Snap. Edit the `npm` object, within the `location` object, and add `iconPath` with
113+
the value `"images/gas.svg"` to point to your new icon:
109114

110115
```json title="snap.manifest.json"
111116
"location": {
@@ -118,8 +123,8 @@ and add `iconPath` with the value `"images/gas.svg"` to point to your new icon:
118123
}
119124
```
120125

121-
Open `packages/snap/package.json` in a text editor.
122-
Edit the `files` array and add the `images/` folder:
126+
Open `packages/snap/package.json` in a text editor. Edit the `files` array and reference the
127+
`images/` folder:
123128

124129
```json title="package.json"
125130
"files": [
@@ -129,6 +134,39 @@ Edit the `files` array and add the `images/` folder:
129134
],
130135
```
131136

137+
#### 2.2. Update your Snap's name
138+
139+
[Optimize your metadata](../best-practices/design-guidelines.md#optimize-your-metadata) and update
140+
your Snap's name in MetaMask.
141+
MetaMask uses the `proposedName` of the Snap, currently "TypeScript Example" in the template.
142+
143+
Open `packages/snap/snap.manifest.json` in a text editor.
144+
Edit the `"proposedName"` property within the metadata to provide a functional name such as
145+
"Gas Estimator":
146+
147+
```json title="snap.manifest.json"
148+
{
149+
"version": "0.1.0",
150+
"description": "An example Snap written in TypeScript.",
151+
"proposedName": "Gas Estimator",
152+
...
153+
}
154+
```
155+
156+
#### 2.3. Update your Snap's button
157+
158+
Open `packages/site/src/components/Buttons.tsx` in a text editor.
159+
Edit the `Button` property to provide functional label text such as "Estimate Gas":
160+
161+
```typescript title="Buttons.tsx"
162+
export const SendHelloButton = (props: ComponentProps<typeof Button>) => {
163+
return <Button {...props}>Estimate Gas</Button>;
164+
};
165+
````
166+
167+
These three updates are the minimum required to ensure that each user interaction with your Snap is well-informed.
168+
However, your Snap will function without these tweaks.
169+
132170
### 3. Enable network access
133171

134172
To enable your Snap to [access the internet using the `fetch` API](../../features/network-access.md),
@@ -144,7 +182,6 @@ permission in `packages/snap/snap.manifest.json`:
144182
},
145183
"endowment:network-access": {}
146184
},
147-
"manifestVersion": "0.1"
148185
```
149186

150187
### 4. Fetch gas fee estimates
@@ -187,7 +224,7 @@ Update the `hello` method with the following code:
187224
case "hello":
188225
const fees = await getFees();
189226
return snap.request({
190-
method: 'snap_dialog',
227+
method: "snap_dialog",
191228
params: {
192229
type: "alert",
193230
content: (
@@ -208,7 +245,7 @@ case "hello":
208245
case "hello":
209246
const fees = await getFees();
210247
return snap.request({
211-
method: 'snap_dialog',
248+
method: "snap_dialog",
212249
params: {
213250
type: "alert",
214251
content: panel([
@@ -223,72 +260,73 @@ case "hello":
223260
</TabItem>
224261
</Tabs>
225262
226-
### 5. Build and test the Snap
263+
### 5. Build and test your Snap
227264
228-
To build and test your Snap:
265+
Complete the following steps to build and test your Snap:
229266
230-
1. Open `package.json` in the root directory of the project, and increment the `"version"` (if the `"version"` is
231-
`0.1.0`, increase it to `0.2.0`).
267+
#### 5.1. Build your Snap
232268
233-
2. From the command line, run `yarn start`.
234-
In the terminal, at the bottom of the message log, you see the browser URL:
269+
From the command line, run `yarn start`.
270+
The following displays:
271+
272+
```bash
273+
You can now view site in the browser.
235274

236-
```bash
237-
You can now view site in the browser.
275+
http://localhost:8000/
276+
```
238277
239-
http://localhost:8000/
240-
```
278+
Open [`localhost:8000`](http://localhost:8000/) in your browser (with MetaMask Flask installed).
279+
A page like the following displays:
241280
242-
3. Open [`localhost:8000`](http://localhost:8000/) in your browser (with MetaMask Flask installed).
243-
A page like the following displays:
281+
<img src={require('../../assets/template-snap.png').default} alt="Test dapp with template Snap" style={{border: '1px solid #DCDCDC'}} />
244282
245-
<img src={require('../../assets/template-snap.png').default} alt="Test dapp with template Snap" style={{border: '1px solid #DCDCDC'}} />
283+
This is a template test dapp for installing and testing your Snap.
246284
247-
This is a boilerplate test dapp for installing and testing your Snap.
285+
#### 5.2. Test your Snap
248286
249-
4. Select **Connect** to connect Flask to the dapp.
250-
After connecting, you're prompted to install the Snap with the following permissions:
287+
Select **Connect** to connect Flask to the dapp.
288+
After connecting, you're prompted to install the Snap with the following permissions:
251289
252-
- **Allow dapps to communicate directly with this Snap.**
253-
- **Access the internet.**
254-
- **Display dialog windows in MetaMask.**
290+
- **Allow websites to communicate directly with this Snap.**
291+
- **Access the internet.**
292+
- **Display dialog windows in MetaMask.**
255293
256-
5. Select **Approve** > **Install**.
294+
Next, select **Confirm** > **OK**.
257295
258-
6. After installing, the **Send message** button on the page is enabled. Select this button. A dialog prompt displays with the response from the gas fee API:
296+
Select the **Send message** button (or **Estimate gas** button, if you followed Step 2). A dialog prompt displays with the response from the gas fee API:
259297
260298
<p align="center">
261299
<img src={require('../../assets/gas-estimation.png').default} alt="Gas estimation dialog" width="400px" style={{border: '1px solid #DCDCDC'}} />
262300
</p>
263301
264-
You have integrated a public API into MetaMask and displayed real-time gas fee estimates.
265-
266-
### 6. Next steps
302+
Congratulations, you have integrated a public API into MetaMask and displayed real-time gas fee estimates.
267303
268-
Next, you can try:
304+
### Next steps
269305
306+
You can improve your Snap's UX by:
307+
- Completing [Step 2](#2-optional-customize-your-snaps-ux).
270308
- Parsing the JSON response from the remote API.
271-
- Displaying the fees in a nicely formatted way.
309+
- Formatting the fees for better readability.
272310
273-
You can also update the fields in `snap.manifest.json` to match your custom Snap:
311+
Before publishing a Snap, it's also important to customize the metadata and properties of your Snap:
274312
275-
- `proposedName` - The name of your Snap.
276-
- `description` - The description of your Snap.
277-
- `source` - The `shasum` is set automatically when you build from the command line.
278-
If you decided to publish your Snap to `npm`, update the `location` to its published location.
313+
- Update the `location` in `snap.manifest.json` to your Snap's published location.
314+
- Update the `description` in `snap.manifest.json` to a description of your Snap.
315+
- Update the `name`, `version`, `description`, and `repository` fields of
316+
`/packages/snap/package.json` (even if you do not plan to publish your Snap to npm).
317+
- Update the content of `/packages/site/src/pages/index.tsx` by changing the
318+
name of the method for showing gas fee estimates. If you change the method name in
319+
`/packages/site/src/pages/index.tsx`, ensure you change the method name in
320+
`/packages/snap/src/index.ts` to match.
279321
280-
Similarly, you should update the `name`, `version`, `description`, and `repository` fields of
281-
`/packages/snap/package.json` even if you do not plan to publish your Snap to npm.
322+
:::note
323+
When editing `source`, the `shasum` is set automatically when you build from the command line.
324+
:::
282325
283326
:::caution important
284327
The `version` and `repository` fields in `snap.manifest.json` inherit the values from
285328
`package.json` and overwrite them in `snap.manifest.json`.
286-
We recommend updating `version` and `repository` in `package.json` first, then building the Snap project.
329+
We recommend updating `version` and `repository` in `package.json` first, then building your Snap project.
287330
:::
288331
289-
You can update the content of `/packages/site/src/pages/index.tsx` by changing the
290-
name of the method for showing gas fee estimates.
291-
If you change the method name in `/packages/site/src/pages/index.tsx`, ensure you change the method name in `/packages/snap/src/index.ts` to match.
292-
293-
After you have made all necessary changes, you can
294-
[publish your Snap to npm](../../how-to/publish-a-snap.md).
332+
After you have made all necessary changes, you can [publish your Snap to npm](../../how-to/publish-a-snap.md).

0 commit comments

Comments
 (0)