@@ -7,11 +7,10 @@ import Header from './components/Header';
77import { Container, Row, Col } from './components/Base';
88
99import { router } from './lib/router';
10−import { initWeb3 } from './lib/web3';
1110import { ROUTE_NAMES } from './lib/routeNames';
1211import { HistoryProvider, withHistory, useHistory } from './store/history';
1312import { TxnConfirmationsProvider } from './store/txnConfirmations';
14−import { NETWORK_NAMES } from './lib/network';
13+import { NETWORK_TYPES } from './lib/network';
1514import {
1615 WALLET_NAMES,
1716 DEFAULT_HD_PATH,
@@ -19,13 +18,16 @@ import {
1918 addressFromSecp256k1Public,
2019} from './lib/wallet';
2120import { BRIDGE_ERROR } from './lib/error';
22−import { isLocal } from './lib/flags';
21+import { isDevelopment } from './lib/flags';
22+import nest from './lib/nest';
23+import { OnlineProvider } from './store/online';
24+import { NetworkProvider } from './store/network';
2325
2426// NB(shrugs): toggle this variable to use the default local state.
2527// don't commit changes to this line, but there shouldn't be a problem
2628// if you do because we'll never stub on a production build.
2729const shouldStubLocal = false;
28−const isStubbed = isLocal && shouldStubLocal;
30+const isStubbed = isDevelopment && shouldStubLocal;
2931const kInitialRoutes = isStubbed
3032 ? [
3133 { name: ROUTE_NAMES.SHIPS },
@@ -34,9 +36,12 @@ const kInitialRoutes = isStubbed
3436 { name: ROUTE_NAMES.LANDING },
3537 ]
3638 : [{ name: ROUTE_NAMES.LANDING }];
39+const kInitialNetworkType = isDevelopment
40+ ? NETWORK_TYPES.LOCAL
41+ : NETWORK_TYPES.MAINNET;
3742
38−// the router itself is a component that renders a specific view
39−// based on the latest history state
43+// the router itself is just a component that renders a specific view
44+// depending on the history
4045const Router = function(props) {
4146 const history = useHistory();
4247 const Route = router(history.peek());
@@ -62,16 +67,18 @@ const VariableWidthColumn = withHistory(({ history, children }) => (
6267 </Col>
6368));
6469
70+// nest all of the providers within each other to avoid hella depth
71+const AllProviders = nest([
72+ HistoryProvider,
73+ TxnConfirmationsProvider,
74+ OnlineProvider,
75+ NetworkProvider,
76+]);
77+
6578class Bridge extends React.Component {
6679 constructor(props) {
6780 super(props);
6881
69− const networkType = isLocal ? NETWORK_NAMES.LOCAL : NETWORK_NAMES.MAINNET;
70−
71− // Sidestepping full network selection to allow for point viewing,
72− // but still respecting the networkType
73− const { web3, contracts } = initWeb3(networkType);
74−
7582 // NB (jtobin):
7683 //
7784 // Note that the 'wallet' prop has type depending on the 'walletType' prop.
@@ -86,10 +93,6 @@ class Bridge extends React.Component {
8693 // 'EthereumWallet'.
8794
8895 this.state = {
89− // network
90− networkType: networkType,
91− web3: Just(web3),
92− contracts: Just(contracts),
9396 // wallet
9497 walletType: WALLET_NAMES.MNEMONIC,
9598 wallet: Nothing(),
@@ -106,8 +109,6 @@ class Bridge extends React.Component {
106109 txnConfirmations: {},
107110 };
108111
109− this.setNetworkType = this.setNetworkType.bind(this);
110− this.setNetwork = this.setNetwork.bind(this);
111112 this.setWalletType = this.setWalletType.bind(this);
112113 this.setWallet = this.setWallet.bind(this);
113114 this.setWalletHdPath = this.setWalletHdPath.bind(this);
@@ -138,16 +139,6 @@ class Bridge extends React.Component {
138139 }
139140 }
140141
141− setNetworkType(symbol) {
142− if (includes(NETWORK_NAMES, symbol)) {
143− this.setState({
144− networkType: symbol,
145− });
146− } else {
147− throw BRIDGE_ERROR.INVALID_NETWORK_TYPE;
148− }
149− }
150−
151142 setNetworkSeedCache(networkSeed, revision) {
152143 this.setState({
153144 networkSeedCache: networkSeed,
@@ -155,13 +146,6 @@ class Bridge extends React.Component {
155146 });
156147 }
157148
158− setNetwork(web3, contracts) {
159− this.setState({
160− web3: web3,
161− contracts: contracts,
162− });
163− }
164−
165149 setWalletType(symbol) {
166150 if (includes(WALLET_NAMES, symbol)) {
167151 this.setState({
@@ -222,7 +206,6 @@ class Bridge extends React.Component {
222206
223207 render() {
224208 const {
225− networkType,
226209 walletType,
227210 walletHdPath,
228211 wallet,
@@ -233,66 +216,53 @@ class Bridge extends React.Component {
233216 pointCursor,
234217 pointCache,
235218 txnHashCursor,
236− web3,
237− contracts,
238219 } = this.state;
239220
240221 return (
241− <HistoryProvider initialRoutes={kInitialRoutes}>
242− <TxnConfirmationsProvider>
243− <Container>
244− <Row>
245− <VariableWidthColumn>
246− <Header
247− skipRoute={this.skipRoute}
248− networkType={networkType}
222+ <AllProviders
223+ initialRoutes={kInitialRoutes}
224+ initialNetworkType={kInitialNetworkType}>
225+ <Container>
226+ <Row>
227+ <VariableWidthColumn>
228+ <Header
229+ skipRoute={this.skipRoute}
230+ wallet={wallet}
231+ pointCursor={pointCursor}
232+ />
233+
234+ <Row className={'row wrapper'}>
235+ <Router
236+ setWalletType={this.setWalletType}
237+ setWalletHdPath={this.setWalletHdPath}
238+ setWallet={this.setWallet}
239+ walletType={walletType}
240+ walletHdPath={walletHdPath}
249241 wallet={wallet}
242+ urbitWallet={urbitWallet}
243+ setUrbitWallet={this.setUrbitWallet}
244+ authMnemonic={authMnemonic}
245+ setAuthMnemonic={this.setAuthMnemonic}
246+ setPointCursor={this.setPointCursor}
247+ addToPointCache={this.addToPointCache}
250248 pointCursor={pointCursor}
249+ pointCache={pointCache}
250+ networkSeedCache={networkSeedCache}
251+ networkRevisionCache={networkRevisionCache}
252+ setNetworkSeedCache={this.setNetworkSeedCache}
253+ onSent={this.setTxnHashCursor}
254+ setTxnHashCursor={this.setTxnHashCursor}
255+ txnHashCursor={txnHashCursor}
251256 />
252257
253− <Row className={'row wrapper'}>
254− <Router
255− // network
256− setNetworkType={this.setNetworkType}
257− setNetwork={this.setNetwork}
258− networkType={networkType}
259− web3={web3}
260− contracts={contracts}
261− // wallet
262− setWalletType={this.setWalletType}
263− setWalletHdPath={this.setWalletHdPath}
264− setWallet={this.setWallet}
265− walletType={walletType}
266− walletHdPath={walletHdPath}
267− wallet={wallet}
268− // urbit wallet
269− urbitWallet={urbitWallet}
270− setUrbitWallet={this.setUrbitWallet}
271− authMnemonic={authMnemonic}
272− setAuthMnemonic={this.setAuthMnemonic}
273− // point
274− setPointCursor={this.setPointCursor}
275− addToPointCache={this.addToPointCache}
276− pointCursor={pointCursor}
277− pointCache={pointCache}
278− networkSeedCache={networkSeedCache}
279− networkRevisionCache={networkRevisionCache}
280− setNetworkSeedCache={this.setNetworkSeedCache}
281− // txn
282− onSent={this.setTxnHashCursor}
283− setTxnHashCursor={this.setTxnHashCursor}
284− txnHashCursor={txnHashCursor}
285− />
286−
287− <div className={'push'} />
288− </Row>
258+ <div className={'push'} />
259+ </Row>
289260
290− <Footer />
291− </VariableWidthColumn>
292− </Row>
293− </Container>
294− </TxnConfirmationsProvider>
295− </HistoryProvider>
261+ <Footer />
262+ </VariableWidthColumn>
263+ </Row>
264+ </Container>
265+ </AllProviders>
296266 );
297267 }
298268}