feat(gator-permissions-controller): add submitDirectRevocation for already-disabled delegations #7244
+375
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation
This PR adds support for revoking already-disabled delegations that don't require an on-chain transaction. Previously, the revocation flow required creating a transaction and waiting for it to confirm, but for delegations that are already disabled on-chain, we can submit the revocation directly to the snap without waiting for a transaction.
What this PR does:
Adds submitDirectRevocation method: This new method combines adding a pending revocation to state (to disable the UI button) and immediately submitting the revocation to the snap. This simplifies the caller code in metamask-extension since they no longer need to call two separate methods.
Adds isPendingRevocation helper method: A utility method to check if a permission context is currently in the pending revocations list. This can be used by the UI to determine button states.
Improves error handling in submitRevocation: Refactored to use a finally block to ensure pending revocations are always cleared when the revocation succeeds, even if the refresh operation fails. This prevents stuck Revocation Pending states in the UI.
Key implementation details:
Usage:
Before (required two calls):
await gatorPermissionsController.addDirectPendingRevocation({ permissionContext });
await gatorPermissionsController.submitRevocation({ permissionContext });
After (single call):
await gatorPermissionsController.submitDirectRevocation({ permissionContext });
Testing:
Related
This change is needed to support revoking already-disabled delegations in the MetaMask extension UI.
Note
Adds
submitDirectRevocationandisPendingRevocation, and improves revocation cleanup and error handling.src/GatorPermissionsController.ts):submitDirectRevocation(params)for already-disabled delegations;isPendingRevocation(permissionContext)helper.GatorPermissionsController:submitDirectRevocationand:isPendingRevocation.submitRevocationnow refreshes permissions after submit, clears pending in afinallyblock, and wraps refresh failures withGatorPermissionsFetchError(specific message).permissionContextis now case-insensitive.src/index.ts): Export new action types for direct revocation and pending check.submitDirectRevocation,isPendingRevocation, andsubmitRevocationcleanup-on-refresh-failure.submitDirectRevocationin Unreleased.Written by Cursor Bugbot for commit 4ea1f04. This will update automatically on new commits. Configure here.