on master help sign in
Add functions for doing common Maybe wrangling as /lib/need
e256356Fang
src/bridge/components/StatelessTransaction.js+3−14
@@ -1,6 +1,7 @@
1import { Nothing, Just } from 'folktale/maybe'
1import { Nothing, Just } from 'folktale/maybe'
2import { Ok } from 'folktale/result'
2import { Ok } from 'folktale/result'
3import React from 'react'
3import React from 'react'
4+import * as n from '../lib/need'
4
5
5import { Code, H3 } from './Base'
6import { Code, H3 } from './Base'
6import { Button } from './Base'
7import { Button } from './Base'
@@ -8,7 +9,6 @@ import { CheckboxButton, Input, InnerLabel,
8 InnerLabelDropdown } from './Base'
9 InnerLabelDropdown } from './Base'
9import { Warning } from '../components/Base'
10import { Warning } from '../components/Base'
10
11
11−import { addressFromSecp256k1Public } from '../lib/wallet'
12import { BRIDGE_ERROR } from '../lib/error'
12import { BRIDGE_ERROR } from '../lib/error'
13import { ROUTE_NAMES } from '../lib/router'
13import { ROUTE_NAMES } from '../lib/router'
14import * as tank from '../lib/tank'
14import * as tank from '../lib/tank'
@@ -65,12 +65,7 @@ class StatelessTransaction extends React.Component {
65 componentDidMount() {
65 componentDidMount() {
66 const { props } = this
66 const { props } = this
67
67
68− const addr = props.wallet.matchWith({
68+ const addr = n.needAddress(props);
69− Just: wal => wal.value.address,
70− Nothing: () => {
71− throw BRIDGE_ERROR.MISSING_WALLET
72− }
73− })
74
69
75 props.web3.matchWith({
70 props.web3.matchWith({
76 Nothing: () => {},
71 Nothing: () => {},
@@ -210,13 +205,7 @@ class StatelessTransaction extends React.Component {
210 const rawTx = hexify(stx.serialize());
205 const rawTx = hexify(stx.serialize());
211 const cost = (state.gasLimit * toWei(state.gasPrice, 'gwei'));
206 const cost = (state.gasLimit * toWei(state.gasPrice, 'gwei'));
212
207
213− //TODO need a lib function or something for address=, it's everywhere
214− const address = props.wallet.matchWith({
208+ const address = n.needAddress(props);
215− Just: wal => wal.value.address,
216− Nothing: () => {
217− throw BRIDGE_ERROR.MISSING_WALLET
218− }
219− });
220 let balance = await web3.eth.getBalance(address);
209 let balance = await web3.eth.getBalance(address);
221 let hasBalance = (balance >= cost);
210 let hasBalance = (balance >= cost);
222
211
src/bridge/lib/invite.js+2−6
@@ -13,13 +13,9 @@ import {
13 waitForTransactionConfirm,
13 waitForTransactionConfirm,
14 isTransactionConfirmed
14 isTransactionConfirmed
15} from './txn'
15} from './txn'
16−import { BRIDGE_ERROR } from './error'
16+import { BRIDGE_ERROR } from '../lib/error'
17import { attemptSeedDerivation } from './keys'
17import { attemptSeedDerivation } from './keys'
18−import {
19− addressFromSecp256k1Public,
20− addHexPrefix,
18+import { addHexPrefix, WALLET_NAMES } from './wallet'
21− WALLET_NAMES
22−} from './wallet'
23
19
24const INVITE_STAGES = {
20const INVITE_STAGES = {
25 INVITE_LOGIN: "invite login",
21 INVITE_LOGIN: "invite login",
src/bridge/lib/keys.js+5−19
@@ -1,5 +1,6 @@
1import BN from 'bn.js'
1import BN from 'bn.js'
2import Maybe from 'folktale/maybe'
2import Maybe from 'folktale/maybe'
3+import * as n from '../lib/need'
3
4
4import * as noun from '../nockjs/noun'
5import * as noun from '../nockjs/noun'
5import * as serial from '../nockjs/serial'
6import * as serial from '../nockjs/serial'
@@ -7,7 +8,6 @@ import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
7
8
8import { BRIDGE_ERROR } from './error'
9import { BRIDGE_ERROR } from './error'
9import {
10import {
10− addressFromSecp256k1Public,
11 WALLET_NAMES,
11 WALLET_NAMES,
12 eqAddr
12 eqAddr
13 } from './wallet'
13 } from './wallet'
@@ -63,24 +63,15 @@ const genKey = (networkSeed, point, revision) => {
63// 'next' refers to setting the next set of keys
63// 'next' refers to setting the next set of keys
64// if false, we use revision - 1
64// if false, we use revision - 1
65const attemptSeedDerivation = async (next, args) => {
65const attemptSeedDerivation = async (next, args) => {
66− const { walletType, wallet, pointCursor, pointCache } = args
66+ const { walletType } = args
67 const { urbitWallet, authMnemonic } = args
67 const { urbitWallet, authMnemonic } = args
68
68
69 // NB (jtobin):
69 // NB (jtobin):
70 //
70 //
71 // following code is intentionally verbose for sake of clarity
71 // following code is intentionally verbose for sake of clarity
72
72
73− const point = pointCursor.matchWith({
73+ const point = n.needPointCursor(args);
74− Just: pt => pt.value,
75− Nothing: _ => {
76− throw BRIDGE_ERROR.MISSING_POINT
77− }
78− })
79−
80− const pointDetails =
74+ const pointDetails = n.needFromPointCache(args, point);
81− point in pointCache
82− ? pointCache[point]
83− : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
84
75
85 const revision =
76 const revision =
86 next === true
77 next === true
@@ -104,12 +95,7 @@ const attemptSeedDerivation = async (next, args) => {
104
95
105 } else if (walletType === WALLET_NAMES.MNEMONIC) {
96 } else if (walletType === WALLET_NAMES.MNEMONIC) {
106
97
107− const walProxy = wallet.matchWith({
98+ const walProxy = n.needAddress(args);
108− Just: wal => wal.value.address,
109− Nothing: _ => {
110− throw BRIDGE_ERROR.MISSING_WALLET
111− }
112− })
113
99
114 const mnemonic = authMnemonic.matchWith({
100 const mnemonic = authMnemonic.matchWith({
115 Just: mnem => mnem.value,
101 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 @@
1import * as ob from 'urbit-ob'
1import * as ob from 'urbit-ob'
2+import * as n from '../lib/need'
2
3
3import React from 'react';
4import React from 'react';
4
5
@@ -35,9 +36,8 @@ import Ticket from '../views/Ticket'
35import Transfer from '../views/Transfer'
36import Transfer from '../views/Transfer'
36import Wallet from '../views/Wallet'
37import Wallet from '../views/Wallet'
37
38
38−import { addressFromSecp256k1Public, EthereumWallet } from './wallet'
39+import { EthereumWallet } from './wallet'
39import { renderNetworkType } from './network'
40import { renderNetworkType } from './network'
40−import { BRIDGE_ERROR } from './error'
41
41
42const ROUTE_NAMES = {
42const ROUTE_NAMES = {
43 DEFAULT: Symbol('DEFAULT'),
43 DEFAULT: Symbol('DEFAULT'),
@@ -111,7 +111,7 @@ const createRoutes = () => {
111const ROUTES = createRoutes()
111const ROUTES = createRoutes()
112
112
113const renderRoute = (props, route) => {
113const renderRoute = (props, route) => {
114− const { wallet, networkType, pointCursor } = props
114+ const { wallet, networkType } = props
115 return (
115 return (
116 route === ROUTE_NAMES.LANDING
116 route === ROUTE_NAMES.LANDING
117 ? 'Bridge'
117 ? 'Bridge'
@@ -168,12 +168,7 @@ const renderRoute = (props, route) => {
168 ? 'View'
168 ? 'View'
169
169
170 : route === ROUTE_NAMES.SHIP
170 : route === ROUTE_NAMES.SHIP
171− ? pointCursor.matchWith({
171+ ? ob.patp(n.needPointCursor(props))
172− Just: (cursor) => ob.patp(cursor.value),
173− Nothing: () => {
174− throw BRIDGE_ERROR.MISSING_POINT
175− }
176− })
177
172
178 : route === ROUTE_NAMES.SET_TRANSFER_PROXY
173 : route === ROUTE_NAMES.SET_TRANSFER_PROXY
179 || route === ROUTE_NAMES.SET_MANAGEMENT_PROXY
174 || 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'
4import { InnerLabel, AddressInput, ShowBlockie, Anchor } from '../components/Base'
4import { InnerLabel, AddressInput, ShowBlockie, Anchor } from '../components/Base'
5import * as azimuth from 'azimuth-js'
5import * as azimuth from 'azimuth-js'
6import * as ob from 'urbit-ob'
6import * as ob from 'urbit-ob'
7+import * as n from '../lib/need'
7
8
8import StatelessTransaction from '../components/StatelessTransaction'
9import StatelessTransaction from '../components/StatelessTransaction'
9−import { BRIDGE_ERROR } from '../lib/error'
10import { NETWORK_NAMES } from '../lib/network'
10import { NETWORK_NAMES } from '../lib/network'
11−import { isValidAddress, addressFromSecp256k1Public } from '../lib/wallet'
11+import { isValidAddress } from '../lib/wallet'
12
12
13class AcceptTransfer extends React.Component {
13class AcceptTransfer extends React.Component {
14 constructor(props) {
14 constructor(props) {
15 super(props)
15 super(props)
16
16
17− const receivingAddress = props.wallet.matchWith({
17+ const receivingAddress = n.needAddress(props);
18− Just: (wal) => wal.value.address,
19− Nothing: () => {
20− throw BRIDGE_ERROR.MISSING_WALLET
21− }
22− })
23
18
24− const incomingPoint = props.pointCursor.matchWith({
19+ const incomingPoint = n.needPointCursor(props);
25− Just: (shp) => shp.value,
26− Nothing: () => {
27− throw BRIDGE_ERROR.MISSING_POINT
28− }
29− })
30
20
31 this.state = {
21 this.state = {
32 receivingAddress: receivingAddress,
22 receivingAddress: receivingAddress,
@@ -46,19 +36,9 @@ class AcceptTransfer extends React.Component {
46 createUnsignedTxn() {
36 createUnsignedTxn() {
47 const { state, props } = this
37 const { state, props } = this
48
38
49− const validContracts = props.contracts.matchWith({
39+ const validContracts = n.needContracts(props);
50− Just: (cs) => cs.value,
40+
51− Nothing: () => {
41+ const validPoint = n.needPointCursor(props); //TODO state.incomingPoint ?
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− })
62
42
63 return Just(azimuth.ecliptic.transferPoint(
43 return Just(azimuth.ecliptic.transferPoint(
64 validContracts,
44 validContracts,
src/bridge/views/CancelTransfer.js+5−20
@@ -3,21 +3,16 @@ import React from 'react'
3import { Row, Col, H1, P } from '../components/Base'
3import { Row, Col, H1, P } from '../components/Base'
4import * as azimuth from 'azimuth-js'
4import * as azimuth from 'azimuth-js'
5import * as ob from 'urbit-ob'
5import * as ob from 'urbit-ob'
6+import * as n from '../lib/need'
6
7
7import StatelessTransaction from '../components/StatelessTransaction'
8import StatelessTransaction from '../components/StatelessTransaction'
8−import { BRIDGE_ERROR } from '../lib/error'
9import { ETH_ZERO_ADDR } from '../lib/wallet'
9import { ETH_ZERO_ADDR } from '../lib/wallet'
10
10
11class CancelTransfer extends React.Component {
11class CancelTransfer extends React.Component {
12 constructor(props) {
12 constructor(props) {
13 super(props)
13 super(props)
14
14
15− const pointInTransfer = props.pointCursor.matchWith({
15+ const pointInTransfer = n.needPointCursor(props);
16− Just: (pt) => pt.value,
17− Nothing: () => {
18− throw BRIDGE_ERROR.MISSING_POINT
19− }
20− })
21
16
22 this.state = {
17 this.state = {
23 proxyAddress: '',
18 proxyAddress: '',
@@ -30,19 +25,9 @@ class CancelTransfer extends React.Component {
30 createUnsignedTxn() {
25 createUnsignedTxn() {
31 const { props } = this
26 const { props } = this
32
27
33− const validContracts = props.contracts.matchWith({
28+ const validContracts = n.needContracts(props);
34− Just: (cs) => cs.value,
29+
35− Nothing: () => {
30+ const validPoint = n.needPointCursor(props); //TODO this.state.pointInTransfer ?
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− })
46
31
47 const txn = azimuth.ecliptic.setTransferProxy(
32 const txn = azimuth.ecliptic.setTransferProxy(
48 validContracts,
33 validContracts,
src/bridge/views/CreateGalaxy.js+4−20
@@ -2,18 +2,17 @@ import React from 'react'
2import Maybe from 'folktale/maybe'
2import Maybe from 'folktale/maybe'
3import * as azimuth from 'azimuth-js'
3import * as azimuth from 'azimuth-js'
4import * as ob from 'urbit-ob'
4import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
5
6
6import { Button, } from '../components/Base'
7import { Button, } from '../components/Base'
7import { Row, Col, H1, P, Anchor } from '../components/Base'
8import { Row, Col, H1, P, Anchor } from '../components/Base'
8import { InnerLabel, GalaxyInput, AddressInput, ValidatedSigil, ShowBlockie } from '../components/Base'
9import { InnerLabel, GalaxyInput, AddressInput, ValidatedSigil, ShowBlockie } from '../components/Base'
9import StatelessTransaction from '../components/StatelessTransaction'
10import StatelessTransaction from '../components/StatelessTransaction'
10
11
11−import { BRIDGE_ERROR } from '../lib/error'
12import { NETWORK_NAMES } from '../lib/network'
12import { NETWORK_NAMES } from '../lib/network'
13import { canDecodePatp } from '../lib/txn'
13import { canDecodePatp } from '../lib/txn'
14
14
15import {
15import {
16− addressFromSecp256k1Public,
17 ETH_ZERO_ADDR,
16 ETH_ZERO_ADDR,
18 isValidAddress,
17 isValidAddress,
19 eqAddr
18 eqAddr
@@ -42,12 +41,7 @@ class CreateGalaxy extends React.Component {
42 constructor(props) {
41 constructor(props) {
43 super(props)
42 super(props)
44
43
45− const galaxyOwner = props.wallet.matchWith({
44+ const galaxyOwner = n.needAddress(props);
46− Just: (wal) => wal.value.address,
47− Nothing: () => {
48− throw BRIDGE_ERROR.MISSING_WALLET
49− }
50− })
51
45
52 this.state = {
46 this.state = {
53 galaxyOwner: galaxyOwner,
47 galaxyOwner: galaxyOwner,
@@ -79,12 +73,7 @@ class CreateGalaxy extends React.Component {
79 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing()
73 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing()
80 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing()
74 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing()
81
75
82− const validContracts = props.contracts.matchWith({
76+ const validContracts = n.needContracts(props);
83− Just: (cs) => cs.value,
84− Nothing: () => {
85− throw BRIDGE_ERROR.MISSING_CONTRACTS
86− }
87− })
88
77
89 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10)
78 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10)
90
79
@@ -105,12 +94,7 @@ class CreateGalaxy extends React.Component {
105 return
94 return
106 }
95 }
107
96
108− const validContracts = props.contracts.matchWith({
97+ const validContracts = n.needContracts(props);
109− Just: (cs) => cs.value,
110− Nothing: () => {
111− throw BRIDGE_ERROR.MISSING_CONTRACTS
112− }
113− })
114
98
115 const galaxyDec = ob.patp2dec(state.galaxyName)
99 const galaxyDec = ob.patp2dec(state.galaxyName)
116
100
src/bridge/views/GenKeyfile.js+4−15
@@ -1,5 +1,6 @@
1import React from 'react'
1import React from 'react'
2import Maybe from 'folktale/maybe'
2import Maybe from 'folktale/maybe'
3+import * as n from '../lib/need'
3
4
4import { Button } from '../components/Base'
5import { Button } from '../components/Base'
5import { Row, Col, H1, P } from '../components/Base'
6import { Row, Col, H1, P } from '../components/Base'
@@ -9,7 +10,6 @@ import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
9import saveAs from 'file-saver'
10import saveAs from 'file-saver'
10
11
11import { attemptSeedDerivation, genKey } from '../lib/keys'
12import { attemptSeedDerivation, genKey } from '../lib/keys'
12−import { BRIDGE_ERROR } from '../lib/error'
13import {
13import {
14 addHexPrefix
14 addHexPrefix
15 } from '../lib/wallet'
15 } from '../lib/wallet'
@@ -25,20 +25,9 @@ class GenKeyfile extends React.Component {
25 }
25 }
26
26
27 getPointDetails() {
27 getPointDetails() {
28− const { pointCache } = this.props
28+ const point = n.needPointCursor(this.props);
29− const { pointCursor } = this.props
29+
30−
30+ const pointDetails = n.needFromPointCache(this.props, point);
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 })()
42
31
43 // in case we did SetKeys earlier this session, make sure to generate the
32 // in case we did SetKeys earlier this session, make sure to generate the
44 // newer keyfile, rather than the one that will expire soon
33 // 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'
3import { InnerLabel, Warning, TicketInput,
3import { InnerLabel, Warning, TicketInput,
4 VerifyTicketInput, Button, Row, Col, Passport } from '../components/Base'
4 VerifyTicketInput, Button, Row, Col, Passport } from '../components/Base'
5import * as azimuth from 'azimuth-js'
5import * as azimuth from 'azimuth-js'
6+import * as n from '../lib/need'
6
7
7import { randomPatq } from '../lib/lib'
8import { randomPatq } from '../lib/lib'
8import { ROUTE_NAMES } from '../lib/router'
9import { ROUTE_NAMES } from '../lib/router'
9import { DEFAULT_HD_PATH, ownershipWalletFromTicket,
10import { DEFAULT_HD_PATH, ownershipWalletFromTicket,
10− walletFromMnemonic, addressFromSecp256k1Public } from '../lib/wallet'
11+ walletFromMnemonic } from '../lib/wallet'
11import { BRIDGE_ERROR } from '../lib/error'
12import { BRIDGE_ERROR } from '../lib/error'
12import { INVITE_STAGES, WALLET_STATES, TRANSACTION_STATES } from '../lib/invite'
13import { INVITE_STAGES, WALLET_STATES, TRANSACTION_STATES } from '../lib/invite'
13import { generateWallet, startTransactions } from '../lib/invite'
14import { generateWallet, startTransactions } from '../lib/invite'
@@ -86,12 +87,7 @@ class InviteTicket extends React.Component {
86
87
87 const addr = inviteWallet.address;
88 const addr = inviteWallet.address;
88
89
89− const ctrcs = this.props.contracts.matchWith({
90+ const ctrcs = n.needContracts(this.props);
90− Just: ctrcs => ctrcs.value,
91− Nothing: () => {
92− throw BRIDGE_ERROR.MISSING_CONTRACTS
93− }
94− })
95
91
96 const incoming = await azimuth.azimuth.getTransferringFor(ctrcs, addr)
92 const incoming = await azimuth.azimuth.getTransferringFor(ctrcs, addr)
97
93
src/bridge/views/InvitesManage.js+3−13
@@ -2,8 +2,8 @@ import { Just, Nothing } from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3import * as ob from 'urbit-ob'
3import * as ob from 'urbit-ob'
4import * as azimuth from 'azimuth-js'
4import * as azimuth from 'azimuth-js'
5+import * as n from '../lib/need'
5
6
6−import { BRIDGE_ERROR } from '../lib/error'
7import { Row, Col, Warning, Input,
7import { Row, Col, Warning, Input,
8 PointInput, InnerLabel, ValidatedSigil } from '../components/Base'
8 PointInput, InnerLabel, ValidatedSigil } from '../components/Base'
9import StatelessTransaction from '../components/StatelessTransaction'
9import StatelessTransaction from '../components/StatelessTransaction'
@@ -32,18 +32,8 @@ class InvitesManage extends React.Component {
32 }
32 }
33
33
34 componentDidMount() {
34 componentDidMount() {
35− this.point = this.props.pointCursor.matchWith({
35+ this.point = n.needPointCursor(this.props);
36− Just: (pt) => parseInt(pt.value, 10),
36+ this.contracts = n.needContracts(this.props);
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− });
47
37
48 azimuth.azimuth.isSpawnProxy(
38 azimuth.azimuth.isSpawnProxy(
49 this.contracts,
39 this.contracts,
src/bridge/views/InvitesSend.js+5−27
@@ -1,11 +1,10 @@
1import { Just, Nothing } from 'folktale/maybe'
1import { Just, Nothing } from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3import * as azimuth from 'azimuth-js'
3import * as azimuth from 'azimuth-js'
4+import * as n from '../lib/need'
4
5
5−import { BRIDGE_ERROR } from '../lib/error'
6import { hasReceived, sendMail } from '../lib/inviteMail'
6import { hasReceived, sendMail } from '../lib/inviteMail'
7import { Row, Col, Button, Input, H3, Warning } from '../components/Base'
7import { Row, Col, Button, Input, H3, Warning } from '../components/Base'
8−import { addressFromSecp256k1Public } from '../lib/wallet'
9
8
10// for wallet generation
9// for wallet generation
11import * as wg from '../../walletgen/lib/lib'
10import * as wg from '../../walletgen/lib/lib'
@@ -70,31 +69,10 @@ class InvitesSend extends React.Component {
70 }
69 }
71
70
72 componentDidMount() {
71 componentDidMount() {
73− this.point = this.props.pointCursor.matchWith({
72+ this.point = parseInt(n.needPointCursor(this.props), 10);
74− Just: (pt) => parseInt(pt.value, 10),
73+ this.address = n.needAddress(this.props);
75− Nothing: () => {
74+ this.contracts = n.needContracts(this.props);
76− throw BRIDGE_ERROR.MISSING_POINT;
75+ this.web3 = n.needWeb3(this.props);
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− });
98
76
99 console.log(azimuth.delegatedSending);
77 console.log(azimuth.delegatedSending);
100 azimuth.delegatedSending.getTotalUsableInvites(this.contracts, this.point)
78 azimuth.delegatedSending.getTotalUsableInvites(this.contracts, this.point)
src/bridge/views/IssueChild.js+4−22
@@ -2,6 +2,7 @@ import { Just, Nothing } from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3import { azimuth, ecliptic } from 'azimuth-js'
3import { azimuth, ecliptic } from 'azimuth-js'
4import * as ob from 'urbit-ob'
4import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
5
6
6import {
7import {
7 Row, Col, H1, P, Anchor,
8 Row, Col, H1, P, Anchor,
@@ -12,7 +13,6 @@ import {
12import StatelessTransaction from '../components/StatelessTransaction'
13import StatelessTransaction from '../components/StatelessTransaction'
13
14
14import { NETWORK_NAMES } from '../lib/network'
15import { NETWORK_NAMES } from '../lib/network'
15−import { BRIDGE_ERROR } from '../lib/error'
16import { getSpawnCandidate } from '../lib/child'
16import { getSpawnCandidate } from '../lib/child'
17import { canDecodePatp } from '../lib/txn'
17import { canDecodePatp } from '../lib/txn'
18
18
@@ -31,12 +31,7 @@ class IssueChild extends React.Component {
31 constructor(props) {
31 constructor(props) {
32 super(props)
32 super(props)
33
33
34− const issuingPoint = props.pointCursor.matchWith({
34+ const issuingPoint = parseInt(n.needPointCursor(props), 10);
35− Just: (pt) => parseInt(pt.value, 10),
36− Nothing: () => {
37− throw BRIDGE_ERROR.MISSING_POINT
38− }
39− })
40
35
41 const getCandidate = () => ob.patp(getSpawnCandidate(issuingPoint))
36 const getCandidate = () => ob.patp(getSpawnCandidate(issuingPoint))
42
37
@@ -69,17 +64,9 @@ class IssueChild extends React.Component {
69 }
64 }
70
65
71 componentWillMount() {
66 componentWillMount() {
72−
73− const { contracts } = this.props
74 const { issuingPoint } = this.state
67 const { issuingPoint } = this.state
75
68
76−
77− const validContracts = contracts.matchWith({
69+ const validContracts = n.needContracts(this.props);
78− Just: cs => cs.value,
79− Nothing: _ => {
80− throw BRIDGE_ERROR.MISSING_CONTRACTS
81− }
82− })
83
70
84 azimuth.getUnspawnedChildren(validContracts, issuingPoint).then(ps => this.setState({ validChildren: new Set(ps.map(ob.patp)) }))
71 azimuth.getUnspawnedChildren(validContracts, issuingPoint).then(ps => this.setState({ validChildren: new Set(ps.map(ob.patp)) }))
85 }
72 }
@@ -110,12 +97,7 @@ class IssueChild extends React.Component {
110 if (state.isAvailable === false) return Nothing()
97 if (state.isAvailable === false) return Nothing()
111 if (canDecodePatp(state.desiredPoint) === false) return Nothing()
98 if (canDecodePatp(state.desiredPoint) === false) return Nothing()
112
99
113− const validContracts = props.contracts.matchWith({
100+ const validContracts = n.needContracts(props);
114− Just: (cs) => cs.value,
115− Nothing: () => {
116− throw BRIDGE_ERROR.MISSING_CONTRACTS
117− }
118− })
119
101
120 const pointDec = ob.patp2dec(state.desiredPoint)
102 const pointDec = ob.patp2dec(state.desiredPoint)
121
103
src/bridge/views/Point.js+3−9
@@ -3,12 +3,12 @@ import React from 'react'
3import { pour } from 'sigil-js'
3import { pour } from 'sigil-js'
4import * as ob from 'urbit-ob'
4import * as ob from 'urbit-ob'
5import * as azimuth from 'azimuth-js'
5import * as azimuth from 'azimuth-js'
6+import * as n from '../lib/need'
6
7
7import PointList from '../components/PointList'
8import PointList from '../components/PointList'
8import ReactSVGComponents from '../components/ReactSVGComponents'
9import ReactSVGComponents from '../components/ReactSVGComponents'
9import KeysAndMetadata from './Point/KeysAndMetadata'
10import KeysAndMetadata from './Point/KeysAndMetadata'
10import Actions from './Point/Actions'
11import Actions from './Point/Actions'
11−import { BRIDGE_ERROR } from '../lib/error'
12import { Row, Col, H1, H3 } from '../components/Base'
12import { Row, Col, H1, H3 } from '../components/Base'
13
13
14
14
@@ -74,18 +74,12 @@ class Point extends React.Component {
74
74
75 const {
75 const {
76 web3, popRoute, pushRoute, wallet,
76 web3, popRoute, pushRoute, wallet,
77− setPointCursor, pointCursor, pointCache
77+ setPointCursor, pointCache
78 } = this.props;
78 } = this.props;
79
79
80 const { spawned } = this.state
80 const { spawned } = this.state
81
81
82−
82+ const point = n.needPointCursor(this.props);
83− const point = pointCursor.matchWith({
84− Just: (cursor) => cursor.value,
85− Nothing: () => {
86− throw BRIDGE_ERROR.MISSING_POINT
87− }
88− })
89
83
90 const pointDetails =
84 const pointDetails =
91 point in pointCache
85 point in pointCache
src/bridge/views/Point/Actions.js+3−9
@@ -1,11 +1,10 @@
1import React from 'react'
1import React from 'react'
2+import * as n from '../../lib/need'
2import {
3import {
3 ETH_ZERO_ADDR,
4 ETH_ZERO_ADDR,
4 CURVE_ZERO_ADDR,
5 CURVE_ZERO_ADDR,
5− addressFromSecp256k1Public,
6 eqAddr
6 eqAddr
7} from '../../lib/wallet'
7} from '../../lib/wallet'
8−import { BRIDGE_ERROR } from '../../lib/error'
9import { Row, Col, H2, P } from '../../components/Base'
8import { Row, Col, H2, P } from '../../components/Base'
10import { Button } from '../../components/Base'
9import { Button } from '../../components/Base'
11import { ROUTE_NAMES } from '../../lib/router'
10import { ROUTE_NAMES } from '../../lib/router'
@@ -18,16 +17,11 @@ const isStar = point =>
18
17
19const Actions = (props) => {
18const Actions = (props) => {
20 const {
19 const {
21− pushRoute, online, wallet,
20+ pushRoute, online,
22 point, pointDetails, invites
21 point, pointDetails, invites
23 } = props
22 } = props
24
23
25− const addr = wallet.matchWith({
24+ const addr = n.needAddress(props);
26− Just: (wal) => wal.value.address,
27− Nothing: () => {
28− throw BRIDGE_ERROR.MISSING_WALLET
29− }
30− })
31
25
32 const isOwner = pointDetails.matchWith({
26 const isOwner = pointDetails.matchWith({
33 Nothing: _ => false,
27 Nothing: _ => false,
src/bridge/views/Points.js−1
@@ -8,7 +8,6 @@ import { NETWORK_NAMES } from '../lib/network'
8import { ROUTE_NAMES } from '../lib/router'
8import { ROUTE_NAMES } from '../lib/router'
9import {
9import {
10 ETH_ZERO_ADDR,
10 ETH_ZERO_ADDR,
11− addressFromSecp256k1Public,
12 eqAddr
11 eqAddr
13 } from '../lib/wallet'
12 } from '../lib/wallet'
14
13
src/bridge/views/SentTransaction.js+3−5
@@ -1,5 +1,6 @@
1import Maybe from 'folktale/maybe'
1import Maybe from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3+import * as n from '../lib/need'
3import { Row, Col, H1, H3, P, Warning, Anchor } from '../components/Base'
4import { Row, Col, H1, H3, P, Warning, Anchor } from '../components/Base'
4import { Button } from '../components/Base'
5import { Button } from '../components/Base'
5
6
@@ -122,15 +123,12 @@ const Failure = (props) =>
122 </Row>
123 </Row>
123
124
124const SentTransaction = (props) => {
125const SentTransaction = (props) => {
125− const { web3, txnHashCursor, networkType, popRoute, pushRoute, txnConfirmations} = props
126+ const { txnHashCursor, networkType, popRoute, pushRoute, txnConfirmations} = props
126 const { setPointCursor, pointCursor } = props
127 const { setPointCursor, pointCursor } = props
127
128
128 const promptKeyfile = props.routeData && props.routeData.promptKeyfile
129 const promptKeyfile = props.routeData && props.routeData.promptKeyfile
129
130
130− const w3 = web3.matchWith({
131+ const w3 = n.needWeb3(props);
131− Nothing: _ => { throw BRIDGE_ERROR.MISSING_WEB3 },
132− Just: res => res.value
133− })
134
132
135 const result = txnHashCursor.matchWith({
133 const result = txnHashCursor.matchWith({
136 Nothing: _ => { throw BRIDGE_ERROR.MISSING_TXN },
134 Nothing: _ => { throw BRIDGE_ERROR.MISSING_TXN },
src/bridge/views/SetKeys.js+7−33
@@ -2,29 +2,21 @@ import React from 'react'
2import Maybe from 'folktale/maybe'
2import Maybe from 'folktale/maybe'
3import * as azimuth from 'azimuth-js'
3import * as azimuth from 'azimuth-js'
4import * as ob from 'urbit-ob'
4import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
5import { Row, Col, H1, P, Warning, CheckboxButton } from '../components/Base'
6import { Row, Col, H1, P, Warning, CheckboxButton } from '../components/Base'
6
7
7import StatelessTransaction from '../components/StatelessTransaction'
8import StatelessTransaction from '../components/StatelessTransaction'
8−import { BRIDGE_ERROR } from '../lib/error'
9import { attemptSeedDerivation } from '../lib/keys'
9import { attemptSeedDerivation } from '../lib/keys'
10
10
11import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
11import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
12
12
13−import {
14− addressFromSecp256k1Public,
15− addHexPrefix
16−} from '../lib/wallet'
13+import { addHexPrefix } from '../lib/wallet'
17
14
18class SetKeys extends React.Component {
15class SetKeys extends React.Component {
19 constructor(props) {
16 constructor(props) {
20 super(props)
17 super(props)
21
18
22− const point = props.pointCursor.matchWith({
19+ const point = n.needPointCursor(props);
23− Just: (shp) => shp.value,
24− Nothing: () => {
25− throw BRIDGE_ERROR.MISSING_POINT
26− }
27− })
28
20
29 this.state = {
21 this.state = {
30 auth: '',
22 auth: '',
@@ -51,12 +43,7 @@ class SetKeys extends React.Component {
51
43
52 this.deriveSeed()
44 this.deriveSeed()
53
45
54− const addr = props.wallet.matchWith({
46+ const addr = n.needAddress(props);
55− Just: wal => wal.value.address,
56− Nothing: () => {
57− throw BRIDGE_ERROR.MISSING_WALLET
58− }
59− })
60
47
61 this.determineManagementSeed(props.contracts.value, addr)
48 this.determineManagementSeed(props.contracts.value, addr)
62 }
49 }
@@ -101,19 +88,9 @@ class SetKeys extends React.Component {
101 createUnsignedTxn() {
88 createUnsignedTxn() {
102 const { state, props } = this
89 const { state, props } = this
103
90
104− const validContracts = props.contracts.matchWith({
91+ const validContracts = n.needContracts(props);
105− Just: (cs) => cs.value,
106− Nothing: () => {
107− throw BRIDGE_ERROR.MISSING_CONTRACTS
108− }
109− })
110
92
111− const validPoint = props.pointCursor.matchWith({
93+ const validPoint = n.needPointCursor(props);
112− Just: (shp) => shp.value,
113− Nothing: () => {
114− throw BRIDGE_ERROR.MISSING_POINT
115− }
116− })
117
94
118 const hexRegExp = /[0-9A-Fa-f]{64}/g
95 const hexRegExp = /[0-9A-Fa-f]{64}/g
119
96
@@ -146,10 +123,7 @@ class SetKeys extends React.Component {
146 state.networkSeed.length === 64
123 state.networkSeed.length === 64
147 && state.networkSeed.length === 64
124 && state.networkSeed.length === 64
148
125
149− const pointDetails =
126+ const pointDetails = n.needFromPointCache(props, state.point);
150− state.point in props.pointCache
151− ? props.pointCache[state.point]
152− : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
153
127
154 return (
128 return (
155 <Row>
129 <Row>
src/bridge/views/SetProxy.js+5−20
@@ -1,12 +1,12 @@
1import Maybe from 'folktale/maybe'
1import Maybe from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3+import * as n from '../lib/need'
3import * as azimuth from 'azimuth-js'
4import * as azimuth from 'azimuth-js'
4import { Row, Col, H1, P, InnerLabel, ShowBlockie, Anchor, HorizontalSelector } from '../components/Base'
5import { Row, Col, H1, P, InnerLabel, ShowBlockie, Anchor, HorizontalSelector } from '../components/Base'
5import { AddressInput } from '../components/Base'
6import { AddressInput } from '../components/Base'
6import * as ob from 'urbit-ob'
7import * as ob from 'urbit-ob'
7
8
8import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
9import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
9−import { BRIDGE_ERROR } from '../lib/error'
10
10
11import { NETWORK_NAMES } from '../lib/network'
11import { NETWORK_NAMES } from '../lib/network'
12
12
@@ -36,12 +36,7 @@ class SetProxy extends React.Component {
36 constructor(props) {
36 constructor(props) {
37 super(props)
37 super(props)
38
38
39− const issuingPoint = props.pointCursor.matchWith({
39+ const issuingPoint = n.needPointCursor(props);
40− Just: (shp) => shp.value,
41− Nothing: () => {
42− throw BRIDGE_ERROR.MISSING_POINT
43− }
44− })
45
40
46 this.state = {
41 this.state = {
47 proxyAddress: '',
42 proxyAddress: '',
@@ -72,19 +67,9 @@ class SetProxy extends React.Component {
72 createUnsignedTxn(proxyAddress) {
67 createUnsignedTxn(proxyAddress) {
73 const { state, props } = this
68 const { state, props } = this
74
69
75− const validContracts = props.contracts.matchWith({
70+ const validContracts = n.needContracts(props);
76− Just: (cs) => cs.value,
71+
77− Nothing: () => {
72+ const validPoint = n.needPointCursor(props);
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− })
88
73
89 const txArgs = [
74 const txArgs = [
90 validContracts,
75 validContracts,
src/bridge/views/Transfer.js+4−19
@@ -2,12 +2,12 @@ import Maybe from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3import * as azimuth from 'azimuth-js'
3import * as azimuth from 'azimuth-js'
4import * as ob from 'urbit-ob'
4import * as ob from 'urbit-ob'
5+import * as n from '../lib/need'
5
6
6import { Row, Col, H1, InnerLabel, ShowBlockie, P, Anchor } from '../components/Base'
7import { Row, Col, H1, InnerLabel, ShowBlockie, P, Anchor } from '../components/Base'
7import { AddressInput } from '../components/Base'
8import { AddressInput } from '../components/Base'
8import StatelessTransaction from '../components/StatelessTransaction'
9import StatelessTransaction from '../components/StatelessTransaction'
9
10
10−import { BRIDGE_ERROR } from '../lib/error'
11import { NETWORK_NAMES } from '../lib/network'
11import { NETWORK_NAMES } from '../lib/network'
12
12
13import {
13import {
@@ -18,12 +18,7 @@ class Transfer extends React.Component {
18 constructor(props) {
18 constructor(props) {
19 super(props)
19 super(props)
20
20
21− const issuingPoint = props.pointCursor.matchWith({
21+ const issuingPoint = n.needPointCursor(props);
22− Just: (pt) => pt.value,
23− Nothing: () => {
24− throw BRIDGE_ERROR.MISSING_POINT
25− }
26− })
27
22
28 this.state = {
23 this.state = {
29 receivingAddress: '',
24 receivingAddress: '',
@@ -49,19 +44,9 @@ class Transfer extends React.Component {
49 createUnsignedTxn() {
44 createUnsignedTxn() {
50 const { state, props } = this
45 const { state, props } = this
51
46
52− const validContracts = props.contracts.matchWith({
47+ const validContracts = n.needContracts(props);
53− Just: (cs) => cs.value,
54− Nothing: () => {
55− throw BRIDGE_ERROR.MISSING_CONTRACTS
56− }
57− })
58
48
59− const validPoint = props.pointCursor.matchWith({
49+ const validPoint = n.needPointCursor(props);
60− Just: (shp) => shp.value,
61− Nothing: () => {
62− throw BRIDGE_ERROR.MISSING_POINTs
63− }
64− })
65
50
66 const txn = azimuth.ecliptic.setTransferProxy(
51 const txn = azimuth.ecliptic.setTransferProxy(
67 validContracts,
52 validContracts,