@@ -1,12 +1,11 @@
1−import React, { useCallback, useMemo, useRef } from 'react';
1+import { useCallback, useMemo, useRef } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
2+import { Just } from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
3import * as azimuth from 'azimuth-js';
4import { Grid, H4, P, CheckboxInput } from 'indigo-react';
4import { Grid, H4, P, CheckboxInput } from 'indigo-react';
5import { FORM_ERROR } from 'final-form';
5import { FORM_ERROR } from 'final-form';
7import View from 'components/View';
7import View from 'components/View';
8import { ForwardButton } from 'components/Buttons';
8import { ForwardButton } from 'components/Buttons';
9−import Passport from 'components/Passport';
10import WarningBox from 'components/WarningBox';
9import WarningBox from 'components/WarningBox';
11import FooterButton from 'components/FooterButton';
10import FooterButton from 'components/FooterButton';
@@ -18,7 +17,7 @@ import { ROUTE_NAMES } from 'lib/routeNames';
18import { walletFromMnemonic } from 'lib/wallet';
17import { walletFromMnemonic } from 'lib/wallet';
19import { DEFAULT_HD_PATH } from 'lib/constants';
18import { DEFAULT_HD_PATH } from 'lib/constants';
20import { generateWallet } from 'lib/invite';
19import { generateWallet } from 'lib/invite';
21−import { generateTemporaryOwnershipWallet } from 'lib/walletgen';
20+import { generateOwnershipWallet } from 'lib/walletgen';
22import { useLocalRouter } from 'lib/LocalRouter';
21import { useLocalRouter } from 'lib/LocalRouter';
23import useImpliedTicket from 'lib/useImpliedTicket';
22import useImpliedTicket from 'lib/useImpliedTicket';
24import { timeout } from 'lib/timeout';
23import { timeout } from 'lib/timeout';
@@ -39,20 +38,20 @@ import FormError from 'form/FormError';
39import { useActivateFlow } from './ActivateFlow';
38import { useActivateFlow } from './ActivateFlow';
40import { WARNING } from 'form/helpers';
39import { WARNING } from 'form/helpers';
41import { convertToInt } from 'lib/convertToInt';
40import { convertToInt } from 'lib/convertToInt';
41+import { patp2dec } from 'lib/patp2dec';
43export default function ActivateCode() {
43export default function ActivateCode() {
44 const history = useHistory();
44 const history = useHistory();
45 const { names, push } = useLocalRouter();
45 const { names, push } = useLocalRouter();
46 const { contracts } = useNetwork();
46 const { contracts } = useNetwork();
47− const impliedTicket = useImpliedTicket();
47+ const { impliedPoint, impliedTicket } = useImpliedTicket();
48 const [hasDisclaimed] = useHasDisclaimed();
48 const [hasDisclaimed] = useHasDisclaimed();
49 const didWarn = useRef(false);
49 const didWarn = useRef(false);
52 setDerivedWallet,
53 setDerivedWallet,
53 setInviteWallet,
54 setInviteWallet,
56 } = useActivateFlow();
55 } = useActivateFlow();
57 // this is a pretty naive way to detect if we're on a mobile device
56 // this is a pretty naive way to detect if we're on a mobile device
58 // (i.e. we're checking the width of the screen)
57 // (i.e. we're checking the width of the screen)
@@ -90,18 +89,23 @@ export default function ActivateCode() {
90 [validateForm]
89 [validateForm]
93− // set our state on submission
92+ // derive and set our state on submission
94 const onSubmit = useCallback(
93 const onSubmit = useCallback(
95− async values => {
94+ async _values => {
96 await timeout(16); // allow the ui changes to flush before we lag it out
95 await timeout(16); // allow the ui changes to flush before we lag it out
97+ // TODO: fallback logic to first use implied values if present, otherwise form values?
99+ const impliedAzimuthPoint = patp2dec(impliedPoint);
98 const _contracts = need.contracts(contracts);
100 const _contracts = need.contracts(contracts);
99− const { seed } = await generateTemporaryOwnershipWallet(values.ticket);
101+ const { seed } = await generateOwnershipWallet(
100−
102+ impliedAzimuthPoint,
101 const inviteWallet = walletFromMnemonic(seed, DEFAULT_HD_PATH);
105 const inviteWallet = walletFromMnemonic(seed, DEFAULT_HD_PATH);
103 const _inviteWallet = need.wallet(inviteWallet);
106 const _inviteWallet = need.wallet(inviteWallet);
108+ // Load associated points
105 const owned = await azimuth.azimuth.getOwnedPoints(
109 const owned = await azimuth.azimuth.getOwnedPoints(
106 _contracts,
110 _contracts,
107 _inviteWallet.address
111 _inviteWallet.address
@@ -110,11 +114,16 @@ export default function ActivateCode() {
110 _contracts,
114 _contracts,
111 _inviteWallet.address
115 _inviteWallet.address
113 const incoming = [...owned, ...transferring];
118 const incoming = [...owned, ...transferring];
120+ setInviteWallet(inviteWallet);
115 if (incoming.length > 0) {
123 if (incoming.length > 0) {
116 if (incoming.length > 1 && !didWarn.current) {
124 if (incoming.length > 1 && !didWarn.current) {
117 didWarn.current = true;
125 didWarn.current = true;
119 [WARNING]:
128 [WARNING]:
120 'This invite code has multiple points available. ' +
129 'This invite code has multiple points available. ' +
@@ -126,7 +135,6 @@ export default function ActivateCode() {
126 const point = convertToInt(incoming[0], 10);
135 const point = convertToInt(incoming[0], 10);
128 setDerivedPoint(Just(point));
137 setDerivedPoint(Just(point));
129− setInviteWallet(inviteWallet);
130 setDerivedWallet(Just(await generateWallet(point, true)));
138 setDerivedWallet(Just(await generateWallet(point, true)));
@@ -136,7 +144,14 @@ export default function ActivateCode() {
139− [contracts, setDerivedPoint, setDerivedWallet, setInviteWallet]
152+ setDerivedWallet,
142 const initialValues = useMemo(
157 const initialValues = useMemo(
@@ -147,19 +162,20 @@ export default function ActivateCode() {
148 <View inset>
163 <View inset>
153− point={derivedPoint}
156 <Grid.Item full as={H4} className="mt3">
165 <Grid.Item full as={H4} className="mt3">
157− Activate
166+ Welcome. This is your Urbit.
159− <Grid.Item full as={P} className="mb2">
160− Someone has invited you to claim your Urbit identity and join the
161− network. {!impliedTicket && 'Enter your activation code to continue.'}
162 </Grid.Item>
167 </Grid.Item>
168+ {!impliedTicket && (
169+ <Grid.Item full as={P} className="mb2">
170+ Enter your activation code to continue.
175+ <Grid.Item full as={P} className="mb2">
163 <BridgeForm
179 <BridgeForm
164 validate={validate}
180 validate={validate}
165 onSubmit={onSubmit}
181 onSubmit={onSubmit}
@@ -201,7 +217,7 @@ export default function ActivateCode() {
201 ? 'Generating...'
217 ? 'Generating...'
202 : isWarning
218 : isWarning
203 ? 'Continue Activation'
219 ? 'Continue Activation'
204− : 'Go'
220+ : 'Claim'
206 </Grid.Item>
222 </Grid.Item>