Skip to content

Commit

Permalink
Fix various 0.6.0 bugs (#168)
Browse files Browse the repository at this point in the history
- `rpc-methods`: Fix `snap_confirm` validation logic
- `example-snap`: Fix `snap_confirm` params
  - Rebuild the `snaps-cli` `init` command template
  • Loading branch information
rekmarks authored Dec 16, 2021
1 parent 7c743fa commit f35a296
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/example-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-skunkworks.git"
},
"source": {
"shasum": "m9N8XOgqscV1o9jCgn9gdE2xZB7sjU6bF3e1XCGpMiE=",
"shasum": "3lEt0yUu080DwV78neROaAAIQWXukSkMnP4OBhOhBnE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/example-snap/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ wallet.registerRpcMessageHandler(async (originString, requestObject) => {
case 'hello':
return wallet.request({
method: 'snap_confirm',
params: [`Hello, ${originString}!`],
params: [{ prompt: `Hello, ${originString}!` }],
});
default:
throw new Error('Method not found.');
Expand Down
4 changes: 2 additions & 2 deletions packages/rpc-methods/src/restricted/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function getValidatedParams(params: unknown): ConfirmFields {
}

if (
!description &&
description &&
(typeof description !== 'string' || description.length > 140)
) {
throw ethErrors.rpc.invalidParams({
Expand All @@ -123,7 +123,7 @@ function getValidatedParams(params: unknown): ConfirmFields {
}

if (
!textAreaContent &&
textAreaContent &&
(typeof textAreaContent !== 'string' || textAreaContent.length > 1800)
) {
throw ethErrors.rpc.invalidParams({
Expand Down
2 changes: 1 addition & 1 deletion packages/snap-examples/examples/bls-signer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function getPubKey() {
async function promptUser(message) {
const response = await wallet.request({
method: 'snap_confirm',
params: [message],
params: [{ prompt: message }],
});
return response;
}
2 changes: 1 addition & 1 deletion packages/snaps-cli/src/cmds/init/init-template.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"html": "<!doctype html>\n<html>\n </head>\n <title>Hello, Snaps!</title>\n </head>\n\n <body>\n <h1>Hello, Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The <code>snap.manifest.json</code> and <code>package.json</code> must be located in located in the server root directory..\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>.\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n\n // When developing locally, we identify Snaps like this\n const snapId = `local:${window.location.href}`;\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the snap\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_snap: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the snap's \"hello\" method\n async function send () {\n try {\n const response = await ethereum.request({\n method: 'wallet_invokeSnap',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n\n </script>\n</html>\n",
"source": "wallet.registerRpcMessageHandler(async (originString, requestObject) => {\n switch (requestObject.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [`Hello, ${originString}!`],\n });\n default:\n throw new Error('Method not found.');\n }\n});\n"
"source": "wallet.registerRpcMessageHandler(async (originString, requestObject) => {\n switch (requestObject.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [{ prompt: `Hello, ${originString}!` }],\n });\n default:\n throw new Error('Method not found.');\n }\n});\n"
}

0 comments on commit f35a296

Please sign in to comment.