Skip to content

Commit

Permalink
Merge pull request #2888 from sqrrm/late-vote-reveal-handling
Browse files Browse the repository at this point in the history
Late vote reveal handling
  • Loading branch information
sqrrm authored Jun 19, 2019
2 parents cbab796 + 8c278a6 commit 386209b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
3 changes: 2 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,8 @@ dao.proposal.table.icon.tooltip.changeVote=Current vote: ''{0}''. Change vote to
dao.proposal.display.myVote.accepted=Accepted
dao.proposal.display.myVote.rejected=Rejected
dao.proposal.display.myVote.ignored=Ignored
dao.proposal.myVote.summary=Voted: {0}; Vote weight: {1} (earned: {2} + stake: {3});
dao.proposal.display.myVote.unCounted=Vote was not included in result
dao.proposal.myVote.summary=Voted: {0}; Vote weight: {1} (earned: {2} + stake: {3}) {4}
dao.proposal.myVote.invalid=Vote was invalid

dao.proposal.voteResult.success=Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ public void applyEvaluatedProposal(@Nullable EvaluatedProposal evaluatedProposal
}

public void applyBallotAndVoteWeight(@Nullable Ballot ballot, long merit, long stake) {
applyBallotAndVoteWeight(ballot, merit, stake, true);
}

