From 55e55d4f19528489f9e6b29d83140e7b335671a2 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sat, 5 Sep 2020 19:18:33 -0500 Subject: [PATCH 1/4] Deactivate confirm payment or payment received buttons once a dispute is opened. --- .../pendingtrades/steps/TradeStepView.java | 14 ++-- .../steps/buyer/BuyerStep2View.java | 6 ++ .../steps/seller/SellerStep3View.java | 65 ++++++++++--------- 3 files changed, 51 insertions(+), 34 deletions(-) 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 dc9a93ec49d..ad352e2eb34 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 @@ -390,7 +390,6 @@ protected void applyOnDisputeOpened() { } private void updateDisputeState(Trade.DisputeState disputeState) { - deactivatePaymentButtons(false); Optional ownDispute; switch (disputeState) { case NO_DISPUTE: @@ -406,7 +405,6 @@ private void updateDisputeState(Trade.DisputeState disputeState) { if (tradeStepInfo != null) tradeStepInfo.setState(TradeStepInfo.State.IN_MEDIATION_SELF_REQUESTED); }); - break; case MEDIATION_STARTED_BY_PEER: if (tradeStepInfo != null) { @@ -435,7 +433,6 @@ private void updateDisputeState(Trade.DisputeState disputeState) { updateMediationResultState(true); break; case REFUND_REQUESTED: - deactivatePaymentButtons(true); if (tradeStepInfo != null) { tradeStepInfo.setFirstHalfOverWarnTextSupplier(this::getFirstHalfOverWarnText); } @@ -449,7 +446,6 @@ private void updateDisputeState(Trade.DisputeState disputeState) { break; case REFUND_REQUEST_STARTED_BY_PEER: - deactivatePaymentButtons(true); if (tradeStepInfo != null) { tradeStepInfo.setFirstHalfOverWarnTextSupplier(this::getFirstHalfOverWarnText); } @@ -462,9 +458,12 @@ private void updateDisputeState(Trade.DisputeState disputeState) { }); break; case REFUND_REQUEST_CLOSED: - deactivatePaymentButtons(true); + break; + default: break; } + + deactivatePaymentButtons(isDisputed()); } private void updateMediationResultState(boolean blockOpeningOfResultAcceptedPopup) { @@ -639,6 +638,11 @@ private void updateTradePeriodState(Trade.TradePeriodState tradePeriodState) { } } + protected boolean isDisputed() { + return trade.getDisputeState() != Trade.DisputeState.NO_DISPUTE; + } + + /////////////////////////////////////////////////////////////////////////////////////////// // TradeDurationLimitInfo /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index 562c716ebec..5189d535b56 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -193,6 +193,8 @@ public void activate() { } }); } + + confirmButton.setDisable(isDisputed()); } @Override @@ -387,6 +389,10 @@ protected void applyOnDisputeOpened() { /////////////////////////////////////////////////////////////////////////////////////////// private void onPaymentStarted() { + if (isDisputed()) { + return; + } + if (!model.dataModel.isBootstrappedOrShowPopup()) { return; } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index b0e0fa57c22..942dd7acec8 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -164,6 +164,8 @@ public void activate() { } applyAssetTxProofResult(trade.getAssetTxProofResult()); + + confirmButton.setDisable(isDisputed()); } @Override @@ -341,40 +343,45 @@ protected void applyOnDisputeOpened() { /////////////////////////////////////////////////////////////////////////////////////////// private void onPaymentReceived() { + if (isDisputed()) { + return; + } + // The confirmPaymentReceived call will trigger the trade protocol to do the payout tx. We want to be sure that we // are well connected to the Bitcoin network before triggering the broadcast. - if (model.dataModel.isReadyForTxBroadcast()) { - String key = "confirmPaymentReceived"; - if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) { - PaymentAccountPayload paymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload(); - String message = Res.get("portfolio.pending.step3_seller.onPaymentReceived.part1", CurrencyUtil.getNameByCode(model.dataModel.getCurrencyCode())); - if (!(paymentAccountPayload instanceof AssetsAccountPayload)) { - if (!(paymentAccountPayload instanceof WesternUnionAccountPayload) && - !(paymentAccountPayload instanceof HalCashAccountPayload) && - !(paymentAccountPayload instanceof F2FAccountPayload)) { - message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.fiat", trade.getShortId()); - } - - Optional optionalHolderName = getOptionalHolderName(); - if (optionalHolderName.isPresent()) { - message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.name", optionalHolderName.get()); - } + if (!model.dataModel.isReadyForTxBroadcast()) { + return; + } + String key = "confirmPaymentReceived"; + if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) { + PaymentAccountPayload paymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload(); + String message = Res.get("portfolio.pending.step3_seller.onPaymentReceived.part1", CurrencyUtil.getNameByCode(model.dataModel.getCurrencyCode())); + if (!(paymentAccountPayload instanceof AssetsAccountPayload)) { + if (!(paymentAccountPayload instanceof WesternUnionAccountPayload) && + !(paymentAccountPayload instanceof HalCashAccountPayload) && + !(paymentAccountPayload instanceof F2FAccountPayload)) { + message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.fiat", trade.getShortId()); } - message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.note"); - if (model.dataModel.isSignWitnessTrade()) { - message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.signer"); + + Optional optionalHolderName = getOptionalHolderName(); + if (optionalHolderName.isPresent()) { + message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.name", optionalHolderName.get()); } - new Popup() - .headLine(Res.get("portfolio.pending.step3_seller.onPaymentReceived.confirm.headline")) - .confirmation(message) - .width(700) - .actionButtonText(Res.get("portfolio.pending.step3_seller.onPaymentReceived.confirm.yes")) - .onAction(this::confirmPaymentReceived) - .closeButtonText(Res.get("shared.cancel")) - .show(); - } else { - confirmPaymentReceived(); } + message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.note"); + if (model.dataModel.isSignWitnessTrade()) { + message += Res.get("portfolio.pending.step3_seller.onPaymentReceived.signer"); + } + new Popup() + .headLine(Res.get("portfolio.pending.step3_seller.onPaymentReceived.confirm.headline")) + .confirmation(message) + .width(700) + .actionButtonText(Res.get("portfolio.pending.step3_seller.onPaymentReceived.confirm.yes")) + .onAction(this::confirmPaymentReceived) + .closeButtonText(Res.get("shared.cancel")) + .show(); + } else { + confirmPaymentReceived(); } } From 9908bcf33abec5c52c320d444c97decb4cb63df3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sat, 5 Sep 2020 19:19:49 -0500 Subject: [PATCH 2/4] Rename method --- .../main/portfolio/pendingtrades/steps/TradeStepView.java | 4 ++-- .../portfolio/pendingtrades/steps/buyer/BuyerStep2View.java | 2 +- .../portfolio/pendingtrades/steps/seller/SellerStep3View.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 ad352e2eb34..8dcea1ee77f 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 @@ -463,7 +463,7 @@ private void updateDisputeState(Trade.DisputeState disputeState) { break; } - deactivatePaymentButtons(isDisputed()); + updateConfirmButtonDisableState(isDisputed()); } private void updateMediationResultState(boolean blockOpeningOfResultAcceptedPopup) { @@ -603,7 +603,7 @@ private void openMediationResultPopup(String headLine) { acceptMediationResultPopup.show(); } - protected void deactivatePaymentButtons(boolean isDisabled) { + protected void updateConfirmButtonDisableState(boolean isDisabled) { } private void updateTradePeriodState(Trade.TradePeriodState tradePeriodState) { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index 5189d535b56..b7783cac737 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -637,7 +637,7 @@ private void showPopup() { } @Override - protected void deactivatePaymentButtons(boolean isDisabled) { + protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index 942dd7acec8..c94317c17b1 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -515,7 +515,7 @@ private Label createPopoverLabel(String text) { } @Override - protected void deactivatePaymentButtons(boolean isDisabled) { + protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); } } From ad34fe5bbca16c7b4631b0402a740fe28471f3c2 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 6 Sep 2020 11:18:28 -0500 Subject: [PATCH 3/4] Add comment to empty method --- .../main/portfolio/pendingtrades/steps/TradeStepView.java | 1 + 1 file changed, 1 insertion(+) 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 8dcea1ee77f..7e1e9ff1190 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 @@ -604,6 +604,7 @@ private void openMediationResultPopup(String headLine) { } protected void updateConfirmButtonDisableState(boolean isDisabled) { + // By default do nothing. Only overwritten in certain trade steps } private void updateTradePeriodState(Trade.TradePeriodState tradePeriodState) { From 300a1bbf03bcbd35df367757e6be5ce8698c35a7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 6 Sep 2020 11:29:19 -0500 Subject: [PATCH 4/4] Add check if trade have been dispute to protocol classes --- .../bisq/core/trade/protocol/BuyerAsMakerProtocol.java | 4 ++++ .../bisq/core/trade/protocol/BuyerAsTakerProtocol.java | 5 +++++ .../core/trade/protocol/SellerAsMakerProtocol.java | 4 ++++ .../core/trade/protocol/SellerAsTakerProtocol.java | 4 ++++ .../java/bisq/core/trade/protocol/TradeProtocol.java | 10 ++++++++++ .../pendingtrades/PendingTradesDataModel.java | 2 +- 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java index ec5d5547937..19dde182b7b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java @@ -212,6 +212,10 @@ private void handle() { // User clicked the "bank transfer started" button @Override public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (wasDisputed(errorMessageHandler)) { + return; + } + if (trade.isDepositConfirmed() && !trade.isFiatSent()) { buyerAsMakerTrade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED); TradeTaskRunner taskRunner = new TradeTaskRunner(buyerAsMakerTrade, diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java index 6665c001ec6..03dc425b5b1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java @@ -237,6 +237,10 @@ private void handle() { // User clicked the "bank transfer started" button @Override public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (wasDisputed(errorMessageHandler)) { + return; + } + if (!trade.isFiatSent()) { buyerAsTakerTrade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED); @@ -262,6 +266,7 @@ public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandle log.warn("onFiatPaymentStarted called twice. tradeState=" + trade.getState()); } } + /////////////////////////////////////////////////////////////////////////////////////////// // Message dispatcher /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java index 3a5ae4df9b8..c7620fccf8c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java @@ -204,6 +204,10 @@ private void handle(CounterCurrencyTransferStartedMessage tradeMessage, NodeAddr // User clicked the "bank transfer received" button, so we release the funds for payout @Override public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (wasDisputed(errorMessageHandler)) { + return; + } + if (trade.getPayoutTx() == null) { sellerAsMakerTrade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT); TradeTaskRunner taskRunner = new TradeTaskRunner(sellerAsMakerTrade, diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java index fd42d66b7c0..6f2f9815c1e 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java @@ -196,6 +196,10 @@ private void handle(CounterCurrencyTransferStartedMessage tradeMessage, NodeAddr // User clicked the "bank transfer received" button, so we release the funds for payout @Override public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (wasDisputed(errorMessageHandler)) { + return; + } + if (trade.getPayoutTx() == null) { sellerAsTakerTrade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT); TradeTaskRunner taskRunner = new TradeTaskRunner(sellerAsTakerTrade, diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index 4cf78045db2..e4afca859ad 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -420,4 +420,14 @@ private void cleanupTradableOnFault() { } } } + + protected boolean wasDisputed(ErrorMessageHandler errorMessageHandler) { + if (trade.getDisputeState() != Trade.DisputeState.NO_DISPUTE) { + String msg = "Dispute have been opened once. We do not allow anymore to confirm payment by button click."; + log.error(msg); + errorMessageHandler.handleErrorMessage(msg); + return true; + } + return false; + } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java index fb03b413f8a..6d1a288f118 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -185,7 +185,7 @@ void onSelectItem(PendingTradesListItem item) { } public void onPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { - final Trade trade = getTrade(); + Trade trade = getTrade(); checkNotNull(trade, "trade must not be null"); checkArgument(trade instanceof BuyerTrade, "Check failed: trade instanceof BuyerTrade"); ((BuyerTrade) trade).onFiatPaymentStarted(resultHandler, errorMessageHandler);