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

Deactive confirm buttons once mediation started #4493

Merged
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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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 @@ -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