Skip to content

Commit d8476fb

Browse files
authored
feat: reject pending confirmations for origin when permissions are revoked for it (#31074)
## **Description** reject pending confirmations for origin when permissions are revoked for it ## **Related issues** Fixes: MetaMask/MetaMask-planning#4443 ## **Manual testing steps** 1. Enable EVM multichain locally 2. Go to test dapp and create a confirmation 3. Revoke permissions, check that pending confirmation is rejected ## **Screenshots/Recordings** https://github.com/user-attachments/assets/bd9c1993-20df-4c1e-91b9-1378e8c09562 ## **Pre-merge author checklist** - [X] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent f7b448a commit d8476fb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app/scripts/lib/rpc-method-middleware/handlers/wallet-revokePermissions.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const createMockedHandler = () => {
2121
const next = jest.fn();
2222
const end = jest.fn();
2323
const revokePermissionsForOrigin = jest.fn();
24+
const rejectApprovalRequestsForOrigin = jest.fn();
2425

2526
const response: PendingJsonRpcResponse<Json> = {
2627
jsonrpc: '2.0' as const,
@@ -29,13 +30,15 @@ const createMockedHandler = () => {
2930
const handler = (request: JsonRpcRequest<Json[]>) =>
3031
revokePermissionsHandler.implementation(request, response, next, end, {
3132
revokePermissionsForOrigin,
33+
rejectApprovalRequestsForOrigin,
3234
});
3335

3436
return {
3537
response,
3638
next,
3739
end,
3840
revokePermissionsForOrigin,
41+
rejectApprovalRequestsForOrigin,
3942
handler,
4043
};
4144
};
@@ -141,6 +144,21 @@ describe('revokePermissionsHandler', () => {
141144
]);
142145
});
143146

147+
it('calls function rejectApprovalRequestsForOrigin to reject pending confirmations', () => {
148+
const { handler, rejectApprovalRequestsForOrigin } = createMockedHandler();
149+
150+
handler({
151+
...baseRequest,
152+
params: [
153+
{
154+
[Caip25EndowmentPermissionName]: {},
155+
otherPermission: {},
156+
},
157+
],
158+
});
159+
expect(rejectApprovalRequestsForOrigin).toHaveBeenCalled();
160+
});
161+
144162
it('returns null', () => {
145163
const { handler, response } = createMockedHandler();
146164

app/scripts/lib/rpc-method-middleware/handlers/wallet-revokePermissions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const revokePermissionsHandler = {
1818
implementation: revokePermissionsImplementation,
1919
hookNames: {
2020
revokePermissionsForOrigin: true,
21+
rejectApprovalRequestsForOrigin: true,
2122
updateCaveat: true,
2223
},
2324
};
@@ -31,6 +32,7 @@ export const revokePermissionsHandler = {
3132
* @param end - JsonRpcEngine end() callback
3233
* @param options - Method hooks passed to the method implementation
3334
* @param options.revokePermissionsForOrigin - A hook that revokes given permission keys for an origin
35+
* @param options.rejectApprovalRequestsForOrigin - A hook that rejects pending confirmation for an origin
3436
* @returns A promise that resolves to nothing
3537
*/
3638
function revokePermissionsImplementation(
@@ -40,8 +42,10 @@ function revokePermissionsImplementation(
4042
end: JsonRpcEngineEndCallback,
4143
{
4244
revokePermissionsForOrigin,
45+
rejectApprovalRequestsForOrigin,
4346
}: {
4447
revokePermissionsForOrigin: (permissionKeys: string[]) => void;
48+
rejectApprovalRequestsForOrigin: () => void;
4549
},
4650
) {
4751
const { params } = req;
@@ -78,6 +82,7 @@ function revokePermissionsImplementation(
7882
}
7983

8084
revokePermissionsForOrigin(relevantPermissionKeys);
85+
rejectApprovalRequestsForOrigin();
8186

8287
res.result = null;
8388

0 commit comments

Comments
 (0)