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 } 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, { pass: validTicket }] = useTicketInput({
45 const goToLogin = useCallback(() => history.popAndPush(ROUTE_NAMES.LOGIN), [
48 const goToDisclaimer = useCallback(() => push(names.DISCLAIMER), [
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(
69 //TODO isn't all this accessible in the ownership object?
70 const inviteWallet = walletFromMnemonic(seed, DEFAULT_HD_PATH);
71 const _inviteWallet = need.wallet(inviteWallet);
73 const incoming = await azimuth.azimuth.getTransferringFor(
78 let realPoint = Maybe.Nothing();
79 let wallet = Maybe.Nothing();
81 if (incoming.length > 0) {
82 const pointNum = parseInt(incoming[0], 10);
83 realPoint = Maybe.Just(pointNum);
84 wallet = Maybe.Just(await generateWallet(pointNum));
86 if (incoming.length > 1) {
88 'This invite code has multiple points available.\n' +
89 "Once you've activated this point, activate the next with the same process."
94 'Invite code has no claimable point.\n' +
95 'Check your invite code and try again?'
99 setDerivedPoint(realPoint);
100 setDerivedWallet(wallet);
101 setInviteWallet(inviteWallet);
105 setGeneralError(false);
116 // when we know the derived point, ensure we have the data to display it
117 useSyncKnownPoints([derivedPoint.getOrElse(null)].filter(p => p !== null));
122 <Grid.Item as={Passport} point={derivedPoint} full />
123 <Grid.Item as={H4} className="mt3 mb2" full>
126 <Grid.Item as={Input} {...ticketInput} full />
129 <ErrorText>{generalError}</ErrorText>{' '}
135 disabled={!pass || deriving}
136 accessory={deriving ? <Blinky /> : undefined}
137 onClick={goToDisclaimer}
140 {deriving && 'Deriving...'}
144 <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