Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.2.0] Fix voteresultview #3500

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public class VoteResultView extends ActivatableView<GridPane, Void> implements D
private ProposalListItem selectedProposalListItem;
private boolean isVoteIncludedInResult;
private final Set<Cycle> cyclesAdded = new HashSet<>();
private boolean hasCalculatedResult = false;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -202,6 +203,7 @@ protected void activate() {
cyclesTableView.getSelectionModel().selectedItemProperty().addListener(selectedVoteResultListItemListener);

if (daoStateService.isParseBlockChainComplete()) {
checkForResultPhase(daoStateService.getChainHeight());
fillCycleList();
}

Expand Down Expand Up @@ -238,23 +240,31 @@ protected void deactivate() {

@Override
public void onParseBlockCompleteAfterBatchProcessing(Block block) {
int chainHeight = daoStateService.getChainHeight();
if (periodService.getFirstBlockOfPhase(chainHeight, DaoPhase.Phase.RESULT) == chainHeight) {
// We had set the cycle initially but at the vote result we want to update it with the actual result.
// We remove the empty cycle to make space for the one with the result.
Optional<Cycle> optionalCurrentCycle = cyclesAdded.stream()
.filter(cycle -> cycle.isInCycle(chainHeight))
.findAny();
optionalCurrentCycle.ifPresent(cyclesAdded::remove);
Optional<CycleListItem> optionalCurrentCycleListItem = cycleListItemList.stream()
.filter(cycleListItem -> cycleListItem.getResultsOfCycle().getCycle().isInCycle(chainHeight))
.findAny();
optionalCurrentCycleListItem.ifPresent(cycleListItemList::remove);
}

checkForResultPhase(daoStateService.getChainHeight());
fillCycleList();
}

private void checkForResultPhase(int chainHeight) {
if (periodService.isInPhase(chainHeight, DaoPhase.Phase.RESULT)) {
if (!hasCalculatedResult) {
hasCalculatedResult = true;
// We had set the cycle initially but at the vote result we want to update it with the actual result.
// We remove the empty cycle to make space for the one with the result.
Optional<Cycle> optionalCurrentCycle = cyclesAdded.stream()
.filter(cycle -> cycle.isInCycle(chainHeight))
.findAny();
optionalCurrentCycle.ifPresent(cyclesAdded::remove);
Optional<CycleListItem> optionalCurrentCycleListItem = cycleListItemList.stream()
.filter(cycleListItem -> cycleListItem.getResultsOfCycle().getCycle().isInCycle(chainHeight))
.findAny();
optionalCurrentCycleListItem.ifPresent(cycleListItemList::remove);
}
} else {
// Reset to be ready to calculate result for next RESULT phase
hasCalculatedResult = false;
}
}


///////////////////////////////////////////////////////////////////////////////////////////
// UI handlers
Expand Down