2017-12-11 17:35:57 -08:00
|
|
|
import React, {Component} from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2017-12-12 00:29:28 -08:00
|
|
|
import swal from 'sweetalert';
|
2017-12-11 17:35:57 -08:00
|
|
|
import App from './App';
|
|
|
|
import registerServiceWorker from './registerServiceWorker';
|
|
|
|
import KeysManager from './contracts/KeysManager.contract'
|
|
|
|
import Metadata from './contracts/Metadata.contract'
|
|
|
|
import getWeb3 from './getWeb3'
|
|
|
|
import { setTimeout } from 'timers';
|
|
|
|
import {
|
2017-12-11 23:01:59 -08:00
|
|
|
Router,
|
2017-12-11 17:35:57 -08:00
|
|
|
Route,
|
2017-12-11 23:01:59 -08:00
|
|
|
Link,
|
|
|
|
NavLink
|
2017-12-11 17:35:57 -08:00
|
|
|
} from 'react-router-dom'
|
2017-12-11 23:01:59 -08:00
|
|
|
import createBrowserHistory from 'history/createBrowserHistory'
|
|
|
|
import Loading from './Loading'
|
|
|
|
import AllValidators from './AllValidators'
|
|
|
|
|
|
|
|
const history = createBrowserHistory()
|
|
|
|
|
|
|
|
class AppMainRouter extends Component {
|
|
|
|
constructor(props){
|
|
|
|
super(props);
|
2017-12-12 01:10:31 -08:00
|
|
|
this.rootPath = '/oracles-dapps-validators'
|
2017-12-11 23:01:59 -08:00
|
|
|
history.listen(this.onRouteChange.bind(this));
|
|
|
|
this.onSetRender = this.onSetRender.bind(this)
|
|
|
|
this.onAllValidatorsRender = this.onAllValidatorsRender.bind(this)
|
|
|
|
this.onSubmit = this.onSubmit.bind(this);
|
|
|
|
this.state = {
|
|
|
|
showSearch: true,
|
|
|
|
web3loaded: false,
|
|
|
|
keysManager :null,
|
|
|
|
metadataContract: null,
|
|
|
|
poaConsensus: null,
|
|
|
|
votingKey :null,
|
2017-12-12 00:29:28 -08:00
|
|
|
loading: true,
|
2017-12-11 23:01:59 -08:00
|
|
|
}
|
|
|
|
getWeb3().then(async (web3Config) => {
|
|
|
|
const keysManager = new KeysManager({
|
|
|
|
web3: web3Config.web3Instance
|
|
|
|
});
|
|
|
|
const metadataContract = new Metadata({
|
|
|
|
web3: web3Config.web3Instance
|
|
|
|
})
|
|
|
|
this.setState({
|
|
|
|
votingKey: web3Config.defaultAccount,
|
|
|
|
keysManager,
|
|
|
|
metadataContract,
|
2017-12-12 00:29:28 -08:00
|
|
|
loading: false,
|
2017-12-11 23:01:59 -08:00
|
|
|
})
|
2017-12-12 00:29:28 -08:00
|
|
|
}).catch((error) => {
|
|
|
|
console.error(error.msg);
|
|
|
|
this.setState({loading: false})
|
|
|
|
swal({
|
|
|
|
icon: 'error',
|
|
|
|
title: 'Error',
|
|
|
|
content: error.node
|
|
|
|
});
|
2017-12-11 23:01:59 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
onRouteChange(){
|
|
|
|
if(history.location.pathname !== "/"){
|
|
|
|
this.setState({showSearch: false})
|
|
|
|
} else {
|
|
|
|
this.setState({showSearch: true})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSubmit(e){
|
|
|
|
e.preventDefault();
|
|
|
|
switch (history.location.pathname) {
|
|
|
|
case "/":
|
|
|
|
console.log('main')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSetRender() {
|
|
|
|
return this.state.votingKey ? <App web3Config={this.state}/> : '';
|
|
|
|
}
|
|
|
|
onAllValidatorsRender() {
|
|
|
|
return this.state.votingKey ? <AllValidators web3Config={this.state} /> : '';
|
|
|
|
}
|
|
|
|
render(){
|
2017-12-12 01:10:31 -08:00
|
|
|
|
|
|
|
console.log('v2', this.rootPath)
|
2017-12-11 23:01:59 -08:00
|
|
|
const search = this.state.showSearch ? <input type="text" className="search-input"/> : ''
|
2017-12-12 00:29:28 -08:00
|
|
|
const loading = this.state.loading ? <Loading /> : ''
|
2017-12-11 23:01:59 -08:00
|
|
|
return (
|
|
|
|
<Router history={history}>
|
|
|
|
<section className="content">
|
|
|
|
{loading}
|
|
|
|
<div className="search">
|
|
|
|
<div className="container">
|
|
|
|
<div className="nav">
|
2017-12-12 01:10:31 -08:00
|
|
|
<NavLink className="nav-i nav-i_actual" exact activeClassName="nav-i_active" to={`${this.rootPath}/`}>All</NavLink>
|
2017-12-12 00:45:37 -08:00
|
|
|
<NavLink className="nav-i nav-i_unanswered" activeClassName="nav-i_active" to={`${this.rootPath}/set`}>Set metadata</NavLink>
|
2017-12-11 23:01:59 -08:00
|
|
|
<NavLink className="nav-i nav-i_expired" activeClassName="nav-i_active" to="/topics">Pending changes</NavLink>
|
|
|
|
</div>
|
|
|
|
<form action="" className="search-form" onSubmit={this.onSubmit}>
|
|
|
|
{search}
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-12-12 01:10:31 -08:00
|
|
|
<Route exact path={`${this.rootPath}/`} render={this.onAllValidatorsRender} onSubmit={this.onSubmit} web3Config={this.state}/>
|
2017-12-12 00:45:37 -08:00
|
|
|
<Route path={`${this.rootPath}/set`} render={this.onSetRender} />
|
2017-12-11 23:01:59 -08:00
|
|
|
</section>
|
|
|
|
</Router>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-12-11 17:35:57 -08:00
|
|
|
|
|
|
|
ReactDOM.render(<AppMainRouter />, document.getElementById('root'));
|
2017-12-11 23:01:59 -08:00
|
|
|
registerServiceWorker();
|
|
|
|
|