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 ]),
45 networkType: networkType,
46 web3: Maybe.Nothing(),
47 contracts: Maybe.Nothing(),
49 walletType: WALLET_NAMES.MNEMONIC,
50 wallet: Maybe.Nothing(),
51 walletHdPath: DEFAULT_HD_PATH,
52 // urbit wallet-related
53 urbitWallet: Maybe.Nothing(),
54 authMnemonic: Maybe.Nothing(),
55 networkSeedCache: null,
57 pointCursor: Maybe.Nothing(),
60 txnHashCursor: Maybe.Nothing()
63 this.pushRoute = this.pushRoute.bind(this)
64 this.popRoute = this.popRoute.bind(this)
65 this.skipRoute = this.skipRoute.bind(this)
66 this.setNetworkType = this.setNetworkType.bind(this)
67 this.setNetwork = this.setNetwork.bind(this)
68 this.setWalletType = this.setWalletType.bind(this)
69 this.setWallet = this.setWallet.bind(this)
70 this.setWalletHdPath = this.setWalletHdPath.bind(this)
71 this.setUrbitWallet = this.setUrbitWallet.bind(this)
72 this.setAuthMnemonic = this.setAuthMnemonic.bind(this)
73 this.setPointCursor = this.setPointCursor.bind(this)
74 this.setTxnHashCursor = this.setTxnHashCursor.bind(this)
75 this.setNetworkSeedCache = this.setNetworkSeedCache.bind(this)
76 this.addToPointCache = this.addToPointCache.bind(this)
80 window.history.pushState(null, null, null);
82 window.onpopstate = (e) => {
83 window.history.pushState(null, null, null);
89 // If running in development, the following can be tweaked to get you set
90 // up with a desirable initial state.
92 // if (process.env.NODE_ENV === 'development') {
94 // const socket = 'ws://localhost:8545'
95 // const provider = new Web3.providers.WebsocketProvider(socket)
96 // const web3 = new Web3(provider)
97 // const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
99 // const mnemonic = process.env.REACT_APP_DEV_MNEMONIC
100 // const hdpath = process.env.REACT_APP_HD_PATH
103 // routeCrumbs: Stack([
104 // // ROUTE_NAMES.CREATE_GALAXY,
105 // // ROUTE_NAMES.SHIP,
106 // ROUTE_NAMES.SHIPS,
107 // // ROUTE_NAMES.MNEMONIC,
108 // ROUTE_NAMES.WALLET,
109 // ROUTE_NAMES.NETWORK,
110 // ROUTE_NAMES.LANDING
112 // networkType: NETWORK_NAMES.LOCAL,
113 // pointCursor: Maybe.Just(0),
114 // web3: Maybe.Just(web3),
115 // contracts: Maybe.Just(contracts),
116 // walletType: WALLET_NAMES.MNEMONIC,
117 // wallet: walletFromMnemonic(mnemonic, hdpath),
118 // urbitWallet: Maybe.Nothing(),
119 // authMnemonic: Maybe.Just('benefit crew supreme gesture quantum web media hazard theory mercy wing kitten')
124 pushRoute(symbol, routeData) {
125 if (lodash.includes(ROUTE_NAMES, symbol)) {
126 this.setState((state, _) => ({
127 routeCrumbs: state.routeCrumbs.push(symbol),
131 // Scroll to top of page with each route transition.
132 window.scrollTo(0, 0);
135 throw BRIDGE_ERROR.INVALID_ROUTE
140 this.setState((state, _) => ({
141 routeCrumbs: state.routeCrumbs.skip(len)
146 this.setState((state, _) => ({
147 routeCrumbs: state.routeCrumbs.shift()
151 setNetworkType(symbol) {
152 if (lodash.includes(NETWORK_NAMES, symbol)) {
157 throw BRIDGE_ERROR.INVALID_NETWORK_TYPE
161 setNetworkSeedCache(networkSeed) {
163 networkSeedCache: networkSeed
167 setNetwork(web3, contracts) {
174 setWalletType(symbol) {
175 if (lodash.includes(WALLET_NAMES, symbol)) {
180 throw BRIDGE_ERROR.INVALID_WALLET_TYPE
185 this.setState({ wallet })
188 setWalletHdPath(walletHdPath) {
189 this.setState({ walletHdPath })
192 setUrbitWallet(urbitWallet) {
193 this.setState({ urbitWallet })
196 setAuthMnemonic(authMnemonic) {
197 this.setState({ authMnemonic })
200 setPointCursor(pointCursor) {
201 this.setState({ pointCursor })
204 addToPointCache(entry) {
205 this.setState((state, _) => ({
206 pointCache: Object.assign(state.pointCache, entry)
210 setTxnHashCursor(txnHashCursor) {
211 this.setState({ txnHashCursor })
232 const View = router(routeCrumbs.peek())
237 <Col className='col-md-1' />
238 <Col className='col-md-10' style={{maxWidth: '620px'}}>
240 routeCrumbs={ routeCrumbs }
241 skipRoute={ this.skipRoute }
242 networkType={ networkType }
244 pointCursor={ pointCursor } />
246 <Row className={ 'row wrapper' }>
250 pushRoute={ this.pushRoute }
251 popRoute={ this.popRoute }
252 routeData={ routeData }
254 setNetworkType={ this.setNetworkType }
255 setNetwork={ this.setNetwork }
256 networkType={ networkType }
258 contracts={ contracts }
260 setWalletType={ this.setWalletType }
261 setWalletHdPath={ this.setWalletHdPath }
262 setWallet={ this.setWallet }
263 walletType={ walletType }
264 walletHdPath={ walletHdPath }
267 urbitWallet={ urbitWallet }
268 setUrbitWallet={ this.setUrbitWallet }
269 authMnemonic={ authMnemonic }
270 setAuthMnemonic={ this.setAuthMnemonic }
272 setPointCursor={ this.setPointCursor }
273 addToPointCache={ this.addToPointCache }
274 pointCursor={ pointCursor }
275 pointCache={ pointCache }
276 networkSeedCache= { networkSeedCache }
277 setNetworkSeedCache= { this.setNetworkSeedCache }
279 setTxnHashCursor={ this.setTxnHashCursor }
280 txnHashCursor={ txnHashCursor } />
282 <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