1import React, { useCallback, useEffect, useState } from 'react';
2import * as azimuth from 'azimuth-js';
3import Maybe from 'folktale/maybe';
4import { useTicketInput } from 'components/Inputs';
5import { Grid, Input, H4, ErrorText } from 'indigo-react';
7import View from 'components/View';
8import { ForwardButton, OfflineButton } from 'components/Buttons';
9import Passport from 'components/Passport';
11import { useHistory } from 'store/history';
13import * as need from 'lib/need';
14import { ROUTE_NAMES } from 'lib/routeNames';
15import { useSyncKnownPoints } from 'lib/useSyncPoints';
16import FooterButton from 'components/FooterButton';
17import Blinky from 'components/Blinky';
18import { DEFAULT_HD_PATH, walletFromMnemonic } from 'lib/wallet';
19import { useNetwork } from 'store/network';
20import { generateWallet } from 'lib/invite';
21import { generateTemporaryOwnershipWallet } from 'lib/walletgen';
22import { useActivateFlow } from './ActivateFlow';
23import { useLocalRouter } from 'lib/LocalRouter';
25export default function ActivateCode() {
26 const history = useHistory();
27 const { names, push } = useLocalRouter();
28 const { contracts } = useNetwork();
29 const [generalError, setGeneralError] = useState();
30 const [deriving, setDeriving] = useState(false);
37 } = useActivateFlow();
39 const ticketInput = useTicketInput({
44 const validTicket = ticketInput.pass;
46 const goToLogin = useCallback(() => history.popAndPush(ROUTE_NAMES.LOGIN), [
49 const goToDisclaimer = useCallback(() => push(names.DISCLAIMER), [
54 const pass = derivedWallet.matchWith({
61 const _contracts = need.contracts(contracts);
64 // when the ticket becomes valid, derive the point
66 const { seed } = await generateTemporaryOwnershipWallet(
70 //TODO isn't all this accessible in the ownership object?
71 const inviteWallet = walletFromMnemonic(
77 setGeneralError('Derivation Error: invalid derived seed.');
82 const incoming = await azimuth.azimuth.getTransferringFor(
87 let realPoint = Maybe.Nothing();
88 let realWallet = Maybe.Nothing();
90 if (incoming.length > 0) {
91 let pointNum = parseInt(incoming[0], 10);
92 realPoint = Maybe.Just(pointNum);
94 const genWallet = await generateWallet(pointNum);
96 realWallet = Maybe.Just(genWallet);
97 if (incoming.length > 1) {
99 'This invite code has multiple points available.\n' +
100 "Once you've activated this point, activate the next with the same process."
105 'Invite code has no claimable point.\n' +
106 'Check your invite code and try again?'
110 setDerivedPoint(realPoint);
111 setDerivedWallet(realWallet);
112 setInviteWallet(Maybe.Just(inviteWallet));
116 setGeneralError(false);
127 // when we know the derived point, ensure we have the data to display it
128 useSyncKnownPoints([derivedPoint.getOrElse(null)].filter(p => p !== null));
133 <Grid.Item as={Passport} point={derivedPoint} full />
134 <Grid.Item as={H4} className="mt3 mb2" full>
137 <Grid.Item as={Input} {...ticketInput} full />
140 <ErrorText>{generalError}</ErrorText>{' '}
146 disabled={!pass || deriving}
147 accessory={deriving ? <Blinky /> : null}
148 onClick={goToDisclaimer}
151 {deriving && 'Deriving...'}
154 <Grid.Divider className="mt3" />
155 <Grid.Item as={ForwardButton} onClick={goToLogin} full>
160 <FooterButton as={OfflineButton} />
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