2017-12-19 07:17:49 -08:00
|
|
|
import React, { Component } from 'react';
|
2017-12-11 14:23:01 -08:00
|
|
|
import ReactDOM from 'react-dom';
|
2017-12-21 08:55:57 -08:00
|
|
|
import { Router, Route } from 'react-router-dom';
|
2017-12-11 14:23:01 -08:00
|
|
|
import App from './App';
|
|
|
|
import registerServiceWorker from './registerServiceWorker';
|
2017-12-19 06:27:27 -08:00
|
|
|
import { Provider } from 'mobx-react';
|
2017-12-21 10:55:19 -08:00
|
|
|
import { RouterStore, syncHistoryWithStore } from 'mobx-react-router';
|
2017-12-20 05:13:28 -08:00
|
|
|
import commonStore from './stores/CommonStore';
|
2017-12-19 08:53:51 -08:00
|
|
|
import validatorStore from './stores/ValidatorStore';
|
|
|
|
import ballotStore from './stores/BallotStore';
|
2017-12-22 07:29:54 -08:00
|
|
|
import ballotsStore from './stores/BallotsStore';
|
2017-12-19 07:17:49 -08:00
|
|
|
import contractsStore from './stores/ContractsStore';
|
2017-12-11 14:23:01 -08:00
|
|
|
import swal from 'sweetalert2';
|
2017-12-20 05:13:28 -08:00
|
|
|
import getWeb3 from './getWeb3';
|
2017-12-19 07:17:49 -08:00
|
|
|
import "babel-polyfill";
|
2017-12-21 08:55:57 -08:00
|
|
|
import createBrowserHistory from 'history/createBrowserHistory'
|
2017-12-19 07:17:49 -08:00
|
|
|
|
2017-12-21 10:55:19 -08:00
|
|
|
const browserHistory = createBrowserHistory();
|
|
|
|
const routingStore = new RouterStore();
|
2017-12-22 07:29:54 -08:00
|
|
|
const stores = { commonStore, contractsStore, ballotStore, ballotsStore, validatorStore, routing: routingStore };
|
2017-12-21 10:55:19 -08:00
|
|
|
const history = syncHistoryWithStore(browserHistory, routingStore);
|
2017-12-19 07:17:49 -08:00
|
|
|
|
|
|
|
function generateElement(msg){
|
|
|
|
let errorNode = document.createElement("div");
|
|
|
|
errorNode.innerHTML = `<div>
|
|
|
|
${msg}
|
|
|
|
</div>`;
|
|
|
|
return errorNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
class AppMainRouter extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
getWeb3().then(async (web3Config) => {
|
2017-12-20 05:13:28 -08:00
|
|
|
contractsStore.setWeb3Instance(web3Config);
|
2017-12-24 23:59:40 -08:00
|
|
|
await contractsStore.setPoaConsensus(web3Config);
|
2017-12-25 00:26:01 -08:00
|
|
|
contractsStore.setBallotsStorage(web3Config);
|
2017-12-24 23:59:40 -08:00
|
|
|
contractsStore.getValidatorsLength();
|
2017-12-25 02:10:35 -08:00
|
|
|
await contractsStore.getKeysBallotThreshold();
|
2017-12-25 00:26:01 -08:00
|
|
|
contractsStore.getMinThresholdBallotThreshold();
|
|
|
|
contractsStore.getProxyBallotThreshold();
|
2017-12-19 07:17:49 -08:00
|
|
|
contractsStore.setVotingToChangeKeys(web3Config);
|
|
|
|
contractsStore.setVotingToChangeMinThreshold(web3Config);
|
|
|
|
contractsStore.setVotingToChangeProxy(web3Config);
|
2017-12-24 23:46:35 -08:00
|
|
|
contractsStore.setValidatorMetadata(web3Config);
|
2017-12-19 08:53:51 -08:00
|
|
|
contractsStore.setVotingKey(web3Config);
|
2017-12-22 07:29:54 -08:00
|
|
|
contractsStore.getAllKeysBallots();
|
|
|
|
contractsStore.getAllProxyBallots();
|
2017-12-19 08:53:51 -08:00
|
|
|
await contractsStore.setMiningKey(web3Config);
|
|
|
|
console.log("votingKey", contractsStore.votingKey)
|
|
|
|
console.log("miningKey", contractsStore.miningKey)
|
2017-12-19 07:17:49 -08:00
|
|
|
}).catch((error) => {
|
|
|
|
console.error(error.message);
|
|
|
|
swal({
|
|
|
|
icon: 'error',
|
|
|
|
title: 'Error',
|
|
|
|
content: generateElement(error.message)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render(){
|
|
|
|
return (
|
|
|
|
<Provider { ...stores }>
|
2017-12-21 08:55:57 -08:00
|
|
|
<Router history={history}>
|
|
|
|
<Route component={App} />
|
|
|
|
</Router>
|
2017-12-19 07:17:49 -08:00
|
|
|
</Provider>
|
|
|
|
)
|
|
|
|
}
|
2017-12-11 14:23:01 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-19 07:17:49 -08:00
|
|
|
ReactDOM.render(<AppMainRouter />, document.getElementById('root'));
|
2017-12-11 14:23:01 -08:00
|
|
|
registerServiceWorker();
|