on master help sign in
qol: address linter, remove legacy flow
commit326b4c92fbe4e312731a4a9c518532808396b733 authortomholford <tomholford@users.noreply.github.com> dateWed 22 Sep 2021, 00:16 (5 years ago) parent7f18d02
9 files changed+15−534
src/lib/useRoller.ts+2−2 src/views/Activate.js−3 src/views/Activate/ActivateCodeForm.tsx+13−16 src/views/Activate/ActivatePassport.js−82 src/views/Activate/MasterKeyDownload.tsx−1 src/views/Activate/PassportDownload.js−96 src/views/Activate/PassportTransfer.js−204 src/views/Activate/PassportVerify.js−103 src/views/Activate/PassportView.js−27
src/lib/useRoller.ts+2−2
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
22import * as azimuth from 'azimuth-js';
33import * as need from 'lib/need';
44import * as ob from 'urbit-ob';
5−import * as wg from 'lib/walletgen';
65
76import { Invite } from 'lib/types/Invite';
87import { convertToInt } from './convertToInt';
@@ -96,7 +95,8 @@ export default function useRoller() {
9695 : isDevelopment
9796 ? ROLLER_HOSTS.LOCAL
9897 : ROLLER_HOSTS.MAINNET;
99− const port = isDevelopment ? 8080 : 80;
98+ // const port = isDevelopment ? 8080 : 80;
99+ const port = 80;
100100 const path = '/v1/roller';
101101
102102 return {
src/views/Activate.js−3
@@ -7,20 +7,17 @@ import { useSyncDates } from 'lib/useSyncPoints';
77import { ActivateFlowProvider } from './Activate/ActivateFlow';
88import useActivateFlowState from './Activate/useActivateFlowState';
99import ActivateCode from './Activate/ActivateCode';
10−import ActivatePassport from './Activate/ActivatePassport';
1110import ActivateMasterKey from './Activate/ActivateMasterKey';
1211import Disclaimer from './Disclaimer';
1312
1413const NAMES = {
1514 CODE: 'CODE',
1615 DISCLAIMER: 'DISCLAIMER',
17− PASSPORT: 'PASSPORT',
1816 MASTER_KEY: 'MASTER_KEY',
1917};
2018
2119const VIEWS = {
2220 [NAMES.CODE]: ActivateCode,
23− [NAMES.PASSPORT]: ActivatePassport,
2421 [NAMES.DISCLAIMER]: Disclaimer,
2522 [NAMES.MASTER_KEY]: ActivateMasterKey,
2623};
src/views/Activate/ActivateCodeForm.tsx+13−16
@@ -36,12 +36,7 @@ interface ActivateCodeFormProps {
3636
3737const ActivateCodeForm = ({ afterSubmit }: ActivateCodeFormProps) => {
3838 const { api, getPoints } = useRoller();
39− const {
40− impliedAzimuthPoint,
41− impliedTicket,
42− impliedPatp,
43− } = useImpliedTicket();
44− console.log(impliedAzimuthPoint, impliedTicket);
39+ const { impliedTicket, impliedPatp } = useImpliedTicket();
4540 const didWarn = useRef<boolean>(false);
4641
4742 const {
@@ -80,16 +75,18 @@ const ActivateCodeForm = ({ afterSubmit }: ActivateCodeFormProps) => {
8075 [validateForm]
8176 );
8277
83− const getTicketAndPoint = (invite: string) => {
84− const segments = invite.split('-');
85− console.log(segments);
86− return {
87− ticket: segments.slice(0, 4).join('-'),
88− point: impliedPatp
89− ? ob.patp2dec(impliedPatp)
90− : ob.patp2dec(`~${segments.slice(4, segments.length).join('-')}`),
91− };
92− };
78+ const getTicketAndPoint = useCallback(
79+ (invite: string) => {
80+ const segments = invite.split('-');
81+ return {
82+ ticket: segments.slice(0, 4).join('-'),
83+ point: impliedPatp
84+ ? ob.patp2dec(impliedPatp)
85+ : ob.patp2dec(`~${segments.slice(4, segments.length).join('-')}`),
86+ };
87+ },
88+ [impliedPatp]
89+ );
9390
9491 const loadPoints = useCallback(
9592 async (address: string): Promise<Ship[]> => {
src/views/Activate/ActivatePassport.jsdeleted−82
@@ -1,82 +0,0 @@
1−import React, { useMemo } from 'react';
2−import cn from 'classnames';
3−import { Grid } from 'indigo-react';
4−
5−import { LocalRouterProvider, useLocalRouter } from 'lib/LocalRouter';
6−
7−import View from 'components/View';
8−import Passport from 'components/Passport';
9−
10−import { useActivateFlow } from './ActivateFlow';
11−import useBreakpoints from 'lib/useBreakpoints';
12−import useRouter from 'lib/useRouter';
13−
14−import PassportDownload from './PassportDownload';
15−import PassportVerify from './PassportVerify';
16−import PassportTransfer from './PassportTransfer';
17−import { walletFromMnemonic } from 'lib/wallet';
18−import { DEFAULT_HD_PATH } from 'lib/constants';
19−import { publicToAddress } from 'lib/utils/address';
20−
21−const NAMES = {
22− DOWNLOAD: 'DOWNLOAD',
23− VERIFY: 'VERIFY',
24− TRANSFER: 'TRANSFER',
25−};
26−
27−const VIEWS = {
28− [NAMES.DOWNLOAD]: PassportDownload,
29− [NAMES.VERIFY]: PassportVerify,
30− [NAMES.TRANSFER]: PassportTransfer,
31−};
32−
33−export default function ActivatePassport() {
34− const { derivedPoint, generated, derivedWallet } = useActivateFlow();
35− // pull the reset function out of the 'activate' router
36− const { reset: resetActivateRouter } = useLocalRouter();
37− const { Route, ...router } = useRouter({
38− names: NAMES,
39− views: VIEWS,
40− initialRoutes: [{ key: NAMES.DOWNLOAD }],
41− });
42−
43− const gap = useBreakpoints([4, 4, 7]);
44− const marginTop = useBreakpoints([false, false, 8]);
45−
46− // addresses are not derived until we set[Urbit]Wallet(), so do that inline
47− const address = useMemo(
48− () =>
49− derivedWallet
50− .chain(wallet =>
51− walletFromMnemonic(
52− wallet.ownership.seed,
53− DEFAULT_HD_PATH,
54− wallet.meta.passphrase
55− )
56− )
57− .map(wallet => publicToAddress(wallet.publicKey)),
58− [derivedWallet]
59− );
60− //~hobbyn-mismur-fonrux-datber
61− return (
62− <View inset>
63− <LocalRouterProvider value={router}>
64− <Grid gap={gap} className="mt8 mb10">
65− <Grid.Item full>
66− <Passport
67− className={cn({ [`mt${marginTop}`]: marginTop })}
68− point={derivedPoint}
69− ticket={generated}
70− address={address}
71− />
72− </Grid.Item>
73− <Grid.Item
74− full
75− as={Route}
76− resetActivateRouter={resetActivateRouter}
77− />
78− </Grid>
79− </LocalRouterProvider>
80− </View>
81− );
82−}
src/views/Activate/MasterKeyDownload.tsx−1
@@ -25,7 +25,6 @@ const MasterKeyDownload = () => {
2525 const {
2626 derivedPoint,
2727 derivedWallet,
28− generated,
2928 setGenerated,
3029 setIsIn,
3130 } = useActivateFlow();
src/views/Activate/PassportDownload.jsdeleted−96
@@ -1,96 +0,0 @@
1−import React, { useState, useEffect, useCallback } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
3−import { Grid, P } from 'indigo-react';
4−import ob from 'urbit-ob';
5−
6−import * as need from 'lib/need';
7−import { downloadWallet } from 'lib/invite';
8−import { useLocalRouter } from 'lib/LocalRouter';
9−import { compileNetworkingKey } from 'lib/keys';
10−
11−import { DownloadButton, ForwardButton } from 'components/Buttons';
12−import PaperBuilder from 'components/PaperBuilder';
13−
14−import { useActivateFlow } from './ActivateFlow';
15−import PassportView from './PassportView';
16−
17−export default function PassportDownload({ className }) {
18− const {
19− derivedPoint,
20− derivedWallet,
21− generated,
22− setGenerated,
23− } = useActivateFlow();
24− const { push, names } = useLocalRouter();
25− const point = need.point(derivedPoint);
26− const wallet = need.wallet(derivedWallet);
27−
28− const [paper, setPaper] = useState(Nothing());
29− const [downloaded, setDownloaded] = useState(false);
30−
31− const pointAsString = derivedPoint.matchWith({
32− Nothing: () => '',
33− Just: p => p.value.toFixed(),
34− });
35−
36− const download = useCallback(() => {
37− const netkey = compileNetworkingKey(wallet.network.keys, point, 1);
38− //TODO could be deduplicated with useKeyfileGenerator's logic
39− const filename = ob.patp(point).slice(1) + '-1.key';
40− downloadWallet(paper.getOrElse([]), netkey, filename);
41− setDownloaded(true);
42− }, [paper, wallet, point, setDownloaded]);
43−
44− // sync paper value to activation state
45− useEffect(
46− () =>
47− setGenerated(
48− paper.matchWith({
49− Nothing: () => false,
50− Just: () => true,
51− })
52− ),
53− [paper, setGenerated]
54− );
55−
56− const goToVerify = useCallback(() => push(names.VERIFY), [push, names]);
57−
58− return (
59− <>
60− <PassportView
61− className={className}
62− header="Download Your Urbit Passport"
63− step={1}>
64− <Grid>
65− <Grid.Item full>
66− <P>
67− Your Passport includes your Master Ticket, a password giving you
68− total control of your Urbit identity. You’ll need it to access the
69− network and manage your identity.
70− </P>
71− <P>
72− After your Passport is downloaded, make sure to print it out on
73− paper and store it somewhere safe.
74− </P>
75− </Grid.Item>
76− <Grid.Item
77− full
78− as={!downloaded ? DownloadButton : ForwardButton}
79− disabled={!generated}
80− onClick={!downloaded ? download : goToVerify}
81− success={downloaded}
82− solid>
83− {!downloaded ? 'Download Passport' : 'Continue'}
84− </Grid.Item>
85− </Grid>
86− </PassportView>
87− <PaperBuilder
88− point={pointAsString}
89− wallets={[wallet]}
90− callback={data => {
91− setPaper(Just(data));
92− }}
93− />
94− </>
95− );
96−}
src/views/Activate/PassportTransfer.jsdeleted−204
@@ -1,204 +0,0 @@
1−import React, { useState, useCallback } from 'react';
2−import { Grid, Text, ErrorText } from 'indigo-react';
3−
4−import { useNetwork } from 'store/network';
5−import { useWallet } from 'store/wallet';
6−import { useHistory } from 'store/history';
7−import { usePointCursor } from 'store/pointCursor';
8−
9−import * as need from 'lib/need';
10−import useLifecycle from 'lib/useLifecycle';
11−import useBlockWindowClose from 'lib/useBlockWindowClose';
12−import {
13− reticketPointBetweenWallets,
14− TRANSACTION_PROGRESS,
15−} from 'lib/reticket';
16−import { timeout } from 'lib/timeout';
17−
18−import WarningBox from 'components/WarningBox';
19−import LoadingBar from 'components/LoadingBar';
20−import { RestartButton } from 'components/Buttons';
21−import NeedFundsNotice from 'components/NeedFundsNotice';
22−
23−import { useActivateFlow } from './ActivateFlow';
24−import PassportView from './PassportView';
25−
26−const labelForProgress = progress => {
27− if (progress <= 0) {
28− return 'Verify Passport';
29− } else if (progress <= TRANSACTION_PROGRESS.GENERATING) {
30− return 'Generating Ethereum Transactions...';
31− } else if (progress <= TRANSACTION_PROGRESS.SIGNING) {
32− return 'Signing Ethereum Transactions...';
33− } else if (progress <= TRANSACTION_PROGRESS.FUNDING) {
34− return 'Funding Ethereum Transactions...';
35− } else if (progress <= TRANSACTION_PROGRESS.TRANSFERRING) {
36− return 'Transferring ID...';
37− } else if (progress <= TRANSACTION_PROGRESS.CLEANING) {
38− return 'Cleaning Up...';
39− } else if (progress <= TRANSACTION_PROGRESS.DONE) {
40− return 'Done';
41− }
42−};
43−
44−export default function PassportTransfer({ className, resetActivateRouter }) {
45− const { replaceWith, names } = useHistory();
46− const { setUrbitWallet } = useWallet();
47− const { setPointCursor } = usePointCursor();
48− const { web3, contracts, networkType } = useNetwork();
49− const {
50− derivedWallet,
51− derivedPoint,
52− inviteWallet,
53− reset: resetActivateFlow,
54− } = useActivateFlow();
55− const [generalError, setGeneralError] = useState();
56− const [progress, setProcesss] = useState(0);
57− const [needFunds, setNeedFunds] = useState();
58−
59− const goToLogin = useCallback(
60− () => replaceWith([{ key: names.LOGIN }, { key: names.POINT }]),
61− [replaceWith, names]
62− );
63−
64− useBlockWindowClose();
65−
66− const goToRestart = useCallback(() => {
67− // NOTE: because we're already on the ACTIVATE view in the history,
68− // react (intelligently) doesn't trigger a re-render and that means the
69− // current state of the two nested routers (activate & passport) stick
70− // around unless we manually clear them.
71− // we only need to clear activate because that will unmount the passport
72− // router (which will be set to initialRoutes when mounted again)
73−
74− // 2) reset local router
75− resetActivateRouter();
76− // 3) clear the state
77− resetActivateFlow();
78− }, [resetActivateRouter, resetActivateFlow]);
79−
80− const handleUpdate = useCallback(
81− ({ type, state, value }) => {
82− switch (type) {
83− case 'progress':
84− return setProcesss(state);
85− case 'askFunding':
86− return setNeedFunds(value);
87− case 'gotFunding':
88− return setNeedFunds(false);
89− default:
90− console.error(`Unknown update: ${type}`);
91− }
92− },
93− [setProcesss, setNeedFunds]
94− );
95−
96− const claimPoint = useCallback(async () => {
97− setGeneralError(false);
98−
99− try {
100− const _inviteWallet = need.wallet(inviteWallet);
101− const _wallet = need.wallet(derivedWallet);
102− const _point = need.point(derivedPoint);
103− const _web3 = need.web3(web3);
104− const _contracts = need.contracts(contracts);
105−
106− await reticketPointBetweenWallets({
107− fromWallet: _inviteWallet,
108− toWallet: _wallet,
109− point: _point,
110− web3: _web3,
111− contracts: _contracts,
112− networkType,
113− onUpdate: handleUpdate,
114− transferEth: true,
115− //NOTE not passing wc function, we always have invite ticket wallet
116− });
117−
118− // set the global wallet
119− setUrbitWallet(derivedWallet);
120− setPointCursor(derivedPoint);
121−
122− // and redirect to login
123− await timeout(3000);
124− goToLogin();
125− } catch (error) {
126− // some generic error
127− setGeneralError(error);
128− }
129− }, [
130− inviteWallet,
131− derivedWallet,
132− derivedPoint,
133− web3,
134− contracts,
135− networkType,
136− setUrbitWallet,
137− setPointCursor,
138− handleUpdate,
139− goToLogin,
140− ]);
141−
142− useLifecycle(() => {
143− claimPoint();
144− });
145−
146− const renderAdditionalInfo = () => {
147− if (generalError) {
148− console.log(generalError);
149− generalError.message = generalError.message || 'Something went wrong!';
150− return (
151− <>
152− <Grid.Item full className="mt8">
153− <ErrorText>{generalError.message.toString()}</ErrorText>
154− </Grid.Item>
155− <Grid.Item
156− full
157− className="mt3"
158− as={RestartButton}
159− solid
160− onClick={goToRestart}>
161− Restart
162− </Grid.Item>
163− </>
164− );
165− }
166−
167− if (needFunds) {
168− return (
169− <Grid.Item full as={NeedFundsNotice} className="mt8" {...needFunds} />
170− );
171− }
172−
173− if (progress < 1.0) {
174− return (
175− <Grid.Item full as={WarningBox} className="mt8">
176− Never give your Master Ticket to anyone
177− </Grid.Item>
178− );
179− }
180−
181− return null;
182− };
183−
184− return (
185− <PassportView
186− className={className}
187− header={labelForProgress(progress)}
188− step={3}>
189− <Grid>
190− <Grid.Item full as={Grid} className="mt3" gap={3}>
191− <Grid.Item full as={LoadingBar} progress={progress} />
192− <Grid.Item full>
193− <Text className="f5 green4">
194− This process can take up to 5 minutes to complete. Don't close
195− this page until the process is complete.
196− </Text>
197− </Grid.Item>
198− </Grid.Item>
199−
200− {renderAdditionalInfo()}
201− </Grid>
202− </PassportView>
203− );
204−}
src/views/Activate/PassportVerify.jsdeleted−103
@@ -1,103 +0,0 @@
1−import React, { useCallback, useMemo } from 'react';
2−import { Grid, P, CheckboxInput } from 'indigo-react';
3−
4−import * as need from 'lib/need';
5−import { useLocalRouter } from 'lib/LocalRouter';
6−import { validateExactly } from 'lib/validators';
7−import { isDevelopment } from 'lib/flags';
8−
9−import SubmitButton from 'form/SubmitButton';
10−import { TicketInput } from 'form/Inputs';
11−import {
12− composeValidator,
13− buildPatqValidator,
14− buildCheckboxValidator,
15−} from 'form/validators';
16−import BridgeForm from 'form/BridgeForm';
17−
18−import { useActivateFlow } from './ActivateFlow';
19−import PassportView from './PassportView';
20−import FormError from 'form/FormError';
21−
22−const STUB_VERIFY_TICKET = isDevelopment;
23−
24−export default function PassportVerify({ className }) {
25− const { push, names } = useLocalRouter();
26− const { derivedWallet } = useActivateFlow();
27− const goToTransfer = useCallback(() => push(names.TRANSFER), [push, names]);
28−
29− const { ticket } = need.wallet(derivedWallet);
30− const validate = useMemo(
31− () =>
32− composeValidator({
33− ticket: buildPatqValidator([
34− validateExactly(ticket, 'Does not match expected master ticket.'),
35− ]),
36− showTicket: buildCheckboxValidator(),
37− }),
38− [ticket]
39− );
40−
41− const initialValues = useMemo(
42− () => ({
43− ticket: STUB_VERIFY_TICKET ? ticket : undefined,
44− showTicket: true,
45− }),
46− [ticket]
47− );
48−
49− return (
50− <PassportView
51− header="Verify Your Master Ticket"
52− step={2}
53− className={className}>
54− <Grid>
55− <Grid.Item full as={P}>
56− We need to verify that you’re you. Unzip the file you downloaded in
57− the previous step. It should yield a directory of images.
58− </Grid.Item>
59− <Grid.Item full as={P}>
60− One of the images includes your Master Ticket. It’s a four-word phrase
61− separated with hyphens. Enter it below to verify you recieved it
62− (include the hyphens).
63− </Grid.Item>
64− <Grid.Item full as={P}>
65− <b>Never share your Master Ticket with anyone else.</b>
66− </Grid.Item>
67− <BridgeForm
68− validate={validate}
69− afterSubmit={goToTransfer}
70− initialValues={initialValues}>
71− {({ values, handleSubmit }) => (
72− <>
73− <Grid.Item
74− full
75− as={TicketInput}
76− type={values.showTicket ? 'text' : 'password'}
77− name="ticket"
78− label="Master Ticket"
79− />
80−
81− <Grid.Item
82− full
83− as={CheckboxInput}
84− name="showTicket"
85− label="Show"
86− />
87−
88− <Grid.Item full as={FormError} />
89−
90− <Grid.Item
91− full
92− className="mt3"
93− as={SubmitButton}
94− handleSubmit={handleSubmit}>
95− Verify
96− </Grid.Item>
97− </>
98− )}
99− </BridgeForm>
100− </Grid>
101− </PassportView>
102− );
103−}
src/views/Activate/PassportView.jsdeleted−27
@@ -1,27 +0,0 @@
1−import React from 'react';
2−import cn from 'classnames';
3−import { Grid, H4 } from 'indigo-react';
4−
5−import Steps from 'components/Steps';
6−
7−// NOTE: the 48px matches the `mt8` class on Passport so things line up nicely
8−// TODO: there's probably a clever grid/flex way to do this instead
9−export default function PassportView({ className, children, header, step }) {
10− return (
11− <>
12− <Grid className={cn(className, 'auto-rows-min')}>
13− <Grid.Item
14− full
15− as={Steps}
16− num={step}
17− total={3}
18− style={{ height: '48px' }}
19− />
20− <Grid.Item full as={H4}>
21− {header}
22− </Grid.Item>
23− <Grid.Item full>{children}</Grid.Item>
24− </Grid>
25− </>
26− );
27−}