on master help sign in
Rename /lib/need functions and usage
commitd5bb617a9e0f56b4a9efa4f215fb647ff0be170e authorFang <git@fang.io> dateTue 11 Jun 2019, 15:46 (7 years ago) parent306d663
18 files changed+72−72
src/bridge/components/StatelessTransaction.js+3−3 src/bridge/lib/keys.js+4−4 src/bridge/lib/need.js+13−13 src/bridge/lib/router.js+2−2 src/bridge/views/AcceptTransfer.js+5−5 src/bridge/views/CancelTransfer.js+4−4 src/bridge/views/CreateGalaxy.js+4−4 src/bridge/views/GenKeyfile.js+3−3 src/bridge/views/InviteTicket.js+2−2 src/bridge/views/InvitesManage.js+3−3 src/bridge/views/InvitesSend.js+5−5 src/bridge/views/IssueChild.js+4−4 src/bridge/views/Point.js+2−2 src/bridge/views/Point/Actions.js+2−2 src/bridge/views/SentTransaction.js+2−2 src/bridge/views/SetKeys.js+6−6 src/bridge/views/SetProxy.js+4−4 src/bridge/views/Transfer.js+4−4
src/bridge/components/StatelessTransaction.js+3−3
@@ -1,7 +1,7 @@
11import { Nothing, Just } from 'folktale/maybe'
22import { Ok } from 'folktale/result'
33import React from 'react'
4−import * as n from '../lib/need'
4+import * as need from '../lib/need'
55
66import { Code, H3 } from './Base'
77import { Button } from './Base'
@@ -65,7 +65,7 @@ class StatelessTransaction extends React.Component {
6565 componentDidMount() {
6666 const { props } = this
6767
68− const addr = n.needAddress(props);
68+ const addr = need.address(props);
6969
7070 props.web3.matchWith({
7171 Nothing: () => {},
@@ -205,7 +205,7 @@ class StatelessTransaction extends React.Component {
205205 const rawTx = hexify(stx.serialize());
206206 const cost = (state.gasLimit * toWei(state.gasPrice, 'gwei'));
207207
208− const address = n.needAddress(props);
208+ const address = need.address(props);
209209 let balance = await web3.eth.getBalance(address);
210210 let hasBalance = (balance >= cost);
211211
src/bridge/lib/keys.js+4−4
@@ -1,6 +1,6 @@
11import BN from 'bn.js'
22import Maybe from 'folktale/maybe'
3−import * as n from '../lib/need'
3+import * as need from '../lib/need'
44
55import * as noun from '../nockjs/noun'
66import * as serial from '../nockjs/serial'
@@ -70,8 +70,8 @@ const attemptSeedDerivation = async (next, args) => {
7070 //
7171 // following code is intentionally verbose for sake of clarity
7272
73− const point = n.needPointCursor(args);
74− const pointDetails = n.needFromPointCache(args, point);
73+ const point = need.pointCursor(args);
74+ const pointDetails = need.fromPointCache(args, point);
7575
7676 const revision =
7777 next === true
@@ -95,7 +95,7 @@ const attemptSeedDerivation = async (next, args) => {
9595
9696 } else if (walletType === WALLET_NAMES.MNEMONIC) {
9797
98− const walProxy = n.needAddress(args);
98+ const walProxy = need.address(args);
9999
100100 const mnemonic = authMnemonic.matchWith({
101101 Just: mnem => mnem.value,
src/bridge/lib/need.js+13−13
@@ -4,7 +4,7 @@
44
55import { BRIDGE_ERROR } from '../lib/error'
66
7−function needWeb3(obj) {
7+function web3(obj) {
88 return ('web3' in obj === false)
99 ? (() => { throw BRIDGE_ERROR.MISSING_WEB3 })()
1010 : obj.web3.matchWith({
@@ -13,7 +13,7 @@ function needWeb3(obj) {
1313 });
1414}
1515
16−function needContracts(obj) {
16+function contracts(obj) {
1717 return ('contracts' in obj === false)
1818 ? (() => { throw BRIDGE_ERROR.MISSING_CONTRACTS })()
1919 : obj.contracts.matchWith({
@@ -22,7 +22,7 @@ function needContracts(obj) {
2222 });
2323}
2424
25−function needWallet(obj) {
25+function wallet(obj) {
2626 return ('wallet' in obj === false)
2727 ? (() => { throw BRIDGE_ERROR.MISSING_WALLET })()
2828 : obj.wallet.matchWith({
@@ -31,11 +31,11 @@ function needWallet(obj) {
3131 });
3232}
3333
34−function needAddress(obj) {
35− return needWallet(obj).address;
34+function address(obj) {
35+ return wallet(obj).address;
3636}
3737
38−function needPointCursor(obj) {
38+function pointCursor(obj) {
3939 return ('pointCursor' in obj === false)
4040 ? (() => { throw BRIDGE_ERROR.MISSING_POINT })()
4141 : obj.pointCursor.matchWith({
@@ -44,7 +44,7 @@ function needPointCursor(obj) {
4444 });
4545}
4646
47−function needFromPointCache(obj, point) {
47+function fromPointCache(obj, point) {
4848 return ('pointCache' in obj === false)
4949 ? (() => { throw BRIDGE_ERROR.MISSING_POINT })()
5050 : point in obj.pointCache
@@ -53,10 +53,10 @@ function needFromPointCache(obj, point) {
5353}
5454
5555export {
56− needWeb3,
57− needContracts,
58− needWallet,
59− needAddress,
60− needPointCursor,
61− needFromPointCache
56+ web3,
57+ contracts,
58+ wallet,
59+ address,
60+ pointCursor,
61+ fromPointCache
6262}
src/bridge/lib/router.js+2−2
@@ -1,5 +1,5 @@
11import * as ob from 'urbit-ob'
2−import * as n from '../lib/need'
2+import * as need from '../lib/need'
33
44import React from 'react';
55
@@ -168,7 +168,7 @@ const renderRoute = (props, route) => {
168168 ? 'View'
169169
170170 : route === ROUTE_NAMES.SHIP
171− ? ob.patp(n.needPointCursor(props))
171+ ? ob.patp(need.pointCursor(props))
172172
173173 : route === ROUTE_NAMES.SET_TRANSFER_PROXY
174174 || route === ROUTE_NAMES.SET_MANAGEMENT_PROXY
src/bridge/views/AcceptTransfer.js+5−5
@@ -4,7 +4,7 @@ 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'
7+import * as need from '../lib/need'
88
99import StatelessTransaction from '../components/StatelessTransaction'
1010import { NETWORK_NAMES } from '../lib/network'
@@ -14,9 +14,9 @@ class AcceptTransfer extends React.Component {
1414 constructor(props) {
1515 super(props)
1616
17− const receivingAddress = n.needAddress(props);
17+ const receivingAddress = need.address(props);
1818
19− const incomingPoint = n.needPointCursor(props);
19+ const incomingPoint = need.pointCursor(props);
2020
2121 this.state = {
2222 receivingAddress: receivingAddress,
@@ -36,9 +36,9 @@ class AcceptTransfer extends React.Component {
3636 createUnsignedTxn() {
3737 const { state, props } = this
3838
39− const validContracts = n.needContracts(props);
39+ const validContracts = need.contracts(props);
4040
41− const validPoint = n.needPointCursor(props); //TODO state.incomingPoint ?
41+ const validPoint = need.pointCursor(props); //TODO state.incomingPoint ?
4242
4343 return Just(azimuth.ecliptic.transferPoint(
4444 validContracts,
src/bridge/views/CancelTransfer.js+4−4
@@ -3,7 +3,7 @@ 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'
6+import * as need from '../lib/need'
77
88import StatelessTransaction from '../components/StatelessTransaction'
99import { ETH_ZERO_ADDR } from '../lib/wallet'
@@ -12,7 +12,7 @@ class CancelTransfer extends React.Component {
1212 constructor(props) {
1313 super(props)
1414
15− const pointInTransfer = n.needPointCursor(props);
15+ const pointInTransfer = need.pointCursor(props);
1616
1717 this.state = {
1818 proxyAddress: '',
@@ -25,9 +25,9 @@ class CancelTransfer extends React.Component {
2525 createUnsignedTxn() {
2626 const { props } = this
2727
28− const validContracts = n.needContracts(props);
28+ const validContracts = need.contracts(props);
2929
30− const validPoint = n.needPointCursor(props); //TODO this.state.pointInTransfer ?
30+ const validPoint = need.pointCursor(props); //TODO this.state.pointInTransfer ?
3131
3232 const txn = azimuth.ecliptic.setTransferProxy(
3333 validContracts,
src/bridge/views/CreateGalaxy.js+4−4
@@ -2,7 +2,7 @@ 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'
5+import * as need from '../lib/need'
66
77import { Button, } from '../components/Base'
88import { Row, Col, H1, P, Anchor } from '../components/Base'
@@ -41,7 +41,7 @@ class CreateGalaxy extends React.Component {
4141 constructor(props) {
4242 super(props)
4343
44− const galaxyOwner = n.needAddress(props);
44+ const galaxyOwner = need.address(props);
4545
4646 this.state = {
4747 galaxyOwner: galaxyOwner,
@@ -73,7 +73,7 @@ class CreateGalaxy extends React.Component {
7373 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing()
7474 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing()
7575
76− const validContracts = n.needContracts(props);
76+ const validContracts = need.contracts(props);
7777
7878 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10)
7979
@@ -94,7 +94,7 @@ class CreateGalaxy extends React.Component {
9494 return
9595 }
9696
97− const validContracts = n.needContracts(props);
97+ const validContracts = need.contracts(props);
9898
9999 const galaxyDec = ob.patp2dec(state.galaxyName)
100100
src/bridge/views/GenKeyfile.js+3−3
@@ -1,6 +1,6 @@
11import React from 'react'
22import Maybe from 'folktale/maybe'
3−import * as n from '../lib/need'
3+import * as need from '../lib/need'
44
55import { Button } from '../components/Base'
66import { Row, Col, H1, P } from '../components/Base'
@@ -25,9 +25,9 @@ class GenKeyfile extends React.Component {
2525 }
2626
2727 getPointDetails() {
28− const point = n.needPointCursor(this.props);
28+ const point = need.pointCursor(this.props);
2929
30− const pointDetails = n.needFromPointCache(this.props, point);
30+ const pointDetails = need.fromPointCache(this.props, point);
3131
3232 // in case we did SetKeys earlier this session, make sure to generate the
3333 // newer keyfile, rather than the one that will expire soon
src/bridge/views/InviteTicket.js+2−2
@@ -3,7 +3,7 @@ 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'
6+import * as need from '../lib/need'
77
88import { randomPatq } from '../lib/lib'
99import { ROUTE_NAMES } from '../lib/router'
@@ -87,7 +87,7 @@ class InviteTicket extends React.Component {
8787
8888 const addr = inviteWallet.address;
8989
90− const ctrcs = n.needContracts(this.props);
90+ const ctrcs = need.contracts(this.props);
9191
9292 const incoming = await azimuth.azimuth.getTransferringFor(ctrcs, addr)
9393
src/bridge/views/InvitesManage.js+3−3
@@ -2,7 +2,7 @@ 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'
5+import * as need from '../lib/need'
66
77import { Row, Col, Warning, Input,
88 PointInput, InnerLabel, ValidatedSigil } from '../components/Base'
@@ -32,8 +32,8 @@ class InvitesManage extends React.Component {
3232 }
3333
3434 componentDidMount() {
35− this.point = n.needPointCursor(this.props);
36− this.contracts = n.needContracts(this.props);
35+ this.point = need.pointCursor(this.props);
36+ this.contracts = need.contracts(this.props);
3737
3838 azimuth.azimuth.isSpawnProxy(
3939 this.contracts,
src/bridge/views/InvitesSend.js+5−5
@@ -1,7 +1,7 @@
11import { Just, Nothing } from 'folktale/maybe'
22import React from 'react'
33import * as azimuth from 'azimuth-js'
4−import * as n from '../lib/need'
4+import * as need from '../lib/need'
55
66import { hasReceived, sendMail } from '../lib/inviteMail'
77import { Row, Col, Button, Input, H3, Warning } from '../components/Base'
@@ -69,10 +69,10 @@ class InvitesSend extends React.Component {
6969 }
7070
7171 componentDidMount() {
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);
72+ this.point = parseInt(need.pointCursor(this.props), 10);
73+ this.address = need.address(this.props);
74+ this.contracts = need.contracts(this.props);
75+ this.web3 = need.web3(this.props);
7676
7777 console.log(azimuth.delegatedSending);
7878 azimuth.delegatedSending.getTotalUsableInvites(this.contracts, this.point)
src/bridge/views/IssueChild.js+4−4
@@ -2,7 +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'
5+import * as need from '../lib/need'
66
77import {
88 Row, Col, H1, P, Anchor,
@@ -31,7 +31,7 @@ class IssueChild extends React.Component {
3131 constructor(props) {
3232 super(props)
3333
34− const issuingPoint = parseInt(n.needPointCursor(props), 10);
34+ const issuingPoint = parseInt(need.pointCursor(props), 10);
3535
3636 const getCandidate = () => ob.patp(getSpawnCandidate(issuingPoint))
3737
@@ -66,7 +66,7 @@ class IssueChild extends React.Component {
6666 componentWillMount() {
6767 const { issuingPoint } = this.state
6868
69− const validContracts = n.needContracts(this.props);
69+ const validContracts = need.contracts(this.props);
7070
7171 azimuth.getUnspawnedChildren(validContracts, issuingPoint).then(ps => this.setState({ validChildren: new Set(ps.map(ob.patp)) }))
7272 }
@@ -97,7 +97,7 @@ class IssueChild extends React.Component {
9797 if (state.isAvailable === false) return Nothing()
9898 if (canDecodePatp(state.desiredPoint) === false) return Nothing()
9999
100− const validContracts = n.needContracts(props);
100+ const validContracts = need.contracts(props);
101101
102102 const pointDec = ob.patp2dec(state.desiredPoint)
103103
src/bridge/views/Point.js+2−2
@@ -3,7 +3,7 @@ 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'
6+import * as need from '../lib/need'
77
88import PointList from '../components/PointList'
99import ReactSVGComponents from '../components/ReactSVGComponents'
@@ -79,7 +79,7 @@ class Point extends React.Component {
7979
8080 const { spawned } = this.state
8181
82− const point = n.needPointCursor(this.props);
82+ const point = need.pointCursor(this.props);
8383
8484 const pointDetails =
8585 point in pointCache
src/bridge/views/Point/Actions.js+2−2
@@ -1,5 +1,5 @@
11import React from 'react'
2−import * as n from '../../lib/need'
2+import * as need from '../../lib/need'
33import {
44 ETH_ZERO_ADDR,
55 CURVE_ZERO_ADDR,
@@ -21,7 +21,7 @@ const Actions = (props) => {
2121 point, pointDetails, invites
2222 } = props
2323
24− const addr = n.needAddress(props);
24+ const addr = need.address(props);
2525
2626 const isOwner = pointDetails.matchWith({
2727 Nothing: _ => false,
src/bridge/views/SentTransaction.js+2−2
@@ -1,6 +1,6 @@
11import Maybe from 'folktale/maybe'
22import React from 'react'
3−import * as n from '../lib/need'
3+import * as need from '../lib/need'
44import { Row, Col, H1, H3, P, Warning, Anchor } from '../components/Base'
55import { Button } from '../components/Base'
66
@@ -128,7 +128,7 @@ const SentTransaction = (props) => {
128128
129129 const promptKeyfile = props.routeData && props.routeData.promptKeyfile
130130
131− const w3 = n.needWeb3(props);
131+ const w3 = need.web3(props);
132132
133133 const result = txnHashCursor.matchWith({
134134 Nothing: _ => { throw BRIDGE_ERROR.MISSING_TXN },
src/bridge/views/SetKeys.js+6−6
@@ -2,7 +2,7 @@ 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'
5+import * as need from '../lib/need'
66import { Row, Col, H1, P, Warning, CheckboxButton } from '../components/Base'
77
88import StatelessTransaction from '../components/StatelessTransaction'
@@ -16,7 +16,7 @@ class SetKeys extends React.Component {
1616 constructor(props) {
1717 super(props)
1818
19− const point = n.needPointCursor(props);
19+ const point = need.pointCursor(props);
2020
2121 this.state = {
2222 auth: '',
@@ -43,7 +43,7 @@ class SetKeys extends React.Component {
4343
4444 this.deriveSeed()
4545
46− const addr = n.needAddress(props);
46+ const addr = need.address(props);
4747
4848 this.determineManagementSeed(props.contracts.value, addr)
4949 }
@@ -88,9 +88,9 @@ class SetKeys extends React.Component {
8888 createUnsignedTxn() {
8989 const { state, props } = this
9090
91− const validContracts = n.needContracts(props);
91+ const validContracts = need.contracts(props);
9292
93− const validPoint = n.needPointCursor(props);
93+ const validPoint = need.pointCursor(props);
9494
9595 const hexRegExp = /[0-9A-Fa-f]{64}/g
9696
@@ -123,7 +123,7 @@ class SetKeys extends React.Component {
123123 state.networkSeed.length === 64
124124 && state.networkSeed.length === 64
125125
126− const pointDetails = n.needFromPointCache(props, state.point);
126+ const pointDetails = need.fromPointCache(props, state.point);
127127
128128 return (
129129 <Row>
src/bridge/views/SetProxy.js+4−4
@@ -1,6 +1,6 @@
11import Maybe from 'folktale/maybe'
22import React from 'react'
3−import * as n from '../lib/need'
3+import * as need from '../lib/need'
44import * as azimuth from 'azimuth-js'
55import { Row, Col, H1, P, InnerLabel, ShowBlockie, Anchor, HorizontalSelector } from '../components/Base'
66import { AddressInput } from '../components/Base'
@@ -36,7 +36,7 @@ class SetProxy extends React.Component {
3636 constructor(props) {
3737 super(props)
3838
39− const issuingPoint = n.needPointCursor(props);
39+ const issuingPoint = need.pointCursor(props);
4040
4141 this.state = {
4242 proxyAddress: '',
@@ -67,9 +67,9 @@ class SetProxy extends React.Component {
6767 createUnsignedTxn(proxyAddress) {
6868 const { state, props } = this
6969
70− const validContracts = n.needContracts(props);
70+ const validContracts = need.contracts(props);
7171
72− const validPoint = n.needPointCursor(props);
72+ const validPoint = need.pointCursor(props);
7373
7474 const txArgs = [
7575 validContracts,
src/bridge/views/Transfer.js+4−4
@@ -2,7 +2,7 @@ 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'
5+import * as need from '../lib/need'
66
77import { Row, Col, H1, InnerLabel, ShowBlockie, P, Anchor } from '../components/Base'
88import { AddressInput } from '../components/Base'
@@ -18,7 +18,7 @@ class Transfer extends React.Component {
1818 constructor(props) {
1919 super(props)
2020
21− const issuingPoint = n.needPointCursor(props);
21+ const issuingPoint = need.pointCursor(props);
2222
2323 this.state = {
2424 receivingAddress: '',
@@ -44,9 +44,9 @@ class Transfer extends React.Component {
4444 createUnsignedTxn() {
4545 const { state, props } = this
4646
47− const validContracts = n.needContracts(props);
47+ const validContracts = need.contracts(props);
4848
49− const validPoint = n.needPointCursor(props);
49+ const validPoint = need.pointCursor(props);
5050
5151 const txn = azimuth.ecliptic.setTransferProxy(
5252 validContracts,