on master help sign in
Merge pull request #342 from urbit/close-window-invite
47b9201Fang
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
src/views/Admin/Reticket/ReticketExecute.js+3
@@ -10,6 +10,7 @@ import * as need from 'lib/need';
10import useLifecycle from 'lib/useLifecycle';
10import useLifecycle from 'lib/useLifecycle';
11import { WALLET_TYPES } from 'lib/wallet';
11import { WALLET_TYPES } from 'lib/wallet';
12import convertToInt from 'lib/convertToInt';
12import convertToInt from 'lib/convertToInt';
13+import useBlockWindowClose from 'lib/useBlockWindowClose';
13
14
14import { useNetwork } from 'store/network';
15import { useNetwork } from 'store/network';
15import { useWallet } from 'store/wallet';
16import { useWallet } from 'store/wallet';
@@ -52,6 +53,8 @@ export default function ReticketExecute({ newWallet, setNewWallet }) {
52 const [needFunds, setNeedFunds] = useState();
53 const [needFunds, setNeedFunds] = useState();
53 const isDone = progress >= 1.0;
54 const isDone = progress >= 1.0;
54
55
56+ useBlockWindowClose();
57+
55 // start reticketing transactions on mount
58 // start reticketing transactions on mount
56 useLifecycle(() => {
59 useLifecycle(() => {
57 (async () => {
60 (async () => {