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..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 @@ -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; @@ -145,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)); }; @@ -203,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); @@ -303,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); @@ -313,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(); @@ -431,11 +430,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 +458,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()); @@ -505,10 +504,6 @@ public class ProposalsView extends ActivatableView implements Bs tableView.refresh(); } - private ProposalsListItem getBallotListItem() { - return selectedItem; - } - private void updateViews() { boolean isBlindVotePhaseButNotLastBlock = isBlindVotePhaseButNotLastBlock(); boolean hasVotedOnProposal = hasVotedOnProposal(); @@ -588,6 +583,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; + } }