Skip to content

Commit 4bbfcc3

Browse files
authored
Preparing for deployment (#17)
* Introduce pill component * more semantic * capitalize components * correct MDX * removing versioning on snaps, fix broken links, add lint command, add gh actions * add cache to CI * add cache CI * bump * review comments, add gitignore for vercel test files
1 parent e0ee2c8 commit 4bbfcc3

25 files changed

+107
-2106
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

.eslintrc

-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
"rules": {
1212
"@typescript-eslint/no-var-requires": "off"
1313
}
14-
},
15-
{
16-
"files": "**/*.md",
17-
"rules": {
18-
"no-multiple-empty-lines": ["error", { "max": 2 }]
19-
}
2014
}
2115
],
2216
"extends": [

.github/workflows/integration.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Node.js CI
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [18.x]
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
cache: yarn
21+
- run: yarn install --prefer-offline
22+
- run: yarn lint
23+
- run: yarn build

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
npm-debug.log*
2020
yarn-debug.log*
2121
yarn-error.log*
22+
.vercel

api-sdk-sidebar.js

+53-53
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,80 @@
33
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
44
const sidebar = {
55
apiSidebar: [
6-
'index',
6+
"index",
77
{
8-
type: 'category',
9-
label: 'Get started',
10-
link: { type: 'generated-index' },
8+
type: "category",
9+
label: "Get started",
10+
link: { type: "generated-index" },
1111
collapsed: false,
1212
items: [
13-
'get-started/set-up-dev-environment',
14-
'get-started/run-test-network',
15-
'get-started/detect-metamask',
16-
'get-started/access-account',
17-
'get-started/log-in-users'
18-
]
13+
"get-started/set-up-dev-environment",
14+
"get-started/run-test-network",
15+
"get-started/detect-metamask",
16+
"get-started/access-account",
17+
"get-started/log-in-users",
18+
],
1919
},
2020
{
21-
type: 'category',
22-
label: 'How to',
23-
link: { type: 'generated-index' },
21+
type: "category",
22+
label: "How to",
23+
link: { type: "generated-index" },
2424
items: [
2525
{
26-
type: 'category',
27-
label: 'Use MetaMask SDK',
26+
type: "category",
27+
label: "Use MetaMask SDK",
2828
collapsed: true,
2929
link: {
30-
type: 'doc',
31-
id: 'how-to/use-sdk/index'
30+
type: "doc",
31+
id: "how-to/use-sdk/index",
3232
},
3333
items: [
34-
'how-to/use-sdk/react-native',
35-
'how-to/use-sdk/pure-js'
36-
]
34+
"how-to/use-sdk/react-native",
35+
"how-to/use-sdk/pure-js",
36+
],
3737
},
38-
'how-to/use-mobile',
39-
'how-to/interact-with-smart-contracts',
40-
'how-to/send-transactions',
41-
'how-to/sign-data',
42-
'how-to/register-token',
43-
'how-to/register-method-names',
44-
'how-to/access-provider',
45-
'how-to/use-onboarding-library',
46-
'how-to/set-icon',
47-
'how-to/migrate-api'
48-
]
38+
"how-to/use-mobile",
39+
"how-to/interact-with-smart-contracts",
40+
"how-to/send-transactions",
41+
"how-to/sign-data",
42+
"how-to/register-token",
43+
"how-to/register-method-names",
44+
"how-to/access-provider",
45+
"how-to/use-onboarding-library",
46+
"how-to/set-icon",
47+
"how-to/migrate-api",
48+
],
4949
},
5050
{
51-
type: 'category',
52-
label: 'Reference',
53-
link: { type: 'generated-index' },
51+
type: "category",
52+
label: "Reference",
53+
link: { type: "generated-index" },
5454
items: [
55-
'reference/provider-api',
56-
'reference/rpc-api',
57-
'reference/sdk-js-options'
58-
]
55+
"reference/provider-api",
56+
"reference/rpc-api",
57+
"reference/sdk-js-options",
58+
],
5959
},
6060
{
61-
type: 'category',
62-
label: 'Concepts',
63-
link: { type: 'generated-index' },
61+
type: "category",
62+
label: "Concepts",
63+
link: { type: "generated-index" },
6464
items: [
65-
'concepts/sdk',
66-
'concepts/signing-methods',
67-
'concepts/onboarding-library'
68-
]
65+
"concepts/sdk",
66+
"concepts/signing-methods",
67+
"concepts/onboarding-library",
68+
],
6969
},
7070
{
71-
type: 'category',
72-
label: 'Tutorials',
73-
link: { type: 'generated-index' },
71+
type: "category",
72+
label: "Tutorials",
73+
link: { type: "generated-index" },
7474
items: [
75-
'tutorials/create-simple-dapp',
76-
'tutorials/create-simple-dapp-with-sdk'
77-
]
78-
}
79-
]
75+
"tutorials/create-simple-dapp",
76+
"tutorials/create-simple-dapp-with-sdk",
77+
],
78+
},
79+
],
8080
};
8181

