mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add missing permissions middleware hook (#13205)
Adds a missing middleware hook for `wallet_requestPermissions` that we failed to add in #12243. Also adds a runtime check that throws an error if any expected hooks are not provided to `createMethodMiddleware`. Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
parent
e213ea77bd
commit
75e8b4f8b9
@ -13,6 +13,12 @@ const handlerMap = allHandlers.reduce((map, handler) => {
|
||||
return map;
|
||||
}, new Map());
|
||||
|
||||
const expectedHookNames = Array.from(
|
||||
new Set(
|
||||
allHandlers.map(({ hookNames }) => Object.keys(hookNames)).flat(),
|
||||
).values(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a json-rpc-engine middleware of RPC method implementations.
|
||||
*
|
||||
@ -24,6 +30,16 @@ const handlerMap = allHandlers.reduce((map, handler) => {
|
||||
* @returns {(req: Object, res: Object, next: Function, end: Function) => void}
|
||||
*/
|
||||
export default function createMethodMiddleware(hooks) {
|
||||
// Fail immediately if we forgot to provide any expected hooks.
|
||||
const missingHookNames = expectedHookNames.filter(
|
||||
(hookName) => !Object.hasOwnProperty.call(hooks, hookName),
|
||||
);
|
||||
if (missingHookNames.length > 0) {
|
||||
throw new Error(
|
||||
`Missing expected hooks:\n\n${missingHookNames.join('\n')}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
return async function methodMiddleware(req, res, next, end) {
|
||||
// Reject unsupported methods.
|
||||
if (UNSUPPORTED_RPC_METHODS.has(req.method)) {
|
||||
|
@ -2759,6 +2759,10 @@ export default class MetamaskController extends EventEmitter {
|
||||
{ origin },
|
||||
{ eth_accounts: {} },
|
||||
),
|
||||
requestPermissionsForOrigin: this.permissionController.requestPermissions.bind(
|
||||
this.permissionController,
|
||||
{ origin },
|
||||
),
|
||||
|
||||
// Custom RPC-related
|
||||
addCustomRpc: async ({
|
||||
|
Loading…
Reference in New Issue
Block a user