@@ -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}