Allowing voting / unvoting

This commit is contained in:
Richard Ramos 2018-06-27 21:42:17 -04:00
parent c2ba506f5e
commit ff338bb7b0
2 changed files with 5 additions and 6 deletions

View File

@ -25,15 +25,15 @@ class Poll extends Component {
this.setState({isSubmitting: true}); this.setState({isSubmitting: true});
const { customVote, poll } = PollManager.methods; const { customVote, poll, unvote } = PollManager.methods;
const { idPoll, value } = this.state; const { idPoll, value } = this.state;
const balance4Voting = value * value; const balance4Voting = value * value;
const toSend = customVote(idPoll, balance4Voting); const toSend = balance4Voting === 0 ? unvote(idPoll) : customVote(idPoll, balance4Voting);
toSend.estimateGas() toSend.estimateGas()
.then(gasEstimated => { .then(gasEstimated => {
console.log("customVote gas estimated: " + gasEstimated); console.log("voting gas estimated: " + gasEstimated);
return toSend.send({gas: gasEstimated + 1000}); return toSend.send({gas: gasEstimated + 1000});
}) })
.then(res => { .then(res => {
@ -67,7 +67,6 @@ class Poll extends Component {
}) })
} }
render(){ render(){
const { _description, const { _description,
_totalCensus, _totalCensus,
@ -86,7 +85,7 @@ class Poll extends Component {
return ( return (
<Card> <Card>
<CardContent> <CardContent>
<Typography variant="headline">Proposal: {_description}</Typography> <Typography variant="headline">{_description}</Typography>
<Typography variant="subheading" color="textSecondary"> <Typography variant="subheading" color="textSecondary">
Number of voters: {_voters} Number of voters: {_voters}
</Typography> </Typography>

View File

@ -137,7 +137,7 @@ contract PollManager is Controlled {
uint balance = MiniMeToken(p.token).balanceOf(msg.sender); uint balance = MiniMeToken(p.token).balanceOf(msg.sender);
require(balance != 0 && balance >= _amount); require(balance != 0 && balance >= _amount && _amount != 0);
require(MiniMeToken(p.token).transferFrom(msg.sender, address(this), _amount)); require(MiniMeToken(p.token).transferFrom(msg.sender, address(this), _amount));
p.votes[msg.sender] = _amount; p.votes[msg.sender] = _amount;