1import React, { useCallback, useEffect, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
4import { Grid, Input, H4, ErrorText } from 'indigo-react';
6import View from 'components/View';
7import { ForwardButton } from 'components/Buttons';
8import Passport from 'components/Passport';
10import { useHistory } from 'store/history';
12import { useTicketInput } from 'lib/useInputs';
13import * as need from 'lib/need';
14import { ROUTE_NAMES } from 'lib/routeNames';
15import { useSyncKnownPoints } from 'lib/useSyncPoints';
16import FooterButton from 'components/FooterButton';
17import { blinkIf } 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';
24import useImpliedTicket from 'lib/useImpliedTicket';
26export default function ActivateCode() {
27 const history = useHistory();
28 const { names, push } = useLocalRouter();
29 const { contracts } = useNetwork();
30 const impliedTicket = useImpliedTicket();
31 const [generalError, setGeneralError] = useState();
32 const [deriving, setDeriving] = useState(false);
39 } = useActivateFlow();
41 const [ticketInput, { pass: validTicket, data: ticket }] = useTicketInput({
44 initialValue: impliedTicket || '',
48 const goToLogin = useCallback(() => history.popAndPush(ROUTE_NAMES.LOGIN), [
51 const goToPassport = useCallback(() => push(names.PASSPORT), [names, push]);
53 const pass = derivedWallet.matchWith({
60 const _contracts = need.contracts(contracts);
63 // when the ticket becomes valid, derive the point
65 const { seed } = await generateTemporaryOwnershipWallet(ticket);
67 //TODO isn't all this accessible in the ownership object?
68 const inviteWallet = walletFromMnemonic(seed, DEFAULT_HD_PATH);
69 const _inviteWallet = need.wallet(inviteWallet);
71 const owned = await azimuth.azimuth.getOwnedPoints(
75 const transferring = await azimuth.azimuth.getTransferringFor(
79 const incoming = [...owned, ...transferring];
81 let realPoint = Nothing();
82 let wallet = Nothing();
84 if (incoming.length > 0) {
85 const pointNum = parseInt(incoming[0], 10);
86 realPoint = Just(pointNum);
87 wallet = Just(await generateWallet(pointNum));
89 if (incoming.length > 1) {
91 'This invite code has multiple points available.\n' +
92 "Once you've activated this point, activate the next with the same process."
95 setGeneralError(false);
99 'Invite code has no claimable point.\n' +
100 'Check your invite code and try again?'
104 setDerivedPoint(realPoint);
105 setDerivedWallet(wallet);
106 setInviteWallet(inviteWallet);
110 setGeneralError(false);
121 // when we know the derived point, ensure we have the data to display it
122 useSyncKnownPoints([derivedPoint.getOrElse(null)].filter(p => p !== null));
127 <Grid.Item as={Passport} point={derivedPoint} full />
128 <Grid.Item as={H4} className="mt3 mb2" full>
131 <Grid.Item as={Input} {...ticketInput} full />
134 <ErrorText>{generalError}</ErrorText>{' '}
140 disabled={!pass || deriving}
141 accessory={blinkIf(deriving)}
142 onClick={goToPassport}
145 {deriving && 'Deriving...'}
149 <FooterButton as={ForwardButton} onClick={goToLogin}>
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