2018-10-18 10:32:38 -04:00
|
|
|
import {Link} from "react-router-dom";
|
|
|
|
import Button from '@material-ui/core/Button';
|
|
|
|
import React, {Component} from 'react';
|
|
|
|
import Typography from '@material-ui/core/Typography'
|
2018-10-18 11:49:06 -04:00
|
|
|
import PollManager from 'Embark/contracts/PollManager';
|
2018-10-18 10:32:38 -04:00
|
|
|
|
|
|
|
class Results extends Component {
|
|
|
|
|
|
|
|
state = {
|
2018-10-18 11:49:06 -04:00
|
|
|
isError: false,
|
|
|
|
poll: null
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props){
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
if(props.polls && props.polls.length)
|
|
|
|
this.state.poll = props.polls[0]; // TODO:
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePoll(){
|
|
|
|
const idPoll = 0; // TODO:
|
|
|
|
PollManager.methods.poll(idPoll).call().then(poll => {
|
|
|
|
this.setState({poll});
|
|
|
|
})
|
2018-10-18 10:32:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
const {transaction} = this.props;
|
|
|
|
|
2018-10-18 11:49:06 -04:00
|
|
|
const idPoll = 0; // TODO:
|
2018-10-18 10:32:38 -04:00
|
|
|
|
2018-10-18 11:49:06 -04:00
|
|
|
this.updatePoll();
|
|
|
|
|
|
|
|
transaction.then(receipt => {
|
|
|
|
this.updatePoll();
|
2018-10-18 10:32:38 -04:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.setState({isError: true});
|
2018-10-18 11:49:06 -04:00
|
|
|
});
|
2018-10-18 10:32:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render(){
|
|
|
|
const {polls} = this.props;
|
2018-10-20 16:52:02 -04:00
|
|
|
let {isError, poll} = this.state;
|
2018-10-18 10:32:38 -04:00
|
|
|
|
2018-10-18 11:49:06 -04:00
|
|
|
const title = polls[0].content.title;
|
|
|
|
const ballots = polls[0].content.ballots;
|
|
|
|
|
|
|
|
if(!poll){
|
2018-10-18 10:32:38 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="section">
|
2018-10-20 16:52:02 -04:00
|
|
|
{ isError && <div className="errorTrx">
|
|
|
|
<div className="image"><img src="images/sad-face.svg" width="24" /></div>
|
2018-10-18 10:32:38 -04:00
|
|
|
<Typography variant="headline">Transaction failed</Typography>
|
|
|
|
<Typography variant="body1">Copy with apologies and invitation to try again</Typography>
|
|
|
|
<Link to="/review">
|
2018-10-20 16:52:02 -04:00
|
|
|
<Button color="primary" variant="contained">Try again</Button>
|
2018-10-18 10:32:38 -04:00
|
|
|
</Link>
|
|
|
|
</div> }
|
|
|
|
{ !isError && <div>
|
2018-10-18 11:49:06 -04:00
|
|
|
<h2>TODO: Transaction details here</h2>
|
|
|
|
|
|
|
|
{ title }
|
|
|
|
{ ballots.map((item, i) => {
|
|
|
|
return <div key={i}>
|
|
|
|
<h2>{item.title}</h2>
|
|
|
|
<p>Voters: ???</p>
|
|
|
|
<p>Total votes: {poll._quadraticVotes[i]}</p>
|
|
|
|
<p>Total SNT: {web3.utils.fromWei(poll._tokenTotal[i], "ether")}</p>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
})}
|
|
|
|
|
|
|
|
</div> }
|
2018-10-18 10:32:38 -04:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Results;
|