Skip to content

Commit

Permalink
question view: add more data
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Oct 12, 2024
1 parent 5e4017b commit 414e367
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/voting/Question.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,26 @@ abstract contract Question is Ownable, IQuestion {
uint256 totalVotes = 0;
// Adjust the array size to exclude the empty option at index 0
OptionView[] memory optionViews = new OptionView[](options.length - 1);
uint256 userOptionVoted = 0;

// Start the loop from index 1 to skip the empty option
for (uint256 i = 1; i < options.length; i++) {
uint256 voteCount = optionVoteCounts[i];
totalVotes += voteCount;
bool userVotedForOption = hasVoted(user, i);
// Adjust the index for optionViews to start at 0
optionViews[i - 1] = OptionView({
title: options[i].title,
description: options[i].description,
proposer: options[i].proposer,
voteCount: voteCount,
pointsAccrued: optionPointsAccrued[i],
userVoted: hasVoted(user, i)
userVoted: userVotedForOption
});

if (userVotedForOption) {
userOptionVoted = i;
}
}

return
Expand All @@ -122,7 +128,10 @@ abstract contract Question is Ownable, IQuestion {
options: optionViews,
status: getStatus(),
owner: owner(),
started: deploymentTime
started: deploymentTime,
userOptionVoted: userOptionVoted,
userPointsCurrent: points.balanceOf(user),
userPointsDeadline: points.balanceAtTimestamp(user, deadline)
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/voting/interfaces/IQuestion.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ interface IQuestion {
Status status;
address owner;
uint256 started;
uint256 userOptionVoted;
uint256 userPointsCurrent;
uint256 userPointsDeadline;
}

// Events
Expand Down

0 comments on commit 414e367

Please sign in to comment.