import {Link} from "react-router-dom"; import Button from '@material-ui/core/Button'; import React, {Component, Fragment} from 'react'; import Typography from '@material-ui/core/Typography' import PollManager from 'Embark/contracts/PollManager'; class Results extends Component { state = { isError: false, poll: null, isPending: true, } constructor(props){ super(props); if(props.polls && props.polls.length) this.state.poll = props.polls[props.idPoll]; } updatePoll(){ const idPoll = this.props.idPoll; PollManager.methods.poll(idPoll).call().then(poll => { this.setState({poll}); }) } componentDidMount(){ const {transaction, idPoll} = this.props; EmbarkJS.onReady(() => { this.updatePoll(); if(transaction){ transaction.then(receipt => { this.setState({isPending: false}); this.updatePoll(); }) .catch(err => { this.setState({isError: true}); }); } }); } render(){ const {polls, idPoll, transaction, transactionHash} = this.props; let {isError, poll, isPending} = this.state; if(!poll || !polls){ return null; } const title = polls[idPoll].content.title; const ballots = polls[idPoll].content.ballots; const totalVotes = poll._quadraticVotes.map(x => parseInt(x, 10)).reduce((x, y) => x + y, 0); return { isError &&
Transaction failed Copy with apologies and invitation to try again
} { !isError && transaction &&
{ isPending &&
Your vote will be posted once the transaction is complete. Your vote is in the process of being confirmed in the blockchain
} { !isPending && transaction &&
Transaction confirmed!
Your vote was posted.
} { transactionHash && View details on Etherscan }
}
{ !isError && {title} { ballots.map((item, i) => ) } }
; } } class BallotResult extends Component { state = { show: false } showDetails = () => { const show = this.state.show; this.setState({show: !show}); } render(){ const {title, quadraticVotes, tokenTotal, totalVotes, totalVoters} = this.props; const {show} = this.state; const votePercentage = totalVotes > 0 ? parseInt(quadraticVotes) / totalVotes * 100 : 0; return (
{votePercentage.toFixed(2)}% {title}
{show && }
); } } export default Results;