1import React, { useCallback, useMemo } from 'react';
2import { Just } 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';
28import { composeValidator, buildPatqValidator } from 'form/validators';
29import FormError from 'form/FormError';
30import { FORM_ERROR } from 'final-form';
32export default function ActivateCode() {
33 const history = useHistory();
34 const { names, push } = useLocalRouter();
35 const { contracts } = useNetwork();
36 const impliedTicket = useImpliedTicket();
37 const [hasDisclaimed] = useHasDisclaimed();
44 } = useActivateFlow();
46 const goToLogin = useCallback(() => history.popAndPush(ROUTE_NAMES.LOGIN), [
50 const goToPassport = useCallback(() => {
54 push(names.DISCLAIMER);
56 }, [names, push, hasDisclaimed]);
58 const validate = useMemo(
59 () => composeValidator({ ticket: buildPatqValidator() }),
63 // set our state on submission
64 const onSubmit = useCallback(
66 await timeout(100); // allow the ui changes to flush before we lag it out
68 const _contracts = need.contracts(contracts);
69 const { seed } = await generateTemporaryOwnershipWallet(values.ticket);
71 const inviteWallet = walletFromMnemonic(seed, DEFAULT_HD_PATH);
73 const _inviteWallet = need.wallet(inviteWallet);
75 const owned = await azimuth.azimuth.getOwnedPoints(
79 const transferring = await azimuth.azimuth.getTransferringFor(
83 const incoming = [...owned, ...transferring];
85 if (incoming.length > 0) {
86 if (incoming.length > 1) {
87 // TODO: putting a warning here doesn't make sense since the user
88 // will be immediately redirected away — what do?
89 // 'This invite code has multiple points available.\n' +
90 // "Once you've activated this point, activate the next with the same process.";
93 const point = parseInt(incoming[0], 10);
95 setDerivedPoint(Just(point));
96 setInviteWallet(inviteWallet);
97 setDerivedWallet(Just(await generateWallet(point)));
101 'Invite code has no claimable point.\n' +
102 'Check your invite code and try again?',
106 [contracts, setDerivedPoint, setDerivedWallet, setInviteWallet]
109 const initialValues = useMemo(() => ({ ticket: impliedTicket || '' }), [
116 <Grid.Item full as={Passport} point={derivedPoint} />
117 <Grid.Item full as={H4} className="mt3 mb2">
123 afterSubmit={goToPassport}
124 initialValues={initialValues}>
125 {({ validating, submitting, handleSubmit }) => (
131 label="Activation Code"
134 <Grid.Item full as={FormError} />
140 handleSubmit={handleSubmit}>
151 <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