2018-07-12 05:40:39 -07:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
import { Router, Route } from 'react-router-dom'
|
|
|
|
import App from './App'
|
|
|
|
import registerServiceWorker from './registerServiceWorker'
|
|
|
|
import { Provider } from 'mobx-react'
|
|
|
|
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'
|
|
|
|
import { getContractsAddresses } from './contracts/addresses'
|
|
|
|
import swal from 'sweetalert2'
|
|
|
|
import getWeb3 from './getWeb3'
|
|
|
|
import 'babel-polyfill'
|
2017-12-21 08:55:57 -08:00
|
|
|
import createBrowserHistory from 'history/createBrowserHistory'
|
2018-10-02 04:07:57 -07:00
|
|
|
import { constants } from './constants'
|
2017-12-19 07:17:49 -08:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
const browserHistory = createBrowserHistory()
|
|
|
|
const routingStore = new RouterStore()
|
|
|
|
const stores = { commonStore, contractsStore, ballotStore, ballotsStore, validatorStore, routing: routingStore }
|
|
|
|
const history = syncHistoryWithStore(browserHistory, routingStore)
|
2017-12-19 07:17:49 -08:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
function generateElement(msg) {
|
|
|
|
let errorNode = document.createElement('div')
|
|
|
|
errorNode.innerHTML = `${msg}`
|
|
|
|
return errorNode
|
2018-01-19 14:59:07 -08:00
|
|
|
}
|
2017-12-19 07:17:49 -08:00
|
|
|
class AppMainRouter extends Component {
|
|
|
|
constructor(props) {
|
2018-07-12 05:40:39 -07:00
|
|
|
super(props)
|
|
|
|
commonStore.showLoading()
|
2017-12-19 07:17:49 -08:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
getWeb3()
|
|
|
|
.then(async web3Config => {
|
|
|
|
let getSokolContractsAddresses = getContractsAddresses('sokol')
|
|
|
|
let getCoreContractsAddresses = getContractsAddresses('core')
|
2018-08-08 12:03:07 -07:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
await Promise.all([getSokolContractsAddresses, getCoreContractsAddresses])
|
2018-03-22 03:04:05 -07:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
contractsStore.setWeb3Instance(web3Config)
|
2018-03-22 03:04:05 -07:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
let setPoaConsensus = contractsStore.setPoaConsensus(web3Config)
|
|
|
|
let setBallotsStorage = contractsStore.setBallotsStorage(web3Config)
|
2018-08-04 03:41:34 -07:00
|
|
|
let setKeysManager = contractsStore.setKeysManager(web3Config)
|
2018-07-12 05:40:39 -07:00
|
|
|
let setProxyStorage = contractsStore.setProxyStorage(web3Config)
|
|
|
|
let setVotingToChangeKeys = contractsStore.setVotingToChangeKeys(web3Config)
|
|
|
|
let setVotingToChangeMinThreshold = contractsStore.setVotingToChangeMinThreshold(web3Config)
|
|
|
|
let setVotingToChangeProxy = contractsStore.setVotingToChangeProxy(web3Config)
|
|
|
|
let setValidatorMetadata = contractsStore.setValidatorMetadata(web3Config)
|
2018-03-21 07:53:27 -07:00
|
|
|
|
2018-09-17 09:17:56 -07:00
|
|
|
let promises = [
|
2018-07-12 05:40:39 -07:00
|
|
|
setPoaConsensus,
|
|
|
|
setBallotsStorage,
|
2018-08-04 03:41:34 -07:00
|
|
|
setKeysManager,
|
2018-07-12 05:40:39 -07:00
|
|
|
setProxyStorage,
|
|
|
|
setVotingToChangeKeys,
|
|
|
|
setVotingToChangeMinThreshold,
|
|
|
|
setVotingToChangeProxy,
|
|
|
|
setValidatorMetadata
|
2018-09-17 09:17:56 -07:00
|
|
|
]
|
|
|
|
|
2018-10-02 04:07:57 -07:00
|
|
|
if (web3Config.netId === constants.NETID_SOKOL) {
|
2018-09-17 09:17:56 -07:00
|
|
|
// if we're in Sokol
|
|
|
|
promises.push(contractsStore.setEmissionFunds(web3Config))
|
|
|
|
promises.push(contractsStore.setVotingToManageEmissionFunds(web3Config))
|
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all(promises)
|
2018-03-20 14:57:28 -07:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
await contractsStore.setMiningKey(web3Config)
|
|
|
|
await contractsStore.setVotingKey(web3Config)
|
2018-06-14 02:06:22 -07:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
contractsStore.getKeysBallotThreshold()
|
|
|
|
contractsStore.getProxyBallotThreshold()
|
2018-09-19 00:54:31 -07:00
|
|
|
contractsStore.getBallotCancelingThreshold()
|
2018-07-12 05:40:39 -07:00
|
|
|
contractsStore.getBallotsLimits()
|
2018-09-19 03:26:04 -07:00
|
|
|
|
|
|
|
await contractsStore.getAllValidatorMetadata()
|
|
|
|
await contractsStore.getAllBallots()
|
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
console.log('votingKey', contractsStore.votingKey)
|
|
|
|
console.log('miningKey', contractsStore.miningKey)
|
2018-09-19 03:26:04 -07:00
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
commonStore.hideLoading()
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error.message)
|
|
|
|
commonStore.hideLoading()
|
|
|
|
swal({
|
|
|
|
title: 'Error',
|
|
|
|
html: generateElement(error.message),
|
|
|
|
icon: 'error',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
2017-12-19 07:17:49 -08:00
|
|
|
}
|
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
render() {
|
2017-12-19 07:17:49 -08:00
|
|
|
return (
|
2018-07-12 05:40:39 -07:00
|
|
|
<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
|
|
|
}
|
|
|
|
|
2018-07-12 05:40:39 -07:00
|
|
|
ReactDOM.render(<AppMainRouter />, document.getElementById('root'))
|
|
|
|
registerServiceWorker()
|