Skip to content

Commit

Permalink
Only automatically open popup if result wasn't accepted and disable a…
Browse files Browse the repository at this point in the history
…ction button when being accepted (#3503)
  • Loading branch information
ripcurlx authored Oct 29, 2019
1 parent 66d3f91 commit 65703d5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 20 additions & 5 deletions desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -495,6 +496,12 @@ public T setHeadlineStyle(String headlineStyle) {
return (T) this;
}

public T disableActionButton() {
this.disableActionButton = true;
//noinspection unchecked
return (T) this;
}


///////////////////////////////////////////////////////////////////////////////////////////
// Protected
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void registerSubscriptions() {

mediationResultStateSubscription = EasyBind.subscribe(trade.mediationResultStateProperty(), newValue -> {
if (newValue != null) {
updateMediationResultState();
updateMediationResultState(true);
}
});

Expand Down Expand Up @@ -416,15 +416,15 @@ private void updateDisputeState(Trade.DisputeState disputeState) {
case MEDIATION_CLOSED:
if (tradeStepInfo != null) {
tradeStepInfo.setOnAction(e -> {
updateMediationResultState();
updateMediationResultState(false);
});
}

if (tradeStepInfo != null) {
tradeStepInfo.setState(TradeStepInfo.State.MEDIATION_RESULT);
}

updateMediationResultState();
updateMediationResultState(true);
break;
case REFUND_REQUESTED:
deactivatePaymentButtons(true);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -535,14 +536,18 @@ 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",
myPayoutAmount,
peersPayoutAmount,
BSFormatter.getDateFromBlockHeight(remaining),
lockTime))
.actionButtonText(Res.get("shared.accept"))
.actionButtonText(actionButtonText)
.onAction(() -> {
model.dataModel.mediationManager.acceptMediationResult(trade,
() -> {
Expand All @@ -569,6 +574,10 @@ private void openMediationResultPopup(String headLine) {
acceptMediationResultPopup = null;
});

if (hasSelfAccepted()) {
acceptMediationResultPopup.disableActionButton();
}

acceptMediationResultPopup.show();
}

Expand Down

0 comments on commit 65703d5

Please sign in to comment.