@@ -1,4 +1,5 @@
1import React, { useState, useCallback } from 'react';
1import React, { useState, useCallback } from 'react';
2+import cn from 'classnames';
2import { Grid, H4, Text, ErrorText } from 'indigo-react';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
4import { useNetwork } from 'store/network';
5import { useNetwork } from 'store/network';
@@ -18,13 +19,19 @@ import LoadingBar from 'components/LoadingBar';
18import Highlighted from 'components/Highlighted';
19import Highlighted from 'components/Highlighted';
20import { useActivateFlow } from './ActivateFlow';
21import { useActivateFlow } from './ActivateFlow';
22+import { RestartButton } from 'components/Buttons';
22−export default function PassportTransfer({ className }) {
24+export default function PassportTransfer({ className, resetActivateRouter }) {
23 const { replaceWith, names } = useHistory();
25 const { replaceWith, names } = useHistory();
24 const { setUrbitWallet } = useWallet();
26 const { setUrbitWallet } = useWallet();
25 const { setPointCursor } = usePointCursor();
27 const { setPointCursor } = usePointCursor();
26 const { web3, contracts } = useNetwork();
28 const { web3, contracts } = useNetwork();
33+ reset: resetActivateFlow,
27− const { derivedWallet, derivedPoint, inviteWallet } = useActivateFlow();
34+ } = useActivateFlow();
28 const [generalError, setGeneralError] = useState();
35 const [generalError, setGeneralError] = useState();
29 const [{ label, progress }, setState] = useState({
36 const [{ label, progress }, setState] = useState({
30 label: 'Verify Passport',
37 label: 'Verify Passport',
@@ -43,10 +50,21 @@ export default function PassportTransfer({ className }) {
43 [replaceWith, names]
50 [replaceWith, names]
46− const goToRestart = useCallback(
53+ const goToRestart = useCallback(() => {
54+ // NOTE: because we're already on the ACTIVATE view in the history,
55+ // react (intelligently) doesn't trigger a re-render and that means the
56+ // current state of the two nested routers (activate & passport) stick
57+ // around unless we manually clear them.
58+ // we only need to clear activate because that will unmount the passport
59+ // router (which will be set to initialRoutes when mounted again)
61+ // 1) replace history
47− () => replaceWith([{ key: names.LANDING }, { key: names.ACTIVATE }]),
62+ replaceWith([{ key: names.LANDING }, { key: names.ACTIVATE }]);
63+ // 2) reset local router
64+ resetActivateRouter();
65+ // 3) clear the state
48− [replaceWith, names]
67+ }, [replaceWith, names, resetActivateRouter, resetActivateFlow]);
51 const handleUpdate = useCallback(
69 const handleUpdate = useCallback(
52 ({ type, state, value }) => {
70 ({ type, state, value }) => {
@@ -65,13 +83,15 @@ export default function PassportTransfer({ className }) {
67 const claimPoint = useCallback(async () => {
85 const claimPoint = useCallback(async () => {
68− const _inviteWallet = need.wallet(inviteWallet);
86+ setGeneralError(false);
69− const _wallet = need.wallet(derivedWallet);
70− const _point = need.point(derivedPoint);
71− const _web3 = need.web3(web3);
72− const _contracts = need.contracts(contracts);
89+ const _inviteWallet = need.wallet(inviteWallet);
90+ const _wallet = need.wallet(derivedWallet);
91+ const _point = need.point(derivedPoint);
92+ const _web3 = need.web3(web3);
93+ const _contracts = need.contracts(contracts);
75 await claimPointFromInvite({
95 await claimPointFromInvite({
76 inviteWallet: _inviteWallet,
96 inviteWallet: _inviteWallet,
77 wallet: _wallet,
97 wallet: _wallet,
@@ -80,11 +100,13 @@ export default function PassportTransfer({ className }) {
80 contracts: _contracts,
100 contracts: _contracts,
81 onUpdate: handleUpdate,
101 onUpdate: handleUpdate,
83 // set the global wallet
104 // set the global wallet
84 setUrbitWallet(derivedWallet);
105 setUrbitWallet(derivedWallet);
85 setPointCursor(derivedPoint);
106 setPointCursor(derivedPoint);
86− await timeout(3000);
107+
87 // and redirect to login
108 // and redirect to login
109+ await timeout(3000);
88 goToLogin();
110 goToLogin();
89 } catch (error) {
111 } catch (error) {
90 // some generic error
112 // some generic error
@@ -106,13 +128,54 @@ export default function PassportTransfer({ className }) {
106 claimPoint();
128 claimPoint();
131+ const renderAdditionalInfo = () => {
135+ <Grid.Item full className="mt8">
136+ <ErrorText>{generalError.message.toString()}</ErrorText>
142+ onClick={goToRestart}
150+ <Grid.Item full className="mt8">
152+ The address {needFunds.address} needs at least{' '}
153+ {fromWei(needFunds.minBalance)} ETH and currently has{' '}
154+ {fromWei(needFunds.balance)} ETH. Waiting until the account has
161+ if (progress < 100) {
163+ <Grid.Item full as={WarningBox} className="mt8">
164+ Never give your Master Ticket to anyone
110− <Grid gap={4} className={className}>
173+ <Grid className={cn(className, 'auto-rows-min')}>
111− <Grid.Item full as={Steps} num={2} total={3} />
174+ <Grid.Item full as={Steps} num={3} total={3} />
112 <Grid.Item full as={H4}>
175 <Grid.Item full as={H4}>
114 </Grid.Item>
177 </Grid.Item>
115− <Grid.Item full as={Grid}>
178+ <Grid.Item full as={Grid} className="mt3" gap={3}>
116 <Grid.Item full as={LoadingBar} progress={progress} />
179 <Grid.Item full as={LoadingBar} progress={progress} />
117 <Grid.Item full>
180 <Grid.Item full>
118 <Text className="f5 green4">
181 <Text className="f5 green4">
@@ -122,28 +185,7 @@ export default function PassportTransfer({ className }) {
122 </Grid.Item>
185 </Grid.Item>
123 </Grid.Item>
186 </Grid.Item>
125− {progress < 0 && (
188+ {renderAdditionalInfo()}
126− <Grid.Item full as={WarningBox}>
127− Never give your Master Ticket to anyone
134− The address {needFunds.address} needs at least{' '}
135− {fromWei(needFunds.minBalance)} ETH and currently has{' '}
136− {fromWei(needFunds.balance)} ETH. Waiting until the account has
144− <ErrorText>{generalError.message.toString()}</ErrorText>