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 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add invokeSnap method; update installSnap method parameter; (#159)
* Add invokeSnap method; update installSnap method parameter; * adjust invokeSnap method after review * Fix params type in invokeSnap method * update invokeSnap Return type * update invokeSnap with generic params * update test expectation * fix lint
- Loading branch information
Showing
5 changed files
with
81 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { flaskOnly } from "./utils"; | ||
export { installSnap } from "./install"; | ||
export { invokeSnap } from "./invokeSnap"; |
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,29 @@ | ||
import { Page, Serializable } from "puppeteer"; | ||
import { flaskOnly } from "./utils"; | ||
|
||
export async function invokeSnap< | ||
R = unknown, | ||
P extends Serializable = Serializable | ||
>( | ||
page: Page, | ||
snapId: string, | ||
method: string, | ||
params: P | ||
): ReturnType<typeof window.ethereum.request<R>> { | ||
flaskOnly(page); | ||
return page.evaluate( | ||
async (opts: { snapId: string; method: string; params: P }) => { | ||
return window.ethereum.request<R>({ | ||
method: "wallet_invokeSnap", | ||
params: [ | ||
`${opts.snapId}`, | ||
{ | ||
method: opts.method, | ||
params: opts.params, | ||
}, | ||
], | ||
}); | ||
}, | ||
{ snapId, method, params } | ||
); | ||
} |
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