on 79c674b help sign in
bridge/src/lib/flowCommand.js
48 lines 1.1 kB history raw
1// looks into the GET parameters and attempts to construct a "flow" object,
2// which would indicate bridge is to be used for one specific flow.
3// expects to find any of the following sets of parameters, varying by kind.
4//
5// ? kind = btc
6// & utx = somebase64string
7//
9const COMMANDS = {
10 BITCOIN: 'btc',
11};
13const useFlowCommand = () => {
14 let flow = {};
15 window.location.search
16 .substr(1)
17 .split('&')
18 .forEach(arg => {
19 if ('' === arg) return;
20 const pam = arg.split('=');
21 flow[pam[0]] = pam.length <= 1 ? true : decodeURIComponent(pam[1]);
22 });
24 if (typeof flow === 'object') {
25 switch (flow.kind) {
26 case COMMANDS.BITCOIN:
27 try {
28 atob(flow.utx);
29 } catch (e) {
30 flow = null;
31 }
32 break;
33 //
34 default:
35 console.log('unrecognized kind of flow:', flow.kind);
36 // eslint-disable-next-line no-fallthrough
37 case undefined:
38 flow = null;
39 break;
40 }
41 } else {
42 flow = null;
43 }
45 return flow;
46};
48export { COMMANDS, useFlowCommand };