on 6542dce help sign in
bridge/src/lib/need.js
32 lines 820 B history raw
1// need.js: +need but worse
2//
4import { BRIDGE_ERROR } from './error';
6const needBuilder = error => obj => {
7 if (!obj) {
8 throw error;
9 }
11 return obj.matchWith({
12 Nothing: () => {
13 throw error;
14 },
15 Just: p => p.value,
16 });
17};
19export const web3 = needBuilder(BRIDGE_ERROR.MISSING_WEB3);
20export const contracts = needBuilder(BRIDGE_ERROR.MISSING_CONTRACTS);
21export const wallet = needBuilder(BRIDGE_ERROR.MISSING_WALLET);
22export const addressFromWallet = obj => wallet(obj).address;
23export const pointCursor = needBuilder(BRIDGE_ERROR.MISSING_POINT);
24export const pointCache = needBuilder(BRIDGE_ERROR.MISSING_POINT);
25export const fromPointCache = (obj, point) => {
26 const cache = pointCache(obj);
27 if (!(point in cache)) {
28 throw BRIDGE_ERROR.MISSING_POINT;
29 }
31 return cache[point];
32};