1import Maybe from 'folktale/maybe'
2import * as lodash from 'lodash'
3import { Stack } from 'immutable'
4import React from 'react'
6import Footer from './components/Footer'
7import Header from './components/Header'
8import { Container, Row, Col } from './components/Base'
10import { ROUTE_NAMES, router } from './lib/router'
11import { NETWORK_NAMES } from './lib/network'
12import { WALLET_NAMES, DEFAULT_HD_PATH } from './lib/wallet'
13import { BRIDGE_ERROR } from './lib/error'
15import './style/index.css'
17class Bridge extends React.Component {
23 process.env.NODE_ENV === 'development'
25 : NETWORK_NAMES.MAINNET
29 // Note that the 'wallet' prop has type depending on the 'walletType' prop.
30 // These could be bound together in a single structure (so that
31 // 'walletType' acted more explicitly as a data constructor of sorts) but
32 // it doesn't necessarily help us much, since we branch on 'walletType'
33 // before setting 'wallet'.
35 // Wallets are always wrapped in Maybe. For most authentication
36 // mechanisms, Maybe wraps a BIP32 HD wallet; for Ethereum private keys,
37 // JSON keystore files, and Metamask authentication, it wraps an
42 routeCrumbs: Stack([ ROUTE_NAMES.LANDING ]),
44 networkType: networkType,
45 web3: Maybe.Nothing(),
46 contracts: Maybe.Nothing(),
48 walletType: WALLET_NAMES.MNEMONIC,
49 wallet: Maybe.Nothing(),
50 walletHdPath: DEFAULT_HD_PATH,
51 // urbit wallet-related
52 urbitWallet: Maybe.Nothing(),
53 authMnemonic: Maybe.Nothing(),
55 pointCursor: Maybe.Nothing(),
58 txnHashCursor: Maybe.Nothing()
61 this.pushRoute = this.pushRoute.bind(this)
62 this.popRoute = this.popRoute.bind(this)
63 this.skipRoute = this.skipRoute.bind(this)
64 this.setNetworkType = this.setNetworkType.bind(this)
65 this.setNetwork = this.setNetwork.bind(this)
66 this.setWalletType = this.setWalletType.bind(this)
67 this.setWallet = this.setWallet.bind(this)
68 this.setWalletHdPath = this.setWalletHdPath.bind(this)
69 this.setUrbitWallet = this.setUrbitWallet.bind(this)
70 this.setAuthMnemonic = this.setAuthMnemonic.bind(this)
71 this.setPointCursor = this.setPointCursor.bind(this)
72 this.setTxnHashCursor = this.setTxnHashCursor.bind(this)
73 this.addToPointCache = this.addToPointCache.bind(this)
80 // If running in development, the following can be tweaked to get you set
81 // up with a desirable initial state.
83 // if (process.env.NODE_ENV === 'development') {
85 // const socket = 'wss://localhost:8545'
86 // const provider = new Web3.providers.WebsocketProvider(socket)
87 // const web3 = new Web3(provider)
88 // const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
90 // const mnemonic = process.env.REACT_APP_DEV_MNEMONIC
91 // const hdpath = process.env.REACT_APP_HD_PATH
94 // routeCrumbs: Stack([
95 // ROUTE_NAMES.CREATE_GALAXY,
97 // // ROUTE_NAMES.MNEMONIC,
98 // ROUTE_NAMES.WALLET,
99 // ROUTE_NAMES.NETWORK,
100 // ROUTE_NAMES.LANDING
102 // networkType: NETWORK_NAMES.LOCAL,
103 // web3: Maybe.Just(web3),
104 // contracts: Maybe.Just(contracts),
105 // walletType: WALLET_NAMES.MNEMONIC,
106 // wallet: walletFromMnemonic(mnemonic, hdpath),
107 // urbitWallet: Maybe.Nothing(),
108 // authMnemonic: Maybe.Nothing()
114 if (lodash.includes(ROUTE_NAMES, symbol)) {
115 this.setState((state, _) => ({
116 routeCrumbs: state.routeCrumbs.push(symbol),
119 // Scroll to top of page with each route transition.
120 window.scrollTo(0, 0);
123 throw BRIDGE_ERROR.INVALID_ROUTE
128 this.setState((state, _) => ({
129 routeCrumbs: state.routeCrumbs.skip(len)
134 this.setState((state, _) => ({
135 routeCrumbs: state.routeCrumbs.shift()
139 setNetworkType(symbol) {
140 if (lodash.includes(NETWORK_NAMES, symbol)) {
145 throw BRIDGE_ERROR.INVALID_NETWORK_TYPE
149 setNetwork(web3, contracts) {
156 setWalletType(symbol) {
157 if (lodash.includes(WALLET_NAMES, symbol)) {
162 throw BRIDGE_ERROR.INVALID_WALLET_TYPE
167 this.setState({ wallet })
170 setWalletHdPath(walletHdPath) {
171 this.setState({ walletHdPath })
174 setUrbitWallet(urbitWallet) {
175 this.setState({ urbitWallet })
178 setAuthMnemonic(authMnemonic) {
179 this.setState({ authMnemonic })
182 setPointCursor(pointCursor) {
183 this.setState({ pointCursor })
186 addToPointCache(entry) {
187 this.setState((state, _) => ({
188 pointCache: Object.assign(state.pointCache, entry)
192 setTxnHashCursor(txnHashCursor) {
193 this.setState({ txnHashCursor })
212 const View = router(routeCrumbs.peek())
217 <Col className='col-md-1' />
218 <Col className='col-md-10' style={{maxWidth: '620px'}}>
220 routeCrumbs={ routeCrumbs }
221 skipRoute={ this.skipRoute }
222 networkType={ networkType }
224 pointCursor={ pointCursor } />
226 <Row className={ 'row wrapper' }>
230 pushRoute={ this.pushRoute }
231 popRoute={ this.popRoute }
233 setNetworkType={ this.setNetworkType }
234 setNetwork={ this.setNetwork }
235 networkType={ networkType }
237 contracts={ contracts }
239 setWalletType={ this.setWalletType }
240 setWalletHdPath={ this.setWalletHdPath }
241 setWallet={ this.setWallet }
242 walletType={ walletType }
243 walletHdPath={ walletHdPath }
246 urbitWallet={ urbitWallet }
247 setUrbitWallet={ this.setUrbitWallet }
248 authMnemonic={ authMnemonic }
249 setAuthMnemonic={ this.setAuthMnemonic }
251 setPointCursor={ this.setPointCursor }
252 addToPointCache={ this.addToPointCache }
253 pointCursor={ pointCursor }
254 pointCache={ pointCache }
256 setTxnHashCursor={ this.setTxnHashCursor }
257 txnHashCursor={ txnHashCursor } />
259 <div className={'push'} />
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