From 1782a364ca6dc0c13a1f6ce78dbdfba144dd73b3 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Thu, 4 Apr 2019 12:06:14 +0200 Subject: [PATCH 1/3] Check if selected proposal is null and ignore vote in this case --- .../governance/proposals/ProposalsView.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java index 7689a20cdb..9df90a0357 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java @@ -135,6 +135,7 @@ public class ProposalsView extends ActivatableView implements Bs private BusyAnimation voteButtonBusyAnimation; private int gridRow = 0; + @Nullable private ProposalsListItem selectedItem; private DaoPhase.Phase currentPhase; private ListChangeListener proposalListChangeListener; @@ -431,11 +432,25 @@ public class ProposalsView extends ActivatableView implements Bs } private void onAccept() { - daoFacade.setVote(getBallotListItem().getBallot(), new Vote(true)); - updateStateAfterVote(); - tableView.getSelectionModel().clearSelection(); + onVoteOnSingleProposal(new Vote(true)); + } - showHowToSetStakeForVotingPopup(); + private void onReject() { + onVoteOnSingleProposal(new Vote(false)); + } + + private void onIgnore() { + onVoteOnSingleProposal(null); + } + + private void onVoteOnSingleProposal(Vote vote) { + if (selectedItem != null) { + daoFacade.setVote(selectedItem.getBallot(), vote); + updateStateAfterVote(); + showHowToSetStakeForVotingPopup(); + } + + tableView.getSelectionModel().clearSelection(); } private void showHowToSetStakeForVotingPopup() { @@ -445,20 +460,6 @@ public class ProposalsView extends ActivatableView implements Bs .dontShowAgainId(id).show(); } - private void onReject() { - daoFacade.setVote(getBallotListItem().getBallot(), new Vote(false)); - updateStateAfterVote(); - tableView.getSelectionModel().clearSelection(); - showHowToSetStakeForVotingPopup(); - } - - private void onIgnore() { - daoFacade.setVote(getBallotListItem().getBallot(), null); - updateStateAfterVote(); - tableView.getSelectionModel().clearSelection(); - showHowToSetStakeForVotingPopup(); - } - private void onVote() { // TODO verify stake Coin stake = bsqFormatter.parseToCoin(stakeInputTextField.getText()); From 77df0f9b53dbffc650a0a1a787f2f4b25e89779e Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Thu, 4 Apr 2019 16:34:27 +0200 Subject: [PATCH 2/3] Hide and show selected proposal window whenever new block has been parsed --- .../governance/proposals/ProposalsView.java | 22 ++++++++++++++----- .../bisq/desktop/main/overlays/Overlay.java | 4 ++++ .../windows/SelectProposalWindow.java | 17 ++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java index 9df90a0357..8f58f09390 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java @@ -146,9 +146,9 @@ public class ProposalsView extends ActivatableView implements Bs private TableColumn lastColumn; private String shownVoteOnProposalWindowForTxId = ""; - private final double initialProposalTableViewHeight = 180; - private final double pixelsPerProposalTableRow = (initialProposalTableViewHeight - 28) / 4.0; private final Function proposalTableViewHeight = (screenSize) -> { + double initialProposalTableViewHeight = 180; + double pixelsPerProposalTableRow = (initialProposalTableViewHeight - 28) / 4.0; int extraRows = screenSize <= INITIAL_WINDOW_HEIGHT ? 0 : (int) ((screenSize - INITIAL_WINDOW_HEIGHT) / pixelsPerProposalTableRow); return extraRows == 0 ? initialProposalTableViewHeight : Math.ceil(initialProposalTableViewHeight + (extraRows * pixelsPerProposalTableRow)); }; @@ -506,10 +506,6 @@ public class ProposalsView extends ActivatableView implements Bs tableView.refresh(); } - private ProposalsListItem getBallotListItem() { - return selectedItem; - } - private void updateViews() { boolean isBlindVotePhaseButNotLastBlock = isBlindVotePhaseButNotLastBlock(); boolean hasVotedOnProposal = hasVotedOnProposal(); @@ -589,6 +585,20 @@ public class ProposalsView extends ActivatableView implements Bs lastColumn.setText(""); break; } + + if (selectedItem == null && listItems.size() > 0 && selectProposalWindow.isDisplayed()) { + Proposal proposal = selectProposalWindow.getProposal(); + + Optional proposalsListItem = listItems.stream() + .filter(item -> item.getProposal().equals(proposal)) + .findAny(); + + selectProposalWindow.onHide(() -> proposalsListItem.ifPresent( + listItem -> tableView.getSelectionModel().select(listItem))); + + shownVoteOnProposalWindowForTxId = ""; + selectProposalWindow.hide(); + } } private boolean hasVotedOnProposal() { diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java b/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java index b2b4ee10b3..0a69ac05c0 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java @@ -942,6 +942,10 @@ public abstract class Overlay { return useAnimation && GlobalSettings.getUseAnimations() ? duration : 1; } + public boolean isDisplayed() { + return isDisplayed; + } + @Override public String toString() { return "Popup{" + diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/SelectProposalWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/SelectProposalWindow.java index e7f464e722..3327d26875 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/SelectProposalWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/SelectProposalWindow.java @@ -49,6 +49,7 @@ public class SelectProposalWindow extends Overlay { private Optional rejectHandlerOptional; private Optional ignoreHandlerOptional; private Optional removeHandlerOptional; + private Optional hideHandlerOptional; private Proposal proposal; private EvaluatedProposal evaluatedProposal; private Ballot ballot; @@ -99,6 +100,10 @@ public class SelectProposalWindow extends Overlay { this.removeHandlerOptional = Optional.of(removeHandler); } + public void onHide(Runnable hideHandler) { + this.hideHandlerOptional = Optional.of(hideHandler); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Protected /////////////////////////////////////////////////////////////////////////////////////////// @@ -125,6 +130,14 @@ public class SelectProposalWindow extends Overlay { addContent(proposal, evaluatedProposal, ballot); } + @Override + protected void onHidden() { + if (hideHandlerOptional != null) { + hideHandlerOptional.ifPresent(Runnable::run); + hideHandlerOptional = null; + } + } + private void addContent(Proposal proposal, EvaluatedProposal evaluatedProposal, Ballot ballot) { ProposalDisplay proposalDisplay = new ProposalDisplay(gridPane, bsqFormatter, daoFacade, changeParamValidator, navigation, preferences); @@ -225,4 +238,8 @@ public class SelectProposalWindow extends Overlay { else return ballot.getVoteAsOptional(); } + + public Proposal getProposal() { + return proposal; + } } From f2eabbc0b041abf9a5e8e5d5e18c3131eaa6da9b Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Thu, 4 Apr 2019 19:29:17 +0200 Subject: [PATCH 3/3] Add missing Bsq state listeners --- .../main/dao/governance/proposals/ProposalsView.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java index 8f58f09390..a7be7c3b3a 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/governance/proposals/ProposalsView.java @@ -204,6 +204,8 @@ public class ProposalsView extends ActivatableView implements Bs selectedProposalSubscription = EasyBind.subscribe(tableView.getSelectionModel().selectedItemProperty(), this::onSelectProposal); + daoFacade.addBsqStateListener(this); + sortedList.comparatorProperty().bind(tableView.comparatorProperty()); tableView.setPrefHeight(100); root.getScene().heightProperty().addListener(sceneHeightListener); @@ -304,7 +306,7 @@ public class ProposalsView extends ActivatableView implements Bs private void addListenersAfterParseBlockChainComplete() { daoFacade.getActiveOrMyUnconfirmedProposals().addListener(proposalListChangeListener); daoFacade.getAllBallots().addListener(ballotListChangeListener); - daoFacade.addBsqStateListener(this); + bsqWalletService.addBsqBalanceListener(this); phaseSubscription = EasyBind.subscribe(daoFacade.phaseProperty(), this::onPhaseChanged); @@ -314,10 +316,6 @@ public class ProposalsView extends ActivatableView implements Bs listItems.forEach(ProposalsListItem::cleanup); listItems.clear(); - fillListItems(); - } - - private void fillListItems() { if (daoFacade.phaseProperty().get().ordinal() < DaoPhase.Phase.BLIND_VOTE.ordinal()) { // proposal phase List list = daoFacade.getActiveOrMyUnconfirmedProposals();