86 lines
2.1 KiB
JavaScript
Raw Normal View History

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[props.idPoll];
2018-10-18 11:49:06 -04:00
}
updatePoll(){
const idPoll = this.props.idPoll;
2018-10-18 11:49:06 -04:00
PollManager.methods.poll(idPoll).call().then(poll => {
this.setState({poll});
})
2018-10-18 10:32:38 -04:00
}
componentDidMount(){
const {transaction, idPoll} = this.props;
2018-10-18 10:32:38 -04:00
EmbarkJS.onReady(() => {
2018-10-18 11:49:06 -04:00
this.updatePoll();
if(transaction){
transaction.then(receipt => {
this.updatePoll();
})
.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, idPoll} = this.props;
2018-10-20 16:52:02 -04:00
let {isError, poll} = this.state;
2018-10-18 10:32:38 -04:00
if(!poll || !polls){
2018-10-18 10:32:38 -04:00
return null;
}
const title = polls[idPoll].content.title;
const ballots = polls[idPoll].content.ballots;
2018-10-18 10:32:38 -04:00
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/" + idPoll}>
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;