uniswap-interface-uncensored/src/pages/App.js

75 lines
2.1 KiB
JavaScript
Raw Normal View History

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
import './App.scss'
2018-10-07 00:24:17 +03:00
class App extends Component {
componentWillMount() {
const { initialize, startWatching } = this.props
initialize().then(startWatching)
}
componentWillUpdate() {
const { web3, setAddresses } = this.props
if (this.hasSetNetworkId || !web3 || !web3.eth || !web3.eth.net || !web3.eth.net.getId) {
return
}
web3.eth.net.getId((err, networkId) => {
if (!err && !this.hasSetNetworkId) {
setAddresses(networkId)
this.hasSetNetworkId = true
}
})
}
2018-10-07 00:30:20 +03:00
render() {
if (!this.props.initialized) {
return <noscript />
}
2018-10-07 00:30:20 +03:00
return (
<div id="app-container">
<MediaQuery query="(min-width: 768px)">
2018-10-28 02:43:16 +03:00
<Header />
</MediaQuery>
<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>
</BrowserRouter>
</div>
)
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(
state => ({
account: state.web3connect.account,
2018-10-28 02:43:16 +03:00
initialized: state.web3connect.initialized,
web3: state.web3connect.web3
}),
dispatch => ({
setAddresses: networkId => dispatch(setAddresses(networkId)),
initialize: () => dispatch(initialize()),
startWatching: () => dispatch(startWatching())
})
)(App)