@@ -1,44 +1,47 @@
1import React from 'react';
1import React from 'react';
2import { Just, Nothing } from 'folktale/maybe';
2import { Just, Nothing } from 'folktale/maybe';
3−import { includes } from 'lodash';
5import Footer from './components/Footer';
4import Footer from './components/Footer';
6import Header from './components/Header';
5import Header from './components/Header';
7import { Container, Row, Col } from './components/Base';
6import { Container, Row, Col } from './components/Base';
8+import nest from './lib/nest';
9import { router } from './lib/router';
9import { router } from './lib/router';
10import { ROUTE_NAMES } from './lib/routeNames';
10import { ROUTE_NAMES } from './lib/routeNames';
11−import { HistoryProvider, withHistory, useHistory } from './store/history';
12−import { TxnConfirmationsProvider } from './store/txnConfirmations';
13import { NETWORK_TYPES } from './lib/network';
11import { NETWORK_TYPES } from './lib/network';
17− walletFromMnemonic,
12+import { DEFAULT_HD_PATH, walletFromMnemonic } from './lib/wallet';
18− addressFromSecp256k1Public,
19−} from './lib/wallet';
20−import { BRIDGE_ERROR } from './lib/error';
21import { isDevelopment } from './lib/flags';
13import { 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';
23import { OnlineProvider } from './store/online';
17import { OnlineProvider } from './store/online';
24import { NetworkProvider } from './store/network';
18import { NetworkProvider } from './store/network';
19+import { WalletProvider } from './store/wallet';
21+const kInitialNetworkType = isDevelopment
22+ ? NETWORK_TYPES.LOCAL
23+ : NETWORK_TYPES.MAINNET;
26−// NB(shrugs): toggle this variable to use the default local state.
25+// NB(shrugs): toggle these variables to change the default local state.
27−// don't commit changes to this line, but there shouldn't be a problem
26+// try not to commit changes to this line, but there shouldn't be a problem
28// if you do because we'll never stub on a production build.
27// if you do because we'll never stub on a production build.
29const shouldStubLocal = false;
28const shouldStubLocal = false;
30−const isStubbed = isDevelopment && shouldStubLocal;
29+const kIsStubbed = isDevelopment && shouldStubLocal;
31−const kInitialRoutes = isStubbed
30+const kInitialRoutes = kIsStubbed
33− { name: ROUTE_NAMES.SHIPS },
34− { name: ROUTE_NAMES.WALLET },
35− { name: ROUTE_NAMES.NETWORK },
36 { name: ROUTE_NAMES.LANDING },
32 { name: ROUTE_NAMES.LANDING },
33+ { name: ROUTE_NAMES.NETWORK },
34+ { name: ROUTE_NAMES.WALLET },
35+ { name: ROUTE_NAMES.SHIPS },
38 : [{ name: ROUTE_NAMES.LANDING }];
37 : [{ name: ROUTE_NAMES.LANDING }];
39−const kInitialNetworkType = isDevelopment
38+
40− ? NETWORK_TYPES.LOCAL
39+const kInitialWallet = kIsStubbed
41− : NETWORK_TYPES.MAINNET;
40+ ? walletFromMnemonic(
41+ process.env.REACT_APP_DEV_MNEMONIC,
42+ process.env.REACT_APP_HD_PATH
43// the router itself is just a component that renders a specific view
46// the router itself is just a component that renders a specific view
44// depending on the history
47// depending on the history
@@ -73,30 +76,14 @@ const AllProviders = nest([
73 TxnConfirmationsProvider,
76 TxnConfirmationsProvider,
74 OnlineProvider,
77 OnlineProvider,
75 NetworkProvider,
78 NetworkProvider,
78class Bridge extends React.Component {
82class Bridge extends React.Component {
79 constructor(props) {
83 constructor(props) {
80 super(props);
84 super(props);
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'.
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
95 this.state = {
86 this.state = {
97− walletType: WALLET_NAMES.MNEMONIC,
99− walletHdPath: DEFAULT_HD_PATH,
100 // urbit wallet-related
87 // urbit wallet-related
101 urbitWallet: Nothing(),
88 urbitWallet: Nothing(),
102 authMnemonic: Nothing(),
89 authMnemonic: Nothing(),
@@ -109,9 +96,6 @@ class Bridge extends React.Component {
109 txnConfirmations: {},
96 txnConfirmations: {},
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);
99 this.setUrbitWallet = this.setUrbitWallet.bind(this);
116 this.setAuthMnemonic = this.setAuthMnemonic.bind(this);
100 this.setAuthMnemonic = this.setAuthMnemonic.bind(this);
117 this.setPointCursor = this.setPointCursor.bind(this);
101 this.setPointCursor = this.setPointCursor.bind(this);
@@ -125,14 +109,11 @@ class Bridge extends React.Component {
126 // If running in development, the following can be tweaked to get you set
110 // If running in development, the following can be tweaked to get you set
127 // up with a desirable initial state.
111 // up with a desirable initial state.
128− if (isStubbed) {
112+ if (kIsStubbed) {
129 const mnemonic = process.env.REACT_APP_DEV_MNEMONIC;
113 const mnemonic = process.env.REACT_APP_DEV_MNEMONIC;
130− const hdpath = process.env.REACT_APP_HD_PATH;
132 this.setState({
115 this.setState({
133 pointCursor: Just(0),
116 pointCursor: Just(0),
134− walletType: WALLET_NAMES.MNEMONIC,
135− wallet: walletFromMnemonic(mnemonic, hdpath),
136 urbitWallet: Nothing(),
117 urbitWallet: Nothing(),
137 authMnemonic: Just(mnemonic),
118 authMnemonic: Just(mnemonic),
@@ -146,28 +127,6 @@ class Bridge extends React.Component {
149− setWalletType(symbol) {
150− if (includes(WALLET_NAMES, symbol)) {
155− throw BRIDGE_ERROR.INVALID_WALLET_TYPE;
161− wal.address = wal.address || addressFromSecp256k1Public(wal.publicKey);
164− this.setState({ wallet });
167− setWalletHdPath(walletHdPath) {
168− this.setState({ walletHdPath });
171 // also sets wallet to ownership address
130 // also sets wallet to ownership address
172 setUrbitWallet(urbitWallet) {
131 setUrbitWallet(urbitWallet) {
173 let wallet = this.state.wallet;
132 let wallet = this.state.wallet;
@@ -206,9 +165,6 @@ class Bridge extends React.Component {
207 render() {
166 render() {
212 urbitWallet,
168 urbitWallet,
213 authMnemonic,
169 authMnemonic,
214 networkSeedCache,
170 networkSeedCache,
@@ -221,20 +177,15 @@ class Bridge extends React.Component {
222 <AllProviders
178 <AllProviders
223 initialRoutes={kInitialRoutes}
179 initialRoutes={kInitialRoutes}
224− initialNetworkType={kInitialNetworkType}>
180+ initialNetworkType={kInitialNetworkType}
181+ initialWallet={kInitialWallet}>
225 <Container>
182 <Container>
227 <VariableWidthColumn>
184 <VariableWidthColumn>
228− <Header wallet={wallet} pointCursor={pointCursor} />
185+ <Header pointCursor={pointCursor} />
230 <Row className={'row wrapper'}>
187 <Row className={'row wrapper'}>
232− setWalletType={this.setWalletType}
233− setWalletHdPath={this.setWalletHdPath}
234− setWallet={this.setWallet}
235− walletType={walletType}
236− walletHdPath={walletHdPath}
238 urbitWallet={urbitWallet}
189 urbitWallet={urbitWallet}
239 setUrbitWallet={this.setUrbitWallet}
190 setUrbitWallet={this.setUrbitWallet}
240 authMnemonic={authMnemonic}
191 authMnemonic={authMnemonic}