Skip to content

Commit 8cb4684

Browse files
committed
Add onbeforeunload prompt while a swap is active
1 parent 9233a54 commit 8cb4684

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/components/swap/SwapNotification.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ export default defineComponent({
6060
),
6161
);
6262
63+
function onUnload(event: BeforeUnloadEvent) {
64+
// Firefox respects the event cancellation to prompt the user
65+
event.preventDefault();
66+
// Chrome requires returnValue to be set
67+
event.returnValue = '';
68+
}
69+
6370
onMounted(() => {
6471
if (activeSwap.value) processSwap();
6572
});
@@ -126,6 +133,8 @@ export default defineComponent({
126133
...activeSwap.value!,
127134
state: SwapState.EXPIRED,
128135
});
136+
} else {
137+
window.addEventListener('beforeunload', onUnload);
129138
}
130139
131140
switch (activeSwap.value!.state) {
@@ -165,6 +174,7 @@ export default defineComponent({
165174
default:
166175
break;
167176
}
177+
window.removeEventListener('beforeunload', onUnload);
168178
}
169179
170180
return {

0 commit comments

Comments
 (0)