on master help sign in
Add functions for doing common Maybe wrangling as /lib/need

This way, local code doesn't have to involve itself in error throwing etc.

commite25635651918439b6a069c9b7f3d91694c1818d3 authorFang <git@fang.io> dateFri 7 Jun 2019, 13:56 (7 years ago) parentb42c62f
20 files changed+126−295
src/bridge/components/StatelessTransaction.js+3−14 src/bridge/lib/invite.js+2−6 src/bridge/lib/keys.js+5−19 src/bridge/lib/need.js+52 src/bridge/lib/router.js+4−9 src/bridge/views/AcceptTransfer.js+7−27 src/bridge/views/CancelTransfer.js+5−20 src/bridge/views/CreateGalaxy.js+4−20 src/bridge/views/GenKeyfile.js+4−15 src/bridge/views/InviteTicket.js+3−7 src/bridge/views/InvitesManage.js+3−13 src/bridge/views/InvitesSend.js+5−27 src/bridge/views/IssueChild.js+4−22 src/bridge/views/Point.js+3−9 src/bridge/views/Point/Actions.js+3−9 src/bridge/views/Points.js−1 src/bridge/views/SentTransaction.js+3−5 src/bridge/views/SetKeys.js+7−33 src/bridge/views/SetProxy.js+5−20 src/bridge/views/Transfer.js+4−19
src/bridge/components/StatelessTransaction.js+3−14
@@ -1,6 +1,7 @@
11import { Nothing, Just } from 'folktale/maybe'
22import { Ok } from 'folktale/result'
33import React from 'react'
4+import * as n from '../lib/need'
45
56import { Code, H3 } from './Base'
67import { Button } from './Base'
@@ -8,7 +9,6 @@ import { CheckboxButton, Input, InnerLabel,
89 InnerLabelDropdown } from './Base'
910import { Warning } from '../components/Base'
1011
11−import { addressFromSecp256k1Public } from '../lib/wallet'
1212import { BRIDGE_ERROR } from '../lib/error'
1313import { ROUTE_NAMES } from '../lib/router'
1414import * as tank from '../lib/tank'
@@ -65,12 +65,7 @@ class StatelessTransaction extends React.Component {
6565 componentDidMount() {
6666 const { props } = this
6767
68− const addr = props.wallet.matchWith({
69− Just: wal => wal.value.address,
70− Nothing: () => {
71− throw BRIDGE_ERROR.MISSING_WALLET
72− }
73− })
68+ const addr = n.needAddress(props);
7469
7570 props.web3.matchWith({
7671 Nothing: () => {},
@@ -210,13 +205,7 @@ class StatelessTransaction extends React.Component {
210205 const rawTx = hexify(stx.serialize());
211206 const cost = (state.gasLimit * toWei(state.gasPrice, 'gwei'));
212207
213− //TODO need a lib function or something for address=, it's everywhere
214− const address = props.wallet.matchWith({
215− Just: wal => wal.value.address,
216− Nothing: () => {
217− throw BRIDGE_ERROR.MISSING_WALLET
218− }
219− });
208+ const address = n.needAddress(props);
220209 let balance = await web3.eth.getBalance(address);
221210 let hasBalance = (balance >= cost);
222211
src/bridge/lib/invite.js+2−6
@@ -13,13 +13,9 @@ import {
1313 waitForTransactionConfirm,
1414 isTransactionConfirmed
1515} from './txn'
16−import { BRIDGE_ERROR } from './error'
16+import { BRIDGE_ERROR } from '../lib/error'
1717import { attemptSeedDerivation } from './keys'
18−import {
19− addressFromSecp256k1Public,
20− addHexPrefix,
21− WALLET_NAMES
22−} from './wallet'
18+import { addHexPrefix, WALLET_NAMES } from './wallet'
2319
2420const INVITE_STAGES = {
2521 INVITE_LOGIN: "invite login",
src/bridge/lib/keys.js+5−19
@@ -1,5 +1,6 @@
11import BN from 'bn.js'
22import Maybe from 'folktale/maybe'
3+import * as n from '../lib/need'
34
45import * as noun from '../nockjs/noun'
56import * as serial from '../nockjs/serial'
@@ -7,7 +8,6 @@ import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
78
89import { BRIDGE_ERROR } from './error'
910import {
10− addressFromSecp256k1Public,
1111 WALLET_NAMES,
1212 eqAddr
1313 } from './wallet'
@@ -63,24 +63,15 @@ const genKey = (networkSeed, point, revision) => {
6363// 'next' refers to setting the next set of keys
6464// if false, we use revision - 1
6565const attemptSeedDerivation = async (next, args) => {
66− const { walletType, wallet, pointCursor, pointCache } = args
66+ const { walletType } = args
6767 const { urbitWallet, authMnemonic } = args
6868
6969 // NB (jtobin):
7070 //
7171 // following code is intentionally verbose for sake of clarity
7272
73− const point = pointCursor.matchWith({
74− Just: pt => pt.value,
75− Nothing: _ => {
76− throw BRIDGE_ERROR.MISSING_POINT
77− }
78− })
79−
80− const pointDetails =
81− point in pointCache
82− ? pointCache[point]
83− : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
73+ const point = n.needPointCursor(args);
74+ const pointDetails = n.needFromPointCache(args, point);
8475
8576 const revision =
8677 next === true
@@ -104,12 +95,7 @@ const attemptSeedDerivation = async (next, args) => {
10495
10596 } else if (walletType === WALLET_NAMES.MNEMONIC) {
10697
107− const walProxy = wallet.matchWith({
108− Just: wal => wal.value.address,
109− Nothing: _ => {
110− throw BRIDGE_ERROR.MISSING_WALLET
111− }
112− })
98+ const walProxy = n.needAddress(args);
11399
114100 const mnemonic = authMnemonic.matchWith({
115101 Just: mnem => mnem.value,
src/bridge/lib/need.jsnew file+52
@@ -0,0 +1,52 @@
1+// need.js: +need but worse
2+//
3+// generally, pass the props object into these functions
4+
5+import { BRIDGE_ERROR } from '../lib/error'
6+
7+function needWeb3(obj) {
8+ return obj.web3.matchWith({
9+ Nothing: () => { throw BRIDGE_ERROR.MISSING_WEB3 },
10+ Just: w => w.value
11+ });
12+}
13+
14+function needContracts(obj) {
15+ return obj.contracts.matchWith({
16+ Nothing: () => { throw BRIDGE_ERROR.MISSING_CONTRACTS },
17+ Just: c => c.value
18+ });
19+}
20+
21+function needWallet(obj) {
22+ return obj.wallet.matchWith({
23+ Nothing: () => { throw BRIDGE_ERROR.MISSING_WALLET },
24+ Just: w => w.value
25+ });
26+}
27+
28+function needAddress(obj) {
29+ return needWallet(obj).address;
30+}
31+
32+function needPointCursor(obj) {
33+ return obj.pointCursor.matchWith({
34+ Nothing: () => { throw BRIDGE_ERROR.MISSING_POINT },
35+ Just: p => p.value
36+ });
37+}
38+
39+function needFromPointCache(obj, point) {
40+ return point in obj.pointCache
41+ ? obj.pointCache[point]
42+ : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
43+}
44+
45+export {
46+ needWeb3,
47+ needContracts,
48+ needWallet,
49+ needAddress,
50+ needPointCursor,
51+ needFromPointCache
52+}
src/bridge/lib/router.js+4−9
@@ -1,4 +1,5 @@
11import * as ob from 'urbit-ob'
2+import * as n from '../lib/need'
23
34import React from 'react';
45
@@ -35,9 +36,8 @@ import Ticket from '../views/Ticket'
3536import Transfer from '../views/Transfer'
3637import Wallet from '../views/Wallet'
3738
38−import { addressFromSecp256k1Public, EthereumWallet } from './wallet'
39+import { EthereumWallet } from './wallet'
3940import { renderNetworkType } from './network'
40−import { BRIDGE_ERROR } from './error'
4141
4242const ROUTE_NAMES = {
4343 DEFAULT: Symbol('DEFAULT'),
@@ -111,7 +111,7 @@ const createRoutes = () => {
111111const ROUTES = createRoutes()
112112
113113const renderRoute = (props, route) => {
114− const { wallet, networkType, pointCursor } = props
114+ const { wallet, networkType } = props
115115 return (
116116 route === ROUTE_NAMES.LANDING
117117 ? 'Bridge'
@@ -168,12 +168,7 @@ const renderRoute = (props, route) => {
168168 ? 'View'
169169
170170 : route === ROUTE_NAMES.SHIP
171− ? pointCursor.matchWith({
172− Just: (cursor) => ob.patp(cursor.value),
173− Nothing: () => {
174− throw BRIDGE_ERROR.MISSING_POINT
175− }
176− })
171+ ? ob.patp(n.needPointCursor(props))
177172
178173 : route === ROUTE_NAMES.SET_TRANSFER_PROXY
179174 || route === ROUTE_NAMES.SET_MANAGEMENT_PROXY
src/bridge/views/AcceptTransfer.js+7−27
@@ -4,29 +4,19 @@ import { Row, Col, H1, P } from '../components/Base'
44import { InnerLabel, AddressInput, ShowBlockie, Anchor } from '../components/Base'
55import * as azimuth from 'azimuth-js'
66import * as ob from 'urbit-ob'
7+import * as n from '../lib/need'
78
89import StatelessTransaction from '../components/StatelessTransaction'
9−import { BRIDGE_ERROR } from '../lib/error'
1010import { NETWORK_NAMES } from '../lib/network'
11−import { isValidAddress, addressFromSecp256k1Public } from '../lib/wallet'
11+import { isValidAddress } from '../lib/wallet'
1212
1313class AcceptTransfer extends React.Component {
1414 constructor(props) {
1515 super(props)
1616
17− const receivingAddress = props.wallet.matchWith({
18− Just: (wal) => wal.value.address,
19− Nothing: () => {
20− throw BRIDGE_ERROR.MISSING_WALLET
21− }
22− })
17+ const receivingAddress = n.needAddress(props);
2318
24− const incomingPoint = props.pointCursor.matchWith({
25− Just: (shp) => shp.value,
26− Nothing: () => {
27− throw BRIDGE_ERROR.MISSING_POINT
28− }
29− })
19+ const incomingPoint = n.needPointCursor(props);
3020
3121 this.state = {
3222 receivingAddress: receivingAddress,
@@ -46,19 +36,9 @@ class AcceptTransfer extends React.Component {
4636 createUnsignedTxn() {
4737 const { state, props } = this
4838
49− const validContracts = props.contracts.matchWith({
50− Just: (cs) => cs.value,
51− Nothing: () => {
52− throw BRIDGE_ERROR.MISSING_CONTRACTS
53− }
54− })
55−
56− const validPoint = props.pointCursor.matchWith({
57− Just: (shp) => shp.value,
58− Nothing: () => {
59− throw BRIDGE_ERROR.MISSING_POINT
60− }
61− })
39+ const validContracts = n.needContracts(props);
40+
41+ const validPoint = n.needPointCursor(props); //TODO state.incomingPoint ?
6242
6343 return Just(azimuth.ecliptic.transferPoint(
6444 validContracts,
src/bridge/views/CancelTransfer.js+5−20
@@ -3,21 +3,16 @@ import React from 'react'
33import { Row, Col, H1, P } from '../components/Base'
44import * as azimuth from 'azimuth-js'
55import * as ob from 'urbit-ob'
6+import * as n from '../lib/need'
67
78import StatelessTransaction from '../components/StatelessTransaction'
8−import { BRIDGE_ERROR } from '../lib/error'
99import { ETH_ZERO_ADDR } from '../lib/wallet'
1010
1111class CancelTransfer extends React.Component {
1212 constructor(props) {
1313 super(props)
1414
15− const pointInTransfer = props.pointCursor.matchWith({
16− Just: (pt) => pt.value,
17− Nothing: () => {
18− throw BRIDGE_ERROR.MISSING_POINT
19− }
20− })
15+ const pointInTransfer = n.needPointCursor(props);
2116
2217 this.state = {
2318 proxyAddress: '',
@@ -30,19 +25,9 @@ class CancelTransfer extends React.Component {
3025 createUnsignedTxn() {
3126 const { props } = this
3227
33− const validContracts = props.contracts.matchWith({
34− Just: (cs) => cs.value,
35− Nothing: () => {
36− throw BRIDGE_ERROR.MISSING_CONTRACTS
37− }
38− })
39−
40− const validPoint = props.pointCursor.matchWith({
41− Just: (pt) => pt.value,
42− Nothing: () => {
43− throw BRIDGE_ERROR.MISSING_POINT
44− }
45− })
28+ const validContracts = n.needContracts(props);
29+
30+ const validPoint = n.needPointCursor(props); //TODO this.state.pointInTransfer ?
4631
4732 const txn = azimuth.ecliptic.setTransferProxy(
4833 validContracts,
src/bridge/views/CreateGalaxy.js+4−20
@@ -2,18 +2,17 @@ import React from 'react'
22import Maybe from 'folktale/maybe'
33import * as azimuth from 'azimuth-js'
44import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
56
67import { Button, } from '../components/Base'
78import { Row, Col, H1, P, Anchor } from '../components/Base'
89import { InnerLabel, GalaxyInput, AddressInput, ValidatedSigil, ShowBlockie } from '../components/Base'
910import StatelessTransaction from '../components/StatelessTransaction'
1011
11−import { BRIDGE_ERROR } from '../lib/error'
1212import { NETWORK_NAMES } from '../lib/network'
1313import { canDecodePatp } from '../lib/txn'
1414
1515import {
16− addressFromSecp256k1Public,
1716 ETH_ZERO_ADDR,
1817 isValidAddress,
1918 eqAddr
@@ -42,12 +41,7 @@ class CreateGalaxy extends React.Component {
4241 constructor(props) {
4342 super(props)
4443
45− const galaxyOwner = props.wallet.matchWith({
46− Just: (wal) => wal.value.address,
47− Nothing: () => {
48− throw BRIDGE_ERROR.MISSING_WALLET
49− }
50− })
44+ const galaxyOwner = n.needAddress(props);
5145
5246 this.state = {
5347 galaxyOwner: galaxyOwner,
@@ -79,12 +73,7 @@ class CreateGalaxy extends React.Component {
7973 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing()
8074 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing()
8175
82− const validContracts = props.contracts.matchWith({
83− Just: (cs) => cs.value,
84− Nothing: () => {
85− throw BRIDGE_ERROR.MISSING_CONTRACTS
86− }
87− })
76+ const validContracts = n.needContracts(props);
8877
8978 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10)
9079
@@ -105,12 +94,7 @@ class CreateGalaxy extends React.Component {
10594 return
10695 }
10796
108− const validContracts = props.contracts.matchWith({
109− Just: (cs) => cs.value,
110− Nothing: () => {
111− throw BRIDGE_ERROR.MISSING_CONTRACTS
112− }
113− })
97+ const validContracts = n.needContracts(props);
11498
11599 const galaxyDec = ob.patp2dec(state.galaxyName)
116100
src/bridge/views/GenKeyfile.js+4−15
@@ -1,5 +1,6 @@
11import React from 'react'
22import Maybe from 'folktale/maybe'
3+import * as n from '../lib/need'
34
45import { Button } from '../components/Base'
56import { Row, Col, H1, P } from '../components/Base'
@@ -9,7 +10,6 @@ import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
910import saveAs from 'file-saver'
1011
1112import { attemptSeedDerivation, genKey } from '../lib/keys'
12−import { BRIDGE_ERROR } from '../lib/error'
1313import {
1414 addHexPrefix
1515 } from '../lib/wallet'
@@ -25,20 +25,9 @@ class GenKeyfile extends React.Component {
2525 }
2626
2727 getPointDetails() {
28− const { pointCache } = this.props
29− const { pointCursor } = this.props
30−
31− const point = pointCursor.matchWith({
32− Just: (pt) => pt.value,
33− Nothing: () => {
34− throw BRIDGE_ERROR.MISSING_POINT
35− }
36− })
37−
38− const pointDetails =
39− point in pointCache
40− ? pointCache[point]
41− : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
28+ const point = n.needPointCursor(this.props);
29+
30+ const pointDetails = n.needFromPointCache(this.props, point);
4231
4332 // in case we did SetKeys earlier this session, make sure to generate the
4433 // newer keyfile, rather than the one that will expire soon
src/bridge/views/InviteTicket.js+3−7
@@ -3,11 +3,12 @@ import React from 'react'
33import { InnerLabel, Warning, TicketInput,
44 VerifyTicketInput, Button, Row, Col, Passport } from '../components/Base'
55import * as azimuth from 'azimuth-js'
6+import * as n from '../lib/need'
67
78import { randomPatq } from '../lib/lib'
89import { ROUTE_NAMES } from '../lib/router'
910import { DEFAULT_HD_PATH, ownershipWalletFromTicket,
10− walletFromMnemonic, addressFromSecp256k1Public } from '../lib/wallet'
11+ walletFromMnemonic } from '../lib/wallet'
1112import { BRIDGE_ERROR } from '../lib/error'
1213import { INVITE_STAGES, WALLET_STATES, TRANSACTION_STATES } from '../lib/invite'
1314import { generateWallet, startTransactions } from '../lib/invite'
@@ -86,12 +87,7 @@ class InviteTicket extends React.Component {
8687
8788 const addr = inviteWallet.address;
8889
89− const ctrcs = this.props.contracts.matchWith({
90− Just: ctrcs => ctrcs.value,
91− Nothing: () => {
92− throw BRIDGE_ERROR.MISSING_CONTRACTS
93− }
94− })
90+ const ctrcs = n.needContracts(this.props);
9591
9692 const incoming = await azimuth.azimuth.getTransferringFor(ctrcs, addr)
9793
src/bridge/views/InvitesManage.js+3−13
@@ -2,8 +2,8 @@ import { Just, Nothing } from 'folktale/maybe'
22import React from 'react'
33import * as ob from 'urbit-ob'
44import * as azimuth from 'azimuth-js'
5+import * as n from '../lib/need'
56
6−import { BRIDGE_ERROR } from '../lib/error'
77import { Row, Col, Warning, Input,
88 PointInput, InnerLabel, ValidatedSigil } from '../components/Base'
99import StatelessTransaction from '../components/StatelessTransaction'
@@ -32,18 +32,8 @@ class InvitesManage extends React.Component {
3232 }
3333
3434 componentDidMount() {
35− this.point = this.props.pointCursor.matchWith({
36− Just: (pt) => parseInt(pt.value, 10),
37− Nothing: () => {
38− throw BRIDGE_ERROR.MISSING_POINT
39− }
40− });
41− this.contracts = this.props.contracts.matchWith({
42− Just: cs => cs.value,
43− Nothing: _ => {
44− throw BRIDGE_ERROR.MISSING_CONTRACTS
45− }
46− });
35+ this.point = n.needPointCursor(this.props);
36+ this.contracts = n.needContracts(this.props);
4737
4838 azimuth.azimuth.isSpawnProxy(
4939 this.contracts,
src/bridge/views/InvitesSend.js+5−27
@@ -1,11 +1,10 @@
11import { Just, Nothing } from 'folktale/maybe'
22import React from 'react'
33import * as azimuth from 'azimuth-js'
4+import * as n from '../lib/need'
45
5−import { BRIDGE_ERROR } from '../lib/error'
66import { hasReceived, sendMail } from '../lib/inviteMail'
77import { Row, Col, Button, Input, H3, Warning } from '../components/Base'
8−import { addressFromSecp256k1Public } from '../lib/wallet'
98
109// for wallet generation
1110import * as wg from '../../walletgen/lib/lib'
@@ -70,31 +69,10 @@ class InvitesSend extends React.Component {
7069 }
7170
7271 componentDidMount() {
73− this.point = this.props.pointCursor.matchWith({
74− Just: (pt) => parseInt(pt.value, 10),
75− Nothing: () => {
76− throw BRIDGE_ERROR.MISSING_POINT;
77− }
78− });
79− //TODO why are we doing this locally, instead of made global on sign-in?
80− this.address = this.props.wallet.matchWith({
81− Just: (wal) => wal.value.address,
82− Nothing: () => {
83− throw BRIDGE_ERROR.MISSING_WALLET;
84− }
85− });
86− this.contracts = this.props.contracts.matchWith({
87− Just: cs => cs.value,
88− Nothing: () => {
89− throw BRIDGE_ERROR.MISSING_CONTRACTS;
90− }
91− });
92− this.web3 = this.props.web3.matchWith({
93− Just: w3 => w3.value,
94− Nothing: () => {
95− throw BRIDGE_ERROR.MISSING_WEB3;
96− }
97− });
72+ this.point = parseInt(n.needPointCursor(this.props), 10);
73+ this.address = n.needAddress(this.props);
74+ this.contracts = n.needContracts(this.props);
75+ this.web3 = n.needWeb3(this.props);
9876
9977 console.log(azimuth.delegatedSending);
10078 azimuth.delegatedSending.getTotalUsableInvites(this.contracts, this.point)
src/bridge/views/IssueChild.js+4−22
@@ -2,6 +2,7 @@ import { Just, Nothing } from 'folktale/maybe'
22import React from 'react'
33import { azimuth, ecliptic } from 'azimuth-js'
44import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
56
67import {
78 Row, Col, H1, P, Anchor,
@@ -12,7 +13,6 @@ import {
1213import StatelessTransaction from '../components/StatelessTransaction'
1314
1415import { NETWORK_NAMES } from '../lib/network'
15−import { BRIDGE_ERROR } from '../lib/error'
1616import { getSpawnCandidate } from '../lib/child'
1717import { canDecodePatp } from '../lib/txn'
1818
@@ -31,12 +31,7 @@ class IssueChild extends React.Component {
3131 constructor(props) {
3232 super(props)
3333
34− const issuingPoint = props.pointCursor.matchWith({
35− Just: (pt) => parseInt(pt.value, 10),
36− Nothing: () => {
37− throw BRIDGE_ERROR.MISSING_POINT
38− }
39− })
34+ const issuingPoint = parseInt(n.needPointCursor(props), 10);
4035
4136 const getCandidate = () => ob.patp(getSpawnCandidate(issuingPoint))
4237
@@ -69,17 +64,9 @@ class IssueChild extends React.Component {
6964 }
7065
7166 componentWillMount() {
72−
73− const { contracts } = this.props
7467 const { issuingPoint } = this.state
7568
76−
77− const validContracts = contracts.matchWith({
78− Just: cs => cs.value,
79− Nothing: _ => {
80− throw BRIDGE_ERROR.MISSING_CONTRACTS
81− }
82− })
69+ const validContracts = n.needContracts(this.props);
8370
8471 azimuth.getUnspawnedChildren(validContracts, issuingPoint).then(ps => this.setState({ validChildren: new Set(ps.map(ob.patp)) }))
8572 }
@@ -110,12 +97,7 @@ class IssueChild extends React.Component {
11097 if (state.isAvailable === false) return Nothing()
11198 if (canDecodePatp(state.desiredPoint) === false) return Nothing()
11299
113− const validContracts = props.contracts.matchWith({
114− Just: (cs) => cs.value,
115− Nothing: () => {
116− throw BRIDGE_ERROR.MISSING_CONTRACTS
117− }
118− })
100+ const validContracts = n.needContracts(props);
119101
120102 const pointDec = ob.patp2dec(state.desiredPoint)
121103
src/bridge/views/Point.js+3−9
@@ -3,12 +3,12 @@ import React from 'react'
33import { pour } from 'sigil-js'
44import * as ob from 'urbit-ob'
55import * as azimuth from 'azimuth-js'
6+import * as n from '../lib/need'
67
78import PointList from '../components/PointList'
89import ReactSVGComponents from '../components/ReactSVGComponents'
910import KeysAndMetadata from './Point/KeysAndMetadata'
1011import Actions from './Point/Actions'
11−import { BRIDGE_ERROR } from '../lib/error'
1212import { Row, Col, H1, H3 } from '../components/Base'
1313
1414
@@ -74,18 +74,12 @@ class Point extends React.Component {
7474
7575 const {
7676 web3, popRoute, pushRoute, wallet,
77− setPointCursor, pointCursor, pointCache
77+ setPointCursor, pointCache
7878 } = this.props;
7979
8080 const { spawned } = this.state
8181
82−
83− const point = pointCursor.matchWith({
84− Just: (cursor) => cursor.value,
85− Nothing: () => {
86− throw BRIDGE_ERROR.MISSING_POINT
87− }
88− })
82+ const point = n.needPointCursor(this.props);
8983
9084 const pointDetails =
9185 point in pointCache
src/bridge/views/Point/Actions.js+3−9
@@ -1,11 +1,10 @@
11import React from 'react'
2+import * as n from '../../lib/need'
23import {
34 ETH_ZERO_ADDR,
45 CURVE_ZERO_ADDR,
5− addressFromSecp256k1Public,
66 eqAddr
77} from '../../lib/wallet'
8−import { BRIDGE_ERROR } from '../../lib/error'
98import { Row, Col, H2, P } from '../../components/Base'
109import { Button } from '../../components/Base'
1110import { ROUTE_NAMES } from '../../lib/router'
@@ -18,16 +17,11 @@ const isStar = point =>
1817
1918const Actions = (props) => {
2019 const {
21− pushRoute, online, wallet,
20+ pushRoute, online,
2221 point, pointDetails, invites
2322 } = props
2423
25− const addr = wallet.matchWith({
26− Just: (wal) => wal.value.address,
27− Nothing: () => {
28− throw BRIDGE_ERROR.MISSING_WALLET
29− }
30− })
24+ const addr = n.needAddress(props);
3125
3226 const isOwner = pointDetails.matchWith({
3327 Nothing: _ => false,
src/bridge/views/Points.js−1
@@ -8,7 +8,6 @@ import { NETWORK_NAMES } from '../lib/network'
88import { ROUTE_NAMES } from '../lib/router'
99import {
1010 ETH_ZERO_ADDR,
11− addressFromSecp256k1Public,
1211 eqAddr
1312 } from '../lib/wallet'
1413
src/bridge/views/SentTransaction.js+3−5
@@ -1,5 +1,6 @@
11import Maybe from 'folktale/maybe'
22import React from 'react'
3+import * as n from '../lib/need'
34import { Row, Col, H1, H3, P, Warning, Anchor } from '../components/Base'
45import { Button } from '../components/Base'
56
@@ -122,15 +123,12 @@ const Failure = (props) =>
122123 </Row>
123124
124125const SentTransaction = (props) => {
125− const { web3, txnHashCursor, networkType, popRoute, pushRoute, txnConfirmations} = props
126+ const { txnHashCursor, networkType, popRoute, pushRoute, txnConfirmations} = props
126127 const { setPointCursor, pointCursor } = props
127128
128129 const promptKeyfile = props.routeData && props.routeData.promptKeyfile
129130
130− const w3 = web3.matchWith({
131− Nothing: _ => { throw BRIDGE_ERROR.MISSING_WEB3 },
132− Just: res => res.value
133− })
131+ const w3 = n.needWeb3(props);
134132
135133 const result = txnHashCursor.matchWith({
136134 Nothing: _ => { throw BRIDGE_ERROR.MISSING_TXN },
src/bridge/views/SetKeys.js+7−33
@@ -2,29 +2,21 @@ import React from 'react'
22import Maybe from 'folktale/maybe'
33import * as azimuth from 'azimuth-js'
44import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
56import { Row, Col, H1, P, Warning, CheckboxButton } from '../components/Base'
67
78import StatelessTransaction from '../components/StatelessTransaction'
8−import { BRIDGE_ERROR } from '../lib/error'
99import { attemptSeedDerivation } from '../lib/keys'
1010
1111import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
1212
13−import {
14− addressFromSecp256k1Public,
15− addHexPrefix
16−} from '../lib/wallet'
13+import { addHexPrefix } from '../lib/wallet'
1714
1815class SetKeys extends React.Component {
1916 constructor(props) {
2017 super(props)
2118
22− const point = props.pointCursor.matchWith({
23− Just: (shp) => shp.value,
24− Nothing: () => {
25− throw BRIDGE_ERROR.MISSING_POINT
26− }
27− })
19+ const point = n.needPointCursor(props);
2820
2921 this.state = {
3022 auth: '',
@@ -51,12 +43,7 @@ class SetKeys extends React.Component {
5143
5244 this.deriveSeed()
5345
54− const addr = props.wallet.matchWith({
55− Just: wal => wal.value.address,
56− Nothing: () => {
57− throw BRIDGE_ERROR.MISSING_WALLET
58− }
59− })
46+ const addr = n.needAddress(props);
6047
6148 this.determineManagementSeed(props.contracts.value, addr)
6249 }
@@ -101,19 +88,9 @@ class SetKeys extends React.Component {
10188 createUnsignedTxn() {
10289 const { state, props } = this
10390
104− const validContracts = props.contracts.matchWith({
105− Just: (cs) => cs.value,
106− Nothing: () => {
107− throw BRIDGE_ERROR.MISSING_CONTRACTS
108− }
109− })
91+ const validContracts = n.needContracts(props);
11092
111− const validPoint = props.pointCursor.matchWith({
112− Just: (shp) => shp.value,
113− Nothing: () => {
114− throw BRIDGE_ERROR.MISSING_POINT
115− }
116− })
93+ const validPoint = n.needPointCursor(props);
11794
11895 const hexRegExp = /[0-9A-Fa-f]{64}/g
11996
@@ -146,10 +123,7 @@ class SetKeys extends React.Component {
146123 state.networkSeed.length === 64
147124 && state.networkSeed.length === 64
148125
149− const pointDetails =
150− state.point in props.pointCache
151− ? props.pointCache[state.point]
152− : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
126+ const pointDetails = n.needFromPointCache(props, state.point);
153127
154128 return (
155129 <Row>
src/bridge/views/SetProxy.js+5−20
@@ -1,12 +1,12 @@
11import Maybe from 'folktale/maybe'
22import React from 'react'
3+import * as n from '../lib/need'
34import * as azimuth from 'azimuth-js'
45import { Row, Col, H1, P, InnerLabel, ShowBlockie, Anchor, HorizontalSelector } from '../components/Base'
56import { AddressInput } from '../components/Base'
67import * as ob from 'urbit-ob'
78
89import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
9−import { BRIDGE_ERROR } from '../lib/error'
1010
1111import { NETWORK_NAMES } from '../lib/network'
1212
@@ -36,12 +36,7 @@ class SetProxy extends React.Component {
3636 constructor(props) {
3737 super(props)
3838
39− const issuingPoint = props.pointCursor.matchWith({
40− Just: (shp) => shp.value,
41− Nothing: () => {
42− throw BRIDGE_ERROR.MISSING_POINT
43− }
44− })
39+ const issuingPoint = n.needPointCursor(props);
4540
4641 this.state = {
4742 proxyAddress: '',
@@ -72,19 +67,9 @@ class SetProxy extends React.Component {
7267 createUnsignedTxn(proxyAddress) {
7368 const { state, props } = this
7469
75− const validContracts = props.contracts.matchWith({
76− Just: (cs) => cs.value,
77− Nothing: () => {
78− throw BRIDGE_ERROR.MISSING_CONTRACTS
79− }
80− })
81−
82− const validPoint = props.pointCursor.matchWith({
83− Just: (shp) => shp.value,
84− Nothing: () => {
85− throw BRIDGE_ERROR.MISSING_POINT
86− }
87− })
70+ const validContracts = n.needContracts(props);
71+
72+ const validPoint = n.needPointCursor(props);
8873
8974 const txArgs = [
9075 validContracts,
src/bridge/views/Transfer.js+4−19
@@ -2,12 +2,12 @@ import Maybe from 'folktale/maybe'
22import React from 'react'
33import * as azimuth from 'azimuth-js'
44import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
56
67import { Row, Col, H1, InnerLabel, ShowBlockie, P, Anchor } from '../components/Base'
78import { AddressInput } from '../components/Base'
89import StatelessTransaction from '../components/StatelessTransaction'
910
10−import { BRIDGE_ERROR } from '../lib/error'
1111import { NETWORK_NAMES } from '../lib/network'
1212
1313import {
@@ -18,12 +18,7 @@ class Transfer extends React.Component {
1818 constructor(props) {
1919 super(props)
2020
21− const issuingPoint = props.pointCursor.matchWith({
22− Just: (pt) => pt.value,
23− Nothing: () => {
24− throw BRIDGE_ERROR.MISSING_POINT
25− }
26− })
21+ const issuingPoint = n.needPointCursor(props);
2722
2823 this.state = {
2924 receivingAddress: '',
@@ -49,19 +44,9 @@ class Transfer extends React.Component {
4944 createUnsignedTxn() {
5045 const { state, props } = this
5146
52− const validContracts = props.contracts.matchWith({
53− Just: (cs) => cs.value,
54− Nothing: () => {
55− throw BRIDGE_ERROR.MISSING_CONTRACTS
56− }
57− })
47+ const validContracts = n.needContracts(props);
5848
59− const validPoint = props.pointCursor.matchWith({
60− Just: (shp) => shp.value,
61− Nothing: () => {
62− throw BRIDGE_ERROR.MISSING_POINTs
63− }
64− })
49+ const validPoint = n.needPointCursor(props);
6550
6651 const txn = azimuth.ecliptic.setTransferProxy(
6752 validContracts,