on fd7a195 help sign in
bridge/src/lib/need.js
75 lines 1.7 kB history raw
1// need.js: +need but worse
2//
3// generally, pass the props object into these functions
5import { BRIDGE_ERROR } from './error';
7function web3(obj) {
8 return 'web3' in obj === false
9 ? (() => {
10 throw BRIDGE_ERROR.MISSING_WEB3;
11 })()
12 : obj.web3.matchWith({
13 Nothing: () => {
14 throw BRIDGE_ERROR.MISSING_WEB3;
15 },
16 Just: w => w.value,
17 });
20function contracts(obj) {
21 return 'contracts' in obj === false
22 ? (() => {
23 throw BRIDGE_ERROR.MISSING_CONTRACTS;
24 })()
25 : obj.contracts.matchWith({
26 Nothing: () => {
27 throw BRIDGE_ERROR.MISSING_CONTRACTS;
28 },
29 Just: c => c.value,
30 });
33function wallet(obj) {
34 return 'wallet' in obj === false
35 ? (() => {
36 throw BRIDGE_ERROR.MISSING_WALLET;
37 })()
38 : obj.wallet.matchWith({
39 Nothing: () => {
40 throw BRIDGE_ERROR.MISSING_WALLET;
41 },
42 Just: w => w.value,
43 });
46function address(obj) {
47 return wallet(obj).address;
50function pointCursor(obj) {
51 return 'pointCursor' in obj === false
52 ? (() => {
53 throw BRIDGE_ERROR.MISSING_POINT;
54 })()
55 : obj.pointCursor.matchWith({
56 Nothing: () => {
57 throw BRIDGE_ERROR.MISSING_POINT;
58 },
59 Just: p => p.value,
60 });
63function fromPointCache(obj, point) {
64 return 'pointCache' in obj === false
65 ? (() => {
66 throw BRIDGE_ERROR.MISSING_POINT;
67 })()
68 : point in obj.pointCache
69 ? obj.pointCache[point]
70 : (() => {
71 throw BRIDGE_ERROR.MISSING_POINT;
72 })();
75export { web3, contracts, wallet, address, pointCursor, fromPointCache };