confirm payment sent and received off main thread

This commit is contained in:
woodser 2022-07-30 16:07:29 -04:00
parent 50126874a0
commit 3d43ae1f20
4 changed files with 90 additions and 82 deletions

View File

@ -126,6 +126,7 @@ public abstract class BuyerProtocol extends DisputeProtocol {
public void onPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { public void onPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
System.out.println("BuyerProtocol.onPaymentStarted()"); System.out.println("BuyerProtocol.onPaymentStarted()");
new Thread(() -> {
synchronized (trade) { synchronized (trade) {
latchTrade(); latchTrade();
this.errorMessageHandler = errorMessageHandler; this.errorMessageHandler = errorMessageHandler;
@ -149,9 +150,10 @@ public abstract class BuyerProtocol extends DisputeProtocol {
handleTaskRunnerFault(event, errorMessage); handleTaskRunnerFault(event, errorMessage);
}))) })))
.run(() -> trade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_PAYMENT_SENT)) .run(() -> trade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_PAYMENT_SENT))
.executeTasks(); .executeTasks(true);
awaitTradeLatch(); awaitTradeLatch();
} }
}).start();
} }
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -124,6 +124,7 @@ public abstract class SellerProtocol extends DisputeProtocol {
public void onPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { public void onPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
log.info("SellerProtocol.onPaymentReceived()"); log.info("SellerProtocol.onPaymentReceived()");
new Thread(() -> {
synchronized (trade) { synchronized (trade) {
latchTrade(); latchTrade();
this.errorMessageHandler = errorMessageHandler; this.errorMessageHandler = errorMessageHandler;
@ -144,9 +145,10 @@ public abstract class SellerProtocol extends DisputeProtocol {
handleTaskRunnerFault(event, errorMessage); handleTaskRunnerFault(event, errorMessage);
}))) })))
.run(() -> trade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_PAYMENT_RECEIPT)) .run(() -> trade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_PAYMENT_RECEIPT))
.executeTasks(); .executeTasks(true);
awaitTradeLatch(); awaitTradeLatch();
} }
}).start();
} }
@Override @Override

View File

@ -159,9 +159,11 @@ public class BuyerStep2View extends TradeStepView {
showPopup(); showPopup();
} else if (state.ordinal() <= Trade.State.BUYER_SEND_FAILED_PAYMENT_SENT_MSG.ordinal()) { } else if (state.ordinal() <= Trade.State.BUYER_SEND_FAILED_PAYMENT_SENT_MSG.ordinal()) {
if (!trade.hasFailed()) { if (!trade.hasFailed()) {
UserThread.execute(() -> {
switch (state) { switch (state) {
case BUYER_CONFIRMED_IN_UI_PAYMENT_SENT: case BUYER_CONFIRMED_IN_UI_PAYMENT_SENT:
busyAnimation.play();
statusLabel.setText("Confirming payment sent...");
break;
case BUYER_SENT_PAYMENT_SENT_MSG: case BUYER_SENT_PAYMENT_SENT_MSG:
busyAnimation.play(); busyAnimation.play();
statusLabel.setText(Res.get("shared.sendingConfirmation")); statusLabel.setText(Res.get("shared.sendingConfirmation"));
@ -193,7 +195,6 @@ public class BuyerStep2View extends TradeStepView {
statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); statusLabel.setText(Res.get("shared.sendingConfirmationAgain"));
break; break;
} }
});
} else { } else {
log.warn("Trade contains error message {}", trade.getErrorMessage()); log.warn("Trade contains error message {}", trade.getErrorMessage());
statusLabel.setText(""); statusLabel.setText("");

View File

@ -120,6 +120,9 @@ public class SellerStep3View extends TradeStepView {
if (!trade.hasFailed()) { if (!trade.hasFailed()) {
switch (state) { switch (state) {
case SELLER_CONFIRMED_IN_UI_PAYMENT_RECEIPT: case SELLER_CONFIRMED_IN_UI_PAYMENT_RECEIPT:
busyAnimation.play();
statusLabel.setText(Res.get("Confirming payment received..."));
break;
case SELLER_PUBLISHED_PAYOUT_TX: case SELLER_PUBLISHED_PAYOUT_TX:
case SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG: case SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG:
case SELLER_SENT_PAYMENT_RECEIVED_MSG: case SELLER_SENT_PAYMENT_RECEIVED_MSG: