Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/gator-permissions-snap/src/core/confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ export class ConfirmationDialog {
id: interfaceId,
},
})
.then(async (result) => {
// Should resolve with false when dialog is closed.
if (result === null) {
unbindGrantButtonClick();
unbindCancelButtonClick();

// clear our stored unbind handler reference
this.#unbindHandlers = undefined;

resolve(false);
}
})
.catch((error) => {
const reason = error as Error;
reject(reason);
Expand Down
19 changes: 19 additions & 0 deletions packages/gator-permissions-snap/test/core/confirmation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ describe('ConfirmationDialog', () => {
expect(result).toStrictEqual({ isConfirmationGranted: false });
});

it('should resolve with false when dialog is closed', async () => {
// Simulate dialog closure
mockSnaps.request.mockResolvedValueOnce(null);

const awaitingUserDecision =
confirmationDialog.displayConfirmationDialogAndAwaitUserDecision();

expect(mockUserEventDispatcher.on).toHaveBeenCalledTimes(2);
expect(mockUnbindFunctions).toHaveLength(2);

const result = await awaitingUserDecision;

mockUnbindFunctions.forEach((mockUnbindFn) => {
expect(mockUnbindFn).toHaveBeenCalledTimes(1);
});

expect(result).toStrictEqual({ isConfirmationGranted: false });
});

it('should clean up event listeners after decision', async () => {
const awaitingUserDecision =
confirmationDialog.displayConfirmationDialogAndAwaitUserDecision();
Expand Down
Loading