on master help sign in
feat: use compose to compose HOCs
e06fa4cMatt Condon (shrugs)
src/bridge/components/StatelessTransaction.js+8−5
@@ -10,9 +10,8 @@ import { Warning } from '../components/Base';
10
10
11import { BRIDGE_ERROR } from '../lib/error';
11import { BRIDGE_ERROR } from '../lib/error';
12import { ROUTE_NAMES } from '../lib/routeNames';
12import { ROUTE_NAMES } from '../lib/routeNames';
13−import { withHistory } from '../store/history';
13+import { compose } from '../lib/lib';
14import * as tank from '../lib/tank';
14import * as tank from '../lib/tank';
15−
16import {
15import {
17 sendSignedTransaction,
16 sendSignedTransaction,
18 fromWei,
17 fromWei,
@@ -21,8 +20,10 @@ import {
21 renderSignedTx,
20 renderSignedTx,
22 signTransaction,
21 signTransaction,
23} from '../lib/txn';
22} from '../lib/txn';
23+
24import { withTxnConfirmations } from '../store/txnConfirmations';
24import { withTxnConfirmations } from '../store/txnConfirmations';
25import { withNetwork } from '../store/network';
25import { withNetwork } from '../store/network';
26+import { withHistory } from '../store/history';
26
27
27const SUBMISSION_STATES = {
28const SUBMISSION_STATES = {
28 PROMPT: 'Send transaction',
29 PROMPT: 'Send transaction',
@@ -580,6 +581,8 @@ class StatelessTransaction extends React.Component {
580 }
581 }
581}
582}
582
583
584+export default compose(
583−export default withNetwork(
585+ withNetwork,
584− withTxnConfirmations(withHistory(StatelessTransaction))
586+ withTxnConfirmations,
585−);
587+ withHistory
588+)(StatelessTransaction);
src/bridge/lib/lib.js+11−25
@@ -1,26 +1,26 @@
1import * as ob from 'urbit-ob';
1import * as ob from 'urbit-ob';
2
2
3−const compose = (...fs) =>
3+export const compose = (...fs) =>
4 fs.reduceRight((pF, nF) => (...args) => nF(pF(...args)), v => v);
4 fs.reduceRight((pF, nF) => (...args) => nF(pF(...args)), v => v);
5
5
6−const allFalse = (...args) => args.every(a => a === false);
6+export const allFalse = (...args) => args.every(a => a === false);
7
7
8−const isLast = (l, i) => i === l - 1;
8+export const isLast = (l, i) => i === l - 1;
9
9
10−const isUndefined = v => v === undefined;
10+export const isUndefined = v => v === undefined;
11
11
12−const defaultTo = (v, d) => (isUndefined(v) ? d : v);
12+export const defaultTo = (v, d) => (isUndefined(v) ? d : v);
13
13
14−const seq = n => Array.from(Array(n), (_, i) => i);
14+export const seq = n => Array.from(Array(n), (_, i) => i);
15
15
16−const fill = (n, v) => Array.from(Array(n), () => v);
16+export const fill = (n, v) => Array.from(Array(n), () => v);
17
17
18// Terse true/false checks
18// Terse true/false checks
19−const t = v => v === true;
19+export const t = v => v === true;
20
20
21−const f = v => v === false;
21+export const f = v => v === false;
22
22
23−const isValidGalaxy = name => {
23+export const isValidGalaxy = name => {
24 let point;
24 let point;
25 try {
25 try {
26 point = parseInt(ob.patp2dec(name), 10);
26 point = parseInt(ob.patp2dec(name), 10);
@@ -30,7 +30,7 @@ const isValidGalaxy = name => {
30 return point >= 0 && point < 256;
30 return point >= 0 && point < 256;
31};
31};
32
32
33−const randomPatq = len => {
33+export const randomPatq = len => {
34 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
34 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
35 let hex = bytes.reduce(
35 let hex = bytes.reduce(
36 (acc, byt) => acc + byt.toString(16).padStart(2, '0'),
36 (acc, byt) => acc + byt.toString(16).padStart(2, '0'),
@@ -38,17 +38,3 @@ const randomPatq = len => {
38 );
38 );
39 return ob.hex2patq(hex);
39 return ob.hex2patq(hex);
40};
40};
41−
42−export {
43− compose,
44− allFalse,
45− isLast,
46− isUndefined,
47− defaultTo,
48− seq,
49− fill,
50− t,
51− f,
52− isValidGalaxy,
53− randomPatq,
54−};
src/bridge/views/AcceptTransfer.js+2−1
@@ -15,6 +15,7 @@ import StatelessTransaction from '../components/StatelessTransaction';
15import { NETWORK_TYPES } from '../lib/network';
15import { NETWORK_TYPES } from '../lib/network';
16import { isValidAddress } from '../lib/wallet';
16import { isValidAddress } from '../lib/wallet';
17import { withNetwork } from '../store/network';
17import { withNetwork } from '../store/network';
18+import { compose } from '../lib/lib';
18
19
19class AcceptTransfer extends React.Component {
20class AcceptTransfer extends React.Component {
20 constructor(props) {
21 constructor(props) {
@@ -118,4 +119,4 @@ class AcceptTransfer extends React.Component {
118 }
119 }
119}
120}
120
121
121−export default withNetwork(AcceptTransfer);
122+export default compose(withNetwork)(AcceptTransfer);
src/bridge/views/CancelTransfer.js+2−1
@@ -8,6 +8,7 @@ import * as need from '../lib/need';
8import StatelessTransaction from '../components/StatelessTransaction';
8import StatelessTransaction from '../components/StatelessTransaction';
9import { ETH_ZERO_ADDR } from '../lib/wallet';
9import { ETH_ZERO_ADDR } from '../lib/wallet';
10import { withNetwork } from '../store/network';
10import { withNetwork } from '../store/network';
11+import { compose } from '../lib/lib';
11
12
12class CancelTransfer extends React.Component {
13class CancelTransfer extends React.Component {
13 constructor(props) {
14 constructor(props) {
@@ -74,4 +75,4 @@ class CancelTransfer extends React.Component {
74 }
75 }
75}
76}
76
77
77−export default withNetwork(CancelTransfer);
78+export default compose(withNetwork)(CancelTransfer);
src/bridge/views/CreateGalaxy.js+2−2
@@ -20,7 +20,7 @@ import { canDecodePatp } from '../lib/txn';
20
20
21import { ETH_ZERO_ADDR, isValidAddress, eqAddr } from '../lib/wallet';
21import { ETH_ZERO_ADDR, isValidAddress, eqAddr } from '../lib/wallet';
22
22
23−import { isValidGalaxy } from '../lib/lib';
23+import { isValidGalaxy, compose } from '../lib/lib';
24import { withNetwork } from '../store/network';
24import { withNetwork } from '../store/network';
25
25
26const buttonTriState = status => {
26const buttonTriState = status => {
@@ -195,4 +195,4 @@ class CreateGalaxy extends React.Component {
195 }
195 }
196}
196}
197
197
198−export default withNetwork(CreateGalaxy);
198+export default compose(withNetwork)(CreateGalaxy);
src/bridge/views/InviteTicket.js+5−2
@@ -13,7 +13,7 @@ import {
13import * as azimuth from 'azimuth-js';
13import * as azimuth from 'azimuth-js';
14import * as need from '../lib/need';
14import * as need from '../lib/need';
15
15
16−import { randomPatq } from '../lib/lib';
16+import { randomPatq, compose } from '../lib/lib';
17import { ROUTE_NAMES } from '../lib/routeNames';
17import { ROUTE_NAMES } from '../lib/routeNames';
18import { withHistory } from '../store/history';
18import { withHistory } from '../store/history';
19import {
19import {
@@ -423,4 +423,7 @@ class InviteTicket extends React.Component {
423 }
423 }
424}
424}
425
425
426+export default compose(
427+ withNetwork,
428+ withHistory
426−export default withNetwork(withHistory(InviteTicket));
429+)(InviteTicket);
src/bridge/views/InvitesManage.js+2−1
@@ -15,6 +15,7 @@ import {
15} from '../components/Base';
15} from '../components/Base';
16import StatelessTransaction from '../components/StatelessTransaction';
16import StatelessTransaction from '../components/StatelessTransaction';
17import { withNetwork } from '../store/network';
17import { withNetwork } from '../store/network';
18+import { compose } from '../lib/lib';
18
19
19class InvitesManage extends React.Component {
20class InvitesManage extends React.Component {
20 constructor(props) {
21 constructor(props) {
@@ -183,4 +184,4 @@ class InvitesManage extends React.Component {
183 }
184 }
184}
185}
185
186
186−export default withNetwork(InvitesManage);
187+export default compose(withNetwork)(InvitesManage);
src/bridge/views/InvitesSend.js+2−1
@@ -20,6 +20,7 @@ import {
20} from '../lib/txn';
20} from '../lib/txn';
21import * as tank from '../lib/tank';
21import * as tank from '../lib/tank';
22import { withNetwork } from '../store/network';
22import { withNetwork } from '../store/network';
23+import { compose } from '../lib/lib';
23
24
24const GAS_PRICE_GWEI = 20; // we pay the premium for faster ux
25const GAS_PRICE_GWEI = 20; // we pay the premium for faster ux
25const GAS_LIMIT = 350000;
26const GAS_LIMIT = 350000;
@@ -492,4 +493,4 @@ class InvitesSend extends React.Component {
492 }
493 }
493}
494}
494
495
495−export default withNetwork(InvitesSend);
496+export default compose(withNetwork)(InvitesSend);
src/bridge/views/IssueChild.js+2−1
@@ -25,6 +25,7 @@ import { canDecodePatp } from '../lib/txn';
25
25
26import { isValidAddress } from '../lib/wallet';
26import { isValidAddress } from '../lib/wallet';
27import { withNetwork } from '../store/network';
27import { withNetwork } from '../store/network';
28+import { compose } from '../lib/lib';
28
29
29const setFind = (set, pred) => {
30const setFind = (set, pred) => {
30 for (const e of set) {
31 for (const e of set) {
@@ -254,4 +255,4 @@ class IssueChild extends React.Component {
254 }
255 }
255}
256}
256
257
257−export default withNetwork(IssueChild);
258+export default compose(withNetwork)(IssueChild);
src/bridge/views/Keystore.js+2−1
@@ -10,6 +10,7 @@ import { BRIDGE_ERROR } from '../lib/error';
10import { ROUTE_NAMES } from '../lib/routeNames';
10import { ROUTE_NAMES } from '../lib/routeNames';
11import { withHistory } from '../store/history';
11import { withHistory } from '../store/history';
12import { EthereumWallet } from '../lib/wallet';
12import { EthereumWallet } from '../lib/wallet';
13+import { compose } from '../lib/lib';
13
14
14class Keystore extends React.Component {
15class Keystore extends React.Component {
15 constructor(props) {
16 constructor(props) {
@@ -159,4 +160,4 @@ class Keystore extends React.Component {
159 }
160 }
160}
161}
161
162
162−export default withHistory(Keystore);
163+export default compose(withHistory)(Keystore);
src/bridge/views/Ledger.js+2−1
@@ -11,6 +11,7 @@ import * as secp256k1 from 'secp256k1';
11import { LEDGER_LIVE_PATH, LEDGER_LEGACY_PATH } from '../lib/ledger';
11import { LEDGER_LIVE_PATH, LEDGER_LEGACY_PATH } from '../lib/ledger';
12import { ROUTE_NAMES } from '../lib/routeNames';
12import { ROUTE_NAMES } from '../lib/routeNames';
13import { withHistory } from '../store/history';
13import { withHistory } from '../store/history';
14+import { compose } from '../lib/lib';
14
15
15const chopHdPrefix = str => (str.slice(0, 2) === 'm/' ? str.slice(2) : str);
16const chopHdPrefix = str => (str.slice(0, 2) === 'm/' ? str.slice(2) : str);
16
17
@@ -217,4 +218,4 @@ class Ledger extends React.Component {
217 }
218 }
218}
219}
219
220
220−export default withHistory(Ledger);
221+export default compose(withHistory)(Ledger);
src/bridge/views/Mnemonic.js+2−1
@@ -13,6 +13,7 @@ import { Row, Col, H1 } from '../components/Base';
13import { ROUTE_NAMES } from '../lib/routeNames';
13import { ROUTE_NAMES } from '../lib/routeNames';
14import { withHistory } from '../store/history';
14import { withHistory } from '../store/history';
15import { DEFAULT_HD_PATH, walletFromMnemonic } from '../lib/wallet';
15import { DEFAULT_HD_PATH, walletFromMnemonic } from '../lib/wallet';
16+import { compose } from '../lib/lib';
16
17
17class Mnemonic extends React.Component {
18class Mnemonic extends React.Component {
18 constructor(props) {
19 constructor(props) {
@@ -160,4 +161,4 @@ class Mnemonic extends React.Component {
160 }
161 }
161}
162}
162
163
163−export default withHistory(Mnemonic);
164+export default compose(withHistory)(Mnemonic);
src/bridge/views/Point.js+5−1
@@ -12,6 +12,7 @@ import Actions from './Point/Actions';
12import { Row, Col, H1, H3 } from '../components/Base';
12import { Row, Col, H1, H3 } from '../components/Base';
13import { withHistory } from '../store/history';
13import { withHistory } from '../store/history';
14import { withNetwork } from '../store/network';
14import { withNetwork } from '../store/network';
15+import { compose } from '../lib/lib';
15
16
16class Point extends React.Component {
17class Point extends React.Component {
17 constructor(props) {
18 constructor(props) {
@@ -136,4 +137,7 @@ class Point extends React.Component {
136 }
137 }
137}
138}
138
139
139−export default withNetwork(withHistory(Point));
140+export default compose(
141+ withNetwork,
142+ withHistory
143+)(Point);
src/bridge/views/Points.js+5−1
@@ -9,6 +9,7 @@ import { ROUTE_NAMES } from '../lib/routeNames';
9import { withHistory } from '../store/history';
9import { withHistory } from '../store/history';
10import { ETH_ZERO_ADDR, eqAddr } from '../lib/wallet';
10import { ETH_ZERO_ADDR, eqAddr } from '../lib/wallet';
11import { withNetwork } from '../store/network';
11import { withNetwork } from '../store/network';
12+import { compose } from '../lib/lib';
12
13
13const hasTransferProxy = (cache, point) =>
14const hasTransferProxy = (cache, point) =>
14 point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false;
15 point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false;
@@ -256,4 +257,7 @@ class Points extends React.Component {
256 }
257 }
257}
258}
258
259
259−export default withNetwork(withHistory(Points));
260+export default compose(
261+ withNetwork,
262+ withHistory
263+)(Points);
src/bridge/views/PrivateKey.js+2−1
@@ -7,6 +7,7 @@ import { Row, Col, H1 } from '../components/Base';
7import { ROUTE_NAMES } from '../lib/routeNames';
7import { ROUTE_NAMES } from '../lib/routeNames';
8import { withHistory } from '../store/history';
8import { withHistory } from '../store/history';
9import { EthereumWallet } from '../lib/wallet';
9import { EthereumWallet } from '../lib/wallet';
10+import { compose } from '../lib/lib';
10
11
11class PrivateKey extends React.Component {
12class PrivateKey extends React.Component {
12 constructor(props) {
13 constructor(props) {
@@ -73,4 +74,4 @@ class PrivateKey extends React.Component {
73 }
74 }
74}
75}
75
76
76−export default withHistory(PrivateKey);
77+export default compose(withHistory)(PrivateKey);
src/bridge/views/SetKeys.js+2−1
@@ -12,6 +12,7 @@ import * as kg from 'urbit-key-generation/dist/index';
12
12
13import { addHexPrefix } from '../lib/wallet';
13import { addHexPrefix } from '../lib/wallet';
14import { withNetwork } from '../store/network';
14import { withNetwork } from '../store/network';
15+import { compose } from '../lib/lib';
15
16
16class SetKeys extends React.Component {
17class SetKeys extends React.Component {
17 constructor(props) {
18 constructor(props) {
@@ -197,4 +198,4 @@ class SetKeys extends React.Component {
197 }
198 }
198}
199}
199
200
200−export default withNetwork(SetKeys);
201+export default compose(withNetwork)(SetKeys);
src/bridge/views/SetProxy.js+2−1
@@ -23,6 +23,7 @@ import StatelessTransaction from '../components/StatelessTransaction';
23
23
24import { isValidAddress } from '../lib/wallet';
24import { isValidAddress } from '../lib/wallet';
25import { withNetwork } from '../store/network';
25import { withNetwork } from '../store/network';
26+import { compose } from '../lib/lib';
26
27
27class _SetProxy extends React.Component {
28class _SetProxy extends React.Component {
28 constructor(props) {
29 constructor(props) {
@@ -168,7 +169,7 @@ class _SetProxy extends React.Component {
168 }
169 }
169}
170}
170
171
171−const SetProxy = withNetwork(_SetProxy);
172+const SetProxy = compose(withNetwork)(_SetProxy);
172
173
173export const SetManagementProxy = props => (
174export const SetManagementProxy = props => (
174 <SetProxy {...props} proxyType={PROXY_TYPE.MANAGEMENT_PROXY} />
175 <SetProxy {...props} proxyType={PROXY_TYPE.MANAGEMENT_PROXY} />
src/bridge/views/Shards.js+2−1
@@ -16,6 +16,7 @@ import * as ob from 'urbit-ob';
16import { ROUTE_NAMES } from '../lib/routeNames';
16import { ROUTE_NAMES } from '../lib/routeNames';
17import { withHistory } from '../store/history';
17import { withHistory } from '../store/history';
18import { urbitWalletFromTicket } from '../lib/wallet';
18import { urbitWalletFromTicket } from '../lib/wallet';
19+import { compose } from '../lib/lib';
19
20
20const placeholder = len => {
21const placeholder = len => {
21 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
22 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
@@ -211,4 +212,4 @@ class Shards extends React.Component {
211 }
212 }
212}
213}
213
214
214−export default withHistory(Shards);
215+export default compose(withHistory)(Shards);
src/bridge/views/Ticket.js+2−2
@@ -11,7 +11,7 @@ import {
11} from '../components/Base';
11} from '../components/Base';
12import { Row, Col, H1, P } from '../components/Base';
12import { Row, Col, H1, P } from '../components/Base';
13
13
14−import { randomPatq } from '../lib/lib';
14+import { randomPatq, compose } from '../lib/lib';
15import { ROUTE_NAMES } from '../lib/routeNames';
15import { ROUTE_NAMES } from '../lib/routeNames';
16import { withHistory } from '../store/history';
16import { withHistory } from '../store/history';
17import { urbitWalletFromTicket } from '../lib/wallet';
17import { urbitWalletFromTicket } from '../lib/wallet';
@@ -150,4 +150,4 @@ class Ticket extends React.Component {
150 }
150 }
151}
151}
152
152
153−export default withHistory(Ticket);
153+export default compose(withHistory)(Ticket);
src/bridge/views/Transfer.js+2−1
@@ -20,6 +20,7 @@ import { NETWORK_TYPES } from '../lib/network';
20
20
21import { isValidAddress } from '../lib/wallet';
21import { isValidAddress } from '../lib/wallet';
22import { withNetwork } from '../store/network';
22import { withNetwork } from '../store/network';
23+import { compose } from '../lib/lib';
23
24
24class Transfer extends React.Component {
25class Transfer extends React.Component {
25 constructor(props) {
26 constructor(props) {
@@ -131,4 +132,4 @@ class Transfer extends React.Component {
131 }
132 }
132}
133}
133
134
134−export default withNetwork(Transfer);
135+export default compose(withNetwork)(Transfer);
src/bridge/views/Trezor.js+2−1
@@ -10,6 +10,7 @@ import * as secp256k1 from 'secp256k1';
10import { TREZOR_PATH } from '../lib/trezor';
10import { TREZOR_PATH } from '../lib/trezor';
11import { ROUTE_NAMES } from '../lib/routeNames';
11import { ROUTE_NAMES } from '../lib/routeNames';
12import { withHistory } from '../store/history';
12import { withHistory } from '../store/history';
13+import { compose } from '../lib/lib';
13
14
14class Trezor extends React.Component {
15class Trezor extends React.Component {
15 constructor(props) {
16 constructor(props) {
@@ -139,4 +140,4 @@ class Trezor extends React.Component {
139 }
140 }
140}
141}
141
142
142−export default withHistory(Trezor);
143+export default compose(withHistory)(Trezor);
src/bridge/views/ViewPoint.js+2−1
@@ -8,6 +8,7 @@ import { InnerLabel, PointInput, ValidatedSigil } from '../components/Base';
8
8
9import { ROUTE_NAMES } from '../lib/routeNames';
9import { ROUTE_NAMES } from '../lib/routeNames';
10import { withHistory } from '../store/history';
10import { withHistory } from '../store/history';
11+import { compose } from '../lib/lib';
11
12
12class ViewPoint extends React.Component {
13class ViewPoint extends React.Component {
13 constructor(props) {
14 constructor(props) {
@@ -80,4 +81,4 @@ class ViewPoint extends React.Component {
80 }
81 }
81}
82}
82
83
83−export default withHistory(ViewPoint);
84+export default compose(withHistory)(ViewPoint);
src/bridge/views/Wallet.js+2−1
@@ -7,6 +7,7 @@ import { Row, Col } from '../components/Base';
7import { ROUTE_NAMES } from '../lib/routeNames';
7import { ROUTE_NAMES } from '../lib/routeNames';
8import { withHistory } from '../store/history';
8import { withHistory } from '../store/history';
9import { WALLET_NAMES, renderWalletType } from '../lib/wallet';
9import { WALLET_NAMES, renderWalletType } from '../lib/wallet';
10+import { compose } from '../lib/lib';
10
11
11class Wallet extends React.Component {
12class Wallet extends React.Component {
12 componentDidMount() {
13 componentDidMount() {
@@ -104,4 +105,4 @@ class Wallet extends React.Component {
104 }
105 }
105}
106}
106
107
107−export default withHistory(Wallet);
108+export default compose(withHistory)(Wallet);
src/walletgen/lib/lib.js+1−4
@@ -68,7 +68,4 @@ const generateOwnershipWallet = (ship, ticket) =>
68
68
69const seq = num => Array.from(Array(num), (_, i) => i);
69const seq = num => Array.from(Array(num), (_, i) => i);
70
70
71−const compose = (...fs) =>
72− fs.reduceRight((pF, nF) => (...args) => nF(pF(...args)), v => v);
73−
74−export { makeTicket, generateWallet, generateOwnershipWallet, compose, seq };
71+export { makeTicket, generateWallet, generateOwnershipWallet, seq };
src/walletgen/views/Upload.js+1−1
@@ -3,7 +3,7 @@ import React, { Component } from 'react';
3import Button from '../components/Button';
3import Button from '../components/Button';
4import UploadButton from '../components/UploadButton';
4import UploadButton from '../components/UploadButton';
5
5
6−import { compose } from '../lib/lib';
6+import { compose } from '../../bridge/lib/lib';
7
7
8import { PROFILE_STATES } from '../lib/constants';
8import { PROFILE_STATES } from '../lib/constants';
9
9