on master help sign in
feat: use compose to compose HOCs
commite06fa4caff1ff814cd3e8e2c8459936f829400b7 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 11 Jun 2019, 15:13 (7 years ago) parentf412226
25 files changed+72−59
src/bridge/components/StatelessTransaction.js+8−5 src/bridge/lib/lib.js+11−25 src/bridge/views/AcceptTransfer.js+2−1 src/bridge/views/CancelTransfer.js+2−1 src/bridge/views/CreateGalaxy.js+2−2 src/bridge/views/InviteTicket.js+5−2 src/bridge/views/InvitesManage.js+2−1 src/bridge/views/InvitesSend.js+2−1 src/bridge/views/IssueChild.js+2−1 src/bridge/views/Keystore.js+2−1 src/bridge/views/Ledger.js+2−1 src/bridge/views/Mnemonic.js+2−1 src/bridge/views/Point.js+5−1 src/bridge/views/Points.js+5−1 src/bridge/views/PrivateKey.js+2−1 src/bridge/views/SetKeys.js+2−1 src/bridge/views/SetProxy.js+2−1 src/bridge/views/Shards.js+2−1 src/bridge/views/Ticket.js+2−2 src/bridge/views/Transfer.js+2−1 src/bridge/views/Trezor.js+2−1 src/bridge/views/ViewPoint.js+2−1 src/bridge/views/Wallet.js+2−1 src/walletgen/lib/lib.js+1−4 src/walletgen/views/Upload.js+1−1
src/bridge/components/StatelessTransaction.js+8−5
@@ -10,9 +10,8 @@ import { Warning } from '../components/Base';
1010
1111import { BRIDGE_ERROR } from '../lib/error';
1212import { ROUTE_NAMES } from '../lib/routeNames';
13−import { withHistory } from '../store/history';
13+import { compose } from '../lib/lib';
1414import * as tank from '../lib/tank';
15−
1615import {
1716 sendSignedTransaction,
1817 fromWei,
@@ -21,8 +20,10 @@ import {
2120 renderSignedTx,
2221 signTransaction,
2322} from '../lib/txn';
23+
2424import { withTxnConfirmations } from '../store/txnConfirmations';
2525import { withNetwork } from '../store/network';
26+import { withHistory } from '../store/history';
2627
2728const SUBMISSION_STATES = {
2829 PROMPT: 'Send transaction',
@@ -580,6 +581,8 @@ class StatelessTransaction extends React.Component {
580581 }
581582}
582583
583−export default withNetwork(
584− withTxnConfirmations(withHistory(StatelessTransaction))
585−);
584+export default compose(
585+ withNetwork,
586+ withTxnConfirmations,
587+ withHistory
588+)(StatelessTransaction);
src/bridge/lib/lib.js+11−25
@@ -1,26 +1,26 @@
11import * as ob from 'urbit-ob';
22
3−const compose = (...fs) =>
3+export const compose = (...fs) =>
44 fs.reduceRight((pF, nF) => (...args) => nF(pF(...args)), v => v);
55
6−const allFalse = (...args) => args.every(a => a === false);
6+export const allFalse = (...args) => args.every(a => a === false);
77
8−const isLast = (l, i) => i === l - 1;
8+export const isLast = (l, i) => i === l - 1;
99
10−const isUndefined = v => v === undefined;
10+export const isUndefined = v => v === undefined;
1111
12−const defaultTo = (v, d) => (isUndefined(v) ? d : v);
12+export const defaultTo = (v, d) => (isUndefined(v) ? d : v);
1313
14−const seq = n => Array.from(Array(n), (_, i) => i);
14+export const seq = n => Array.from(Array(n), (_, i) => i);
1515
16−const fill = (n, v) => Array.from(Array(n), () => v);
16+export const fill = (n, v) => Array.from(Array(n), () => v);
1717
1818// Terse true/false checks
19−const t = v => v === true;
19+export const t = v => v === true;
2020
21−const f = v => v === false;
21+export const f = v => v === false;
2222
23−const isValidGalaxy = name => {
23+export const isValidGalaxy = name => {
2424 let point;
2525 try {
2626 point = parseInt(ob.patp2dec(name), 10);
@@ -30,7 +30,7 @@ const isValidGalaxy = name => {
3030 return point >= 0 && point < 256;
3131};
3232
33−const randomPatq = len => {
33+export const randomPatq = len => {
3434 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
3535 let hex = bytes.reduce(
3636 (acc, byt) => acc + byt.toString(16).padStart(2, '0'),
@@ -38,17 +38,3 @@ const randomPatq = len => {
3838 );
3939 return ob.hex2patq(hex);
4040};
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';
1515import { NETWORK_TYPES } from '../lib/network';
1616import { isValidAddress } from '../lib/wallet';
1717import { withNetwork } from '../store/network';
18+import { compose } from '../lib/lib';
1819
1920class AcceptTransfer extends React.Component {
2021 constructor(props) {
@@ -118,4 +119,4 @@ class AcceptTransfer extends React.Component {
118119 }
119120}
120121
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';
88import StatelessTransaction from '../components/StatelessTransaction';
99import { ETH_ZERO_ADDR } from '../lib/wallet';
1010import { withNetwork } from '../store/network';
11+import { compose } from '../lib/lib';
1112
1213class CancelTransfer extends React.Component {
1314 constructor(props) {
@@ -74,4 +75,4 @@ class CancelTransfer extends React.Component {
7475 }
7576}
7677
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';
2020
2121import { ETH_ZERO_ADDR, isValidAddress, eqAddr } from '../lib/wallet';
2222
23−import { isValidGalaxy } from '../lib/lib';
23+import { isValidGalaxy, compose } from '../lib/lib';
2424import { withNetwork } from '../store/network';
2525
2626const buttonTriState = status => {
@@ -195,4 +195,4 @@ class CreateGalaxy extends React.Component {
195195 }
196196}
197197
198−export default withNetwork(CreateGalaxy);
198+export default compose(withNetwork)(CreateGalaxy);
src/bridge/views/InviteTicket.js+5−2
@@ -13,7 +13,7 @@ import {
1313import * as azimuth from 'azimuth-js';
1414import * as need from '../lib/need';
1515
16−import { randomPatq } from '../lib/lib';
16+import { randomPatq, compose } from '../lib/lib';
1717import { ROUTE_NAMES } from '../lib/routeNames';
1818import { withHistory } from '../store/history';
1919import {
@@ -423,4 +423,7 @@ class InviteTicket extends React.Component {
423423 }
424424}
425425
426−export default withNetwork(withHistory(InviteTicket));
426+export default compose(
427+ withNetwork,
428+ withHistory
429+)(InviteTicket);
src/bridge/views/InvitesManage.js+2−1
@@ -15,6 +15,7 @@ import {
1515} from '../components/Base';
1616import StatelessTransaction from '../components/StatelessTransaction';
1717import { withNetwork } from '../store/network';
18+import { compose } from '../lib/lib';
1819
1920class InvitesManage extends React.Component {
2021 constructor(props) {
@@ -183,4 +184,4 @@ class InvitesManage extends React.Component {
183184 }
184185}
185186
186−export default withNetwork(InvitesManage);
187+export default compose(withNetwork)(InvitesManage);
src/bridge/views/InvitesSend.js+2−1
@@ -20,6 +20,7 @@ import {
2020} from '../lib/txn';
2121import * as tank from '../lib/tank';
2222import { withNetwork } from '../store/network';
23+import { compose } from '../lib/lib';
2324
2425const GAS_PRICE_GWEI = 20; // we pay the premium for faster ux
2526const GAS_LIMIT = 350000;
@@ -492,4 +493,4 @@ class InvitesSend extends React.Component {
492493 }
493494}
494495
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';
2525
2626import { isValidAddress } from '../lib/wallet';
2727import { withNetwork } from '../store/network';
28+import { compose } from '../lib/lib';
2829
2930const setFind = (set, pred) => {
3031 for (const e of set) {
@@ -254,4 +255,4 @@ class IssueChild extends React.Component {
254255 }
255256}
256257
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';
1010import { ROUTE_NAMES } from '../lib/routeNames';
1111import { withHistory } from '../store/history';
1212import { EthereumWallet } from '../lib/wallet';
13+import { compose } from '../lib/lib';
1314
1415class Keystore extends React.Component {
1516 constructor(props) {
@@ -159,4 +160,4 @@ class Keystore extends React.Component {
159160 }
160161}
161162
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';
1111import { LEDGER_LIVE_PATH, LEDGER_LEGACY_PATH } from '../lib/ledger';
1212import { ROUTE_NAMES } from '../lib/routeNames';
1313import { withHistory } from '../store/history';
14+import { compose } from '../lib/lib';
1415
1516const chopHdPrefix = str => (str.slice(0, 2) === 'm/' ? str.slice(2) : str);
1617
@@ -217,4 +218,4 @@ class Ledger extends React.Component {
217218 }
218219}
219220
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';
1313import { ROUTE_NAMES } from '../lib/routeNames';
1414import { withHistory } from '../store/history';
1515import { DEFAULT_HD_PATH, walletFromMnemonic } from '../lib/wallet';
16+import { compose } from '../lib/lib';
1617
1718class Mnemonic extends React.Component {
1819 constructor(props) {
@@ -160,4 +161,4 @@ class Mnemonic extends React.Component {
160161 }
161162}
162163
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';
1212import { Row, Col, H1, H3 } from '../components/Base';
1313import { withHistory } from '../store/history';
1414import { withNetwork } from '../store/network';
15+import { compose } from '../lib/lib';
1516
1617class Point extends React.Component {
1718 constructor(props) {
@@ -136,4 +137,7 @@ class Point extends React.Component {
136137 }
137138}
138139
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';
99import { withHistory } from '../store/history';
1010import { ETH_ZERO_ADDR, eqAddr } from '../lib/wallet';
1111import { withNetwork } from '../store/network';
12+import { compose } from '../lib/lib';
1213
1314const hasTransferProxy = (cache, point) =>
1415 point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false;
@@ -256,4 +257,7 @@ class Points extends React.Component {
256257 }
257258}
258259
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';
77import { ROUTE_NAMES } from '../lib/routeNames';
88import { withHistory } from '../store/history';
99import { EthereumWallet } from '../lib/wallet';
10+import { compose } from '../lib/lib';
1011
1112class PrivateKey extends React.Component {
1213 constructor(props) {
@@ -73,4 +74,4 @@ class PrivateKey extends React.Component {
7374 }
7475}
7576
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';
1212
1313import { addHexPrefix } from '../lib/wallet';
1414import { withNetwork } from '../store/network';
15+import { compose } from '../lib/lib';
1516
1617class SetKeys extends React.Component {
1718 constructor(props) {
@@ -197,4 +198,4 @@ class SetKeys extends React.Component {
197198 }
198199}
199200
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';
2323
2424import { isValidAddress } from '../lib/wallet';
2525import { withNetwork } from '../store/network';
26+import { compose } from '../lib/lib';
2627
2728class _SetProxy extends React.Component {
2829 constructor(props) {
@@ -168,7 +169,7 @@ class _SetProxy extends React.Component {
168169 }
169170}
170171
171−const SetProxy = withNetwork(_SetProxy);
172+const SetProxy = compose(withNetwork)(_SetProxy);
172173
173174export const SetManagementProxy = props => (
174175 <SetProxy {...props} proxyType={PROXY_TYPE.MANAGEMENT_PROXY} />
src/bridge/views/Shards.js+2−1
@@ -16,6 +16,7 @@ import * as ob from 'urbit-ob';
1616import { ROUTE_NAMES } from '../lib/routeNames';
1717import { withHistory } from '../store/history';
1818import { urbitWalletFromTicket } from '../lib/wallet';
19+import { compose } from '../lib/lib';
1920
2021const placeholder = len => {
2122 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
@@ -211,4 +212,4 @@ class Shards extends React.Component {
211212 }
212213}
213214
214−export default withHistory(Shards);
215+export default compose(withHistory)(Shards);
src/bridge/views/Ticket.js+2−2
@@ -11,7 +11,7 @@ import {
1111} from '../components/Base';
1212import { Row, Col, H1, P } from '../components/Base';
1313
14−import { randomPatq } from '../lib/lib';
14+import { randomPatq, compose } from '../lib/lib';
1515import { ROUTE_NAMES } from '../lib/routeNames';
1616import { withHistory } from '../store/history';
1717import { urbitWalletFromTicket } from '../lib/wallet';
@@ -150,4 +150,4 @@ class Ticket extends React.Component {
150150 }
151151}
152152
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';
2020
2121import { isValidAddress } from '../lib/wallet';
2222import { withNetwork } from '../store/network';
23+import { compose } from '../lib/lib';
2324
2425class Transfer extends React.Component {
2526 constructor(props) {
@@ -131,4 +132,4 @@ class Transfer extends React.Component {
131132 }
132133}
133134
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';
1010import { TREZOR_PATH } from '../lib/trezor';
1111import { ROUTE_NAMES } from '../lib/routeNames';
1212import { withHistory } from '../store/history';
13+import { compose } from '../lib/lib';
1314
1415class Trezor extends React.Component {
1516 constructor(props) {
@@ -139,4 +140,4 @@ class Trezor extends React.Component {
139140 }
140141}
141142
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';
88
99import { ROUTE_NAMES } from '../lib/routeNames';
1010import { withHistory } from '../store/history';
11+import { compose } from '../lib/lib';
1112
1213class ViewPoint extends React.Component {
1314 constructor(props) {
@@ -80,4 +81,4 @@ class ViewPoint extends React.Component {
8081 }
8182}
8283
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';
77import { ROUTE_NAMES } from '../lib/routeNames';
88import { withHistory } from '../store/history';
99import { WALLET_NAMES, renderWalletType } from '../lib/wallet';
10+import { compose } from '../lib/lib';
1011
1112class Wallet extends React.Component {
1213 componentDidMount() {
@@ -104,4 +105,4 @@ class Wallet extends React.Component {
104105 }
105106}
106107
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) =>
6868
6969const seq = num => Array.from(Array(num), (_, i) => i);
7070
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';
33import Button from '../components/Button';
44import UploadButton from '../components/UploadButton';
55
6−import { compose } from '../lib/lib';
6+import { compose } from '../../bridge/lib/lib';
77
88import { PROFILE_STATES } from '../lib/constants';
99