From 65703d5495423e744ad263569b686389372beb84 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 29 Oct 2019 11:04:19 +0100 Subject: [PATCH] Only automatically open popup if result wasn't accepted and disable action button when being accepted (#3503) --- .../resources/i18n/displayStrings.properties | 1 + .../bisq/desktop/main/overlays/Overlay.java | 25 +++++++++++++++---- .../pendingtrades/steps/TradeStepView.java | 21 +++++++++++----- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 21d712af4d2..0b29fdb67e0 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -833,6 +833,7 @@ portfolio.pending.mediationResult.popup.info=The mediator has suggested the foll More details about the new arbitration model:\n\ https://docs.bisq.network/trading-rules.html#arbitration portfolio.pending.mediationResult.popup.openArbitration=Reject and request arbitration +portfolio.pending.mediationResult.popup.alreadyAccepted=You've already accepted portfolio.closed.completed=Completed portfolio.closed.ticketClosed=Arbitrated 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 084abd29156..9231d79b785 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java @@ -152,6 +152,7 @@ protected enum Type { private boolean showBusyAnimation; protected boolean hideCloseButton; protected boolean isDisplayed; + protected boolean disableActionButton; @Getter protected BooleanProperty isHiddenProperty = new SimpleBooleanProperty(); @@ -495,6 +496,12 @@ public T setHeadlineStyle(String headlineStyle) { return (T) this; } + public T disableActionButton() { + this.disableActionButton = true; + //noinspection unchecked + return (T) this; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Protected @@ -925,16 +932,24 @@ protected void addButtons() { if (actionHandlerOptional.isPresent() || actionButtonText != null) { actionButton = new AutoTooltipButton(actionButtonText == null ? Res.get("shared.ok") : actionButtonText); - actionButton.setDefaultButton(true); + + if (!disableActionButton) + actionButton.setDefaultButton(true); + else + actionButton.setDisable(true); + HBox.setHgrow(actionButton, Priority.SOMETIMES); actionButton.getStyleClass().add("action-button"); //TODO app wide focus //actionButton.requestFocus(); - actionButton.setOnAction(event -> { - hide(); - actionHandlerOptional.ifPresent(Runnable::run); - }); + + if (!disableActionButton) { + actionButton.setOnAction(event -> { + hide(); + actionHandlerOptional.ifPresent(Runnable::run); + }); + } buttonBox.setSpacing(10); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index fb09be39ebd..6387a5d7488 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -217,7 +217,7 @@ private void registerSubscriptions() { mediationResultStateSubscription = EasyBind.subscribe(trade.mediationResultStateProperty(), newValue -> { if (newValue != null) { - updateMediationResultState(); + updateMediationResultState(true); } }); @@ -416,7 +416,7 @@ private void updateDisputeState(Trade.DisputeState disputeState) { case MEDIATION_CLOSED: if (tradeStepInfo != null) { tradeStepInfo.setOnAction(e -> { - updateMediationResultState(); + updateMediationResultState(false); }); } @@ -424,7 +424,7 @@ private void updateDisputeState(Trade.DisputeState disputeState) { tradeStepInfo.setState(TradeStepInfo.State.MEDIATION_RESULT); } - updateMediationResultState(); + updateMediationResultState(true); break; case REFUND_REQUESTED: deactivatePaymentButtons(true); @@ -459,7 +459,7 @@ private void updateDisputeState(Trade.DisputeState disputeState) { } } - private void updateMediationResultState() { + private void updateMediationResultState(boolean blockOpeningOfResultAcceptedPopup) { if (isInArbitration()) { if (isRefundRequestStartedByPeer()) { tradeStepInfo.setState(TradeStepInfo.State.IN_REFUND_REQUEST_PEER_REQUESTED); @@ -471,7 +471,8 @@ private void updateMediationResultState() { // (e.g. we might receive a RECEIVED_SIG_MSG but then later a SIG_MSG_IN_MAILBOX). if (hasSelfAccepted()) { tradeStepInfo.setState(TradeStepInfo.State.MEDIATION_RESULT_SELF_ACCEPTED); - openMediationResultPopup(Res.get("portfolio.pending.mediationResult.popup.headline", trade.getShortId())); + if (!blockOpeningOfResultAcceptedPopup) + openMediationResultPopup(Res.get("portfolio.pending.mediationResult.popup.headline", trade.getShortId())); } else if (peerAccepted()) { tradeStepInfo.setState(TradeStepInfo.State.MEDIATION_RESULT_PEER_ACCEPTED); if (acceptMediationResultPopup == null) { @@ -535,6 +536,10 @@ private void openMediationResultPopup(String headLine) { long lockTime = trade.getDelayedPayoutTx().getLockTime(); int bestChainHeight = model.dataModel.btcWalletService.getBestChainHeight(); long remaining = lockTime - bestChainHeight; + + String actionButtonText = hasSelfAccepted() ? + Res.get("portfolio.pending.mediationResult.popup.alreadyAccepted") : Res.get("shared.accept"); + acceptMediationResultPopup = new Popup<>().width(900) .headLine(headLine) .instruction(Res.get("portfolio.pending.mediationResult.popup.info", @@ -542,7 +547,7 @@ private void openMediationResultPopup(String headLine) { peersPayoutAmount, BSFormatter.getDateFromBlockHeight(remaining), lockTime)) - .actionButtonText(Res.get("shared.accept")) + .actionButtonText(actionButtonText) .onAction(() -> { model.dataModel.mediationManager.acceptMediationResult(trade, () -> { @@ -569,6 +574,10 @@ private void openMediationResultPopup(String headLine) { acceptMediationResultPopup = null; }); + if (hasSelfAccepted()) { + acceptMediationResultPopup.disableActionButton(); + } + acceptMediationResultPopup.show(); }