8282
module.exports = sidebar;

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
2+
presets: [require.resolve("@docusaurus/core/lib/babel/preset")],
33
};

docusaurus.config.js

-6
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ const config = {
6060
routeBasePath: "snaps",
6161
sidebarPath: require.resolve("./snaps-sidebar.js"),
6262
breadcrumbs: false,
63-
versions: {
64-
production: {
65-
label: "Current",
66-
badge: false,
67-
},
68-
},
6963
}),
7064
],
7165
],

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"serve": "docusaurus serve",
1313
"write-translations": "docusaurus write-translations",
1414
"write-heading-ids": "docusaurus write-heading-ids",
15-
"typecheck": "tsc"
15+
"typecheck": "tsc",
16+
"lint": "eslint .",
17+
"lint:fix": "eslint . --fix"
1618
},
1719
"dependencies": {
1820
"@docusaurus/core": "2.2.0",

snaps-sidebar.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ const sidebar = {
1616

1717
// But you can create a sidebar manually
1818
snapsSidebar: [
19-
'index',
19+
"index",
2020
{
2121
type: "category",
2222
label: "How To",
2323
link: { type: "generated-index" },
2424
items: [
2525
"how-to/guide",
2626
"how-to/patching-dependencies",
27-
]
27+
],
2828
},
2929
{
3030
type: "category",
@@ -33,10 +33,10 @@ const sidebar = {
3333
items: [
3434
"reference/rpc-api",
3535
"reference/permissions",
36-
"reference/exports"
37-
]
38-
}
39-
]
36+
"reference/exports",
37+
],
38+
},
39+
],
4040
};
4141

4242
module.exports = sidebar;

snaps/how-to/guide.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Development Guide
22

