Handling poll cancelation

This commit is contained in:
Richard Ramos 2018-09-26 15:31:34 -04:00
parent 6f5a029d87
commit 71ad38ec42
2 changed files with 12 additions and 12 deletions

View File

@ -18,7 +18,7 @@ import CircularProgress from '@material-ui/core/CircularProgress';
import { withStyles } from '@material-ui/core/styles';
import { VotingContext } from '../../context';
import rlp from 'rlp';
window.PollManager = PollManager;
const styles = {
card: {
display: 'flex',
@ -102,7 +102,7 @@ class Poll extends PureComponent {
this.setState({isSubmitting: true});
const { vote, poll, unvote } = PollManager.methods;
const { vote, unvote } = PollManager.methods;
const { updatePoll, idPoll } = this.props;
const { votes } = this.state;
const { toWei } = web3.utils;
@ -150,7 +150,6 @@ class Poll extends PureComponent {
const cantVote = balance == 0 || !_canVote;
const disableVote = cantVote || isSubmitting;
const quadVotes = [];
const sntTotals = [];
for(let i = 0; i < _numBallots; i++){
@ -213,7 +212,7 @@ class Poll extends PureComponent {
{cantVote && <Typography variant="body2" color="error">
{balance == 0 && <span>Voting disabled for proposals made when there was no SNT in the account</span>}
{balance != 0 && !_canVote && <span>You can not vote on this poll</span>}
{balance != 0 && cantVote && <span>Voting is not enabled for this poll</span>}
</Typography>}
@ -267,7 +266,7 @@ const PollsList = ({ classes }) => (
<Fragment>
{rawPolls
.sort(sortingFn[pollOrder])
.map((poll, i) => <Poll key={poll.idPoll} classes={classes} appendToPoll={appendToPoll} updatePoll={updatePoll} ideaSites={ideaSites} {...poll} />)}
.map((poll, i) => !poll._canceled && <Poll key={poll.idPoll} classes={classes} appendToPoll={appendToPoll} updatePoll={updatePoll} ideaSites={ideaSites} {...poll} />)}
</Fragment>
}
</VotingContext.Consumer>
@ -295,14 +294,13 @@ class BallotSlider extends Component {
const {value} = this.state;
const nextVote = value + 1;
//cantVote={cantVote} balance={balance}
return <Fragment>
<Slider classes={{ thumb: classes.thumb }} style={{ width: '95%' }} value={value} min={0} max={maxVotes} step={1} onChange={this.handleChange} />
{balance > 0 && <b>Your votes: {value} ({value * value} SNT)</b>}
{ nextVote <= maxVotesAvailable ? <small>- Additional vote will cost {nextVote*nextVote - value*value} SNT</small> : (balance > 0 && <small>- Not enough balance available to buy additional votes</small>) }
<Slider disabled={cantVote} classes={{ thumb: classes.thumb }} style={{ width: '95%' }} value={value} min={0} max={maxVotes} step={1} onChange={this.handleChange} />
{balance > 0 && !cantVote && <b>Your votes: {value} ({value * value} SNT)</b>}
{ nextVote <= maxVotesAvailable && !cantVote ? <small>- Additional vote will cost {nextVote*nextVote - value*value} SNT</small> : (balance > 0 && !cantVote && <small>- Not enough balance available to buy additional votes</small>) }
</Fragment>
}
}

View File

@ -119,12 +119,12 @@ contract PollManager is Controlled {
Poll storage p = _polls[_idPoll];
require(!p.canceled, "Poll has been canceled already");
require(p.endBlock < block.number, "Only active polls can be canceled");
require(p.endBlock > block.number, "Only active polls can be canceled");
if(p.startBlock <= block.number){
if(p.startBlock < block.number){
require(msg.sender == controller, "Only the controller can cancel the poll");
} else {
require(p.author == msg.sender, "Only the controller can cancel the poll");
require(p.author == msg.sender, "Only the owner can cancel the poll");
}
p.canceled = true;
@ -247,6 +247,7 @@ contract PollManager is Controlled {
uint8 _numBallots,
bool _finalized,
uint _voters,
address _author,
uint[15] _tokenTotal,
uint[15] _quadraticVotes
)
@ -261,6 +262,7 @@ contract PollManager is Controlled {
_canVote = canVote(_idPoll);
_description = p.description;
_numBallots = p.numBallots;
_author = p.author;
_finalized = (!p.canceled) && (block.number >= _endBlock);
_voters = p.voters;