public void applyBallotAndVoteWeight(@Nullable Ballot ballot, long merit, long stake, boolean ballotIncluded) {
boolean ballotIsNotNull = ballot != null;
boolean hasVoted = stake > 0;
if (hasVoted) {
Expand All @@ -487,11 +491,12 @@ public void applyBallotAndVoteWeight(@Nullable Ballot ballot, long merit, long s
Res.get("dao.proposal.display.myVote.rejected");
}

String voteIncluded = ballotIncluded ? "" : " - " + Res.get("dao.proposal.display.myVote.unCounted");
String meritString = bsqFormatter.formatCoinWithCode(Coin.valueOf(merit));
String stakeString = bsqFormatter.formatCoinWithCode(Coin.valueOf(stake));
String weight = bsqFormatter.formatCoinWithCode(Coin.valueOf(merit + stake));
String myVoteSummary = Res.get("dao.proposal.myVote.summary", myVote,
weight, meritString, stakeString);
weight, meritString, stakeString, voteIncluded);
myVoteTextField.setText(myVoteSummary);

GridPane.setRowSpan(myVoteTitledGroup, votingBoxRowSpan - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,34 @@

import javafx.scene.control.Label;
import javafx.scene.control.TableRow;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;

import javafx.geometry.Insets;

import lombok.Getter;

import org.jetbrains.annotations.NotNull;

public class ProposalListItem {

@Getter
private EvaluatedProposal evaluatedProposal;
@Getter
private final Proposal proposal;
private final Vote vote;
private final boolean isMyBallotIncluded;
private final BsqFormatter bsqFormatter;

private TableRow tableRow;


ProposalListItem(EvaluatedProposal evaluatedProposal, Ballot ballot, BsqFormatter bsqFormatter) {
ProposalListItem(EvaluatedProposal evaluatedProposal, Ballot ballot, boolean isMyBallotIncluded,
BsqFormatter bsqFormatter) {
this.evaluatedProposal = evaluatedProposal;
proposal = evaluatedProposal.getProposal();
vote = ballot.getVote();

this.isMyBallotIncluded = isMyBallotIncluded;
this.bsqFormatter = bsqFormatter;
}

Expand All @@ -68,19 +76,33 @@ public Label getMyVoteIcon() {
Label myVoteIcon;
if (vote != null) {
if ((vote).isAccepted()) {
myVoteIcon = FormBuilder.getIcon(AwesomeIcon.THUMBS_UP);
myVoteIcon.getStyleClass().add("dao-accepted-icon");
myVoteIcon = getIcon(AwesomeIcon.THUMBS_UP, "dao-accepted-icon");
} else {
myVoteIcon = FormBuilder.getIcon(AwesomeIcon.THUMBS_DOWN);
myVoteIcon.getStyleClass().add("dao-rejected-icon");
myVoteIcon = getIcon(AwesomeIcon.THUMBS_DOWN, "dao-rejected-icon");
}
if (!isMyBallotIncluded) {
Label notIncluded = FormBuilder.getIcon(AwesomeIcon.BAN_CIRCLE);
return new Label("", new HBox(10, new StackPane(myVoteIcon, notIncluded),
getIcon(AwesomeIcon.MINUS, "dao-ignored-icon")));
}
} else {
myVoteIcon = FormBuilder.getIcon(AwesomeIcon.MINUS);
myVoteIcon.getStyleClass().add("dao-ignored-icon");
myVoteIcon = getIcon(AwesomeIcon.MINUS, "dao-ignored-icon");
if (!isMyBallotIncluded) {
myVoteIcon.setPadding(new Insets(0, 0, 0, 25));
return myVoteIcon;
}
}
return myVoteIcon;
}

@NotNull
private Label getIcon(AwesomeIcon awesomeIcon, String s) {
Label myVoteIcon;
myVoteIcon = FormBuilder.getIcon(awesomeIcon);
myVoteIcon.getStyleClass().add(s);
return myVoteIcon;
}

public void setTableRow(TableRow tableRow) {
this.tableRow = tableRow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public class VoteResultView extends ActivatableView<GridPane, Void> implements D
private ChangeListener<CycleListItem> selectedVoteResultListItemListener;
private ResultsOfCycle resultsOfCycle;
private ProposalListItem selectedProposalListItem;
private boolean isVoteIncludedInResult;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -253,6 +254,18 @@ private void onResultsListItemSelected(CycleListItem item) {
if (item != null) {
resultsOfCycle = item.getResultsOfCycle();

// Check if my vote is included in result
isVoteIncludedInResult = false;
resultsOfCycle.getEvaluatedProposals().forEach(evProposal -> resultsOfCycle.getDecryptedVotesForCycle()
.forEach(decryptedBallotsWithMerits -> {
// Iterate through all included votes to see if any of those are ours
if (!isVoteIncludedInResult) {
isVoteIncludedInResult = bsqWalletService.isWalletTransaction(decryptedBallotsWithMerits
.getVoteRevealTxId()).isPresent();
}
}));


maybeShowVoteResultErrors(item.getResultsOfCycle().getCycle());
createProposalsTable();

Expand Down Expand Up @@ -327,10 +340,6 @@ private void onSelectProposalResultListItem(ProposalListItem item) {
.findAny();

Ballot ballot = optionalBallot.orElse(null);
// Check if my vote is included in result
boolean isVoteIncludedInResult = voteListItemList.stream()
.anyMatch(voteListItem -> bsqWalletService.getTransaction(voteListItem.getBlindVoteTxId()) != null);

voteListItemList.clear();
resultsOfCycle.getEvaluatedProposals().stream()
.filter(evProposal -> evProposal.getProposal().equals(selectedProposalListItem.getEvaluatedProposal().getProposal()))
Expand Down Expand Up @@ -460,6 +469,7 @@ private void createProposalsTable() {
})
.map(evaluatedProposal -> new ProposalListItem(evaluatedProposal,
ballotByProposalTxIdMap.get(evaluatedProposal.getProposalTxId()),
isVoteIncludedInResult,
bsqFormatter))
.collect(Collectors.toList()));
GUIUtil.setFitToRowsForTableView(proposalsTableView, 25, 28, 6, 6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void addContent(EvaluatedProposal evaluatedProposal, Ballot ballot) {
Tuple2<Long, Long> meritAndStakeTuple = daoFacade.getMeritAndStakeForProposal(proposal.getTxId());
long merit = meritAndStakeTuple.first;
long stake = meritAndStakeTuple.second;
proposalDisplay.applyBallotAndVoteWeight(ballot, merit, stake);
proposalDisplay.applyBallotAndVoteWeight(ballot, merit, stake, isVoteIncludedInResult);

Region spacer = new Region();
GridPane.setVgrow(spacer, Priority.ALWAYS);
Expand Down

0 comments on commit 386209b

Please sign in to comment.