-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- extract icon from tar file - show request permissions for install snap and account access - move snap webview to the root of the app and make it invisible - create RPC method handlers to register snaps rpc methods
- Loading branch information
1 parent
e6eb204
commit 4ffc810
Showing
11 changed files
with
155 additions
and
39 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
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
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,6 +1,6 @@ | ||
const snapsState = { | ||
stream: null, | ||
webview: null, | ||
stream: undefined, | ||
webview: undefined, | ||
}; | ||
|
||
export default snapsState; |
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,47 @@ | ||
import { handlers as permittedSnapMethods } from '@metamask/rpc-methods/dist/permitted'; | ||
import { selectHooks } from '@metamask/rpc-methods/dist/utils'; | ||
import { ethErrors } from 'eth-rpc-errors'; | ||
|
||
/* | ||
copied form extension | ||
https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js#L83 | ||
*/ | ||
const snapHandlerMap = permittedSnapMethods.reduce((map, handler) => { | ||
for (const methodName of handler.methodNames) { | ||
map.set(methodName, handler); | ||
} | ||
return map; | ||
}, new Map()); | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function createSnapMethodMiddleware(isSnap: boolean, hooks: any) { | ||
return async function methodMiddleware( | ||
req: unknown, | ||
res: unknown, | ||
next: unknown, | ||
end: unknown, | ||
) { | ||
const handler = snapHandlerMap.get(req.method); | ||
if (handler) { | ||
if (/^snap_/iu.test(req.method) && !isSnap) { | ||
return end(ethErrors.rpc.methodNotFound()); | ||
} | ||
|
||
const { implementation, hookNames } = handler; | ||
try { | ||
// Implementations may or may not be async, so we must await them. | ||
return await implementation( | ||
req, | ||
res, | ||
next, | ||
end, | ||
selectHooks(hooks, hookNames), | ||
); | ||
} catch (error) { | ||
console.error(error); | ||
return end(error); | ||
} | ||
} | ||
return next(); | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -71,5 +71,4 @@ class RNTar: NSObject { | |
rejecter("Error uncompressing file:", error.localizedDescription, error) | ||
} | ||
} | ||
|
||
} |