on master help sign in
In /lib/need, check for value existence before unpacking
2741f6bFang
src/bridge/lib/need.js+29−19
@@ -5,24 +5,30 @@
5import { BRIDGE_ERROR } from '../lib/error'
5import { BRIDGE_ERROR } from '../lib/error'
6
6
7function needWeb3(obj) {
7function needWeb3(obj) {
8+ return ('web3' in obj === false)
9+ ? (() => { throw BRIDGE_ERROR.MISSING_WEB3 })()
8− return obj.web3.matchWith({
10+ : obj.web3.matchWith({
9− Nothing: () => { throw BRIDGE_ERROR.MISSING_WEB3 },
11+ Nothing: () => { throw BRIDGE_ERROR.MISSING_WEB3 },
10− Just: w => w.value
12+ Just: w => w.value
11− });
13+ });
12}
14}
13
15
14function needContracts(obj) {
16function needContracts(obj) {
17+ return ('contracts' in obj === false)
18+ ? (() => { throw BRIDGE_ERROR.MISSING_CONTRACTS })()
15− return obj.contracts.matchWith({
19+ : obj.contracts.matchWith({
16− Nothing: () => { throw BRIDGE_ERROR.MISSING_CONTRACTS },
20+ Nothing: () => { throw BRIDGE_ERROR.MISSING_CONTRACTS },
17− Just: c => c.value
21+ Just: c => c.value
18− });
22+ });
19}
23}
20
24
21function needWallet(obj) {
25function needWallet(obj) {
26+ return ('wallet' in obj === false)
27+ ? (() => { throw BRIDGE_ERROR.MISSING_WALLET })()
22− return obj.wallet.matchWith({
28+ : obj.wallet.matchWith({
23− Nothing: () => { throw BRIDGE_ERROR.MISSING_WALLET },
29+ Nothing: () => { throw BRIDGE_ERROR.MISSING_WALLET },
24− Just: w => w.value
30+ Just: w => w.value
25− });
31+ });
26}
32}
27
33
28function needAddress(obj) {
34function needAddress(obj) {
@@ -30,16 +36,20 @@ function needAddress(obj) {
30}
36}
31
37
32function needPointCursor(obj) {
38function needPointCursor(obj) {
39+ return ('pointCursor' in obj === false)
40+ ? (() => { throw BRIDGE_ERROR.MISSING_POINT })()
33− return obj.pointCursor.matchWith({
41+ : obj.pointCursor.matchWith({
34− Nothing: () => { throw BRIDGE_ERROR.MISSING_POINT },
42+ Nothing: () => { throw BRIDGE_ERROR.MISSING_POINT },
35− Just: p => p.value
43+ Just: p => p.value
36− });
44+ });
37}
45}
38
46
39function needFromPointCache(obj, point) {
47function needFromPointCache(obj, point) {
48+ return ('pointCache' in obj === false)
49+ ? (() => { throw BRIDGE_ERROR.MISSING_POINT })()
40− return point in obj.pointCache
50+ : point in obj.pointCache
41− ? obj.pointCache[point]
51+ ? obj.pointCache[point]
42− : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
52+ : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
43}
53}
44
54
45export {
55export {