@@ -1,204 +0,0 @@
1−import React, { useState, useCallback } from 'react';
2−import { Grid, Text, ErrorText } from 'indigo-react';
3−
4−import { useNetwork } from 'store/network';
5−import { useWallet } from 'store/wallet';
6−import { useHistory } from 'store/history';
7−import { usePointCursor } from 'store/pointCursor';
8−
9−import * as need from 'lib/need';
10−import useLifecycle from 'lib/useLifecycle';
11−import useBlockWindowClose from 'lib/useBlockWindowClose';
12−import {
13− reticketPointBetweenWallets,
14− TRANSACTION_PROGRESS,
15−} from 'lib/reticket';
16−import { timeout } from 'lib/timeout';
17−
18−import WarningBox from 'components/WarningBox';
19−import LoadingBar from 'components/LoadingBar';
20−import { RestartButton } from 'components/Buttons';
21−import NeedFundsNotice from 'components/NeedFundsNotice';
22−
23−import { useActivateFlow } from './ActivateFlow';
24−import PassportView from './PassportView';
25−
26−const labelForProgress = progress => {
27− if (progress <= 0) {
28− return 'Verify Passport';
29− } else if (progress <= TRANSACTION_PROGRESS.GENERATING) {
30− return 'Generating Ethereum Transactions...';
31− } else if (progress <= TRANSACTION_PROGRESS.SIGNING) {
32− return 'Signing Ethereum Transactions...';
33− } else if (progress <= TRANSACTION_PROGRESS.FUNDING) {
34− return 'Funding Ethereum Transactions...';
35− } else if (progress <= TRANSACTION_PROGRESS.TRANSFERRING) {
36− return 'Transferring ID...';
37− } else if (progress <= TRANSACTION_PROGRESS.CLEANING) {
38− return 'Cleaning Up...';
39− } else if (progress <= TRANSACTION_PROGRESS.DONE) {
40− return 'Done';
41− }
42−};
43−
44−export default function PassportTransfer({ className, resetActivateRouter }) {
45− const { replaceWith, names } = useHistory();
46− const { setUrbitWallet } = useWallet();
47− const { setPointCursor } = usePointCursor();
48− const { web3, contracts, networkType } = useNetwork();
49− const {
50− derivedWallet,
51− derivedPoint,
52− inviteWallet,
53− reset: resetActivateFlow,
54− } = useActivateFlow();
55− const [generalError, setGeneralError] = useState();
56− const [progress, setProcesss] = useState(0);
57− const [needFunds, setNeedFunds] = useState();
58−
59− const goToLogin = useCallback(
60− () => replaceWith([{ key: names.LOGIN }, { key: names.POINT }]),
61− [replaceWith, names]
62− );
63−
64− useBlockWindowClose();
65−
66− const goToRestart = useCallback(() => {
67− // NOTE: because we're already on the ACTIVATE view in the history,
68− // react (intelligently) doesn't trigger a re-render and that means the
69− // current state of the two nested routers (activate & passport) stick
70− // around unless we manually clear them.
71− // we only need to clear activate because that will unmount the passport
72− // router (which will be set to initialRoutes when mounted again)
73−
74− // 2) reset local router
75− resetActivateRouter();
76− // 3) clear the state
77− resetActivateFlow();
78− }, [resetActivateRouter, resetActivateFlow]);
79−
80− const handleUpdate = useCallback(
81− ({ type, state, value }) => {
82− switch (type) {
83− case 'progress':
84− return setProcesss(state);
85− case 'askFunding':
86− return setNeedFunds(value);
87− case 'gotFunding':
88− return setNeedFunds(false);
89− default:
90− console.error(`Unknown update: ${type}`);
91− }
92− },
93− [setProcesss, setNeedFunds]
94− );
95−
96− const claimPoint = useCallback(async () => {
97− setGeneralError(false);
98−
99− try {
100− const _inviteWallet = need.wallet(inviteWallet);
101− const _wallet = need.wallet(derivedWallet);
102− const _point = need.point(derivedPoint);
103− const _web3 = need.web3(web3);
104− const _contracts = need.contracts(contracts);
105−
106− await reticketPointBetweenWallets({
107− fromWallet: _inviteWallet,
108− toWallet: _wallet,
109− point: _point,
110− web3: _web3,
111− contracts: _contracts,
112− networkType,
113− onUpdate: handleUpdate,
114− transferEth: true,
115− //NOTE not passing wc function, we always have invite ticket wallet
116− });
117−
118− // set the global wallet
119− setUrbitWallet(derivedWallet);
120− setPointCursor(derivedPoint);
121−
122− // and redirect to login
123− await timeout(3000);
124− goToLogin();
125− } catch (error) {
126− // some generic error
127− setGeneralError(error);
128− }
129− }, [
130− inviteWallet,
131− derivedWallet,
132− derivedPoint,
133− web3,
134− contracts,
135− networkType,
136− setUrbitWallet,
137− setPointCursor,
138− handleUpdate,
139− goToLogin,
140− ]);
141−
142− useLifecycle(() => {
143− claimPoint();
144− });
145−
146− const renderAdditionalInfo = () => {
147− if (generalError) {
148− console.log(generalError);
149− generalError.message = generalError.message || 'Something went wrong!';
150− return (
151− <>
152− <Grid.Item full className="mt8">
153− <ErrorText>{generalError.message.toString()}</ErrorText>
154− </Grid.Item>
155− <Grid.Item
156− full
157− className="mt3"
158− as={RestartButton}
159− solid
160− onClick={goToRestart}>
161− Restart
162− </Grid.Item>
163− </>
164− );
165− }
166−
167− if (needFunds) {
168− return (
169− <Grid.Item full as={NeedFundsNotice} className="mt8" {...needFunds} />
170− );
171− }
172−
173− if (progress < 1.0) {
174− return (
175− <Grid.Item full as={WarningBox} className="mt8">
176− Never give your Master Ticket to anyone
177− </Grid.Item>
178− );
179− }
180−
181− return null;
182− };
183−
184− return (
185− <PassportView
186− className={className}
187− header={labelForProgress(progress)}
188− step={3}>
189− <Grid>
190− <Grid.Item full as={Grid} className="mt3" gap={3}>
191− <Grid.Item full as={LoadingBar} progress={progress} />
192− <Grid.Item full>
193− <Text className="f5 green4">
194− This process can take up to 5 minutes to complete. Don't close
195− this page until the process is complete.
196− </Text>
197− </Grid.Item>
198− </Grid.Item>
199−
200− {renderAdditionalInfo()}
201− </Grid>
202− </PassportView>
203− );
204−}