This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat:add ability to accept dialogs (#138) * fix lint * move installSnap, invokeSnap to dappeteer api; add bringToFront call to dialog methods * pair improvements * fix lint * add methods snap * exclude flask tests from global * exclude flask tests from global Co-authored-by: Bernard <bero4net@gmail.com>
- Loading branch information
Showing
16 changed files
with
3,595 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Page } from "puppeteer"; | ||
import { clickOnButton } from "../helpers"; | ||
|
||
export const acceptDialog = (page: Page) => async (): Promise<void> => { | ||
await page.bringToFront(); | ||
await page.reload(); | ||
await clickOnButton(page, "Approve"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Page } from "puppeteer"; | ||
import { clickOnButton } from "../helpers"; | ||
|
||
export const rejectDialog = (page: Page) => async (): Promise<void> => { | ||
await page.bringToFront(); | ||
await page.reload(); | ||
await clickOnButton(page, "Reject"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export interface InstallSnapResult { | ||
accounts: []; | ||
permissions: [ | ||
{ | ||
id: string; | ||
parentCapability: string; | ||
invoker: string; | ||
caveats: null; | ||
date: number; | ||
} | ||
]; | ||
snaps: { | ||
[id: string]: { | ||
permissionName: string; | ||
id: string; | ||
initialPermissions: Object; | ||
version: string; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!doctype html> | ||
<html> | ||
</head> | ||
<title>Hello, Snaps!</title> | ||
<link rel="icon" type="image/svg" href="./images/icon.svg"/> | ||
</head> | ||
|
||
<body> | ||
<h1>Hello, Snaps!</h1> | ||
<details> | ||
<summary>Instructions</summary> | ||
<ul> | ||
<li>First, click "Connect". Then, try out the other buttons!</li> | ||
<li>Please note that:</li> | ||
<ul> | ||
<li> | ||
The <code>snap.manifest.json</code> and <code>package.json</code> must be located in the server root directory... | ||
</li> | ||
<li> | ||
The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>. | ||
</li> | ||
</ul> | ||
</ul> | ||
</details> | ||
<br/> | ||
|
||
<button class="connect">Connect</button> | ||
<button class="sendHello">Send Hello</button> | ||
</body> | ||
|
||
<script> | ||
const snapId = `local:${window.location.href}`; | ||
|
||
const connectButton = document.querySelector('button.connect') | ||
const sendButton = document.querySelector('button.sendHello') | ||
|
||
connectButton.addEventListener('click', connect) | ||
sendButton.addEventListener('click', send) | ||
|
||
// here we get permissions to interact with and install the snap | ||
async function connect () { | ||
await ethereum.request({ | ||
method: 'wallet_enable', | ||
params: [{ | ||
wallet_snap: { [snapId]: {} }, | ||
}] | ||
}) | ||
} | ||
|
||
// here we call the snap's "hello" method | ||
async function send () { | ||
try { | ||
await ethereum.request({ | ||
method: 'wallet_invokeSnap', | ||
params: [snapId, { | ||
method: 'hello' | ||
}] | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
alert('Problem happened: ' + err.message || err) | ||
} | ||
} | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "base-snap", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"prefix": "mm-snap build", | ||
"fix": "mm-snap manifest --fix" | ||
}, | ||
"devDependencies": { | ||
"@metamask/snaps-cli": "^0.22.0" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@metamask/snap-types": "^0.22.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
cliOptions: { | ||
src: './src/index.ts', | ||
port: 8080, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": "1.0.0", | ||
"description": "An example Snap written in TypeScript.", | ||
"proposedName": "Methods Snap\n", | ||
"source": { | ||
"shasum": "BCwqoDyQltaL0dh0IrzN1A66D1jPMLAseJOHmqI1faU=", | ||
"location": { | ||
"npm": { | ||
"filePath": "dist/bundle.js", | ||
"packageName": "base-snap", | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} | ||
}, | ||
"initialPermissions": { | ||
"snap_confirm": {}, | ||
"snap_notify": {} | ||
}, | ||
"manifestVersion": "0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { OnRpcRequestHandler } from "@metamask/snap-types"; | ||
|
||
export const onRpcRequest: OnRpcRequestHandler = ({ origin, request }) => { | ||
switch (request.method) { | ||
case "confirm": | ||
return wallet.request({ | ||
method: "snap_confirm", | ||
params: [ | ||
{ | ||
prompt: `Hello, ${origin}!`, | ||
description: | ||
"This custom confirmation is just for display purposes.", | ||
textAreaContent: | ||
"But you can edit the snap source code to make it do something, if you want to!", | ||
}, | ||
], | ||
}); | ||
default: | ||
throw new Error("Method not found."); | ||
} | ||
}; |
Oops, something went wrong.