1import React, { useCallback, useRef } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
4import { Grid, H4 } from 'indigo-react';
6import View from 'components/View';
7import { ForwardButton } from 'components/Buttons';
8import Passport from 'components/Passport';
10import { useHistory } from 'store/history';
12import * as need from 'lib/need';
13import { ROUTE_NAMES } from 'lib/routeNames';
14import FooterButton from 'components/FooterButton';
15import { DEFAULT_HD_PATH, walletFromMnemonic } from 'lib/wallet';
16import { useNetwork } from 'store/network';
17import { generateWallet } from 'lib/invite';
18import { generateTemporaryOwnershipWallet } from 'lib/walletgen';
19import { useActivateFlow } from './ActivateFlow';
20import { useLocalRouter } from 'lib/LocalRouter';
21import useImpliedTicket from 'lib/useImpliedTicket';
22import timeout from 'lib/timeout';
23import useHasDisclaimed from 'lib/useHasDisclaimed';
25import BridgeForm from 'form/BridgeForm';
26import SubmitButton from 'form/SubmitButton';
27import { TicketInput } from 'form/Inputs';
29export default function ActivateCode() {
30 const history = useHistory();
31 const { names, push } = useLocalRouter();
32 const { contracts } = useNetwork();
33 const impliedTicket = useImpliedTicket();
34 const [hasDisclaimed] = useHasDisclaimed();
36 const cachedInviteWallet = useRef(Nothing());
37 const cachedPoint = useRef();
44 } = useActivateFlow();
46 const goToLogin = useCallback(() => history.popAndPush(ROUTE_NAMES.LOGIN), [
49 const goToPassport = useCallback(() => {
53 push(names.DISCLAIMER);
55 }, [names, push, hasDisclaimed]);
57 const validate = useCallback(
59 await timeout(100); // allow the ui changes to flush before we lag it out
61 const _contracts = need.contracts(contracts);
62 const { seed } = await generateTemporaryOwnershipWallet(ticket);
64 // TODO(fang): isn't all this accessible in the ownership object?
65 const inviteWallet = walletFromMnemonic(seed, DEFAULT_HD_PATH);
66 cachedInviteWallet.current = inviteWallet;
68 const _inviteWallet = need.wallet(inviteWallet);
70 const owned = await azimuth.azimuth.getOwnedPoints(
74 const transferring = await azimuth.azimuth.getTransferringFor(
78 const incoming = [...owned, ...transferring];
80 if (incoming.length > 0) {
81 if (incoming.length > 1) {
84 // 'This invite code has multiple points available.\n' +
85 // "Once you've activated this point, activate the next with the same process."
89 const point = parseInt(incoming[0], 10);
90 setDerivedPoint(Just(point));
91 cachedPoint.current = point;
94 'Invite code has no claimable point.\n' +
95 'Check your invite code and try again?'
99 [contracts, setDerivedPoint]
102 const onSubmit = useCallback(
104 setInviteWallet(cachedInviteWallet.current);
105 setDerivedWallet(Just(await generateWallet(cachedPoint)));
109 [goToPassport, setDerivedWallet, setInviteWallet]
115 <Grid.Item as={Passport} point={derivedPoint} full />
116 <Grid.Item as={H4} className="mt3 mb2" full>
121 initialValues={{ ticket: impliedTicket || '' }}>
122 {({ validating, submitting, handleSubmit }) => (
128 label="Activation Code"
137 handleSubmit={handleSubmit}>
148 <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