on master help sign in
Merge pull request #522 from urbit/m/flow-selection

Bridge "flows"

commitf3b6250273ea6db052bf10c6408fe622f671b98f authorfang <git@fang.io> dateThu 4 Mar 2021, 17:39 (6 years ago) parent9916088cc2983c
3 files changed+82−8
src/lib/flowCommand.js+46 src/lib/useInviter.js+1 src/views/Login.js+35−8
src/lib/flowCommand.jsnew file+46
@@ -0,0 +1,46 @@
1+import ob from 'urbit-ob';
2+
3+import { ensurePatFormat } from 'form/formatters';
4+
5+// looks into the GET parameters and attempts to construct a "flow" object,
6+// which would indicate bridge is to be used for one specific flow.
7+// expects to find any of the following sets of parameters, varying by kind.
8+//
9+// ? kind = invite
10+// & as = ~ship // who to send the invite as
11+// & ship = ~ship // what planet to send as the invite
12+// & email = ex@amp.le // email to send the invite code to
13+//
14+
15+const COMMANDS = {
16+ //
17+};
18+
19+const useFlowCommand = () => {
20+ let flow = {};
21+ window.location.search
22+ .substr(1)
23+ .split('&')
24+ .forEach(arg => {
25+ if ('' === arg) return;
26+ const pam = arg.split('=');
27+ flow[pam[0]] = pam.length <= 1 ? true : decodeURIComponent(pam[1]);
28+ });
29+
30+ if (typeof flow === 'object') {
31+ switch (flow.kind) {
32+ default:
33+ console.log('unrecognized kind of flow:', flow.kind);
34+ // eslint-disable-next-line no-fallthrough
35+ case undefined:
36+ flow = null;
37+ break;
38+ }
39+ } else {
40+ flow = null;
41+ }
42+
43+ return flow;
44+};
45+
46+export { COMMANDS, useFlowCommand };
src/lib/useInviter.js+1
@@ -61,6 +61,7 @@ const useInviter = () => {
6161 setTxStatus(STATUS.INPUT);
6262 }, [setProgress, setInvites, setTxStatus]);
6363
64+ //TODO split this out into smaller callbacks within useInviter
6465 const generateInvites = useCallback(
6566 async numInvites => {
6667 const _contracts = contracts.getOrElse(null);
src/views/Login.js+35−8
@@ -5,8 +5,10 @@ import { version } from '../../package.json';
55
66import { useHistory } from 'store/history';
77import { useWallet } from 'store/wallet';
8+import { usePointCursor } from 'store/pointCursor';
89
910import { WALLET_TYPES } from 'lib/wallet';
11+import { COMMANDS, useFlowCommand } from 'lib/flowCommand';
1012
1113import View from 'components/View';
1214import Tabs from 'components/Tabs';
@@ -43,6 +45,8 @@ export default function Login() {
4345 // globals
4446 const { pop, push, names } = useHistory();
4547 const { walletType } = useWallet();
48+ const { setPointCursor } = usePointCursor();
49+ const flow = useFlowCommand();
4650
4751 // inputs
4852 const [isOther, setisOther] = useState(false);
@@ -53,8 +57,22 @@ export default function Login() {
5357 ]);
5458
5559 const goHome = useCallback(() => {
56− push(names.POINTS);
57− }, [push, names]);
60+ if (!flow) {
61+ push(names.POINTS);
62+ } else {
63+ switch (flow.kind) {
64+ default:
65+ throw new Error('unimplemented flow ' + flow.kind);
66+ }
67+ }
68+ }, [flow, push, names]);
69+
70+ const flowDescription = command => {
71+ switch (command.kind) {
72+ default:
73+ return <>Flow: {command.kind}</>;
74+ }
75+ };
5876
5977 return (
6078 <View inset>
@@ -65,8 +83,12 @@ export default function Login() {
6583 </Grid.Item>
6684 <Grid.Item as={Text}>Login</Grid.Item>
6785 </Grid.Item>
68− {isOther && <Grid.Item full as={Other} goHome={goHome} />}
69− {!isOther && <Grid.Item full as={Ticket} goHome={goHome} />}
86+ {flow && (
87+ <Grid.Item full as={Text} className="t-center mb4">
88+ {flowDescription(flow)}
89+ </Grid.Item>
90+ )}
91+ <Grid.Item full as={isOther ? Other : Ticket} goHome={goHome} />
7092 {!isOther && (
7193 <>
7294 <Grid.Item full className="t-center mv4 gray4">
@@ -80,10 +102,15 @@ export default function Login() {
80102 onClick={() => setisOther(true)}>
81103 Metamask, Mnemonic, Hardware Wallet...
82104 </Grid.Item>
83− <Grid.Item full onClick={goToActivate} className="mv10 t-center f6">
84− <span className="gray4">New Urbit ID? </span>
85− <LinkButton>Activate</LinkButton>
86− </Grid.Item>
105+ {!flow && (
106+ <Grid.Item
107+ full
108+ onClick={goToActivate}
109+ className="mv10 t-center f6">
110+ <span className="gray4">New Urbit ID? </span>
111+ <LinkButton>Activate</LinkButton>
112+ </Grid.Item>
113+ )}
87114 </>
88115 )}
89116 {isOther && (