on master help sign in
flows: remove invite flow

Not inviting in general! Just the one you enter using GET params.

commitacf71dd563d79971eac8f47552c932dbe3f2aabd authorfang <git@fang.io> dateWed 24 Feb 2021, 22:27 (6 years ago) parent5a7d61b
5 files changed+3−287
src/lib/flowCommand.js+1−10 src/lib/routeNames.js−2 src/lib/router.js−4 src/views/Login.js+2−15 src/views/flows/JustInvite.js−256
src/lib/flowCommand.js+1−10
@@ -13,7 +13,7 @@ import { ensurePatFormat } from 'form/formatters';
1313//
1414
1515const COMMANDS = {
16− INVITE: 'invite',
16+ //
1717};
1818
1919const useFlowCommand = () => {
@@ -29,15 +29,6 @@ const useFlowCommand = () => {
2929
3030 if (typeof flow === 'object') {
3131 switch (flow.kind) {
32− case COMMANDS.INVITE:
33− flow.as = ensurePatFormat(flow.as);
34− flow.ship = ensurePatFormat(flow.ship);
35− if (!ob.isValidPatp(flow.as) || !ob.isValidPatp(flow.ship)) {
36− console.log('invalid inviting flow arguments', flow.as, flow.ship);
37− flow = null;
38− }
39− break;
40− //
4132 default:
4233 console.log('unrecognized kind of flow:', flow.kind);
4334 // eslint-disable-next-line no-fallthrough
src/lib/routeNames.js−2
@@ -27,6 +27,4 @@ export const ROUTE_NAMES = {
2727 URBIT_ID: Symbol('URBIT_ID'),
2828 RESIDENTS: Symbol('RESIDENTS'),
2929 ADOPT: Symbol('ADOPT'),
30− //
31− JUST_INVITE: Symbol('JUST_INVITE'),
3230};
src/lib/router.js−4
@@ -19,8 +19,6 @@ import UrbitID from 'views/UrbitID';
1919import Residents from 'views/Residents';
2020import Adopt from 'views/Adopt';
2121
22−import JustInvite from 'views/flows/JustInvite';
23−
2422import { ROUTE_NAMES } from './routeNames';
2523
2624export const ROUTES = {
@@ -44,6 +42,4 @@ export const ROUTES = {
4442 [ROUTE_NAMES.URBIT_ID]: UrbitID,
4543 [ROUTE_NAMES.RESIDENTS]: Residents,
4644 [ROUTE_NAMES.ADOPT]: Adopt,
47− //
48− [ROUTE_NAMES.JUST_INVITE]: JustInvite,
4945};
src/views/Login.js+2−15
@@ -1,7 +1,5 @@
11import React, { useCallback, useState } from 'react';
22import { P, H4, H5, Grid, Text, Button, Flex, LinkButton } from 'indigo-react';
3−import { Just } from 'folktale/maybe';
4−import ob from 'urbit-ob';
53
64import { version } from '../../package.json';
75
@@ -63,27 +61,16 @@ export default function Login() {
6361 push(names.POINTS);
6462 } else {
6563 switch (flow.kind) {
66− case COMMANDS.INVITE:
67− setPointCursor(Just(ob.patp2dec(flow.as)));
68− push(names.JUST_INVITE);
69− break;
70− //
7164 default:
7265 throw new Error('unimplemented flow ' + flow.kind);
73− break;
7466 }
7567 }
7668 }, [flow, push, names]);
7769
7870 const flowDescription = command => {
7971 switch (command.kind) {
80− case COMMANDS.INVITE:
81− return (
82− <>
83− To send an invite, please sign in as <b>{command.as}</b>.
84− </>
85− );
86− break;
72+ default:
73+ return <>Flow: {command.kind}</>;
8774 }
8875 };
8976
src/views/flows/JustInvite.jsdeleted−256
@@ -1,256 +0,0 @@
1−//NOTE repurposed from /views/Activate/PassportTransfer,
2−// with a lot of logic from /lib/useInviter
3−
4−//TODO display "you may now _close this window_" cta after calling a flow cb
5−//TODO make sure we also call failure cb if we get closed prematurely
6−
7−import React, { useState, useCallback } from 'react';
8−import { Grid, Text, ErrorText, H4 } from 'indigo-react';
9−import cn from 'classnames';
10−import ob from 'urbit-ob';
11−import { toBN } from 'web3-utils';
12−
13−import { useNetwork } from 'store/network';
14−import { useWallet } from 'store/wallet';
15−
16−import * as wg from 'lib/walletgen';
17−import * as tank from 'lib/tank';
18−import { GAS_LIMITS } from 'lib/constants';
19−import {
20− signTransaction,
21− sendSignedTransaction,
22− waitForTransactionConfirm,
23− hexify,
24−} from 'lib/txn';
25−import useGasPrice from 'lib/useGasPrice';
26−import useLifecycle from 'lib/useLifecycle';
27−import useBlockWindowClose from 'lib/useBlockWindowClose';
28−import { useFlowCommand } from 'lib/flowCommand';
29−import { hasReceived, sendMail } from 'lib/inviteMail';
30−import { safeToWei } from 'lib/lib';
31−
32−import LoadingBar from 'components/LoadingBar';
33−import { RestartButton } from 'components/Buttons';
34−import NeedFundsNotice from 'components/NeedFundsNotice';
35−
36−import * as az from 'azimuth-js';
37−
38−const labelForProgress = progress => {
39− if (progress <= 0) {
40− return 'Checking sanity...';
41− } else if (progress <= 0.2) {
42− return 'Generating invite...';
43− } else if (progress <= 0.3) {
44− return 'Building transaction...';
45− } else if (progress <= 0.4) {
46− return 'Signing transaction...';
47− } else if (progress <= 0.5) {
48− return 'Funding transaction...';
49− } else if (progress <= 0.7) {
50− return 'Sending transaction...';
51− } else if (progress <= 0.9) {
52− return 'Sending invite email...';
53− } else {
54− return 'Done';
55− }
56−};
57−
58−export default function JustInvite({ className, resetActivateRouter }) {
59− const { wallet, walletType, walletHdPath, authToken } = useWallet();
60− const flow = useFlowCommand();
61− const { web3, contracts, networkType } = useNetwork();
62− const { gasPrice } = useGasPrice();
63− const [generalError, setGeneralError] = useState();
64− const [progress, setProgress] = useState(0);
65− const [needFunds, setNeedFunds] = useState(null);
66−
67− useBlockWindowClose();
68−
69− // useEffect(() => {
70− // switch (type) {
71− // case 'progress':
72− // return setProcesss(state);
73− // case 'askFunding':
74− // return setNeedFunds(value);
75− // case 'gotFunding':
76− // return setNeedFunds(false);
77− // default:
78− // console.error(`Unknown update: ${type}`);
79− // }
80− // }, [progress]);
81−
82− const sendInvite = useCallback(async () => {
83− setGeneralError(false);
84−
85− try {
86− const _contracts = contracts.getOrElse(null);
87− const _web3 = web3.getOrElse(null);
88− const _wallet = wallet.getOrElse(null);
89− const _authToken = authToken.getOrElse(null);
90− if (!_contracts || !_web3 || !_wallet || !_authToken) {
91− // not using need because we want a custom error
92− throw new Error('Internal Error: Missing Contracts/Web3/Wallet');
93− }
94−
95− const _as = ob.patp2dec(flow.as);
96− const _ship = ob.patp2dec(flow.ship);
97− const _email = flow.email;
98−
99− console.log('xx checking email');
100− // check if email not invited before
101− if (await hasReceived(_email)) {
102− throw new Error(
103− `This email (${_email}) has already received an invite.`
104− );
105− }
106− setProgress(0.1);
107−
108− console.log('xx checking owner', _wallet.address, _as);
109− // check if logged in with flow.as's owner
110− //TODO we could move this check to the login screen
111− if (!(await az.azimuth.isOwner(_contracts, _as, _wallet.address))) {
112− throw new Error(`You are not logged in as ${flow.as}'s owner.'`);
113− }
114− setProgress(0.2);
115−
116− // generate invite code + address
117− const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
118− _ship,
119− _authToken
120− );
121− setProgress(0.3);
122−
123− // generate invite tx
124− const inviteTx = az.delegatedSending.sendPoint(
125− _contracts,
126− _as,
127− _ship,
128− owner.keys.address
129− );
130− setProgress(0.4);
131−
132− // sign invite tx
133− const signedTx = await signTransaction({
134− wallet: _wallet,
135− walletType,
136− walletHdPath,
137− networkType,
138− chainId: await _web3.eth.net.getId(),
139− nonce: await _web3.eth.getTransactionCount(_wallet.address),
140− txn: inviteTx,
141− gasPrice: gasPrice.toFixed(), // expects string gwei
142− gasLimit: GAS_LIMITS.GIFT_PLANET.toFixed(),
143− });
144− const rawTx = hexify(signedTx.serialize());
145− setProgress(0.5);
146−
147− // ensure funds
148− const totalCost = toBN(GAS_LIMITS.GIFT_PLANET).mul(toBN(gasPrice));
149− const tankWasUsed = await tank.ensureFundsFor(
150− _web3,
151− _as,
152− _wallet.address,
153− walletType,
154− safeToWei(totalCost, 'gwei'),
155− [rawTx],
156− (address, minBalance, balance) =>
157− setNeedFunds({ address, minBalance, balance }),
158− () => setNeedFunds(undefined)
159− );
160− setProgress(0.7);
161−
162− // send and await transaction
163− const txHash = await sendSignedTransaction(_web3, signedTx, tankWasUsed);
164− await waitForTransactionConfirm(_web3, txHash);
165− setProgress(0.9);
166−
167− // send invite email
168− //NOTE we could chuck a "pls join group-name" message in here
169− await sendMail(_email, ticket, flow.as, '', rawTx);
170− setProgress(1);
171− } catch (error) {
172− // some generic error
173− setGeneralError(error);
174− }
175− }, [
176− wallet,
177− web3,
178− contracts,
179− networkType,
180− authToken,
181− flow,
182− gasPrice,
183− walletHdPath,
184− walletType,
185− ]);
186−
187− useLifecycle(() => {
188− sendInvite();
189− });
190−
191− const goToRestart = useCallback(() => {
192− sendInvite();
193− }, [sendInvite]);
194−
195− const renderAdditionalInfo = () => {
196− if (generalError) {
197− console.log(generalError);
198− let msg =
199− typeof generalError === 'string'
200− ? generalError
201− : generalError.message || 'Something went wrong!';
202− return (
203− <>
204− <Grid.Item full className="mt8">
205− <ErrorText>{msg}</ErrorText>
206− </Grid.Item>
207− <Grid.Item
208− full
209− className="mt3"
210− as={RestartButton}
211− solid
212− onClick={goToRestart}>
213− Restart
214− </Grid.Item>
215− </>
216− );
217− }
218−
219− if (needFunds) {
220− return (
221− <Grid.Item full as={NeedFundsNotice} className="mt8" {...needFunds} />
222− );
223− }
224−
225− // if (progress < 1.0) {
226− // return (
227− // <Grid.Item full as={WarningBox} className="mt8">
228− // Never give your Master Ticket to anyone
229− // </Grid.Item>
230− // );
231− // }
232−
233− return null;
234− };
235−
236− return (
237− <Grid className={cn(className, 'auto-rows-min')}>
238− <Grid.Item full as={H4}>
239− {labelForProgress(progress)}
240− </Grid.Item>
241− <Grid>
242− <Grid.Item full as={Grid} className="mt3" gap={3}>
243− <Grid.Item full as={LoadingBar} progress={progress} />
244− <Grid.Item full>
245− <Text className="f5 green4">
246− This process can take up to 5 minutes to complete. Don't close
247− this page until the process is complete.
248− </Text>
249− </Grid.Item>
250− </Grid.Item>
251−
252− {renderAdditionalInfo()}
253− </Grid>
254− </Grid>
255− );
256−}