mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-24 08:08:19 +00:00
Storing and displaying voters by ballot
This commit is contained in:
parent
fe9c65fa0f
commit
0914943af5
@ -85,7 +85,7 @@ class Results extends Component {
|
|||||||
<div className="section">
|
<div className="section">
|
||||||
{ !isError && <Fragment>
|
{ !isError && <Fragment>
|
||||||
<Typography variant="headline" gutterBottom>{title}</Typography>
|
<Typography variant="headline" gutterBottom>{title}</Typography>
|
||||||
{ ballots.map((item, i) => <BallotResult title={item.title} totalVotes={totalVotes} quadraticVotes={poll._quadraticVotes[i]} tokenTotal={poll._tokenTotal[i]} key={i} />) }
|
{ ballots.map((item, i) => <BallotResult title={item.title} totalVotes={totalVotes} quadraticVotes={poll._quadraticVotes[i]} tokenTotal={poll._tokenTotal[i]} totalVoters={poll._votersByBallot[i]} key={i} />) }
|
||||||
</Fragment>
|
</Fragment>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@ -106,7 +106,7 @@ class BallotResult extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
const {title, quadraticVotes, tokenTotal, totalVotes} = this.props;
|
const {title, quadraticVotes, tokenTotal, totalVotes, totalVoters} = this.props;
|
||||||
const {show} = this.state;
|
const {show} = this.state;
|
||||||
|
|
||||||
const votePercentage = totalVotes > 0 ? parseInt(quadraticVotes) / totalVotes * 100 : 0;
|
const votePercentage = totalVotes > 0 ? parseInt(quadraticVotes) / totalVotes * 100 : 0;
|
||||||
@ -118,7 +118,7 @@ class BallotResult extends Component {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{show && <ul>
|
{show && <ul>
|
||||||
<Typography component="li">Voters: <span>N/A</span></Typography>
|
<Typography component="li">Voters: <span>{totalVoters}</span></Typography>
|
||||||
<Typography component="li">Total votes: <span>{quadraticVotes}</span></Typography>
|
<Typography component="li">Total votes: <span>{quadraticVotes}</span></Typography>
|
||||||
<Typography component="li" className="noBorder">Total SNT: <span>{web3.utils.fromWei(tokenTotal, "ether")}</span></Typography>
|
<Typography component="li" className="noBorder">Total SNT: <span>{web3.utils.fromWei(tokenTotal, "ether")}</span></Typography>
|
||||||
</ul>}
|
</ul>}
|
||||||
|
@ -17,6 +17,7 @@ contract PollManager is Controlled {
|
|||||||
mapping(uint8 => mapping(address => uint)) ballots;
|
mapping(uint8 => mapping(address => uint)) ballots;
|
||||||
mapping(uint8 => uint) qvResults;
|
mapping(uint8 => uint) qvResults;
|
||||||
mapping(uint8 => uint) results;
|
mapping(uint8 => uint) results;
|
||||||
|
mapping(uint8 => uint) votersByBallot;
|
||||||
address author;
|
address author;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ contract PollManager is Controlled {
|
|||||||
{
|
{
|
||||||
require(_endTime > block.timestamp, "End time must be greater than current timestamp");
|
require(_endTime > block.timestamp, "End time must be greater than current timestamp");
|
||||||
require(_startBlock >= block.number, "Start block must not be in the past");
|
require(_startBlock >= block.number, "Start block must not be in the past");
|
||||||
require(_numBallots <= 50, "Only a max of 50 ballots are allowed");
|
require(_numBallots <= 100, "Only a max of 100 ballots are allowed");
|
||||||
|
|
||||||
_idPoll = _polls.length;
|
_idPoll = _polls.length;
|
||||||
_polls.length ++;
|
_polls.length ++;
|
||||||
@ -98,7 +99,7 @@ contract PollManager is Controlled {
|
|||||||
public
|
public
|
||||||
{
|
{
|
||||||
require(_idPoll < _polls.length, "Invalid _idPoll");
|
require(_idPoll < _polls.length, "Invalid _idPoll");
|
||||||
require(_numBallots <= 50, "Only a max of 50 ballots are allowed");
|
require(_numBallots <= 100, "Only a max of 100 ballots are allowed");
|
||||||
|
|
||||||
Poll storage p = _polls[_idPoll];
|
Poll storage p = _polls[_idPoll];
|
||||||
require(p.startBlock > block.number, "You cannot modify an active poll");
|
require(p.startBlock > block.number, "You cannot modify an active poll");
|
||||||
@ -186,6 +187,7 @@ contract PollManager is Controlled {
|
|||||||
if(_ballots[i] != 0){
|
if(_ballots[i] != 0){
|
||||||
p.qvResults[i] += sqrt(_ballots[i] / 1 ether);
|
p.qvResults[i] += sqrt(_ballots[i] / 1 ether);
|
||||||
p.results[i] += _ballots[i];
|
p.results[i] += _ballots[i];
|
||||||
|
p.votersByBallot[i]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +217,7 @@ contract PollManager is Controlled {
|
|||||||
if(ballotAmount != 0){
|
if(ballotAmount != 0){
|
||||||
p.qvResults[i] -= sqrt(ballotAmount / 1 ether);
|
p.qvResults[i] -= sqrt(ballotAmount / 1 ether);
|
||||||
p.results[i] -= ballotAmount;
|
p.results[i] -= ballotAmount;
|
||||||
|
p.votersByBallot[i]--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,8 +255,9 @@ contract PollManager is Controlled {
|
|||||||
bool _finalized,
|
bool _finalized,
|
||||||
uint _voters,
|
uint _voters,
|
||||||
address _author,
|
address _author,
|
||||||
uint[50] _tokenTotal,
|
uint[100] _tokenTotal,
|
||||||
uint[50] _quadraticVotes
|
uint[100] _quadraticVotes,
|
||||||
|
uint[100] _votersByBallot
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
require(_idPoll < _polls.length, "Invalid _idPoll");
|
require(_idPoll < _polls.length, "Invalid _idPoll");
|
||||||
@ -273,6 +277,7 @@ contract PollManager is Controlled {
|
|||||||
for(uint8 i = 0; i < p.numBallots; i++){
|
for(uint8 i = 0; i < p.numBallots; i++){
|
||||||
_tokenTotal[i] = p.results[i];
|
_tokenTotal[i] = p.results[i];
|
||||||
_quadraticVotes[i] = p.qvResults[i];
|
_quadraticVotes[i] = p.qvResults[i];
|
||||||
|
_votersByBallot[i] = p.votersByBallot[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +308,7 @@ contract PollManager is Controlled {
|
|||||||
function getVote(uint _idPoll, address _voter)
|
function getVote(uint _idPoll, address _voter)
|
||||||
public
|
public
|
||||||
view
|
view
|
||||||
returns (uint[50] votes){
|
returns (uint[100] votes){
|
||||||
require(_idPoll < _polls.length, "Invalid _idPoll");
|
require(_idPoll < _polls.length, "Invalid _idPoll");
|
||||||
Poll storage p = _polls[_idPoll];
|
Poll storage p = _polls[_idPoll];
|
||||||
for(uint8 i = 0; i < p.numBallots; i++){
|
for(uint8 i = 0; i < p.numBallots; i++){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user