on master help sign in
prevent users bailing midway through activate
9a09bfcLiam Fitzgerald
src/lib/useBlockWindowClose.jsnew file+17
@@ -0,0 +1,17 @@
1+import { useEffect } from 'react';
2+
3+function onBeforeUnload(e) {
4+ e.preventDefault();
5+
6+ e.returnValue = '';
7+}
8+
9+export default function useBlockWindowClose() {
10+ return useEffect(() => {
11+ window.addEventListener('beforeunload', onBeforeUnload);
12+
13+ return function cleanup() {
14+ window.removeEventListener('beforeunload', onBeforeUnload);
15+ };
16+ });
17+}
src/views/Activate/PassportTransfer.js+3
@@ -8,6 +8,7 @@ import { usePointCursor } from 'store/pointCursor';
8
8
9import * as need from 'lib/need';
9import * as need from 'lib/need';
10import useLifecycle from 'lib/useLifecycle';
10import useLifecycle from 'lib/useLifecycle';
11+import useBlockWindowClose from 'lib/useBlockWindowClose';
11import {
12import {
12 reticketPointBetweenWallets,
13 reticketPointBetweenWallets,
13 TRANSACTION_PROGRESS,
14 TRANSACTION_PROGRESS,
@@ -60,6 +61,8 @@ export default function PassportTransfer({ className, resetActivateRouter }) {
60 [replaceWith, names]
61 [replaceWith, names]
61 );
62 );
62
63
64+ useBlockWindowClose();
65+
63 const goToRestart = useCallback(() => {
66 const goToRestart = useCallback(() => {
64 // NOTE: because we're already on the ACTIVATE view in the history,
67 // NOTE: because we're already on the ACTIVATE view in the history,
65 // react (intelligently) doesn't trigger a re-render and that means the
68 // react (intelligently) doesn't trigger a re-render and that means the