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 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 owned = await azimuth.azimuth.getOwnedPoints(
77 const transferring = await azimuth.azimuth.getTransferringFor(
81 const incoming = [...owned, ...transferring];
83 let realPoint = Nothing();
84 let wallet = Nothing();
86 if (incoming.length > 0) {
87 const pointNum = parseInt(incoming[0], 10);
88 realPoint = Just(pointNum);
89 wallet = Just(await generateWallet(pointNum));
91 if (incoming.length > 1) {
93 'This invite code has multiple points available.\n' +
94 "Once you've activated this point, activate the next with the same process."
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={deriving ? <Blinky /> : undefined}
142 onClick={goToDisclaimer}
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