on master help sign in
cleanup: comments and restructuring
e2171dfMatt Condon (shrugs)
src/bridge/Bridge.js+35−60
@@ -1,15 +1,13 @@
1+import React from "react";
1import { Just, Nothing } from "folktale/maybe";
2import { Just, Nothing } from "folktale/maybe";
2import { includes } from "lodash";
3import { includes } from "lodash";
3−import * as azimuth from "azimuth-js";
4−import { CONTRACT_ADDRESSES } from "./lib/contracts";
5−import React from "react";
6
4
7−import Web3 from "web3";
8import Footer from "./components/Footer";
5import Footer from "./components/Footer";
9import Header from "./components/Header";
6import Header from "./components/Header";
10import { Container, Row, Col } from "./components/Base";
7import { Container, Row, Col } from "./components/Base";
11
8
12import { router } from "./lib/router";
9import { router } from "./lib/router";
10+import { initWeb3 } from "./lib/web3";
13import { ROUTE_NAMES } from "./lib/routeNames";
11import { ROUTE_NAMES } from "./lib/routeNames";
14import { HistoryProvider, withHistory, useHistory } from "./lib/history";
12import { HistoryProvider, withHistory, useHistory } from "./lib/history";
15import { TxnConfirmationsProvider } from "./store/txnConfirmations";
13import { TxnConfirmationsProvider } from "./store/txnConfirmations";
@@ -21,34 +19,32 @@ import {
21 addressFromSecp256k1Public,
19 addressFromSecp256k1Public,
22} from "./lib/wallet";
20} from "./lib/wallet";
23import { BRIDGE_ERROR } from "./lib/error";
21import { BRIDGE_ERROR } from "./lib/error";
22+import { isLocal } from "./lib/flags";
24
23
25−const initWeb3 = networkType => {
24+// NB(shrugs): toggle this shouldStubLocal variable to use the default local state.
26− if (networkType === NETWORK_NAMES.MAINNET) {
25+// don't commit changes to this line, but there shouldn't be a problem because we'll never stub
27− const endpoint = `https://mainnet.infura.io/v3/${
26+// on a production build.
28− process.env.REACT_APP_INFURA_ENDPOINT
27+const shouldStubLocal = false;
29− }`;
28+const isStubbed = isLocal && shouldStubLocal;
29+const kInitialRoutes = isStubbed
30+ ? [
31+ { name: ROUTE_NAMES.SHIPS },
32+ { name: ROUTE_NAMES.WALLET },
33+ { name: ROUTE_NAMES.NETWORK },
34+ { name: ROUTE_NAMES.LANDING },
35+ ]
36+ : [{ name: ROUTE_NAMES.LANDING }];
30
37
31− const provider = new Web3.providers.HttpProvider(endpoint);
38+// the router itself is a component that renders a specific view based on the latest history state
32− const web3 = new Web3(provider);
33− const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.MAINNET);
34− return { web3: web3, contracts: contracts };
35− } else if (networkType === NETWORK_NAMES.LOCAL) {
36− const protocol = process.env.NODE_ENV === "development" ? "ws" : "wss";
37− const endpoint = `${protocol}://localhost:8545`;
38− const provider = new Web3.providers.WebsocketProvider(endpoint);
39− const web3 = new Web3(provider);
40− const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV);
41− return { web3: web3, contracts: contracts };
42− }
43−};
44−
45−export const View = function(props) {
39+const Router = function(props) {
46 const history = useHistory();
40 const history = useHistory();
47 const Route = router(history.peek());
41 const Route = router(history.peek());
48
42
49 return <Route {...props} />;
43 return <Route {...props} />;
50};
44};
51
45
46+// NB(shrugs): separate component because it needs withHistory
47+// this will be must better structured as part of the UI overhaul
52const VariableWidthColumn = withHistory(({ history, children }) => (
48const VariableWidthColumn = withHistory(({ history, children }) => (
53 // For the invite acceptance flow, widen the screen to use the full
49 // For the invite acceptance flow, widen the screen to use the full
54 // container, and hide the breadcrumbs
50 // container, and hide the breadcrumbs
@@ -70,10 +66,7 @@ class Bridge extends React.Component {
70 constructor(props) {
66 constructor(props) {
71 super(props);
67 super(props);
72
68
73− const networkType =
74− process.env.NODE_ENV === "development"
75− ? NETWORK_NAMES.LOCAL
76− : NETWORK_NAMES.MAINNET;
69+ const networkType = isLocal ? NETWORK_NAMES.LOCAL : NETWORK_NAMES.MAINNET;
77
70
78 // Sidestepping full network selection to allow for point viewing,
71 // Sidestepping full network selection to allow for point viewing,
79 // but still respecting the networkType
72 // but still respecting the networkType
@@ -127,40 +120,22 @@ class Bridge extends React.Component {
127 }
120 }
128
121
129 componentDidMount() {
122 componentDidMount() {
130− // NB (jtobin):
123+ // NB (jtobin, shrugs):
131 //
124 //
132 // If running in development, the following can be tweaked to get you set
125 // If running in development, the following can be tweaked to get you set
133 // up with a desirable initial state.
126 // up with a desirable initial state.
134− // if (process.env.NODE_ENV === 'development') {
127+ if (isStubbed) {
135− //
136− // const socket = 'ws://localhost:8545'
137− // const provider = new Web3.providers.WebsocketProvider(socket)
138− // const web3 = new Web3(provider)
139− // const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
140− //
141− // const mnemonic = process.env.REACT_APP_DEV_MNEMONIC
128+ const mnemonic = process.env.REACT_APP_DEV_MNEMONIC;
142− // const hdpath = process.env.REACT_APP_HD_PATH
129+ const hdpath = process.env.REACT_APP_HD_PATH;
143− //
130+
144− // this.setState({
131+ this.setState({
145− // routeCrumbs: Stack([
146− // // ROUTE_NAMES.CREATE_GALAXY,
147− // // ROUTE_NAMES.SHIP,
148− // ROUTE_NAMES.SHIPS,
149− // // ROUTE_NAMES.MNEMONIC,
150− // ROUTE_NAMES.WALLET,
151− // ROUTE_NAMES.NETWORK,
152− // ROUTE_NAMES.LANDING
153− // ]),
154− // networkType: NETWORK_NAMES.LOCAL,
155− // pointCursor: Just(0),
132+ pointCursor: Just(0),
156− // web3: Just(web3),
157− // contracts: Just(contracts),
158− // walletType: WALLET_NAMES.MNEMONIC,
133+ walletType: WALLET_NAMES.MNEMONIC,
159− // wallet: walletFromMnemonic(mnemonic, hdpath),
134+ wallet: walletFromMnemonic(mnemonic, hdpath),
160− // urbitWallet: Nothing(),
135+ urbitWallet: Nothing(),
161− // authMnemonic: Just('benefit crew supreme gesture quantum web media hazard theory mercy wing kitten')
136+ authMnemonic: Just(mnemonic),
162− // })
137+ });
163− // }
138+ }
164 }
139 }
165
140
166 setNetworkType(symbol) {
141 setNetworkType(symbol) {
@@ -276,7 +251,7 @@ class Bridge extends React.Component {
276 />
251 />
277
252
278 <Row className={"row wrapper"}>
253 <Row className={"row wrapper"}>
279− <View
254+ <Router
280 // network
255 // network
281 setNetworkType={this.setNetworkType}
256 setNetworkType={this.setNetworkType}
282 setNetwork={this.setNetwork}
257 setNetwork={this.setNetwork}
src/bridge/lib/flags.jsnew file+1
@@ -0,0 +1 @@
1+export const isLocal = process.env.NODE_ENV === "development";
src/bridge/lib/web3.jsnew file+25
@@ -0,0 +1,25 @@
1+import * as azimuth from "azimuth-js";
2+import Web3 from "web3";
3+
4+import { CONTRACT_ADDRESSES } from "./contracts";
5+import { NETWORK_NAMES } from "./network";
6+
7+export const initWeb3 = networkType => {
8+ if (networkType === NETWORK_NAMES.MAINNET) {
9+ const endpoint = `https://mainnet.infura.io/v3/${
10+ process.env.REACT_APP_INFURA_ENDPOINT
11+ }`;
12+
13+ const provider = new Web3.providers.HttpProvider(endpoint);
14+ const web3 = new Web3(provider);
15+ const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.MAINNET);
16+ return { web3: web3, contracts: contracts };
17+ } else if (networkType === NETWORK_NAMES.LOCAL) {
18+ const protocol = process.env.NODE_ENV === "development" ? "ws" : "wss";
19+ const endpoint = `${protocol}://localhost:8545`;
20+ const provider = new Web3.providers.WebsocketProvider(endpoint);
21+ const web3 = new Web3(provider);
22+ const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV);
23+ return { web3: web3, contracts: contracts };
24+ }
25+};