33
:::tip Developer Preview Software
4-
[Snaps](./snaps.html) is pre-release software. To try Snaps, install [MetaMask Flask](https://metamask.io/flask).
4+
[Snaps](../) is pre-release software. To try Snaps, install [MetaMask Flask](https://metamask.io/flask).
55
:::
66

77
Developing a snap is much like developing any JavaScript project, but there are some things that may be new even to a seasoned developer.
@@ -20,7 +20,7 @@ Executing `mm-snap --help` will provide detailed usage instructions.
2020
## The Anatomy of a Snap
2121

2222
:::caution Prerequisite Reading
23-
This guide assumes that you've completed the ["Getting Started" tutorial](./snaps.html#getting-started).
23+
This guide assumes that you've completed the ["Getting Started" tutorial](../#getting-started).
2424
:::
2525

2626
So, you have installed [MetaMask Flask](https://metamask.io/flask), cloned the [@metamask/template-snap-monorepo](https://github.com/MetaMask/template-snap-monorepo) repository, and have served the "Hello, World!" snap locally.
@@ -198,10 +198,10 @@ If this sounds like a lot to worry about, `mm-snap build` is your friend, becaus
198198
## Developing a Snap
199199

200200
Snaps exist in order to modify the functionality of MetaMask at runtime while only asking the user for permission.
201-
As we have seen in the [introduction to snaps](./snaps.html) and this guide, snaps can:
201+
As we have seen in the [introduction to snaps](../) and this guide, snaps can:
202202

203203
1. Extend the dapp-facing MetaMask JSON-RPC API in arbitrary ways.
204-
1. Integrate with and extend the functionality of MetaMask using the [snaps RPC methods and permissions](./snaps-rpc-api.html).
204+
1. Integrate with and extend the functionality of MetaMask using the [snaps RPC methods and permissions](../reference/rpc-api).
205205

206206
In this section, we'll go into detail about how to actually develop a snap and overcome common issues encountered during development.
207207

@@ -224,7 +224,7 @@ If a snap is disabled, the user must re-enable it before it can start again.
224224
### Permissions
225225

226226
Just like dapps need to request the `eth_accounts` permission in order to access the user's Ethereum accounts, snaps need to request access to the sensitive methods in the snaps RPC API.
227-
Snaps can effectively expand the MetaMask RPC API by implementing their own and exposing it via `onRpcRequest`, but in order to integrate deeply with MetaMask, you need to make use of the Snaps RPC API's [restricted methods](./snaps-rpc-api.html#restricted-methods).
227+
Snaps can effectively expand the MetaMask RPC API by implementing their own and exposing it via `onRpcRequest`, but in order to integrate deeply with MetaMask, you need to make use of the Snaps RPC API's [restricted methods](../reference/rpc-api#restricted-methods).
228228
Access restriction is implemented using [EIP-2255 wallet permissions](https://eips.ethereum.org/EIPS/eip-2255), and you must specify the permissions required by your snap in the manifest's `initialPermissions` field.
229229
You can find an example of how to do this in the [template snap's manifest](https://github.com/MetaMask/template-snap-monorepo/blob/main/packages/snap/snap.manifest.json).
230230

@@ -250,7 +250,7 @@ Via the MetaMask settings page, the user can see their installed snaps. For each
250250
- see its execution status (running, stopped, or crashed)
251251
- enable and disable the snap
252252

253-
Other than the settings page, the only way a snap can modify the MetaMask UI is by creating a confirmation using the [`snap_confirm`](./snaps-rpc-api.html#snap-confirm) RPC method.
253+
Other than the settings page, the only way a snap can modify the MetaMask UI is by creating a confirmation using the [`snap_confirm`](../reference/rpc-api#snap-confirm) RPC method.
254254
This means that many snaps will have to rely on web pages (i.e., dapps) and their own RPC methods to present their data to the user.
255255

256256
Providing more ways for snaps to modify the MetaMask UI is an important goal of the snaps system, and over time more and more snaps will be able to contain their user interfaces entirely within MetaMask itself.
@@ -330,7 +330,7 @@ In this way, you can identify if the error is due to your code or one of your de
330330
If the problem is in a dependency, you can try a different version or to fix the issue locally by using tools such as [`patch-package`](https://npmjs.com/package/patch-package) or by modifying the snap bundle file directly.
331331
332332
:::tip Patching Dependencies
333-
You can read more about patching dependencies [here](./snaps-patching-dependencies.html)
333+
You can read more about patching dependencies [here](./patching-dependencies)
334334
:::
335335
336336
To give you an idea of a common error and how to fix it, "sloppily" declared variables (i.e. assigning to a new variable without an explicit variable declaration) are forbidden in strict mode, and therefore in SES as well.
@@ -394,7 +394,7 @@ After publishing the Snap, any dapp can connect to the Snap by using the snapId
394394
### Distributing Your Snap
395395

396396
Since snaps are currently intended for a developer audience, MetaMask does not currently facilitate distributing snaps to a wide audience.
397-
If you have a website that expects the user to install a snap, ask the user to install MetaMask Flask, and then ask the user to install the snap using the [`wallet_enable`](./snaps-rpc-api.html#wallet-enable) RPC method.
397+
If you have a website that expects the user to install a snap, ask the user to install MetaMask Flask, and then ask the user to install the snap using the [`wallet_enable`](../reference/rpc-api#wallet-enable) RPC method.
398398

399399
In the future, MetaMask will create some way for users to more easily discover snaps, but everyone will always be able to build, publish, and use snaps without MetaMask's permission.
400400
(Although we may try to make it difficult to use known scams.)

snaps/how-to/patching-dependencies.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Patching Dependencies
22

33
:::tip Only Available in MetaMask Flask
4-
[Snaps](./snaps.html) is only available in [MetaMask Flask](https://metamask.io/flask).
4+
[Snaps](../) is only available in [MetaMask Flask](https://metamask.io/flask).
55
:::
66

7-
A problem that may arise as you develop your snap is that some dependencies make use of APIs that aren't available in the snaps execution environment. To work around this, we firstly recommend that you check if another library is available that makes use of the APIs made available for snaps (see [Snaps Development Guide](./snaps-development-guide.html#the-snap-execution-environment) for a list of APIs).
7+
A problem that may arise as you develop your snap is that some dependencies make use of APIs that aren't available in the snaps execution environment. To work around this, we firstly recommend that you check if another library is available that makes use of the APIs made available for snaps (see [Snaps Development Guide](./guide#the-snap-execution-environment) for a list of APIs).
88

99
If you are unable to find another library (or version) that works with the snaps execution environment, another way of solving the problem is by patching the dependency yourself. For this we can leverage [`patch-package`](https://npmjs.com/package/patch-package).
1010

snaps/reference/exports.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports.onRpcRequest = async ({ origin, request }) => {
8181
If the snap wants to provide transaction insights before a user signs a transaction, the snap must export a function called `onTransaction`. Whenever there is a contract interaction and a transaction is submitted via the extension, this function will be called. The raw unsigned transaction payload will be passed to the `onTransaction` handler function.
8282

8383
:::tip Requesting the transaction insight permission
84-
In order for the extension to call the `onTransaction` method of the snap, the `endowment:transaction-insight` permission must be requested. see [Permissions](./snaps-permissions.html#endowment-transaction-insight)
84+
In order for the extension to call the `onTransaction` method of the snap, the `endowment:transaction-insight` permission must be requested. see [Permissions](./permissions#endowment-transaction-insight)
8585
:::
8686

8787
### Parameters

snaps/reference/permissions.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Snaps is pre-release software. To try Snaps, install [MetaMask Flask](https://me
88
Do you have feature requests? Other ideas? We'd love to hear about them! [Click here](https://github.com/MetaMask/snaps-monorepo/discussions) to join the discussion.
99
:::
1010

11-
To access certain powerful JavaScript globals or JSON-RPC methods, your snap will need to ask the user for permission. Snaps follow the [EIP-2255 wallet permissions specification](https://eips.ethereum.org/EIPS/eip-2255), and your snap's required permissions must be specified in the `initialPermissions` field of your [`snap.manifest.json` file](./snaps-development-guide.md#the-snap-manifest).
11+
To access certain powerful JavaScript globals or JSON-RPC methods, your snap will need to ask the user for permission. Snaps follow the [EIP-2255 wallet permissions specification](https://eips.ethereum.org/EIPS/eip-2255), and your snap's required permissions must be specified in the `initialPermissions` field of your [`snap.manifest.json` file](../how-to/guide#the-snap-manifest).
1212

1313
## Table of Contents
1414

@@ -18,21 +18,21 @@ To access certain powerful JavaScript globals or JSON-RPC methods, your snap wil
1818

1919
### `endowment:long-running`
2020

21-
For snaps that are computationally heavy and can't finish execution within [the snap lifecycle requirements](./snaps-development-guide.md#the-snap-lifecycle), the snap can request the `endowment:long-running` permission.
21+
For snaps that are computationally heavy and can't finish execution within [the snap lifecycle requirements](../how-to/guide#the-snap-lifecycle), the snap can request the `endowment:long-running` permission.
2222
This permission will effectively allow snaps to run indefinitely while processing RPC requests.
2323

2424
### `endowment:network-access`
2525

2626
For snaps that need to access the internet, the snap can request the `endowment:network-access` permission. This permission will expose the global networking APIs `fetch` and `WebSocket` to the snap execution environment. Without this permission, these globals will not be available.
2727

2828
:::caution Avoid XMLHttpRequest
29-
`XMLHttpRequest` is never available in snaps, and you should replace it with `fetch`. If your dependencies are using `XMLHttpRequest`, you can learn how to patch it away [here](./snaps-patching-dependencies.md#patching-the-use-of-xmlhttprequest).
29+
`XMLHttpRequest` is never available in snaps, and you should replace it with `fetch`. If your dependencies are using `XMLHttpRequest`, you can learn how to patch it away [here](../how-to/patching-dependencies#patching-the-use-of-xmlhttprequest).
3030
:::
3131

3232
### `endowment:transaction-insight`
3333

34-
For snaps that provide transaction insights, the snap can request the `endowment:transaction-insight` permission. This permission grants a snap read-only access to raw transaction payloads, before they are accepted for signing by the user, by exporting the `onTransaction` method. see [Exports](./snaps-exports.html#ontransaction)
34+
For snaps that provide transaction insights, the snap can request the `endowment:transaction-insight` permission. This permission grants a snap read-only access to raw transaction payloads, before they are accepted for signing by the user, by exporting the `onTransaction` method. see [Exports](./exports#ontransaction)
3535

3636
## RPC Permissions
3737

38-
To use any restricted RPC method, a snap will need to request permissions to access that method. For a list of available RPC methods and thus valid RPC permissions see [JSON-RPC API](./snaps-rpc-api.html#restricted-methods)
38+
To use any restricted RPC method, a snap will need to request permissions to access that method. For a list of available RPC methods and thus valid RPC permissions see [JSON-RPC API](./rpc-api#restricted-methods)

snaps/reference/rpc-api.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface WalletEnableResult {
5858
#### Description
5959

6060
This is a convenience method for requesting the user's accounts and connecting to / installing snaps.
61-
You can think of it as a combination of [`eth_requestAccounts`](./rpc-api.html#eth-requestaccounts), [`wallet_installSnaps`](#wallet-installsnaps), and [`wallet_requestPermissions`](./rpc-api.html#wallet-requestpermissions).
61+
You can think of it as a combination of [`eth_requestAccounts`](#eth-requestaccounts), [`wallet_installSnaps`](#wallet-installsnaps), and [`wallet_requestPermissions`](#wallet-requestpermissions).
6262

6363
See the examples for details.
6464

@@ -332,7 +332,7 @@ console.log(result); // We happen to know that this will be `true` or `false`
332332
If a method is _restricted_, it means that you need the requisite permission before you can call it.
333333
Both snaps and dapps / websites can have permissions.
334334
Some permissions are only available to snaps, and some are only available to websites.
335-
See [here](./rpc-api.html#restricted-methods) for more information about the permission system.
335+
See [here](#restricted-methods) for more information about the permission system.
336336

337337
### `wallet_snap_*`
338338

Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)