1import React, { useState, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
5import { reticketPointBetweenWallets } from 'lib/invite';
6import { fromWei } from 'lib/txn';
7import * as need from 'lib/need';
8import useLifecycle from 'lib/useLifecycle';
10import { useNetwork } from 'store/network';
11import { useWallet } from 'store/wallet';
12import { usePointCursor } from 'store/pointCursor';
13import { useHistory } from 'store/history';
15import { RestartButton, ForwardButton } from 'components/Buttons';
16import WarningBox from 'components/WarningBox';
17import LoadingBar from 'components/LoadingBar';
18import Highlighted from 'components/Highlighted';
19import { WALLET_TYPES } from 'lib/wallet';
21// TODO: maybe we can merge PassportTransfer here?
22export default function ReticketExecute({ newWallet, setNewWallet }) {
23 const { popTo, names, reset } = useHistory();
24 const { web3, contracts } = useNetwork();
25 const { wallet, setWalletType, resetWallet, setUrbitWallet } = useWallet();
26 const { pointCursor } = usePointCursor();
28 const [generalError, setGeneralError] = useState();
29 const [{ label, progress }, setState] = useState({
33 const [needFunds, setNeedFunds] = useState();
34 const isDone = progress >= 1.0;
36 // start reticketing transactions on mount
40 await reticketPointBetweenWallets({
41 fromWallet: need.wallet(wallet),
42 toWallet: newWallet.value.wallet,
43 point: need.point(pointCursor),
44 web3: need.web3(web3),
45 contracts: need.contracts(contracts),
46 onUpdate: handleUpdate,
54 const goToRestart = useCallback(() => {
56 setNewWallet(Nothing());
57 }, [reset, setNewWallet]);
59 const loginAndGoHome = useCallback(() => {
62 setWalletType(WALLET_TYPES.TICKET);
63 setUrbitWallet(Just(newWallet.value.wallet));
64 // (implicit) pointCursor stays the same
67 }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
69 const handleUpdate = useCallback(
70 ({ type, state, value }) => {
73 return setState(state);
75 return setNeedFunds(value);
77 return setNeedFunds(false);
79 console.error(`Unknown update: ${type}`);
82 [setState, setNeedFunds]
85 const renderAdditionalInfo = () => {
90 <ErrorText>{generalError.message.toString()}</ErrorText>
97 onClick={goToRestart}>
108 The address {needFunds.address} needs at least{' '}
109 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
110 {fromWei(needFunds.balance)} ETH. Waiting until the account has
118 <Grid.Item full as={WarningBox}>
119 Never give your Master Ticket to anyone
125 <Grid gap={4} className="mt4">
126 <Grid.Item full as={H4}>
132 <Grid.Item full as={Grid} className="mt3" gap={3}>
133 <Grid.Item full as={LoadingBar} progress={progress} />
135 <Text className="f5 green4">
136 This process can take up to 5 minutes to complete. Don't leave
137 this page until the process is complete.
142 {renderAdditionalInfo()}
148 <Grid.Item full as={Text}>
149 Your changes are now reflected on-chain and you can use the new
150 ticket to manage your point.
157 onClick={loginAndGoHome}>
158 Login with New Master Ticket
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