@@ -7,9 +7,10 @@ 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 { WALLET_TYPES } from 'lib/constants';
10+import { POINT_DOMINIONS, WALLET_TYPES } from 'lib/constants';
11import { convertToInt } from 'lib/convertToInt';
11import { convertToInt } from 'lib/convertToInt';
12import useBlockWindowClose from 'lib/useBlockWindowClose';
12import useBlockWindowClose from 'lib/useBlockWindowClose';
13+import { useReticketL2Spawn } from 'lib/useReticketL2Spawn';
14import { useNetwork } from 'store/network';
15import { useNetwork } from 'store/network';
15import { useWallet } from 'store/wallet';
16import { useWallet } from 'store/wallet';
@@ -25,8 +26,10 @@ import { RestartButton, ForwardButton } from 'components/Buttons';
25import WarningBox from 'components/WarningBox';
26import WarningBox from 'components/WarningBox';
26import LoadingBar from 'components/LoadingBar';
27import LoadingBar from 'components/LoadingBar';
27import NeedFundsNotice from 'components/NeedFundsNotice';
28import NeedFundsNotice from 'components/NeedFundsNotice';
29+import { debugLog } from 'lib/utils/debug';
30+import { ReticketProgressCallback } from 'lib/types/L2Transaction';
29−const labelForProgress = progress => {
32+const labelForProgress = (progress: number) => {
30 if (progress <= 0) {
33 if (progress <= 0) {
31 return 'Starting...';
34 return 'Starting...';
32 } else if (progress <= TRANSACTION_PROGRESS.GENERATING) {
35 } else if (progress <= TRANSACTION_PROGRESS.GENERATING) {
@@ -44,9 +47,19 @@ const labelForProgress = progress => {
50+interface ResetExecuteProps {
51+ // a Maybe<UrbitWallet>
53+ // a useState setter, accepts Maybe<UrbitWallet>
54+ setNewWallet: (args: any) => {};
47−export default function ResetExecute({ newWallet, setNewWallet }) {
57+export default function ResetExecute({
60+}: ResetExecuteProps) {
48− const { popTo, names, reset } = useHistory();
61+ const { popTo, names, reset }: any = useHistory();
49− const { web3, contracts, networkType } = useNetwork();
62+ const { web3, contracts, networkType }: any = useNetwork();
52 setWalletType,
65 setWalletType,
@@ -54,23 +67,25 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
54 setUrbitWallet,
67 setUrbitWallet,
55 walletType,
68 walletType,
56 walletHdPath,
69 walletHdPath,
57− } = useWallet();
70+ }: any = useWallet();
58− const { performL2Reticket } = useRoller();
71+ const { api, performL2Reticket } = useRoller();
60− point: { isL2Spawn },
73+ point: { isL2 },
61 } = useRollerStore();
74 } = useRollerStore();
62− const { pointCursor } = usePointCursor();
75+ const { pointCursor }: any = usePointCursor();
63− const { getDetails } = usePointCache();
76+ const { getDetails }: any = usePointCache();
65 signTransaction: wcSign,
78 signTransaction: wcSign,
66 sendTransaction: wcSend,
79 sendTransaction: wcSend,
67 connector,
80 connector,
68 } = useWalletConnect();
81 } = useWalletConnect();
82+ const { performL2SpawnReticket } = useReticketL2Spawn();
70− const [generalError, setGeneralError] = useState();
84+ const [generalError, setGeneralError] = useState<Error | undefined>();
71 const [progress, setProgress] = useState(0);
85 const [progress, setProgress] = useState(0);
72− const [needFunds, setNeedFunds] = useState();
86+ const [needFunds, setNeedFunds] = useState<string | boolean | undefined>();
73 const isDone = progress >= 1.0;
87 const isDone = progress >= 1.0;
88+ const point = need.point(pointCursor);
75 useBlockWindowClose();
90 useBlockWindowClose();
@@ -79,17 +94,26 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
79 setNewWallet(Nothing());
94 setNewWallet(Nothing());
80 }, [reset, setNewWallet]);
95 }, [reset, setNewWallet]);
82− const loginAndGoHome = useCallback(() => {
97+ const loginAndGoHome = useCallback(async () => {
83 // set wallet state
98 // set wallet state
84 resetWallet();
99 resetWallet();
85 setWalletType(WALLET_TYPES.TICKET);
100 setWalletType(WALLET_TYPES.TICKET);
86 setUrbitWallet(Just(newWallet.value.wallet));
101 setUrbitWallet(Just(newWallet.value.wallet));
87 // (implicit) pointCursor stays the same
102 // (implicit) pointCursor stays the same
103+ // TODO: do we need to update the point?
104+ // await getAndUpdatePoint(point);
88 // redirect to point
105 // redirect to point
89 popTo(names.POINT);
106 popTo(names.POINT);
90− }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
107+ }, [
111+ newWallet.value.wallet,
92− const handleUpdate = useCallback(
116+ const handleUpdate: ReticketProgressCallback = useCallback(
93 ({ type, state, value }) => {
117 ({ type, state, value }) => {
94 switch (type) {
118 switch (type) {
95 case 'progress':
119 case 'progress':
@@ -106,69 +130,92 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
108 const performReticket = useCallback(async () => {
132 const performReticket = useCallback(async () => {
110− // due to react shenanigans we may need to wait for the connector
133+ // due to react shenanigans we may need to wait for the connector
112− walletType === WALLET_TYPES.WALLET_CONNECT &&
135+ walletType === WALLET_TYPES.WALLET_CONNECT &&
113− (!connector || !connector.connected)
136+ (!connector || !connector.connected)
115− setGeneralError(new Error('Awaiting WalletConnect connection...'));
138+ setGeneralError(new Error('Awaiting WalletConnect connection...'));
120− const point = need.point(pointCursor);
142+ setGeneralError(undefined);
121− const details = need.details(getDetails(point));
122− const networkRevision = convertToInt(details.keyRevisionNumber, 10);
124− // see also comment in useEthereumTransaction
144+ const l2point = await api.getPoint(point);
125− const txnSigner =
145+ const details = need.details(getDetails(point));
126− walletType === WALLET_TYPES.WALLET_CONNECT ? wcSign : undefined;
146+ const networkRevision = convertToInt(details.keyRevisionNumber, 10);
128− walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
148+ // see also comment in useEthereumTransaction
150+ walletType === WALLET_TYPES.WALLET_CONNECT ? wcSign : undefined;
152+ walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
131− if (isL2Spawn) {
155+ // if L1 point with migrated spawn proxy (dominion = 'spawn')
132− // FIXME: the useEffect is called twice, which is fine since the duplicate
156+ if (l2point.dominion === POINT_DOMINIONS.SPAWN) {
133− // L2 txs will be discarded
157+ debugLog('reticketing L1 point with dominion spawn...');
158+ await performL2SpawnReticket({
159+ fromWallet: need.wallet(wallet),
160+ fromWalletType: walletType,
161+ fromWalletHdPath: walletHdPath,
162+ toWallet: newWallet.value.wallet,
163+ to: newWallet.value.wallet.ownership.keys.address,
165+ web3: need.web3(web3),
166+ contracts: need.contracts(contracts),
168+ onUpdate: handleUpdate,
169+ nextRevision: networkRevision + 1,
176+ debugLog('reticketing L2 point ...');
134− await performL2Reticket({
177+ await performL2Reticket({
136− to: newWallet.value.wallet.ownership.keys.address,
179+ to: newWallet.value.wallet.ownership.keys.address,
137− manager: newWallet.value.wallet.management.keys.address,
180+ manager: newWallet.value.wallet.management.keys.address,
138− toWallet: newWallet.value.wallet,
181+ toWallet: newWallet.value.wallet,
139− fromWallet: need.wallet(wallet),
182+ fromWallet: need.wallet(wallet),
140− onUpdate: handleUpdate,
183+ onUpdate: handleUpdate,
142− } else
185+ debugLog('done');
186+ // Fallback to L1 point flow
187+ } else debugLog('reticketing L1 point ...');
143− await reticketPointBetweenWallets({
188+ await reticketPointBetweenWallets({
144− fromWallet: need.wallet(wallet),
189+ fromWallet: need.wallet(wallet),
145− fromWalletType: walletType,
190+ fromWalletType: walletType,
146− fromWalletHdPath: walletHdPath,
191+ fromWalletHdPath: walletHdPath,
147− toWallet: newWallet.value.wallet,
192+ toWallet: newWallet.value.wallet,
148− point: point,
193+ point: point,
149− web3: need.web3(web3),
194+ web3: need.web3(web3),
150− contracts: need.contracts(contracts),
195+ contracts: need.contracts(contracts),
151− networkType,
196+ networkType,
152− onUpdate: handleUpdate,
197+ onUpdate: handleUpdate,
153− nextRevision: networkRevision + 1,
198+ nextRevision: networkRevision + 1,
154− txnSigner,
199+ txnSigner,
155− txnSender,
200+ txnSender,
157− } catch (err) {
203+ } catch (err) {
158− console.error(err);
204+ console.error(err);
159− setGeneralError(err);
205+ setGeneralError(err);
163 connector,
209 connector,
164 contracts,
210 contracts,
165 getDetails,
211 getDetails,
166 handleUpdate,
212 handleUpdate,
167− isL2Spawn,
213+ isL2,
168 networkType,
214 networkType,
169 newWallet.value.wallet,
215 newWallet.value.wallet,
170 performL2Reticket,
216 performL2Reticket,
171− pointCursor,
217+ performL2SpawnReticket,
173 walletHdPath,
220 walletHdPath,
174 walletType,
221 walletType,
@@ -177,12 +224,14 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
180− // start reticketing transactions on mount
181 useEffect(() => {
227 useEffect(() => {
182 performReticket();
232 performReticket();
183− //NOTE this was using useLifecycle previously (which is useEffect without
233+ // We want to perform the reticket only once, after the WalletConnect
184− // dependencies) and worked fine, but in the wc case we might need to
234+ // connector has finished instantiating and setting up a websocket
185− // wait for the connector to get set due to react state shenanigans.
186 // eslint-disable-next-line react-hooks/exhaustive-deps
235 // eslint-disable-next-line react-hooks/exhaustive-deps
187 }, [connector]);
236 }, [connector]);
@@ -193,7 +242,9 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
195 <Grid.Item full className="mt4">
244 <Grid.Item full className="mt4">
245+ <ErrorText className={''}>
196− <ErrorText>{generalError.message.toString()}</ErrorText>
246+ {generalError.message.toString()}
197 </Grid.Item>
248 </Grid.Item>
198 <Grid.Item
249 <Grid.Item