1import Maybe from 'folktale/maybe'
2import * as lodash from 'lodash'
3import * as azimuth from 'azimuth-js'
4import { Stack } from 'immutable'
5import { CONTRACT_ADDRESSES } from './lib/contracts'
6import React from 'react'
9import Footer from './components/Footer'
10import Header from './components/Header'
11import { Container, Row, Col } from './components/Base'
13import { ROUTE_NAMES, router } from './lib/router'
14import { NETWORK_NAMES } from './lib/network'
15import { WALLET_NAMES, DEFAULT_HD_PATH } from './lib/wallet'
16import { BRIDGE_ERROR } from './lib/error'
18import './style/index.css'
20const initWeb3 = (networkType) => {
21 if (networkType === NETWORK_NAMES.MAINNET) {
23 `https://mainnet.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`
25 const provider = new Web3.providers.HttpProvider(endpoint)
26 const web3 = new Web3(provider)
27 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.MAINNET)
28 return {web3: web3, contracts: contracts}
29 } else if (networkType === NETWORK_NAMES.LOCAL) {
30 const endpoint = 'wss://localhost:8545'
31 const provider = new Web3.providers.WebsocketProvider(endpoint)
32 const web3 = new Web3(provider)
33 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
34 return {web3: web3, contracts: contracts}
38class Bridge extends React.Component {
44 process.env.NODE_ENV === 'development'
46 : NETWORK_NAMES.MAINNET
48 // Sidestepping full network selection to allow for point viewing,
49 // but still respecting the networkType
50 const { web3, contracts } = initWeb3(networkType)
54 // Note that the 'wallet' prop has type depending on the 'walletType' prop.
55 // These could be bound together in a single structure (so that
56 // 'walletType' acted more explicitly as a data constructor of sorts) but
57 // it doesn't necessarily help us much, since we branch on 'walletType'
58 // before setting 'wallet'.
60 // Wallets are always wrapped in Maybe. For most authentication
61 // mechanisms, Maybe wraps a BIP32 HD wallet; for Ethereum private keys,
62 // JSON keystore files, and Metamask authentication, it wraps an
67 routeCrumbs: Stack([ ROUTE_NAMES.LANDING ]),
69 networkType: networkType,
70 web3: Maybe.Just(web3),
71 contracts: Maybe.Just(contracts),
73 walletType: WALLET_NAMES.MNEMONIC,
74 wallet: Maybe.Nothing(),
75 walletHdPath: DEFAULT_HD_PATH,
76 // urbit wallet-related
77 urbitWallet: Maybe.Nothing(),
78 authMnemonic: Maybe.Nothing(),
80 pointCursor: Maybe.Nothing(),
83 txnHashCursor: Maybe.Nothing()
86 this.pushRoute = this.pushRoute.bind(this)
87 this.popRoute = this.popRoute.bind(this)
88 this.skipRoute = this.skipRoute.bind(this)
89 this.setNetworkType = this.setNetworkType.bind(this)
90 this.setNetwork = this.setNetwork.bind(this)
91 this.setWalletType = this.setWalletType.bind(this)
92 this.setWallet = this.setWallet.bind(this)
93 this.setWalletHdPath = this.setWalletHdPath.bind(this)
94 this.setUrbitWallet = this.setUrbitWallet.bind(this)
95 this.setAuthMnemonic = this.setAuthMnemonic.bind(this)
96 this.setPointCursor = this.setPointCursor.bind(this)
97 this.setTxnHashCursor = this.setTxnHashCursor.bind(this)
98 this.addToPointCache = this.addToPointCache.bind(this)
101 componentDidMount() {
105 // If running in development, the following can be tweaked to get you set
106 // up with a desirable initial state.
108 // if (process.env.NODE_ENV === 'development') {
110 // const socket = 'wss://localhost:8545'
111 // const provider = new Web3.providers.WebsocketProvider(socket)
112 // const web3 = new Web3(provider)
113 // const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
115 // const mnemonic = process.env.REACT_APP_DEV_MNEMONIC
116 // const hdpath = process.env.REACT_APP_HD_PATH
119 // routeCrumbs: Stack([
120 // ROUTE_NAMES.CREATE_GALAXY,
121 // ROUTE_NAMES.SHIPS,
122 // // ROUTE_NAMES.MNEMONIC,
123 // ROUTE_NAMES.WALLET,
124 // ROUTE_NAMES.NETWORK,
125 // ROUTE_NAMES.LANDING
127 // networkType: NETWORK_NAMES.LOCAL,
128 // web3: Maybe.Just(web3),
129 // contracts: Maybe.Just(contracts),
130 // walletType: WALLET_NAMES.MNEMONIC,
131 // wallet: walletFromMnemonic(mnemonic, hdpath),
132 // urbitWallet: Maybe.Nothing(),
133 // authMnemonic: Maybe.Nothing()
139 if (lodash.includes(ROUTE_NAMES, symbol)) {
140 this.setState((state, _) => ({
141 routeCrumbs: state.routeCrumbs.push(symbol),
144 // Scroll to top of page with each route transition.
145 window.scrollTo(0, 0);
148 throw BRIDGE_ERROR.INVALID_ROUTE
153 this.setState((state, _) => ({
154 routeCrumbs: state.routeCrumbs.skip(len)
159 this.setState((state, _) => ({
160 routeCrumbs: state.routeCrumbs.shift()
164 setNetworkType(symbol) {
165 if (lodash.includes(NETWORK_NAMES, symbol)) {
170 throw BRIDGE_ERROR.INVALID_NETWORK_TYPE
174 setNetwork(web3, contracts) {
181 setWalletType(symbol) {
182 if (lodash.includes(WALLET_NAMES, symbol)) {
187 throw BRIDGE_ERROR.INVALID_WALLET_TYPE
192 this.setState({ wallet })
195 setWalletHdPath(walletHdPath) {
196 this.setState({ walletHdPath })
199 setUrbitWallet(urbitWallet) {
200 this.setState({ urbitWallet })
203 setAuthMnemonic(authMnemonic) {
204 this.setState({ authMnemonic })
207 setPointCursor(pointCursor) {
208 this.setState({ pointCursor })
211 addToPointCache(entry) {
212 this.setState((state, _) => ({
213 pointCache: Object.assign(state.pointCache, entry)
217 setTxnHashCursor(txnHashCursor) {
218 this.setState({ txnHashCursor })
237 const View = router(routeCrumbs.peek())
242 <Col className='col-md-1' />
243 <Col className='col-md-10' style={{maxWidth: '620px'}}>
245 routeCrumbs={ routeCrumbs }
246 skipRoute={ this.skipRoute }
247 networkType={ networkType }
249 pointCursor={ pointCursor } />
251 <Row className={ 'row wrapper' }>
255 pushRoute={ this.pushRoute }
256 popRoute={ this.popRoute }
258 setNetworkType={ this.setNetworkType }
259 setNetwork={ this.setNetwork }
260 networkType={ networkType }
262 contracts={ contracts }
264 setWalletType={ this.setWalletType }
265 setWalletHdPath={ this.setWalletHdPath }
266 setWallet={ this.setWallet }
267 walletType={ walletType }
268 walletHdPath={ walletHdPath }
271 urbitWallet={ urbitWallet }
272 setUrbitWallet={ this.setUrbitWallet }
273 authMnemonic={ authMnemonic }
274 setAuthMnemonic={ this.setAuthMnemonic }
276 setPointCursor={ this.setPointCursor }
277 addToPointCache={ this.addToPointCache }
278 pointCursor={ pointCursor }
279 pointCache={ pointCache }
281 setTxnHashCursor={ this.setTxnHashCursor }
282 txnHashCursor={ txnHashCursor } />
284 <div className={'push'} />
290 <Col className='col-md-1' />
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list