@@ -1,25 +1,28 @@
1import React, { useState, useCallback } from 'react';
1import React, { useState, useCallback } from 'react';
2import { Just } from 'folktale/maybe';
2import { Just } from 'folktale/maybe';
4import { Grid, H4, Text, ErrorText } from 'indigo-react';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
5−import { RestartButton } from 'components/Buttons';
6−import WarningBox from 'components/WarningBox';
7−import LoadingBar from 'components/LoadingBar';
8−import Highlighted from 'components/Highlighted';
10−import { claimPointFromInvite } from 'lib/invite';
5+import { reticketPointBetweenWallets } from 'lib/invite';
11import { fromWei } from 'lib/txn';
6import { fromWei } from 'lib/txn';
13import * as need from 'lib/need';
7import * as need from 'lib/need';
8+import useLifecycle from 'lib/useLifecycle';
14import { useNetwork } from 'store/network';
10import { useNetwork } from 'store/network';
15import { useWallet } from 'store/wallet';
11import { useWallet } from 'store/wallet';
16import { usePointCursor } from 'store/pointCursor';
12import { usePointCursor } from 'store/pointCursor';
17−import useLifecycle from 'lib/useLifecycle';
13+import { useHistory } from 'store/history';
15+import { RestartButton, ForwardButton } from 'components/Buttons';
16+import WarningBox from 'components/WarningBox';
17+import LoadingBar from 'components/LoadingBar';
18+import Highlighted from 'components/Highlighted';
19+import { WALLET_TYPES } from 'lib/wallet';
19−//TODO maybe we want to drop in PassportTransfer here?
21+// TODO: maybe we can merge PassportTransfer here?
20−export default function DoReticket({ newWallet, completed }) {
22+export default function ReticketExecute({ newWallet }) {
23+ const { popTo, names } = useHistory();
21 const { web3, contracts } = useNetwork();
24 const { web3, contracts } = useNetwork();
22− const { wallet, setUrbitWallet } = useWallet();
25+ const { wallet, setWalletType, resetWallet, setUrbitWallet } = useWallet();
23 const { pointCursor } = usePointCursor();
26 const { pointCursor } = usePointCursor();
25 const [generalError, setGeneralError] = useState();
28 const [generalError, setGeneralError] = useState();
@@ -28,28 +31,36 @@ export default function DoReticket({ newWallet, completed }) {
28 progress: 0,
31 progress: 0,
30 const [needFunds, setNeedFunds] = useState();
33 const [needFunds, setNeedFunds] = useState();
34+ const isDone = progress >= 1.0;
32 // start reticketing transactions on mount
36 // start reticketing transactions on mount
33 useLifecycle(() => {
37 useLifecycle(() => {
34 (async () => {
38 (async () => {
36− await claimPointFromInvite({
40+ await reticketPointBetweenWallets({
37− inviteWallet: need.wallet(wallet),
41+ fromWallet: need.wallet(wallet),
38− wallet: newWallet.value.wallet,
42+ toWallet: newWallet.value.wallet,
39 point: need.point(pointCursor),
43 point: need.point(pointCursor),
40 web3: need.web3(web3),
44 web3: need.web3(web3),
41 contracts: need.contracts(contracts),
45 contracts: need.contracts(contracts),
42 onUpdate: handleUpdate,
46 onUpdate: handleUpdate,
44− //TODO would it be better for this to happen in completed()?
45− setUrbitWallet(Just(newWallet.value.wallet));
46− completed(); //TODO don't auto-redirect
47 } catch (err) {
48 } catch (err) {
48 setGeneralError(err);
49 setGeneralError(err);
54+ const loginAndGoHome = useCallback(() => {
57+ setWalletType(WALLET_TYPES.TICKET);
58+ setUrbitWallet(Just(newWallet.value.wallet));
59+ // (implicit) pointCursor stays the same
62+ }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
53 const handleUpdate = useCallback(
64 const handleUpdate = useCallback(
54 ({ type, state, value }) => {
65 ({ type, state, value }) => {
55 switch (type) {
66 switch (type) {
@@ -70,7 +81,7 @@ export default function DoReticket({ newWallet, completed }) {
70 if (generalError) {
81 if (generalError) {
73− <Grid.Item full className="mt8">
84+ <Grid.Item full>
74 <ErrorText>{generalError.message.toString()}</ErrorText>
85 <ErrorText>{generalError.message.toString()}</ErrorText>
75 </Grid.Item>
86 </Grid.Item>
76 <Grid.Item
87 <Grid.Item
@@ -85,7 +96,7 @@ export default function DoReticket({ newWallet, completed }) {
86 if (needFunds) {
97 if (needFunds) {
88− <Grid.Item full className="mt8">
99+ <Grid.Item full>
89 <Highlighted>
100 <Highlighted>
90 The address {needFunds.address} needs at least{' '}
101 The address {needFunds.address} needs at least{' '}
91 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
102 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
@@ -96,33 +107,51 @@ export default function DoReticket({ newWallet, completed }) {
99− if (progress < 100) {
100− return (
110+ return (
101− <Grid.Item full as={WarningBox} className="mt8">
111+ <Grid.Item full as={WarningBox}>
102− Never give your Master Ticket to anyone
112+ Never give your Master Ticket to anyone
103− </Grid.Item>
113+ </Grid.Item>
111− <Grid className={'auto-rows-min'}>
118+ <Grid gap={4} className="mt4">
112 <Grid.Item full as={H4}>
119 <Grid.Item full as={H4}>
114 </Grid.Item>
121 </Grid.Item>
115− <Grid.Item full as={Grid} className="mt3" gap={3}>
116− <Grid.Item full as={LoadingBar} progress={progress} />
118− <Text className="f5 green4">
119− This process can take up to 5 minutes to complete. Don't leave this
120− page until the process is complete.
125+ <Grid.Item full as={Grid} className="mt3" gap={3}>
126+ <Grid.Item full as={LoadingBar} progress={progress} />
128+ <Text className="f5 green4">
129+ This process can take up to 5 minutes to complete. Don't leave
130+ this page until the process is complete.
125− {renderAdditionalInfo()}
135+ {renderAdditionalInfo()}
141+ <Grid.Item full as={Text}>
142+ Your changes are now reflected on-chain and you can use the new
143+ ticket to manage your point.
150+ onClick={loginAndGoHome}>
151+ Login with New Master Ticket