@@ -1,204 +0,0 @@
1−import React, { useState, useCallback } from 'react';
2−import { Grid, Text, ErrorText } from 'indigo-react';
4−import { useNetwork } from 'store/network';
5−import { useWallet } from 'store/wallet';
6−import { useHistory } from 'store/history';
7−import { usePointCursor } from 'store/pointCursor';
9−import * as need from 'lib/need';
10−import useLifecycle from 'lib/useLifecycle';
11−import useBlockWindowClose from 'lib/useBlockWindowClose';
13− reticketPointBetweenWallets,
14− TRANSACTION_PROGRESS,
15−} from 'lib/reticket';
16−import { timeout } from 'lib/timeout';
18−import WarningBox from 'components/WarningBox';
19−import LoadingBar from 'components/LoadingBar';
20−import { RestartButton } from 'components/Buttons';
21−import NeedFundsNotice from 'components/NeedFundsNotice';
23−import { useActivateFlow } from './ActivateFlow';
24−import PassportView from './PassportView';
26−const labelForProgress = progress => {
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) {
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();
53− reset: resetActivateFlow,
54− } = useActivateFlow();
55− const [generalError, setGeneralError] = useState();
56− const [progress, setProcesss] = useState(0);
57− const [needFunds, setNeedFunds] = useState();
59− const goToLogin = useCallback(
60− () => replaceWith([{ key: names.LOGIN }, { key: names.POINT }]),
64− useBlockWindowClose();
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)
74− // 2) reset local router
75− resetActivateRouter();
76− // 3) clear the state
78− }, [resetActivateRouter, resetActivateFlow]);
80− const handleUpdate = useCallback(
81− ({ type, state, value }) => {
84− return setProcesss(state);
86− return setNeedFunds(value);
88− return setNeedFunds(false);
90− console.error(`Unknown update: ${type}`);
93− [setProcesss, setNeedFunds]
96− const claimPoint = useCallback(async () => {
97− setGeneralError(false);
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);
106− await reticketPointBetweenWallets({
107− fromWallet: _inviteWallet,
111− contracts: _contracts,
113− onUpdate: handleUpdate,
115− //NOTE not passing wc function, we always have invite ticket wallet
118− // set the global wallet
119− setUrbitWallet(derivedWallet);
120− setPointCursor(derivedPoint);
122− // and redirect to login
123− await timeout(3000);
126− // some generic error
127− setGeneralError(error);
142− useLifecycle(() => {
146− const renderAdditionalInfo = () => {
148− console.log(generalError);
149− generalError.message = generalError.message || 'Something went wrong!';
152− <Grid.Item full className="mt8">
153− <ErrorText>{generalError.message.toString()}</ErrorText>
160− onClick={goToRestart}>
169− <Grid.Item full as={NeedFundsNotice} className="mt8" {...needFunds} />
173− if (progress < 1.0) {
175− <Grid.Item full as={WarningBox} className="mt8">
176− Never give your Master Ticket to anyone
186− className={className}
187− header={labelForProgress(progress)}
190− <Grid.Item full as={Grid} className="mt3" gap={3}>
191− <Grid.Item full as={LoadingBar} progress={progress} />
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.
200− {renderAdditionalInfo()}