on master help sign in
flows: look at GET params instead of window object
5ca3bf8fang
src/lib/flowCommand.js+18−12
@@ -2,28 +2,32 @@ import ob from 'urbit-ob';
2
2
3import { ensurePatFormat } from 'form/formatters';
3import { ensurePatFormat } from 'form/formatters';
4
4
5−// looks into the window context to find a "flow command", an object indicating
5+// looks into the GET parameters and attempts to construct a "flow" object,
6−// if bridge is to be used for one specific flow.
6+// which would indicate bridge is to be used for one specific flow.
7−// expects to find objects of the following shape, varying by kind:
7+// expects to find any of the following sets of parameters, varying by kind.
8//
8//
9−// { kind: 'invite',
9+// ? kind = invite
10−// as: '~ship', // who to send the invite as
10+// & as = ~ship // who to send the invite as
11−// ship: '~ship', // what planet to send as the invite
11+// & ship = ~ship // what planet to send as the invite
12−// email: 'ex@amp.le' // email to send the invite code to
12+// & email = ex@amp.le // email to send the invite code to
13−// }
14//
13//
15−// you may optionally include .success() and .failure(reason) callbacks.
16
14
17const COMMANDS = {
15const COMMANDS = {
18 INVITE: 'invite',
16 INVITE: 'invite',
19};
17};
20
18
21const useFlowCommand = () => {
19const useFlowCommand = () => {
22− let flow = window.flow;
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+ });
23
29
24 if (typeof flow === 'object') {
30 if (typeof flow === 'object') {
25− flow.success = flow.success || (() => {});
26− flow.failure = flow.failure || (() => {});
27 switch (flow.kind) {
31 switch (flow.kind) {
28 case COMMANDS.INVITE:
32 case COMMANDS.INVITE:
29 flow.as = ensurePatFormat(flow.as);
33 flow.as = ensurePatFormat(flow.as);
@@ -36,6 +40,8 @@ const useFlowCommand = () => {
36 //
40 //
37 default:
41 default:
38 console.log('unrecognized kind of flow:', flow.kind);
42 console.log('unrecognized kind of flow:', flow.kind);
43+ // eslint-disable-next-line no-fallthrough
44+ case undefined:
39 flow = null;
45 flow = null;
40 break;
46 break;
41 }
47 }
src/views/flows/JustInvite.js−3
@@ -168,12 +168,9 @@ export default function JustInvite({ className, resetActivateRouter }) {
168 //NOTE we could chuck a "pls join group-name" message in here
168 //NOTE we could chuck a "pls join group-name" message in here
169 await sendMail(_email, ticket, flow.as, '', rawTx);
169 await sendMail(_email, ticket, flow.as, '', rawTx);
170 setProgress(1);
170 setProgress(1);
171−
172− flow.success();
173 } catch (error) {
171 } catch (error) {
174 // some generic error
172 // some generic error
175 setGeneralError(error);
173 setGeneralError(error);
176− flow.failure(error);
177 }
174 }
178 }, [
175 }, [
179 wallet,
176 wallet,