@@ -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,9 @@ 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 { ReticketProgressCallback } from 'lib/types/L2Transaction';
29−const labelForProgress = progress => {
31+const labelForProgress = (progress: number) => {
30 if (progress <= 0) {
32 if (progress <= 0) {
31 return 'Starting...';
33 return 'Starting...';
32 } else if (progress <= TRANSACTION_PROGRESS.GENERATING) {
34 } else if (progress <= TRANSACTION_PROGRESS.GENERATING) {
@@ -44,9 +46,19 @@ const labelForProgress = progress => {
49+interface ResetExecuteProps {
50+ // a Maybe<UrbitWallet>
52+ // a useState setter, accepts Maybe<UrbitWallet>
53+ setNewWallet: (args: any) => {};
47−export default function ResetExecute({ newWallet, setNewWallet }) {
56+export default function ResetExecute({
59+}: ResetExecuteProps) {
48− const { popTo, names, reset } = useHistory();
60+ const { popTo, names, reset }: any = useHistory();
49− const { web3, contracts, networkType } = useNetwork();
61+ const { web3, contracts, networkType }: any = useNetwork();
52 setWalletType,
64 setWalletType,
@@ -54,94 +66,34 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
54 setUrbitWallet,
66 setUrbitWallet,
55 walletType,
67 walletType,
56 walletHdPath,
68 walletHdPath,
57− } = useWallet();
69+ }: any = useWallet();
58− const { performL2Reticket } = useRoller();
70+ const { api, performL2Reticket } = useRoller();
60 point: { isL2 },
72 point: { isL2 },
61 } = useRollerStore();
73 } = useRollerStore();
62− const { pointCursor } = usePointCursor();
74+ const { pointCursor }: any = usePointCursor();
63− const { getDetails } = usePointCache();
75+ const { getDetails }: any = usePointCache();
65 signTransaction: wcSign,
77 signTransaction: wcSign,
66 sendTransaction: wcSend,
78 sendTransaction: wcSend,
67 connector,
79 connector,
68 } = useWalletConnect();
80 } = useWalletConnect();
81+ const { performL2SpawnReticket } = useReticketL2Spawn();
70− const [generalError, setGeneralError] = useState();
83+ const [generalError, setGeneralError] = useState<Error | undefined>();
71 const [progress, setProgress] = useState(0);
84 const [progress, setProgress] = useState(0);
72− const [needFunds, setNeedFunds] = useState();
85+ const [needFunds, setNeedFunds] = useState<string | boolean | undefined>();
73 const isDone = progress >= 1.0;
86 const isDone = progress >= 1.0;
87+ const point = need.point(pointCursor);
75 useBlockWindowClose();
89 useBlockWindowClose();
77− // start reticketing transactions on mount
80− // due to react shenanigans we may need to wait for the connector
82− walletType === WALLET_TYPES.WALLET_CONNECT &&
83− (!connector || !connector.connected)
85− setGeneralError(new Error('Awaiting WalletConnect connection...'));
90− const point = need.point(pointCursor);
91− const details = need.details(getDetails(point));
92− const networkRevision = convertToInt(details.keyRevisionNumber, 10);
94− // see also comment in useEthereumTransaction
96− walletType === WALLET_TYPES.WALLET_CONNECT ? wcSign : undefined;
98− walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
102− console.log(newWallet.value);
103− // FIXME: the useEffect is called twice, which is fine since the duplicate
104− // L2 txs will be discarded
106− await performL2Reticket({
108− to: newWallet.value.wallet.ownership.keys.address,
109− manager: newWallet.value.wallet.management.keys.address,
110− toWallet: newWallet.value.wallet,
111− fromWallet: need.wallet(wallet),
114− await reticketPointBetweenWallets({
115− fromWallet: need.wallet(wallet),
116− fromWalletType: walletType,
117− fromWalletHdPath: walletHdPath,
118− toWallet: newWallet.value.wallet,
120− web3: need.web3(web3),
121− contracts: need.contracts(contracts),
123− onUpdate: handleUpdate,
124− nextRevision: networkRevision + 1,
130− setGeneralError(err);
133− //NOTE this was using useLifecycle previously (which is useEffect without
134− // dependencies) and worked fine, but in the wc case we might need to
135− // wait for the connector to get set due to react state shenanigans.
136− // eslint-disable-next-line react-hooks/exhaustive-deps
139 const goToRestart = useCallback(() => {
91 const goToRestart = useCallback(() => {
141 setNewWallet(Nothing());
93 setNewWallet(Nothing());
142 }, [reset, setNewWallet]);
94 }, [reset, setNewWallet]);
144− const loginAndGoHome = useCallback(() => {
96+ const loginAndGoHome = useCallback(async () => {
145 // set wallet state
97 // set wallet state
146 resetWallet();
98 resetWallet();
147 setWalletType(WALLET_TYPES.TICKET);
99 setWalletType(WALLET_TYPES.TICKET);
@@ -149,9 +101,16 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
149 // (implicit) pointCursor stays the same
101 // (implicit) pointCursor stays the same
150 // redirect to point
102 // redirect to point
151 popTo(names.POINT);
103 popTo(names.POINT);
152− }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
104+ }, [
108+ newWallet.value.wallet,
154− const handleUpdate = useCallback(
113+ const handleUpdate: ReticketProgressCallback = useCallback(
155 ({ type, state, value }) => {
114 ({ type, state, value }) => {
156 switch (type) {
115 switch (type) {
157 case 'progress':
116 case 'progress':
@@ -167,6 +126,108 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
167 [setProgress, setNeedFunds]
126 [setProgress, setNeedFunds]
129+ const performReticket = useCallback(async () => {
130+ // due to react shenanigans we may need to wait for the connector
132+ walletType === WALLET_TYPES.WALLET_CONNECT &&
133+ (!connector || !connector.connected)
135+ setGeneralError(new Error('Awaiting WalletConnect connection...'));
139+ setGeneralError(undefined);
141+ const l2point = await api.getPoint(point);
142+ const details = need.details(getDetails(point));
143+ const networkRevision = convertToInt(details.keyRevisionNumber, 10);
145+ // see also comment in useEthereumTransaction
147+ walletType === WALLET_TYPES.WALLET_CONNECT ? wcSign : undefined;
149+ walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
152+ // if L1 point with migrated spawn proxy (dominion = 'spawn')
153+ if (l2point.dominion === POINT_DOMINIONS.SPAWN) {
154+ await performL2SpawnReticket({
155+ fromWallet: need.wallet(wallet),
156+ fromWalletType: walletType,
157+ fromWalletHdPath: walletHdPath,
158+ toWallet: newWallet.value.wallet,
159+ to: newWallet.value.wallet.ownership.keys.address,
161+ web3: need.web3(web3),
162+ contracts: need.contracts(contracts),
164+ onUpdate: handleUpdate,
165+ nextRevision: networkRevision + 1,
171+ await performL2Reticket({
173+ to: newWallet.value.wallet.ownership.keys.address,
174+ manager: newWallet.value.wallet.management.keys.address,
175+ toWallet: newWallet.value.wallet,
176+ fromWallet: need.wallet(wallet),
177+ onUpdate: handleUpdate,
179+ // Fallback to L1 point flow
181+ await reticketPointBetweenWallets({
182+ fromWallet: need.wallet(wallet),
183+ fromWalletType: walletType,
184+ fromWalletHdPath: walletHdPath,
185+ toWallet: newWallet.value.wallet,
187+ web3: need.web3(web3),
188+ contracts: need.contracts(contracts),
190+ onUpdate: handleUpdate,
191+ nextRevision: networkRevision + 1,
198+ setGeneralError(err);
208+ newWallet.value.wallet,
210+ performL2SpawnReticket,
226+ // We want to perform the reticket only once, after the WalletConnect
227+ // connector has finished instantiating and setting up a websocket
228+ // eslint-disable-next-line react-hooks/exhaustive-deps
170 const renderAdditionalInfo = () => {
231 const renderAdditionalInfo = () => {
171 if (generalError) {
232 if (generalError) {
172 console.log(generalError);
233 console.log(generalError);
@@ -174,7 +235,9 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
176 <Grid.Item full className="mt4">
237 <Grid.Item full className="mt4">
238+ <ErrorText className={''}>
177− <ErrorText>{generalError.message.toString()}</ErrorText>
239+ {generalError.message.toString()}
178 </Grid.Item>
241 </Grid.Item>
179 <Grid.Item
242 <Grid.Item