@@ -1,4 +1,4 @@
1−import React, { useState, useCallback } from 'react';
1+import React, { useState, useCallback, useEffect } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
@@ -7,7 +7,6 @@ import {
7 TRANSACTION_PROGRESS,
7 TRANSACTION_PROGRESS,
8} from 'lib/reticket';
8} from 'lib/reticket';
9import * as need from 'lib/need';
9import * as need from 'lib/need';
10−import useLifecycle from 'lib/useLifecycle';
11import { WALLET_TYPES } from 'lib/constants';
10import { WALLET_TYPES } from 'lib/constants';
12import { convertToInt } from 'lib/convertToInt';
11import { convertToInt } from 'lib/convertToInt';
13import useBlockWindowClose from 'lib/useBlockWindowClose';
12import useBlockWindowClose from 'lib/useBlockWindowClose';
@@ -18,6 +17,8 @@ import { usePointCursor } from 'store/pointCursor';
18import { usePointCache } from 'store/pointCache';
17import { usePointCache } from 'store/pointCache';
19import { useHistory } from 'store/history';
18import { useHistory } from 'store/history';
20+import { useWalletConnect } from 'lib/useWalletConnect';
21import { RestartButton, ForwardButton } from 'components/Buttons';
22import { RestartButton, ForwardButton } from 'components/Buttons';
22import WarningBox from 'components/WarningBox';
23import WarningBox from 'components/WarningBox';
23import LoadingBar from 'components/LoadingBar';
24import LoadingBar from 'components/LoadingBar';
@@ -54,6 +55,11 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
54 } = useWallet();
55 } = useWallet();
55 const { pointCursor } = usePointCursor();
56 const { pointCursor } = usePointCursor();
56 const { getDetails } = usePointCache();
57 const { getDetails } = usePointCache();
59+ signTransaction: wcSign,
60+ sendTransaction: wcSend,
62+ } = useWalletConnect();
58 const [generalError, setGeneralError] = useState();
64 const [generalError, setGeneralError] = useState();
59 const [progress, setProgress] = useState(0);
65 const [progress, setProgress] = useState(0);
@@ -63,11 +69,28 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
63 useBlockWindowClose();
69 useBlockWindowClose();
65 // start reticketing transactions on mount
71 // start reticketing transactions on mount
66− useLifecycle(() => {
72+ useEffect(() => {
67 (async () => {
73 (async () => {
74+ // due to react shenanigans we may need to wait for the connector
76+ walletType === WALLET_TYPES.WALLET_CONNECT &&
77+ (!connector || !connector.connected)
79+ setGeneralError(new Error('Awaiting WalletConnect connection...'));
68 const point = need.point(pointCursor);
84 const point = need.point(pointCursor);
69 const details = need.details(getDetails(point));
85 const details = need.details(getDetails(point));
70 const networkRevision = convertToInt(details.keyRevisionNumber, 10);
86 const networkRevision = convertToInt(details.keyRevisionNumber, 10);
88+ // see also comment in useEthereumTransaction
90+ walletType === WALLET_TYPES.WALLET_CONNECT ? wcSign : undefined;
92+ walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
72 await reticketPointBetweenWallets({
95 await reticketPointBetweenWallets({
73 fromWallet: need.wallet(wallet),
96 fromWallet: need.wallet(wallet),
@@ -80,13 +103,19 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
80 networkType,
103 networkType,
81 onUpdate: handleUpdate,
104 onUpdate: handleUpdate,
82 nextRevision: networkRevision + 1,
105 nextRevision: networkRevision + 1,
84 } catch (err) {
109 } catch (err) {
85 console.error(err);
110 console.error(err);
86 setGeneralError(err);
111 setGeneralError(err);
89− });
114+ //NOTE this was using useLifecycle previously (which is useEffect without
115+ // dependencies) and worked fine, but in the wc case we might need to
116+ // wait for the connector to get set due to react state shenanigans.
117+ // eslint-disable-next-line react-hooks/exhaustive-deps
91 const goToRestart = useCallback(() => {
120 const goToRestart = useCallback(() => {
@@ -99,7 +128,7 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
99 setWalletType(WALLET_TYPES.TICKET);
128 setWalletType(WALLET_TYPES.TICKET);
100 setUrbitWallet(Just(newWallet.value.wallet));
129 setUrbitWallet(Just(newWallet.value.wallet));
101 // (implicit) pointCursor stays the same
130 // (implicit) pointCursor stays the same
102− // rediect to point
131+ // redirect to point
103 popTo(names.POINT);
132 popTo(names.POINT);
104 }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
133 }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);