poa-dapps-voting/src/index.js

82 lines
2.8 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
2017-12-11 14:23:01 -08:00
import ReactDOM from 'react-dom';
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';
import commonStore from './stores/CommonStore';
import validatorStore from './stores/ValidatorStore';
import ballotStore from './stores/BallotStore';
import ballotsStore from './stores/BallotsStore';
import contractsStore from './stores/ContractsStore';
2017-12-11 14:23:01 -08:00
import swal from 'sweetalert2';
import getWeb3 from './getWeb3';
import "babel-polyfill";
import createBrowserHistory from 'history/createBrowserHistory'
2017-12-21 10:55:19 -08:00
const browserHistory = createBrowserHistory();
const routingStore = new RouterStore();
const stores = { commonStore, contractsStore, ballotStore, ballotsStore, validatorStore, routing: routingStore };
2017-12-21 10:55:19 -08:00
const history = syncHistoryWithStore(browserHistory, routingStore);
function generateElement(msg){
let errorNode = document.createElement("div");
errorNode.innerHTML = `${msg}`;
return errorNode;
}
class AppMainRouter extends Component {
constructor(props) {
super(props);
2017-12-25 11:25:17 -08:00
commonStore.showLoading();
getWeb3().then(async (web3Config) => {
await contractsStore.setWeb3Instance(web3Config);
await contractsStore.setPoaConsensus(web3Config);
await contractsStore.setBallotsStorage(web3Config);
await contractsStore.setVotingToChangeKeys(web3Config);
await contractsStore.setVotingToChangeMinThreshold(web3Config);
await contractsStore.setVotingToChangeProxy(web3Config);
await contractsStore.setValidatorMetadata(web3Config);
contractsStore.getValidatorsLength();
contractsStore.getKeysBallotThreshold();
contractsStore.getMinThresholdBallotThreshold();
contractsStore.getProxyBallotThreshold();
contractsStore.getAllKeysBallots();
2017-12-25 11:25:17 -08:00
contractsStore.getAllMinThresholdBallots();
contractsStore.getAllProxyBallots();
contractsStore.setVotingKey(web3Config);
await contractsStore.setMiningKey(web3Config);
contractsStore.getValidatorActiveBallots();
2018-01-03 20:51:10 -08:00
contractsStore.getAllValidatorMetadata();
console.log("votingKey", contractsStore.votingKey);
console.log("miningKey", contractsStore.miningKey);
commonStore.hideLoading();
}).catch((error) => {
console.error(error.message)
2017-12-25 11:25:17 -08:00
commonStore.hideLoading();
swal({
title: 'Error',
html: generateElement(error.message),
icon: 'error',
type: 'error'
});
});
}
render(){
return (
<Provider { ...stores }>
<Router history={history}>
<Route component={App} />
</Router>
</Provider>
)
}
2017-12-11 14:23:01 -08:00
}
ReactDOM.render(<AppMainRouter />, document.getElementById('root'));
2017-12-11 14:23:01 -08:00
registerServiceWorker();