Skip to content

Commit

Permalink
Add state to know when user closed overlay for blocked scenario with …
Browse files Browse the repository at this point in the history
…no confirmation window
  • Loading branch information
imx-mikhala committed May 9, 2024
1 parent c22fe86 commit 7e29728
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/passport/sdk/src/confirmation/confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default class ConfirmationScreen {

private overlay: Overlay | undefined;

private overlayClosed: boolean = false;

private timer: NodeJS.Timeout | undefined;

constructor(config: PassportConfiguration) {
Expand Down Expand Up @@ -184,7 +186,10 @@ export default class ConfirmationScreen {
});
} catch { /* Empty */ }
},
() => this.closeWindow(),
() => {
this.overlayClosed = true;
this.closeWindow();
},
);
}

Expand All @@ -202,16 +207,18 @@ export default class ConfirmationScreen {

// This indicates the user closed the overlay so the transaction should be rejected
if (!this.overlay) {
this.overlayClosed = false;
resolve({ confirmed: false });
return;
}

// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
const timerCallback = () => {
if (this.confirmationWindow?.closed) {
if (this.confirmationWindow?.closed || this.overlayClosed) {
clearInterval(this.timer);
window.removeEventListener('message', messageHandler);
resolve({ confirmed: false });
this.overlayClosed = false;
this.confirmationWindow = undefined;
}
};
Expand Down

0 comments on commit 7e29728

Please sign in to comment.