mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Merge pull request #2636 from ripcurlx/check-for-nullable-selected-proposal
Check if selected proposal is null
This commit is contained in:
commit
4e173ac976
@ -135,6 +135,7 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||
private BusyAnimation voteButtonBusyAnimation;
|
||||
|
||||
private int gridRow = 0;
|
||||
@Nullable
|
||||
private ProposalsListItem selectedItem;
|
||||
private DaoPhase.Phase currentPhase;
|
||||
private ListChangeListener<Proposal> proposalListChangeListener;
|
||||
@ -145,9 +146,9 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
|
||||
private TableColumn<ProposalsListItem, ProposalsListItem> lastColumn;
|
||||
private String shownVoteOnProposalWindowForTxId = "";
|
||||
|
||||
private final double initialProposalTableViewHeight = 180;
|
||||
private final double pixelsPerProposalTableRow = (initialProposalTableViewHeight - 28) / 4.0;
|
||||
private final Function<Double, Double> 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<GridPane, Void> 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<GridPane, Void> 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<GridPane, Void> 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<Proposal> list = daoFacade.getActiveOrMyUnconfirmedProposals();
|
||||
@ -431,11 +430,25 @@ public class ProposalsView extends ActivatableView<GridPane, Void> 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<GridPane, Void> 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<GridPane, Void> 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<GridPane, Void> implements Bs
|
||||
lastColumn.setText("");
|
||||
break;
|
||||
}
|
||||
|
||||
if (selectedItem == null && listItems.size() > 0 && selectProposalWindow.isDisplayed()) {
|
||||
Proposal proposal = selectProposalWindow.getProposal();
|
||||
|
||||
Optional<ProposalsListItem> 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() {
|
||||
|
@ -942,6 +942,10 @@ public abstract class Overlay<T extends Overlay> {
|
||||
return useAnimation && GlobalSettings.getUseAnimations() ? duration : 1;
|
||||
}
|
||||
|
||||
public boolean isDisplayed() {
|
||||
return isDisplayed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Popup{" +
|
||||
|
@ -49,6 +49,7 @@ public class SelectProposalWindow extends Overlay<SelectProposalWindow> {
|
||||
private Optional<Runnable> rejectHandlerOptional;
|
||||
private Optional<Runnable> ignoreHandlerOptional;
|
||||
private Optional<Runnable> removeHandlerOptional;
|
||||
private Optional<Runnable> hideHandlerOptional;
|
||||
private Proposal proposal;
|
||||
private EvaluatedProposal evaluatedProposal;
|
||||
private Ballot ballot;
|
||||
@ -99,6 +100,10 @@ public class SelectProposalWindow extends Overlay<SelectProposalWindow> {
|
||||
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<SelectProposalWindow> {
|
||||
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<SelectProposalWindow> {
|
||||
else
|
||||
return ballot.getVoteAsOptional();
|
||||
}
|
||||
|
||||
public Proposal getProposal() {
|
||||
return proposal;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user