Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deactivate confirm buttons once mediation started #4486

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -262,6 +266,7 @@ public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandle
log.warn("onFiatPaymentStarted called twice. tradeState=" + trade.getState());
}
}

///////////////////////////////////////////////////////////////////////////////////////////
// Message dispatcher
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
chimp1984 marked this conversation as resolved.
Show resolved Hide resolved
errorMessageHandler.handleErrorMessage(msg);
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ protected void applyOnDisputeOpened() {
}

private void updateDisputeState(Trade.DisputeState disputeState) {
deactivatePaymentButtons(false);
Optional<Dispute> ownDispute;
switch (disputeState) {
case NO_DISPUTE:
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -462,9 +458,12 @@ private void updateDisputeState(Trade.DisputeState disputeState) {
});
break;
case REFUND_REQUEST_CLOSED:
deactivatePaymentButtons(true);
break;
default:
break;
}

updateConfirmButtonDisableState(isDisputed());
}

private void updateMediationResultState(boolean blockOpeningOfResultAcceptedPopup) {
Expand Down Expand Up @@ -604,7 +603,8 @@ private void openMediationResultPopup(String headLine) {
acceptMediationResultPopup.show();
}

protected void deactivatePaymentButtons(boolean isDisabled) {
protected void updateConfirmButtonDisableState(boolean isDisabled) {
// By default do nothing. Only overwritten in certain trade steps
}

private void updateTradePeriodState(Trade.TradePeriodState tradePeriodState) {
Expand Down Expand Up @@ -639,6 +639,11 @@ private void updateTradePeriodState(Trade.TradePeriodState tradePeriodState) {
}
}

protected boolean isDisputed() {
return trade.getDisputeState() != Trade.DisputeState.NO_DISPUTE;
}


///////////////////////////////////////////////////////////////////////////////////////////
// TradeDurationLimitInfo
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public void activate() {
}
});
}

confirmButton.setDisable(isDisputed());
}

@Override
Expand Down Expand Up @@ -387,6 +389,10 @@ protected void applyOnDisputeOpened() {
///////////////////////////////////////////////////////////////////////////////////////////

private void onPaymentStarted() {
if (isDisputed()) {
return;
}

if (!model.dataModel.isBootstrappedOrShowPopup()) {
return;
}
Expand Down Expand Up @@ -631,7 +637,7 @@ private void showPopup() {
}

@Override
protected void deactivatePaymentButtons(boolean isDisabled) {
protected void updateConfirmButtonDisableState(boolean isDisabled) {
confirmButton.setDisable(isDisabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public void activate() {
}

applyAssetTxProofResult(trade.getAssetTxProofResult());

confirmButton.setDisable(isDisputed());
}

@Override
Expand Down Expand Up @@ -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<String> 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<String> 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();
}
}

Expand Down Expand Up @@ -508,7 +515,7 @@ private Label createPopoverLabel(String text) {
}

@Override
protected void deactivatePaymentButtons(boolean isDisabled) {
protected void updateConfirmButtonDisableState(boolean isDisabled) {
confirmButton.setDisable(isDisabled);
}
}