mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 15:48:10 +00:00
Display voting results
This commit is contained in:
parent
f28d7ae1bb
commit
d4543b36c8
@ -2,36 +2,56 @@ 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'
|
||||
import PollManager from 'Embark/contracts/PollManager';
|
||||
|
||||
class Results extends Component {
|
||||
|
||||
state = {
|
||||
isError: false
|
||||
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});
|
||||
})
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
const {transaction} = this.props;
|
||||
|
||||
transaction.then(receipt => {
|
||||
const idPoll = 0; // TODO:
|
||||
|
||||
this.updatePoll();
|
||||
|
||||
transaction.then(receipt => {
|
||||
this.updatePoll();
|
||||
})
|
||||
.catch(err => {
|
||||
this.setState({isError: true});
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
render(){
|
||||
const {polls} = this.props;
|
||||
const {isError} = this.state;
|
||||
const {isError, poll} = this.state;
|
||||
|
||||
if(!polls || !polls.length){
|
||||
const title = polls[0].content.title;
|
||||
const ballots = polls[0].content.ballots;
|
||||
|
||||
if(!poll){
|
||||
return null;
|
||||
}
|
||||
|
||||
return <div className="section">
|
||||
|
||||
{ isError && <div>
|
||||
<Typography variant="headline">Transaction failed</Typography>
|
||||
<Typography variant="body1">Copy with apologies and invitation to try again</Typography>
|
||||
@ -40,9 +60,20 @@ class Results extends Component {
|
||||
</Link>
|
||||
</div> }
|
||||
{ !isError && <div>
|
||||
<h2>Transaction details here</h2>
|
||||
<h2>Voting results here</h2>
|
||||
</div> }
|
||||
<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> }
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user