@@ -1,44 +1,50 @@
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 { 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, 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
45+const kInitialMnemonic = kIsStubbed
46+ ? process.env.REACT_APP_DEV_MNEMONIC
43// the router itself is just a component that renders a specific view
49// the router itself is just a component that renders a specific view
44// depending on the history
50// depending on the history
@@ -49,23 +55,26 @@ const Router = function(props) {
49 return <Route {...props} />;
55 return <Route {...props} />;
52−// NB(shrugs): separate component because it needs withHistory
58+// NB(shrugs): separate component because it needs useHistory
53// this will be must better structured as part of the UI overhaul
59// 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();
55 // For the invite acceptance flow, widen the screen to use the full
62 // For the invite acceptance flow, widen the screen to use the full
56 // container, and hide the breadcrumbs
63 // container, and hide the breadcrumbs
58− className={
66+ className={
59− history.includes(ROUTE_NAMES.INVITE_TICKET)
67+ history.includes(ROUTE_NAMES.INVITE_TICKET)
60− ? 'col-md-12'
68+ ? 'col-md-12'
61− : 'col-md-offset-1 col-md-10'
69+ : 'col-md-offset-1 col-md-10'
64− history.includes(ROUTE_NAMES.INVITE_TICKET) ? {} : { maxWidth: '620px' }
72+ history.includes(ROUTE_NAMES.INVITE_TICKET) ? {} : { maxWidth: '620px' }
66− {children}
74+ {children}
70// nest all of the providers within each other to avoid hella depth
79// nest all of the providers within each other to avoid hella depth
71const AllProviders = nest([
80const AllProviders = nest([
@@ -73,33 +82,14 @@ const AllProviders = nest([
73 TxnConfirmationsProvider,
82 TxnConfirmationsProvider,
74 OnlineProvider,
83 OnlineProvider,
75 NetworkProvider,
84 NetworkProvider,
78class Bridge extends React.Component {
88class Bridge extends React.Component {
79 constructor(props) {
89 constructor(props) {
80 super(props);
90 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 = {
92 this.state = {
97− walletType: WALLET_NAMES.MNEMONIC,
99− walletHdPath: DEFAULT_HD_PATH,
100− // urbit wallet-related
101− urbitWallet: Nothing(),
102− authMnemonic: Nothing(),
103 networkSeedCache: null,
93 networkSeedCache: null,
105 pointCursor: Nothing(),
95 pointCursor: Nothing(),
@@ -109,11 +99,6 @@ class Bridge extends React.Component {
109 txnConfirmations: {},
99 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);
116− this.setAuthMnemonic = this.setAuthMnemonic.bind(this);
117 this.setPointCursor = this.setPointCursor.bind(this);
102 this.setPointCursor = this.setPointCursor.bind(this);
118 this.setTxnHashCursor = this.setTxnHashCursor.bind(this);
103 this.setTxnHashCursor = this.setTxnHashCursor.bind(this);
119 this.setNetworkSeedCache = this.setNetworkSeedCache.bind(this);
104 this.setNetworkSeedCache = this.setNetworkSeedCache.bind(this);
@@ -125,16 +110,9 @@ class Bridge extends React.Component {
126 // If running in development, the following can be tweaked to get you set
111 // If running in development, the following can be tweaked to get you set
127 // up with a desirable initial state.
112 // up with a desirable initial state.
128− if (isStubbed) {
113+ if (kIsStubbed) {
129− const mnemonic = process.env.REACT_APP_DEV_MNEMONIC;
130− const hdpath = process.env.REACT_APP_HD_PATH;
132 this.setState({
114 this.setState({
133 pointCursor: Just(0),
115 pointCursor: Just(0),
134− walletType: WALLET_NAMES.MNEMONIC,
135− wallet: walletFromMnemonic(mnemonic, hdpath),
136− urbitWallet: Nothing(),
137− authMnemonic: Just(mnemonic),
@@ -146,50 +124,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
172− setUrbitWallet(urbitWallet) {
173− let wallet = this.state.wallet;
174− if (Just.hasInstance(urbitWallet)) {
175− const mnemonic = urbitWallet.value.ownership.seed;
176− wallet = walletFromMnemonic(
179− urbitWallet.value.meta.passphrase
182− wal.address = urbitWallet.value.ownership.keys.address;
186− this.setState({ urbitWallet, wallet });
189− setAuthMnemonic(authMnemonic) {
190− this.setState({ authMnemonic });
193 setPointCursor(pointCursor) {
127 setPointCursor(pointCursor) {
194 this.setState({ pointCursor });
128 this.setState({ pointCursor });
@@ -206,11 +140,6 @@ class Bridge extends React.Component {
207 render() {
141 render() {
214 networkSeedCache,
143 networkSeedCache,
215 networkRevisionCache,
144 networkRevisionCache,
216 pointCursor,
145 pointCursor,
@@ -221,24 +150,16 @@ class Bridge extends React.Component {
222 <AllProviders
151 <AllProviders
223 initialRoutes={kInitialRoutes}
152 initialRoutes={kInitialRoutes}
224− initialNetworkType={kInitialNetworkType}>
153+ initialNetworkType={kInitialNetworkType}
154+ initialWallet={kInitialWallet}
155+ initialMnemonic={kInitialMnemonic}>
225 <Container>
156 <Container>
227 <VariableWidthColumn>
158 <VariableWidthColumn>
228− <Header wallet={wallet} pointCursor={pointCursor} />
159+ <Header pointCursor={pointCursor} />
230 <Row className={'row wrapper'}>
161 <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}
239− setUrbitWallet={this.setUrbitWallet}
240− authMnemonic={authMnemonic}
241− setAuthMnemonic={this.setAuthMnemonic}
242 setPointCursor={this.setPointCursor}
163 setPointCursor={this.setPointCursor}
243 addToPointCache={this.addToPointCache}
164 addToPointCache={this.addToPointCache}
244 pointCursor={pointCursor}
165 pointCursor={pointCursor}