2019-04-15 19:56:40 +03:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom'
|
|
|
|
import MediaQuery from 'react-responsive'
|
|
|
|
import { Web3Connect, startWatching, initialize } from '../ducks/web3connect'
|
|
|
|
import { setAddresses } from '../ducks/addresses'
|
|
|
|
import Header from '../components/Header'
|
|
|
|
import Swap from './Swap'
|
|
|
|
import Send from './Send'
|
|
|
|
import Pool from './Pool'
|
2018-10-07 05:30:55 +03:00
|
|
|
|
2019-04-15 19:56:40 +03:00
|
|
|
import './App.scss'
|
2018-10-07 00:24:17 +03:00
|
|
|
|
|
|
|
class App extends Component {
|
2018-10-27 10:54:52 +03:00
|
|
|
componentWillMount() {
|
2019-04-15 19:56:40 +03:00
|
|
|
const { initialize, startWatching } = this.props
|
|
|
|
initialize().then(startWatching)
|
|
|
|
}
|
2018-10-27 10:54:52 +03:00
|
|
|
|
|
|
|
componentWillUpdate() {
|
2019-04-15 19:56:40 +03:00
|
|
|
const { web3, setAddresses } = this.props
|
2018-10-27 10:54:52 +03:00
|
|
|
|
|
|
|
if (this.hasSetNetworkId || !web3 || !web3.eth || !web3.eth.net || !web3.eth.net.getId) {
|
2019-04-15 19:56:40 +03:00
|
|
|
return
|
2018-10-27 10:54:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
web3.eth.net.getId((err, networkId) => {
|
|
|
|
if (!err && !this.hasSetNetworkId) {
|
2019-04-15 19:56:40 +03:00
|
|
|
setAddresses(networkId)
|
|
|
|
this.hasSetNetworkId = true
|
2018-10-27 10:54:52 +03:00
|
|
|
}
|
2019-04-15 19:56:40 +03:00
|
|
|
})
|
2018-10-27 10:54:52 +03:00
|
|
|
}
|
|
|
|
|
2018-10-07 00:30:20 +03:00
|
|
|
render() {
|
2018-10-10 12:09:26 +03:00
|
|
|
if (!this.props.initialized) {
|
2019-04-15 19:56:40 +03:00
|
|
|
return <noscript />
|
2018-10-10 12:09:26 +03:00
|
|
|
}
|
|
|
|
|
2018-10-07 00:30:20 +03:00
|
|
|
return (
|
2018-10-22 23:42:29 +03:00
|
|
|
<div id="app-container">
|
2019-01-03 12:04:27 +03:00
|
|
|
<MediaQuery query="(min-width: 768px)">
|
2018-10-28 02:43:16 +03:00
|
|
|
<Header />
|
|
|
|
</MediaQuery>
|
2018-10-22 23:42:29 +03:00
|
|
|
<Web3Connect />
|
|
|
|
<BrowserRouter>
|
2019-04-15 21:09:46 +03:00
|
|
|
<div className="app__wrapper">
|
|
|
|
<Switch>
|
2019-01-07 18:35:00 +03:00
|
|
|
<Route exact path="/swap" component={Swap} />
|
|
|
|
<Route exact path="/send" component={Send} />
|
|
|
|
<Route exact path="/add-liquidity" component={Pool} />
|
|
|
|
<Route exact path="/remove-liquidity" component={Pool} />
|
|
|
|
<Route exact path="/create-exchange/:tokenAddress?" component={Pool} />
|
|
|
|
<Redirect exact from="/" to="/swap" />
|
2019-04-15 21:09:46 +03:00
|
|
|
</Switch>
|
|
|
|
</div>
|
2018-10-22 23:42:29 +03:00
|
|
|
</BrowserRouter>
|
|
|
|
</div>
|
2019-04-15 19:56:40 +03:00
|
|
|
)
|
2018-10-07 00:30:20 +03:00
|
|
|
}
|
2018-10-07 00:24:17 +03:00
|
|
|
}
|
|
|
|
|
2018-10-28 02:43:16 +03:00
|
|
|
export default connect(
|
2018-10-10 12:09:26 +03:00
|
|
|
state => ({
|
2018-10-27 10:54:52 +03:00
|
|
|
account: state.web3connect.account,
|
2018-10-28 02:43:16 +03:00
|
|
|
initialized: state.web3connect.initialized,
|
2019-04-15 19:56:40 +03:00
|
|
|
web3: state.web3connect.web3
|
2018-10-27 10:54:52 +03:00
|
|
|
}),
|
|
|
|
dispatch => ({
|
|
|
|
setAddresses: networkId => dispatch(setAddresses(networkId)),
|
|
|
|
initialize: () => dispatch(initialize()),
|
2019-04-15 19:56:40 +03:00
|
|
|
startWatching: () => dispatch(startWatching())
|
|
|
|
})
|
|
|
|
)(App)
|