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 7689a20cdb3..a7be7c3b3ae 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 @@ protected void activate() { 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 void onParseBlockChainComplete() { 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 @@ private void updateListItems() { 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,32 +430,32 @@ private void applyMerit() { } 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 showHowToSetStakeForVotingPopup() { - String id = "explainHowToSetStakeForVoting"; - if (preferences.showAgain(id)) - new Popup<>().information(Res.get("dao.proposal.myVote.setStake.description")) - .dontShowAgainId(id).show(); + private void onIgnore() { + onVoteOnSingleProposal(null); } - private void onReject() { - daoFacade.setVote(getBallotListItem().getBallot(), new Vote(false)); - updateStateAfterVote(); + private void onVoteOnSingleProposal(Vote vote) { + if (selectedItem != null) { + daoFacade.setVote(selectedItem.getBallot(), vote); + updateStateAfterVote(); + showHowToSetStakeForVotingPopup(); + } + tableView.getSelectionModel().clearSelection(); - showHowToSetStakeForVotingPopup(); } - private void onIgnore() { - daoFacade.setVote(getBallotListItem().getBallot(), null); - updateStateAfterVote(); - tableView.getSelectionModel().clearSelection(); - showHowToSetStakeForVotingPopup(); + private void showHowToSetStakeForVotingPopup() { + String id = "explainHowToSetStakeForVoting"; + if (preferences.showAgain(id)) + new Popup<>().information(Res.get("dao.proposal.myVote.setStake.description")) + .dontShowAgainId(id).show(); } private void onVote() { @@ -505,10 +504,6 @@ private void updateStateAfterVote() { tableView.refresh(); } - private ProposalsListItem getBallotListItem() { - return selectedItem; - } - private void updateViews() { boolean isBlindVotePhaseButNotLastBlock = isBlindVotePhaseButNotLastBlock(); boolean hasVotedOnProposal = hasVotedOnProposal(); @@ -588,6 +583,20 @@ private void updateViews() { 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 b2b4ee10b3c..0a69ac05c02 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 @@ protected double getDuration(double duration) { 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 e7f464e7226..3327d26875e 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 void onRemove(Runnable removeHandler) { this.removeHandlerOptional = Optional.of(removeHandler); } + public void onHide(Runnable hideHandler) { + this.hideHandlerOptional = Optional.of(hideHandler); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Protected /////////////////////////////////////////////////////////////////////////////////////////// @@ -125,6 +130,14 @@ protected void addMessage() { 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 @@ private Optional getVote(@Nullable Ballot ballot) { else return ballot.getVoteAsOptional(); } + + public Proposal getProposal() { + return proposal; + } }