on master help sign in
feat: extract wallet to container
commit0770795060f721fc9e664655e4f2fcc7e6ac33b8 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateWed 12 Jun 2019, 17:20 (7 years ago) parentcf42d8d
22 files changed+225−135
src/bridge/Bridge.js+29−78 src/bridge/components/Header.js+7−2 src/bridge/components/Passport.js+3−1 src/bridge/components/StatelessTransaction.js+3−1 src/bridge/lib/invite.js+2−2 src/bridge/lib/keys.js+4−5 src/bridge/lib/txn.js+4−4 src/bridge/lib/wallet.js+9−9 src/bridge/store/wallet.js+86 src/bridge/views/GenKeyfile.js+3−1 src/bridge/views/InvitesSend.js+5−1 src/bridge/views/Keystore.js+5−1 src/bridge/views/Ledger.js+5−1 src/bridge/views/Mnemonic.js+5−1 src/bridge/views/Point.js+3−1 src/bridge/views/Points.js+4−3 src/bridge/views/PrivateKey.js+5−1 src/bridge/views/SetKeys.js+8−4 src/bridge/views/Shards.js+5−1 src/bridge/views/Ticket.js+5−1 src/bridge/views/Trezor.js+5−1 src/bridge/views/Wallet.js+20−16
src/bridge/Bridge.js+29−78
@@ -1,44 +1,47 @@
11import React from 'react';
22import { Just, Nothing } from 'folktale/maybe';
3−import { includes } from 'lodash';
43
54import Footer from './components/Footer';
65import Header from './components/Header';
76import { Container, Row, Col } from './components/Base';
87
8+import nest from './lib/nest';
99import { router } from './lib/router';
1010import { ROUTE_NAMES } from './lib/routeNames';
11−import { HistoryProvider, withHistory, useHistory } from './store/history';
12−import { TxnConfirmationsProvider } from './store/txnConfirmations';
1311import { NETWORK_TYPES } from './lib/network';
14−import {
15− WALLET_NAMES,
16− DEFAULT_HD_PATH,
17− walletFromMnemonic,
18− addressFromSecp256k1Public,
19−} from './lib/wallet';
20−import { BRIDGE_ERROR } from './lib/error';
12+import { DEFAULT_HD_PATH, walletFromMnemonic } from './lib/wallet';
2113import { isDevelopment } from './lib/flags';
22−import nest from './lib/nest';
14+
15+import { HistoryProvider, withHistory, useHistory } from './store/history';
16+import { TxnConfirmationsProvider } from './store/txnConfirmations';
2317import { OnlineProvider } from './store/online';
2418import { NetworkProvider } from './store/network';
19+import { WalletProvider } from './store/wallet';
2520
26−// NB(shrugs): toggle this variable to use the default local state.
27−// don't commit changes to this line, but there shouldn't be a problem
21+const kInitialNetworkType = isDevelopment
22+ ? NETWORK_TYPES.LOCAL
23+ : NETWORK_TYPES.MAINNET;
24+
25+// NB(shrugs): toggle these variables to change the default local state.
26+// try not to commit changes to this line, but there shouldn't be a problem
2827// if you do because we'll never stub on a production build.
2928const shouldStubLocal = false;
30−const isStubbed = isDevelopment && shouldStubLocal;
31−const kInitialRoutes = isStubbed
29+const kIsStubbed = isDevelopment && shouldStubLocal;
30+const kInitialRoutes = kIsStubbed
3231 ? [
33− { name: ROUTE_NAMES.SHIPS },
34− { name: ROUTE_NAMES.WALLET },
35− { name: ROUTE_NAMES.NETWORK },
3632 { name: ROUTE_NAMES.LANDING },
33+ { name: ROUTE_NAMES.NETWORK },
34+ { name: ROUTE_NAMES.WALLET },
35+ { name: ROUTE_NAMES.SHIPS },
3736 ]
3837 : [{ name: ROUTE_NAMES.LANDING }];
39−const kInitialNetworkType = isDevelopment
40− ? NETWORK_TYPES.LOCAL
41− : NETWORK_TYPES.MAINNET;
38+
39+const kInitialWallet = kIsStubbed
40+ ? walletFromMnemonic(
41+ process.env.REACT_APP_DEV_MNEMONIC,
42+ process.env.REACT_APP_HD_PATH
43+ )
44+ : undefined;
4245
4346// the router itself is just a component that renders a specific view
4447// depending on the history
@@ -73,30 +76,14 @@ const AllProviders = nest([
7376 TxnConfirmationsProvider,
7477 OnlineProvider,
7578 NetworkProvider,
79+ WalletProvider,
7680]);
7781
7882class Bridge extends React.Component {
7983 constructor(props) {
8084 super(props);
8185
82− // NB (jtobin):
83− //
84− // Note that the 'wallet' prop has type depending on the 'walletType' prop.
85− // These could be bound together in a single structure (so that
86− // 'walletType' acted more explicitly as a data constructor of sorts) but
87− // it doesn't necessarily help us much, since we branch on 'walletType'
88− // before setting 'wallet'.
89− //
90− // Wallets are always wrapped in Maybe. For most authentication
91− // mechanisms, Maybe wraps a BIP32 HD wallet; for Ethereum private keys,
92− // JSON keystore files, and Metamask authentication, it wraps an
93− // 'EthereumWallet'.
94−
9586 this.state = {
96− // wallet
97− walletType: WALLET_NAMES.MNEMONIC,
98− wallet: Nothing(),
99− walletHdPath: DEFAULT_HD_PATH,
10087 // urbit wallet-related
10188 urbitWallet: Nothing(),
10289 authMnemonic: Nothing(),
@@ -109,9 +96,6 @@ class Bridge extends React.Component {
10996 txnConfirmations: {},
11097 };
11198
112− this.setWalletType = this.setWalletType.bind(this);
113− this.setWallet = this.setWallet.bind(this);
114− this.setWalletHdPath = this.setWalletHdPath.bind(this);
11599 this.setUrbitWallet = this.setUrbitWallet.bind(this);
116100 this.setAuthMnemonic = this.setAuthMnemonic.bind(this);
117101 this.setPointCursor = this.setPointCursor.bind(this);
@@ -125,14 +109,11 @@ class Bridge extends React.Component {
125109 //
126110 // If running in development, the following can be tweaked to get you set
127111 // up with a desirable initial state.
128− if (isStubbed) {
112+ if (kIsStubbed) {
129113 const mnemonic = process.env.REACT_APP_DEV_MNEMONIC;
130− const hdpath = process.env.REACT_APP_HD_PATH;
131114
132115 this.setState({
133116 pointCursor: Just(0),
134− walletType: WALLET_NAMES.MNEMONIC,
135− wallet: walletFromMnemonic(mnemonic, hdpath),
136117 urbitWallet: Nothing(),
137118 authMnemonic: Just(mnemonic),
138119 });
@@ -146,28 +127,6 @@ class Bridge extends React.Component {
146127 });
147128 }
148129
149− setWalletType(symbol) {
150− if (includes(WALLET_NAMES, symbol)) {
151− this.setState({
152− walletType: symbol,
153− });
154− } else {
155− throw BRIDGE_ERROR.INVALID_WALLET_TYPE;
156− }
157− }
158−
159− setWallet(wallet) {
160− wallet.map(wal => {
161− wal.address = wal.address || addressFromSecp256k1Public(wal.publicKey);
162− return wal;
163− });
164− this.setState({ wallet });
165− }
166−
167− setWalletHdPath(walletHdPath) {
168− this.setState({ walletHdPath });
169− }
170−
171130 // also sets wallet to ownership address
172131 setUrbitWallet(urbitWallet) {
173132 let wallet = this.state.wallet;
@@ -206,9 +165,6 @@ class Bridge extends React.Component {
206165
207166 render() {
208167 const {
209− walletType,
210− walletHdPath,
211− wallet,
212168 urbitWallet,
213169 authMnemonic,
214170 networkSeedCache,
@@ -221,20 +177,15 @@ class Bridge extends React.Component {
221177 return (
222178 <AllProviders
223179 initialRoutes={kInitialRoutes}
224− initialNetworkType={kInitialNetworkType}>
180+ initialNetworkType={kInitialNetworkType}
181+ initialWallet={kInitialWallet}>
225182 <Container>
226183 <Row>
227184 <VariableWidthColumn>
228− <Header wallet={wallet} pointCursor={pointCursor} />
185+ <Header pointCursor={pointCursor} />
229186
230187 <Row className={'row wrapper'}>
231188 <Router
232− setWalletType={this.setWalletType}
233− setWalletHdPath={this.setWalletHdPath}
234− setWallet={this.setWallet}
235− walletType={walletType}
236− walletHdPath={walletHdPath}
237− wallet={wallet}
238189 urbitWallet={urbitWallet}
239190 setUrbitWallet={this.setUrbitWallet}
240191 authMnemonic={authMnemonic}
src/bridge/components/Header.js+7−2
@@ -6,10 +6,15 @@ import { ROUTE_NAMES } from '../lib/routeNames';
66import { useHistory } from '../store/history';
77import { isLast } from '../lib/lib';
88import { useNetwork } from '../store/network';
9+import { useWallet } from '../store/wallet';
910
11+// hook to create a breadcrumb builder function based on the current
12+// global states
1013function useRouteBreadcrumbBuilder(props) {
1114 const { networkType } = useNetwork();
12− return getRouteBreadcrumb({ ...props, networkType });
15+ const { wallet } = useWallet();
16+
17+ return getRouteBreadcrumb({ ...props, networkType, wallet });
1318}
1419
1520function Crumbs(props) {
@@ -48,7 +53,7 @@ function Header(props) {
4853 if (showCrumbs) {
4954 return (
5055 <div className={'flex items-center h-10'}>
51− <Crumbs wallet={props.wallet} pointCursor={props.pointCursor} />
56+ <Crumbs pointCursor={props.pointCursor} />
5257 </div>
5358 );
5459 }
src/bridge/components/Passport.js+3−1
@@ -8,6 +8,8 @@ import { Button } from './Base';
88
99import { WALLET_STATES } from '../lib/invite';
1010import { downloadWallet } from '../lib/invite';
11+import { compose } from '../lib/lib';
12+import { withWallet } from '../store/wallet';
1113
1214class Passport extends React.Component {
1315 constructor(props) {
@@ -231,4 +233,4 @@ Passport.defaultProps = {
231233 wallet: null,
232234};
233235
234−export default Passport;
236+export default compose(withWallet)(Passport);
src/bridge/components/StatelessTransaction.js+3−1
@@ -24,6 +24,7 @@ import {
2424import { withTxnConfirmations } from '../store/txnConfirmations';
2525import { withNetwork } from '../store/network';
2626import { withHistory } from '../store/history';
27+import { withWallet } from '../store/wallet';
2728
2829const SUBMISSION_STATES = {
2930 PROMPT: 'Send transaction',
@@ -584,5 +585,6 @@ class StatelessTransaction extends React.Component {
584585export default compose(
585586 withNetwork,
586587 withTxnConfirmations,
587− withHistory
588+ withHistory,
589+ withWallet
588590)(StatelessTransaction);
src/bridge/lib/invite.js+2−2
@@ -12,7 +12,7 @@ import saveAs from 'file-saver';
1212import { sendSignedTransaction } from './txn';
1313import { BRIDGE_ERROR } from '../lib/error';
1414import { attemptSeedDerivation } from './keys';
15−import { addHexPrefix, WALLET_NAMES } from './wallet';
15+import { addHexPrefix, WALLET_TYPES } from './wallet';
1616
1717const INVITE_STAGES = {
1818 INVITE_LOGIN: 'invite login',
@@ -213,7 +213,7 @@ async function startTransactions(args) {
213213 // configure networking public keys
214214 //TODO feels like more of this logic should live in a lib?
215215 let networkSeed = await attemptSeedDerivation(true, {
216− walletType: WALLET_NAMES.TICKET,
216+ walletType: WALLET_TYPES.TICKET,
217217 urbitWallet: Just(realWallet),
218218 pointCursor: Just(point),
219219 pointCache: { [point]: { keyRevisionNumber: 0 } },
src/bridge/lib/keys.js+4−5
@@ -7,7 +7,7 @@ import * as serial from '../nockjs/serial';
77import * as kg from 'urbit-key-generation/dist/index';
88
99import { BRIDGE_ERROR } from './error';
10−import { WALLET_NAMES, eqAddr } from './wallet';
10+import { WALLET_TYPES, eqAddr } from './wallet';
1111
1212// ctsy joemfb
1313const b64 = buf => {
@@ -67,8 +67,7 @@ const genKey = (networkSeed, point, revision) => {
6767// 'next' refers to setting the next set of keys
6868// if false, we use revision - 1
6969const attemptSeedDerivation = async (next, args) => {
70− const { walletType } = args;
71− const { urbitWallet, authMnemonic } = args;
70+ const { walletType, urbitWallet, authMnemonic } = args;
7271
7372 // NB (jtobin):
7473 //
@@ -84,7 +83,7 @@ const attemptSeedDerivation = async (next, args) => {
8483
8584 let managementSeed = '';
8685
87− const ticketLike = [WALLET_NAMES.TICKET, WALLET_NAMES.SHARDS];
86+ const ticketLike = [WALLET_TYPES.TICKET, WALLET_TYPES.SHARDS];
8887
8988 if (ticketLike.includes(walletType)) {
9089 const uwal = urbitWallet.matchWith({
@@ -95,7 +94,7 @@ const attemptSeedDerivation = async (next, args) => {
9594 });
9695
9796 managementSeed = uwal.management.seed;
98− } else if (walletType === WALLET_NAMES.MNEMONIC) {
97+ } else if (walletType === WALLET_TYPES.MNEMONIC) {
9998 const walProxy = need.address(args);
10099
101100 const mnemonic = authMnemonic.matchWith({
src/bridge/lib/txn.js+4−4
@@ -7,7 +7,7 @@ import { BRIDGE_ERROR } from '../lib/error';
77import { NETWORK_TYPES } from '../lib/network';
88import { ledgerSignTransaction } from '../lib/ledger';
99import { trezorSignTransaction } from '../lib/trezor';
10−import { WALLET_NAMES, addHexPrefix } from '../lib/wallet';
10+import { WALLET_TYPES, addHexPrefix } from '../lib/wallet';
1111
1212const TXN_PURPOSE = {
1313 SET_MANAGEMENT_PROXY: Symbol('SET_MANAGEMENT_PROXY'),
@@ -96,7 +96,7 @@ const signTransaction = async config => {
9696 ];
9797
9898 const needEip155Params =
99− walletType === WALLET_NAMES.LEDGER &&
99+ walletType === WALLET_TYPES.LEDGER &&
100100 defaultEip155Networks.includes(networkType);
101101
102102 const signingParams = needEip155Params
@@ -121,9 +121,9 @@ const signTransaction = async config => {
121121
122122 const stx = new Tx(utx);
123123
124− if (walletType === WALLET_NAMES.LEDGER) {
124+ if (walletType === WALLET_TYPES.LEDGER) {
125125 await ledgerSignTransaction(stx, walletHdPath);
126− } else if (walletType === WALLET_NAMES.TREZOR) {
126+ } else if (walletType === WALLET_TYPES.TREZOR) {
127127 await trezorSignTransaction(stx, walletHdPath);
128128 } else {
129129 stx.sign(sec);
src/bridge/lib/wallet.js+9−9
@@ -14,7 +14,7 @@ const ETH_ZERO_ADDR = '0x0000000000000000000000000000000000000000';
1414const CURVE_ZERO_ADDR =
1515 '0x0000000000000000000000000000000000000000000000000000000000000000';
1616
17−const WALLET_NAMES = {
17+const WALLET_TYPES = {
1818 MNEMONIC: Symbol('MNEMONIC'),
1919 TICKET: Symbol('TICKET'),
2020 SHARDS: Symbol('SHARDS'),
@@ -32,19 +32,19 @@ function EthereumWallet(privateKey) {
3232}
3333
3434const renderWalletType = wallet =>
35− wallet === WALLET_NAMES.MNEMONIC
35+ wallet === WALLET_TYPES.MNEMONIC
3636 ? 'Mnemonic'
37− : wallet === WALLET_NAMES.TICKET
37+ : wallet === WALLET_TYPES.TICKET
3838 ? 'Ticket'
39− : wallet === WALLET_NAMES.SHARDS
39+ : wallet === WALLET_TYPES.SHARDS
4040 ? 'Ticket Shards'
41− : wallet === WALLET_NAMES.LEDGER
41+ : wallet === WALLET_TYPES.LEDGER
4242 ? 'Ledger'
43− : wallet === WALLET_NAMES.TREZOR
43+ : wallet === WALLET_TYPES.TREZOR
4444 ? 'Trezor'
45− : wallet === WALLET_NAMES.PRIVATE_KEY
45+ : wallet === WALLET_TYPES.PRIVATE_KEY
4646 ? 'Private Key'
47− : wallet === WALLET_NAMES.KEYSTORE
47+ : wallet === WALLET_TYPES.KEYSTORE
4848 ? 'Keystore File'
4949 : 'Wallet';
5050
@@ -135,7 +135,7 @@ const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
135135
136136export {
137137 DEFAULT_HD_PATH,
138− WALLET_NAMES,
138+ WALLET_TYPES,
139139 ETH_ZERO_ADDR,
140140 CURVE_ZERO_ADDR,
141141 renderWalletType,
src/bridge/store/wallet.jsnew file+86
@@ -0,0 +1,86 @@
1+import React, { createContext, forwardRef, useContext, useState } from 'react';
2+import Maybe from 'folktale/maybe';
3+import { includes } from 'lodash';
4+
5+import {
6+ WALLET_TYPES,
7+ DEFAULT_HD_PATH,
8+ addressFromSecp256k1Public,
9+} from '../lib/wallet';
10+import { BRIDGE_ERROR } from '../lib/error';
11+
12+export const WalletContext = createContext(null);
13+
14+// NB (jtobin):
15+//
16+// Note that the 'wallet' prop has type depending on the 'walletType' prop.
17+// These could be bound together in a single structure (so that
18+// 'walletType' acted more explicitly as a data constructor of sorts) but
19+// it doesn't necessarily help us much, since we branch on 'walletType'
20+// before setting 'wallet'.
21+//
22+// Wallets are always wrapped in Maybe. For most authentication
23+// mechanisms, Maybe wraps a BIP32 HD wallet; for Ethereum private keys,
24+// JSON keystore files, and Metamask authentication, it wraps an
25+// 'EthereumWallet'.
26+function _useWallet(initialWallet = Maybe.Nothing()) {
27+ const [walletType, _setWalletType] = useState(WALLET_TYPES.MNEMONIC);
28+ const [walletHdPath, setWalletHdPath] = useState(DEFAULT_HD_PATH);
29+ const [wallet, _setWallet] = useState(initialWallet);
30+
31+ const setWalletType = walletType => {
32+ if (!includes(WALLET_TYPES, walletType)) {
33+ throw BRIDGE_ERROR.INVALID_WALLET_TYPE;
34+ }
35+
36+ _setWalletType(walletType);
37+ };
38+
39+ const setWallet = wallet => {
40+ // force that public addresses are derived for each wallet
41+ wallet.map(wal => {
42+ wal.address = wal.address || addressFromSecp256k1Public(wal.publicKey);
43+ return wal;
44+ });
45+
46+ _setWallet(wallet);
47+ };
48+
49+ return {
50+ //
51+ walletType,
52+ setWalletType,
53+ //
54+ walletHdPath,
55+ setWalletHdPath,
56+ //
57+ wallet,
58+ setWallet,
59+ //
60+ // urbitWallet
61+ // setUrbitWallet
62+ // authMnemonic
63+ // setAuthMnemonic
64+ };
65+}
66+
67+export function WalletProvider({ initialWallet, children }) {
68+ const wallet = _useWallet(initialWallet);
69+
70+ return (
71+ <WalletContext.Provider value={wallet}>{children}</WalletContext.Provider>
72+ );
73+}
74+
75+// Hook version
76+export function useWallet() {
77+ return useContext(WalletContext);
78+}
79+
80+// HOC version
81+export const withWallet = Component =>
82+ forwardRef((props, ref) => (
83+ <WalletContext.Consumer>
84+ {wallet => <Component ref={ref} {...wallet} {...props} />}
85+ </WalletContext.Consumer>
86+ ));
src/bridge/views/GenKeyfile.js+3−1
@@ -11,6 +11,8 @@ import saveAs from 'file-saver';
1111
1212import { attemptSeedDerivation, genKey } from '../lib/keys';
1313import { addHexPrefix } from '../lib/wallet';
14+import { compose } from '../lib/lib';
15+import { withWallet } from '../store/wallet';
1416
1517class GenKeyfile extends React.Component {
1618 constructor(props) {
@@ -132,4 +134,4 @@ class GenKeyfile extends React.Component {
132134 }
133135}
134136
135−export default GenKeyfile;
137+export default compose(withWallet)(GenKeyfile);
src/bridge/views/InvitesSend.js+5−1
@@ -21,6 +21,7 @@ import {
2121import * as tank from '../lib/tank';
2222import { withNetwork } from '../store/network';
2323import { compose } from '../lib/lib';
24+import { withWallet } from '../store/wallet';
2425
2526const GAS_PRICE_GWEI = 20; // we pay the premium for faster ux
2627const GAS_LIMIT = 350000;
@@ -493,4 +494,7 @@ class InvitesSend extends React.Component {
493494 }
494495}
495496
496−export default compose(withNetwork)(InvitesSend);
497+export default compose(
498+ withNetwork,
499+ withWallet
500+)(InvitesSend);
src/bridge/views/Keystore.js+5−1
@@ -11,6 +11,7 @@ import { ROUTE_NAMES } from '../lib/routeNames';
1111import { withHistory } from '../store/history';
1212import { EthereumWallet } from '../lib/wallet';
1313import { compose } from '../lib/lib';
14+import { withWallet } from '../store/wallet';
1415
1516class Keystore extends React.Component {
1617 constructor(props) {
@@ -160,4 +161,7 @@ class Keystore extends React.Component {
160161 }
161162}
162163
163−export default compose(withHistory)(Keystore);
164+export default compose(
165+ withHistory,
166+ withWallet
167+)(Keystore);
src/bridge/views/Ledger.js+5−1
@@ -12,6 +12,7 @@ import { LEDGER_LIVE_PATH, LEDGER_LEGACY_PATH } from '../lib/ledger';
1212import { ROUTE_NAMES } from '../lib/routeNames';
1313import { withHistory } from '../store/history';
1414import { compose } from '../lib/lib';
15+import { withWallet } from '../store/wallet';
1516
1617const chopHdPrefix = str => (str.slice(0, 2) === 'm/' ? str.slice(2) : str);
1718
@@ -218,4 +219,7 @@ class Ledger extends React.Component {
218219 }
219220}
220221
221−export default compose(withHistory)(Ledger);
222+export default compose(
223+ withHistory,
224+ withWallet
225+)(Ledger);
src/bridge/views/Mnemonic.js+5−1
@@ -14,6 +14,7 @@ import { ROUTE_NAMES } from '../lib/routeNames';
1414import { withHistory } from '../store/history';
1515import { DEFAULT_HD_PATH, walletFromMnemonic } from '../lib/wallet';
1616import { compose } from '../lib/lib';
17+import { withWallet } from '../store/wallet';
1718
1819class Mnemonic extends React.Component {
1920 constructor(props) {
@@ -161,4 +162,7 @@ class Mnemonic extends React.Component {
161162 }
162163}
163164
164−export default compose(withHistory)(Mnemonic);
165+export default compose(
166+ withHistory,
167+ withWallet
168+)(Mnemonic);
src/bridge/views/Point.js+3−1
@@ -13,6 +13,7 @@ import { Row, Col, H1, H3 } from '../components/Base';
1313import { withHistory } from '../store/history';
1414import { withNetwork } from '../store/network';
1515import { compose } from '../lib/lib';
16+import { withWallet } from '../store/wallet';
1617
1718class Point extends React.Component {
1819 constructor(props) {
@@ -139,5 +140,6 @@ class Point extends React.Component {
139140
140141export default compose(
141142 withNetwork,
142− withHistory
143+ withHistory,
144+ withWallet
143145)(Point);
src/bridge/views/Points.js+4−3
@@ -10,6 +10,7 @@ import { withHistory } from '../store/history';
1010import { ETH_ZERO_ADDR, eqAddr } from '../lib/wallet';
1111import { withNetwork } from '../store/network';
1212import { compose } from '../lib/lib';
13+import { withWallet } from '../store/wallet';
1314
1415const hasTransferProxy = (cache, point) =>
1516 point in cache ? !eqAddr(cache[point].transferProxy, ETH_ZERO_ADDR) : false;
@@ -82,8 +83,7 @@ class Points extends React.Component {
8283 }
8384
8485 render() {
85− const { setPointCursor, history } = this.props;
86− const { pointCache } = this.props;
86+ const { setPointCursor, history, pointCache } = this.props;
8787
8888 const {
8989 points,
@@ -259,5 +259,6 @@ class Points extends React.Component {
259259
260260export default compose(
261261 withNetwork,
262− withHistory
262+ withHistory,
263+ withWallet
263264)(Points);
src/bridge/views/PrivateKey.js+5−1
@@ -8,6 +8,7 @@ import { ROUTE_NAMES } from '../lib/routeNames';
88import { withHistory } from '../store/history';
99import { EthereumWallet } from '../lib/wallet';
1010import { compose } from '../lib/lib';
11+import { withWallet } from '../store/wallet';
1112
1213class PrivateKey extends React.Component {
1314 constructor(props) {
@@ -74,4 +75,7 @@ class PrivateKey extends React.Component {
7475 }
7576}
7677
77−export default compose(withHistory)(PrivateKey);
78+export default compose(
79+ withHistory,
80+ withWallet
81+)(PrivateKey);
src/bridge/views/SetKeys.js+8−4
@@ -3,17 +3,18 @@ import Maybe from 'folktale/maybe';
33import * as azimuth from 'azimuth-js';
44import * as ob from 'urbit-ob';
55import * as need from '../lib/need';
6+import * as kg from 'urbit-key-generation/dist/index';
67import { Row, Col, H1, P, Warning, CheckboxButton } from '../components/Base';
78
89import StatelessTransaction from '../components/StatelessTransaction';
910import { attemptSeedDerivation } from '../lib/keys';
1011
11−import * as kg from 'urbit-key-generation/dist/index';
12−
1312import { addHexPrefix } from '../lib/wallet';
14−import { withNetwork } from '../store/network';
1513import { compose } from '../lib/lib';
1614
15+import { withNetwork } from '../store/network';
16+import { withWallet } from '../store/wallet';
17+
1718class SetKeys extends React.Component {
1819 constructor(props) {
1920 super(props);
@@ -198,4 +199,7 @@ class SetKeys extends React.Component {
198199 }
199200}
200201
201−export default compose(withNetwork)(SetKeys);
202+export default compose(
203+ withNetwork,
204+ withWallet
205+)(SetKeys);
src/bridge/views/Shards.js+5−1
@@ -17,6 +17,7 @@ import { ROUTE_NAMES } from '../lib/routeNames';
1717import { withHistory } from '../store/history';
1818import { urbitWalletFromTicket } from '../lib/wallet';
1919import { compose } from '../lib/lib';
20+import { withWallet } from '../store/wallet';
2021
2122const placeholder = len => {
2223 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
@@ -212,4 +213,7 @@ class Shards extends React.Component {
212213 }
213214}
214215
215−export default compose(withHistory)(Shards);
216+export default compose(
217+ withHistory,
218+ withWallet
219+)(Shards);
src/bridge/views/Ticket.js+5−1
@@ -15,6 +15,7 @@ import { randomPatq, compose } from '../lib/lib';
1515import { ROUTE_NAMES } from '../lib/routeNames';
1616import { withHistory } from '../store/history';
1717import { urbitWalletFromTicket } from '../lib/wallet';
18+import { withWallet } from '../store/wallet';
1819
1920class Ticket extends React.Component {
2021 constructor(props) {
@@ -150,4 +151,7 @@ class Ticket extends React.Component {
150151 }
151152}
152153
153−export default compose(withHistory)(Ticket);
154+export default compose(
155+ withHistory,
156+ withWallet
157+)(Ticket);
src/bridge/views/Trezor.js+5−1
@@ -11,6 +11,7 @@ import { TREZOR_PATH } from '../lib/trezor';
1111import { ROUTE_NAMES } from '../lib/routeNames';
1212import { withHistory } from '../store/history';
1313import { compose } from '../lib/lib';
14+import { withWallet } from '../store/wallet';
1415
1516class Trezor extends React.Component {
1617 constructor(props) {
@@ -140,4 +141,7 @@ class Trezor extends React.Component {
140141 }
141142}
142143
143−export default compose(withHistory)(Trezor);
144+export default compose(
145+ withHistory,
146+ withWallet
147+)(Trezor);
src/bridge/views/Wallet.js+20−16
@@ -6,8 +6,9 @@ import { Row, Col } from '../components/Base';
66
77import { ROUTE_NAMES } from '../lib/routeNames';
88import { withHistory } from '../store/history';
9−import { WALLET_NAMES, renderWalletType } from '../lib/wallet';
9+import { WALLET_TYPES, renderWalletType } from '../lib/wallet';
1010import { compose } from '../lib/lib';
11+import { withWallet } from '../store/wallet';
1112
1213class Wallet extends React.Component {
1314 componentDidMount() {
@@ -19,37 +20,37 @@ class Wallet extends React.Component {
1920 return [
2021 {
2122 title: 'Urbit Master Ticket',
22− value: WALLET_NAMES.TICKET,
23+ value: WALLET_TYPES.TICKET,
2324 },
2425 {
2526 title: 'Urbit Master Ticket (Shards)',
26− value: WALLET_NAMES.SHARDS,
27+ value: WALLET_TYPES.SHARDS,
2728 },
2829 {
2930 type: 'divider',
3031 },
3132 {
3233 title: 'Ledger',
33− value: WALLET_NAMES.LEDGER,
34+ value: WALLET_TYPES.LEDGER,
3435 },
3536 {
3637 title: 'Trezor',
37− value: WALLET_NAMES.TREZOR,
38+ value: WALLET_TYPES.TREZOR,
3839 },
3940 {
4041 type: 'divider',
4142 },
4243 {
4344 title: 'BIP39 Mnemonic',
44− value: WALLET_NAMES.MNEMONIC,
45+ value: WALLET_TYPES.MNEMONIC,
4546 },
4647 {
4748 title: 'Ethereum Private Key',
48− value: WALLET_NAMES.PRIVATE_KEY,
49+ value: WALLET_TYPES.PRIVATE_KEY,
4950 },
5051 {
5152 title: 'Ethereum Keystore File',
52− value: WALLET_NAMES.KEYSTORE,
53+ value: WALLET_TYPES.KEYSTORE,
5354 },
5455 ];
5556 }
@@ -80,19 +81,19 @@ class Wallet extends React.Component {
8081 className={'mt-10'}
8182 onClick={() =>
8283 props.history.push(
83− props.walletType === WALLET_NAMES.MNEMONIC
84+ props.walletType === WALLET_TYPES.MNEMONIC
8485 ? ROUTE_NAMES.MNEMONIC
85− : props.walletType === WALLET_NAMES.TICKET
86+ : props.walletType === WALLET_TYPES.TICKET
8687 ? ROUTE_NAMES.TICKET
87− : props.walletType === WALLET_NAMES.SHARDS
88+ : props.walletType === WALLET_TYPES.SHARDS
8889 ? ROUTE_NAMES.SHARDS
89− : props.walletType === WALLET_NAMES.LEDGER
90+ : props.walletType === WALLET_TYPES.LEDGER
9091 ? ROUTE_NAMES.LEDGER
91− : props.walletType === WALLET_NAMES.TREZOR
92+ : props.walletType === WALLET_TYPES.TREZOR
9293 ? ROUTE_NAMES.TREZOR
93− : props.walletType === WALLET_NAMES.PRIVATE_KEY
94+ : props.walletType === WALLET_TYPES.PRIVATE_KEY
9495 ? ROUTE_NAMES.PRIVATE_KEY
95− : props.walletType === WALLET_NAMES.KEYSTORE
96+ : props.walletType === WALLET_TYPES.KEYSTORE
9697 ? ROUTE_NAMES.KEYSTORE
9798 : ROUTE_NAMES.DEFAULT
9899 )
@@ -105,4 +106,7 @@ class Wallet extends React.Component {
105106 }
106107}
107108
108−export default compose(withHistory)(Wallet);
109+export default compose(
110+ withHistory,
111+ withWallet
112+)(Wallet);