1import React, { useState, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
6 reticketPointBetweenWallets,
9import * as need from 'lib/need';
10import useLifecycle from 'lib/useLifecycle';
11import { WALLET_TYPES } from 'lib/wallet';
12import convertToInt from 'lib/convertToInt';
13import useBlockWindowClose from 'lib/useBlockWindowClose';
15import { useNetwork } from 'store/network';
16import { useWallet } from 'store/wallet';
17import { usePointCursor } from 'store/pointCursor';
18import { usePointCache } from 'store/pointCache';
19import { useHistory } from 'store/history';
21import { RestartButton, ForwardButton } from 'components/Buttons';
22import WarningBox from 'components/WarningBox';
23import LoadingBar from 'components/LoadingBar';
24import NeedFundsNotice from 'components/NeedFundsNotice';
26const labelForProgress = progress => {
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) {
44export default function ReticketExecute({ newWallet, setNewWallet }) {
45 const { popTo, names, reset } = useHistory();
46 const { web3, contracts, networkType } = useNetwork();
47 const { wallet, setWalletType, resetWallet, setUrbitWallet } = useWallet();
48 const { pointCursor } = usePointCursor();
49 const { getDetails } = usePointCache();
51 const [generalError, setGeneralError] = useState();
52 const [progress, setProgress] = useState(0);
53 const [needFunds, setNeedFunds] = useState();
54 const isDone = progress >= 1.0;
56 useBlockWindowClose();
58 // start reticketing transactions on mount
61 const point = need.point(pointCursor);
62 const details = need.details(getDetails(point));
63 const networkRevision = convertToInt(details.keyRevisionNumber, 10);
65 await reticketPointBetweenWallets({
66 fromWallet: need.wallet(wallet),
67 toWallet: newWallet.value.wallet,
69 web3: need.web3(web3),
70 contracts: need.contracts(contracts),
72 onUpdate: handleUpdate,
73 nextRevision: networkRevision + 1,
81 const goToRestart = useCallback(() => {
83 setNewWallet(Nothing());
84 }, [reset, setNewWallet]);
86 const loginAndGoHome = useCallback(() => {
89 setWalletType(WALLET_TYPES.TICKET);
90 setUrbitWallet(Just(newWallet.value.wallet));
91 // (implicit) pointCursor stays the same
94 }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
96 const handleUpdate = useCallback(
97 ({ type, state, value }) => {
100 return setProgress(state);
102 return setNeedFunds(value);
104 return setNeedFunds(false);
106 console.error(`Unknown update: ${type}`);
109 [setProgress, setNeedFunds]
112 const renderAdditionalInfo = () => {
116 <Grid.Item full className="mt4">
117 <ErrorText>{generalError.message.toString()}</ErrorText>
124 onClick={goToRestart}>
133 <Grid.Item full as={NeedFundsNotice} className="mt4" {...needFunds} />
138 <Grid.Item full as={WarningBox} className="mt4">
139 Never give your Master Ticket to anyone
145 <Grid className="mt4">
146 <Grid.Item full as={H4}>
147 {labelForProgress(progress)}
152 <Grid.Item full as={Text} className="mt4">
153 Your changes are now reflected on-chain and you can use the new
154 ticket to manage your point.
162 onClick={loginAndGoHome}>
163 Login with New Master Ticket
168 <Grid.Item full as={Grid} className="mt4" gap={3}>
169 <Grid.Item full as={LoadingBar} progress={progress} />
170 <Grid.Item full as={Text} className="f5 green4">
171 This process can take up to 5 minutes to complete. Don't close
172 this page until the process is complete.
176 {renderAdditionalInfo()}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list