Skip to content

Commit

Permalink
Merge pull request #4493 from chimp1984/deactive-confirm-buttons-once…
Browse files Browse the repository at this point in the history
…-mediation-started

Deactive confirm buttons once mediation started
  • Loading branch information
ripcurlx committed Sep 7, 2020
2 parents cafbbdf + c40bcfe commit 27a9f96
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 9 deletions.
Expand Up @@ -55,6 +55,8 @@

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
public class BuyerAsMakerProtocol extends TradeProtocol implements BuyerProtocol, MakerProtocol {
private final BuyerAsMakerTrade buyerAsMakerTrade;
Expand Down Expand Up @@ -212,6 +214,9 @@ private void handle() {
// User clicked the "bank transfer started" button
@Override
public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
checkArgument(!wasDisputed(), "A call to onFiatPaymentStarted is not permitted once a " +
"dispute has been opened.");

if (trade.isDepositConfirmed() && !trade.isFiatSent()) {
buyerAsMakerTrade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED);
TradeTaskRunner taskRunner = new TradeTaskRunner(buyerAsMakerTrade,
Expand Down
Expand Up @@ -59,6 +59,7 @@

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

@Slf4j
Expand Down Expand Up @@ -237,6 +238,9 @@ private void handle() {
// User clicked the "bank transfer started" button
@Override
public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
checkArgument(!wasDisputed(), "A call to onFiatPaymentStarted is not permitted once a " +
"dispute has been opened.");

if (!trade.isFiatSent()) {
buyerAsTakerTrade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED);

Expand Down
Expand Up @@ -57,6 +57,8 @@

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
public class SellerAsMakerProtocol extends TradeProtocol implements SellerProtocol, MakerProtocol {
private final SellerAsMakerTrade sellerAsMakerTrade;
Expand Down Expand Up @@ -204,6 +206,9 @@ 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) {
checkArgument(!wasDisputed(), "A call to onFiatPaymentReceived is not permitted once a " +
"dispute has been opened.");

if (trade.getPayoutTx() == null) {
sellerAsMakerTrade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT);
TradeTaskRunner taskRunner = new TradeTaskRunner(sellerAsMakerTrade,
Expand Down
Expand Up @@ -56,6 +56,7 @@

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

@Slf4j
Expand Down Expand Up @@ -196,6 +197,9 @@ 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) {
checkArgument(!wasDisputed(), "A call to onFiatPaymentReceived is not permitted once a " +
"dispute has been opened.");

if (trade.getPayoutTx() == null) {
sellerAsTakerTrade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT);
TradeTaskRunner taskRunner = new TradeTaskRunner(sellerAsTakerTrade,
Expand Down
Expand Up @@ -345,6 +345,10 @@ protected void handleTaskRunnerFault(@Nullable TradeMessage tradeMessage, String
cleanup();
}

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

private void sendAckMessage(@Nullable TradeMessage tradeMessage, boolean result, @Nullable String errorMessage) {
// We complete at initial protocol setup with the setup listener tasks.
// Other cases are if we start from an UI event the task runner (payment started, confirmed).
Expand Down
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
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
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);
}
}
Expand Up @@ -313,7 +313,7 @@ protected void addContent() {
}

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

Expand Down Expand Up @@ -364,6 +364,10 @@ 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()) {
Expand Down

0 comments on commit 27a9f96

Please sign in to comment.