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