on master help sign in
Merge pull request #157 from urbit/feat/extract-wallet

Extract Wallet Store

commit2bfe55178ed392876e5748692057c204039b139c authorMatt Condon <mattgcondon@gmail.com> dateMon 17 Jun 2019, 11:45 (7 years ago) parentcf42d8dfeca660
26 files changed+290−191
src/bridge/Bridge.js+50−129 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+114 src/bridge/views/AcceptTransfer.js+5−1 src/bridge/views/CreateGalaxy.js+5−1 src/bridge/views/GenKeyfile.js+3−1 src/bridge/views/InviteTicket.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−2 src/bridge/views/Point/Actions.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+50−129
@@ -1,44 +1,50 @@
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 { walletFromMnemonic } from './lib/wallet';
2113import { isDevelopment } from './lib/flags';
22−import nest from './lib/nest';
14+
15+import { HistoryProvider, 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;
45+const kInitialMnemonic = kIsStubbed
46+ ? process.env.REACT_APP_DEV_MNEMONIC
47+ : Nothing();
4248
4349// the router itself is just a component that renders a specific view
4450// depending on the history
@@ -49,23 +55,26 @@ const Router = function(props) {
4955 return <Route {...props} />;
5056};
5157
52−// NB(shrugs): separate component because it needs withHistory
58+// NB(shrugs): separate component because it needs useHistory
5359// this will be must better structured as part of the UI overhaul
54−const VariableWidthColumn = withHistory(({ history, children }) => (
60+const VariableWidthColumn = function({ children }) {
61+ const history = useHistory();
5562 // For the invite acceptance flow, widen the screen to use the full
5663 // container, and hide the breadcrumbs
57− <Col
58− className={
59− history.includes(ROUTE_NAMES.INVITE_TICKET)
60− ? 'col-md-12'
61− : 'col-md-offset-1 col-md-10'
62− }
63− style={
64− history.includes(ROUTE_NAMES.INVITE_TICKET) ? {} : { maxWidth: '620px' }
65− }>
66− {children}
67− </Col>
68−));
64+ return (
65+ <Col
66+ className={
67+ history.includes(ROUTE_NAMES.INVITE_TICKET)
68+ ? 'col-md-12'
69+ : 'col-md-offset-1 col-md-10'
70+ }
71+ style={
72+ history.includes(ROUTE_NAMES.INVITE_TICKET) ? {} : { maxWidth: '620px' }
73+ }>
74+ {children}
75+ </Col>
76+ );
77+};
6978
7079// nest all of the providers within each other to avoid hella depth
7180const AllProviders = nest([
@@ -73,33 +82,14 @@ const AllProviders = nest([
7382 TxnConfirmationsProvider,
7483 OnlineProvider,
7584 NetworkProvider,
85+ WalletProvider,
7686]);
7787
7888class Bridge extends React.Component {
7989 constructor(props) {
8090 super(props);
8191
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−
9592 this.state = {
96− // wallet
97− walletType: WALLET_NAMES.MNEMONIC,
98− wallet: Nothing(),
99− walletHdPath: DEFAULT_HD_PATH,
100− // urbit wallet-related
101− urbitWallet: Nothing(),
102− authMnemonic: Nothing(),
10393 networkSeedCache: null,
10494 // point
10595 pointCursor: Nothing(),
@@ -109,11 +99,6 @@ class Bridge extends React.Component {
10999 txnConfirmations: {},
110100 };
111101
112− this.setWalletType = this.setWalletType.bind(this);
113− this.setWallet = this.setWallet.bind(this);
114− this.setWalletHdPath = this.setWalletHdPath.bind(this);
115− this.setUrbitWallet = this.setUrbitWallet.bind(this);
116− this.setAuthMnemonic = this.setAuthMnemonic.bind(this);
117102 this.setPointCursor = this.setPointCursor.bind(this);
118103 this.setTxnHashCursor = this.setTxnHashCursor.bind(this);
119104 this.setNetworkSeedCache = this.setNetworkSeedCache.bind(this);
@@ -125,16 +110,9 @@ class Bridge extends React.Component {
125110 //
126111 // If running in development, the following can be tweaked to get you set
127112 // up with a desirable initial state.
128− if (isStubbed) {
129− const mnemonic = process.env.REACT_APP_DEV_MNEMONIC;
130− const hdpath = process.env.REACT_APP_HD_PATH;
131−
113+ if (kIsStubbed) {
132114 this.setState({
133115 pointCursor: Just(0),
134− walletType: WALLET_NAMES.MNEMONIC,
135− wallet: walletFromMnemonic(mnemonic, hdpath),
136− urbitWallet: Nothing(),
137− authMnemonic: Just(mnemonic),
138116 });
139117 }
140118 }
@@ -146,50 +124,6 @@ class Bridge extends React.Component {
146124 });
147125 }
148126
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−
171− // also sets wallet to ownership address
172− setUrbitWallet(urbitWallet) {
173− let wallet = this.state.wallet;
174− if (Just.hasInstance(urbitWallet)) {
175− const mnemonic = urbitWallet.value.ownership.seed;
176− wallet = walletFromMnemonic(
177− mnemonic,
178− DEFAULT_HD_PATH,
179− urbitWallet.value.meta.passphrase
180− );
181− wallet.map(wal => {
182− wal.address = urbitWallet.value.ownership.keys.address;
183− return wal;
184− });
185− }
186− this.setState({ urbitWallet, wallet });
187− }
188−
189− setAuthMnemonic(authMnemonic) {
190− this.setState({ authMnemonic });
191− }
192−
193127 setPointCursor(pointCursor) {
194128 this.setState({ pointCursor });
195129 }
@@ -206,11 +140,6 @@ class Bridge extends React.Component {
206140
207141 render() {
208142 const {
209− walletType,
210− walletHdPath,
211− wallet,
212− urbitWallet,
213− authMnemonic,
214143 networkSeedCache,
215144 networkRevisionCache,
216145 pointCursor,
@@ -221,24 +150,16 @@ class Bridge extends React.Component {
221150 return (
222151 <AllProviders
223152 initialRoutes={kInitialRoutes}
224− initialNetworkType={kInitialNetworkType}>
153+ initialNetworkType={kInitialNetworkType}
154+ initialWallet={kInitialWallet}
155+ initialMnemonic={kInitialMnemonic}>
225156 <Container>
226157 <Row>
227158 <VariableWidthColumn>
228− <Header wallet={wallet} pointCursor={pointCursor} />
159+ <Header pointCursor={pointCursor} />
229160
230161 <Row className={'row wrapper'}>
231162 <Router
232− setWalletType={this.setWalletType}
233− setWalletHdPath={this.setWalletHdPath}
234− setWallet={this.setWallet}
235− walletType={walletType}
236− walletHdPath={walletHdPath}
237− wallet={wallet}
238− urbitWallet={urbitWallet}
239− setUrbitWallet={this.setUrbitWallet}
240− authMnemonic={authMnemonic}
241− setAuthMnemonic={this.setAuthMnemonic}
242163 setPointCursor={this.setPointCursor}
243164 addToPointCache={this.addToPointCache}
244165 pointCursor={pointCursor}
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+114
@@ -0,0 +1,114 @@
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+ walletFromMnemonic,
10+} from '../lib/wallet';
11+import { BRIDGE_ERROR } from '../lib/error';
12+
13+export const WalletContext = createContext(null);
14+
15+// NB (jtobin):
16+//
17+// Note that the 'wallet' prop has type depending on the 'walletType' prop.
18+// These could be bound together in a single structure (so that
19+// 'walletType' acted more explicitly as a data constructor of sorts) but
20+// it doesn't necessarily help us much, since we branch on 'walletType'
21+// before setting 'wallet'.
22+//
23+// Wallets are always wrapped in Maybe. For most authentication
24+// mechanisms, Maybe wraps a BIP32 HD wallet; for Ethereum private keys,
25+// JSON keystore files, and Metamask authentication, it wraps an
26+// 'EthereumWallet'.
27+function _useWallet(
28+ initialWallet = Maybe.Nothing(),
29+ initialMnemonic = Maybe.Nothing()
30+) {
31+ const [walletType, _setWalletType] = useState(WALLET_TYPES.MNEMONIC);
32+ const [walletHdPath, setWalletHdPath] = useState(DEFAULT_HD_PATH);
33+ const [wallet, _setWallet] = useState(initialWallet);
34+ const [urbitWallet, _setUrbitWallet] = useState(Maybe.Nothing());
35+ const [authMnemonic, setAuthMnemonic] = useState(initialMnemonic);
36+
37+ const setWalletType = walletType => {
38+ if (!includes(WALLET_TYPES, walletType)) {
39+ throw BRIDGE_ERROR.INVALID_WALLET_TYPE;
40+ }
41+
42+ _setWalletType(walletType);
43+ };
44+
45+ const setWallet = wallet => {
46+ // force that public addresses are derived for each wallet
47+ wallet.map(wal => {
48+ wal.address = wal.address || addressFromSecp256k1Public(wal.publicKey);
49+ return wal;
50+ });
51+
52+ _setWallet(wallet);
53+ };
54+
55+ const setUrbitWallet = urbitWallet => {
56+ if (Maybe.Just.hasInstance(urbitWallet)) {
57+ // when an urbit wallet is set, also derive
58+ // a normal bip32 wallet using the ownership address
59+ const wallet = walletFromMnemonic(
60+ urbitWallet.value.ownership.seed,
61+ DEFAULT_HD_PATH,
62+ urbitWallet.value.meta.passphrase
63+ );
64+
65+ // manually set the public address
66+ wallet.map(wal => {
67+ wal.address = urbitWallet.value.ownership.keys.address;
68+ return wal;
69+ });
70+
71+ setWallet(wallet);
72+ }
73+
74+ _setUrbitWallet(urbitWallet);
75+ };
76+
77+ return {
78+ //
79+ walletType,
80+ setWalletType,
81+ //
82+ walletHdPath,
83+ setWalletHdPath,
84+ //
85+ wallet,
86+ setWallet,
87+ //
88+ urbitWallet,
89+ setUrbitWallet,
90+ authMnemonic,
91+ setAuthMnemonic,
92+ };
93+}
94+
95+export function WalletProvider({ initialWallet, initialMnemonic, children }) {
96+ const wallet = _useWallet(initialWallet, initialMnemonic);
97+
98+ return (
99+ <WalletContext.Provider value={wallet}>{children}</WalletContext.Provider>
100+ );
101+}
102+
103+// Hook version
104+export function useWallet() {
105+ return useContext(WalletContext);
106+}
107+
108+// HOC version
109+export const withWallet = Component =>
110+ forwardRef((props, ref) => (
111+ <WalletContext.Consumer>
112+ {wallet => <Component ref={ref} {...wallet} {...props} />}
113+ </WalletContext.Consumer>
114+ ));
src/bridge/views/AcceptTransfer.js+5−1
@@ -16,6 +16,7 @@ import { NETWORK_TYPES } from '../lib/network';
1616import { isValidAddress } from '../lib/wallet';
1717import { withNetwork } from '../store/network';
1818import { compose } from '../lib/lib';
19+import { withWallet } from '../store/wallet';
1920
2021class AcceptTransfer extends React.Component {
2122 constructor(props) {
@@ -119,4 +120,7 @@ class AcceptTransfer extends React.Component {
119120 }
120121}
121122
122−export default compose(withNetwork)(AcceptTransfer);
123+export default compose(
124+ withNetwork,
125+ withWallet
126+)(AcceptTransfer);
src/bridge/views/CreateGalaxy.js+5−1
@@ -22,6 +22,7 @@ import { ETH_ZERO_ADDR, isValidAddress, eqAddr } from '../lib/wallet';
2222
2323import { isValidGalaxy, compose } from '../lib/lib';
2424import { withNetwork } from '../store/network';
25+import { withWallet } from '../store/wallet';
2526
2627const buttonTriState = status => {
2728 if (status === null) return 'blue';
@@ -195,4 +196,7 @@ class CreateGalaxy extends React.Component {
195196 }
196197}
197198
198−export default compose(withNetwork)(CreateGalaxy);
199+export default compose(
200+ withNetwork,
201+ withWallet
202+)(CreateGalaxy);
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/InviteTicket.js+3−1
@@ -29,6 +29,7 @@ import {
2929} from '../lib/invite';
3030import { generateWallet, startTransactions } from '../lib/invite';
3131import { withNetwork } from '../store/network';
32+import { withWallet } from '../store/wallet';
3233
3334class InviteTicket extends React.Component {
3435 constructor(props) {
@@ -425,5 +426,6 @@ class InviteTicket extends React.Component {
425426
426427export default compose(
427428 withNetwork,
428− withHistory
429+ withHistory,
430+ withWallet
429431)(InviteTicket);
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−2
@@ -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) {
@@ -122,7 +123,6 @@ class Point extends React.Component {
122123 {authenticated ? (
123124 <Actions
124125 online={online}
125− wallet={wallet}
126126 point={point}
127127 pointDetails={pointDetails}
128128 invites={this.state.invites}
@@ -139,5 +139,6 @@ class Point extends React.Component {
139139
140140export default compose(
141141 withNetwork,
142− withHistory
142+ withHistory,
143+ withWallet
143144)(Point);
src/bridge/views/Point/Actions.js+3−1
@@ -7,6 +7,7 @@ import { Row, Col, H2, P } from '../../components/Base';
77import { Button } from '../../components/Base';
88import { ROUTE_NAMES } from '../../lib/routeNames';
99import { useHistory } from '../../store/history';
10+import { useWallet } from '../../store/wallet';
1011
1112const isPlanet = point =>
1213 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
@@ -14,9 +15,10 @@ const isStar = point => azimuth.getPointSize(point) === azimuth.PointSize.Star;
1415
1516function Actions(props) {
1617 const history = useHistory();
18+ const { wallet } = useWallet();
1719 const { online, point, pointDetails, invites } = props;
1820
19− const addr = need.address(props);
21+ const addr = need.address({ wallet });
2022
2123 const isOwner = pointDetails.matchWith({
2224 Nothing: _ => false,
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);