mirror of
https://github.com/retoaccess1/haveno-reto.git
synced 2024-11-10 05:03:35 +01:00
cancel offer waits for result
This commit is contained in:
parent
4a57b26469
commit
216260da85
@ -458,8 +458,8 @@ public class CoreApi {
|
||||
paymentAccount);
|
||||
}
|
||||
|
||||
public void cancelOffer(String id) {
|
||||
coreOffersService.cancelOffer(id);
|
||||
public void cancelOffer(String id, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
|
||||
coreOffersService.cancelOffer(id, resultHandler, errorMessageHandler);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -38,6 +38,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import haveno.common.crypto.KeyRing;
|
||||
import haveno.common.handlers.ErrorMessageHandler;
|
||||
import haveno.common.handlers.ResultHandler;
|
||||
import static haveno.common.util.MathUtils.exactMultiply;
|
||||
import static haveno.common.util.MathUtils.roundDoubleToLong;
|
||||
import static haveno.common.util.MathUtils.scaleUpByPowerOf10;
|
||||
@ -236,14 +237,9 @@ public class CoreOffersService {
|
||||
paymentAccount);
|
||||
}
|
||||
|
||||
void cancelOffer(String id) {
|
||||
void cancelOffer(String id, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
|
||||
Offer offer = getMyOffer(id).getOffer();
|
||||
openOfferManager.removeOffer(offer,
|
||||
() -> {
|
||||
},
|
||||
errorMessage -> {
|
||||
throw new IllegalStateException(errorMessage);
|
||||
});
|
||||
openOfferManager.removeOffer(offer, resultHandler, errorMessageHandler);
|
||||
}
|
||||
|
||||
// -------------------------- PRIVATE HELPERS -----------------------------
|
||||
|
@ -620,9 +620,13 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
if (!offersToBeEdited.containsKey(openOffer.getId())) {
|
||||
if (openOffer.isDeactivated()) {
|
||||
onCancelled(openOffer);
|
||||
resultHandler.handleResult();
|
||||
} else {
|
||||
offerBookService.removeOffer(openOffer.getOffer().getOfferPayload(),
|
||||
() -> onCancelled(openOffer),
|
||||
() -> {
|
||||
onCancelled(openOffer);
|
||||
resultHandler.handleResult();
|
||||
},
|
||||
errorMessageHandler);
|
||||
}
|
||||
} else {
|
||||
|
@ -140,11 +140,7 @@ class GrpcOffersService extends OffersImplBase {
|
||||
@Override
|
||||
public void postOffer(PostOfferRequest req,
|
||||
StreamObserver<PostOfferReply> responseObserver) {
|
||||
GrpcErrorMessageHandler errorMessageHandler =
|
||||
new GrpcErrorMessageHandler(getPostOfferMethod().getFullMethodName(),
|
||||
responseObserver,
|
||||
exceptionHandler,
|
||||
log);
|
||||
GrpcErrorMessageHandler errorMessageHandler = new GrpcErrorMessageHandler(getPostOfferMethod().getFullMethodName(), responseObserver, exceptionHandler, log);
|
||||
try {
|
||||
coreApi.postOffer(
|
||||
req.getCurrencyCode(),
|
||||
@ -170,8 +166,7 @@ class GrpcOffersService extends OffersImplBase {
|
||||
responseObserver.onCompleted();
|
||||
},
|
||||
errorMessage -> {
|
||||
if (!errorMessageHandler.isErrorHandled())
|
||||
errorMessageHandler.handleErrorMessage(errorMessage);
|
||||
if (!errorMessageHandler.isErrorHandled()) errorMessageHandler.handleErrorMessage(errorMessage);
|
||||
});
|
||||
} catch (Throwable cause) {
|
||||
exceptionHandler.handleException(log, cause, responseObserver);
|
||||
@ -181,11 +176,15 @@ class GrpcOffersService extends OffersImplBase {
|
||||
@Override
|
||||
public void cancelOffer(CancelOfferRequest req,
|
||||
StreamObserver<CancelOfferReply> responseObserver) {
|
||||
GrpcErrorMessageHandler errorMessageHandler = new GrpcErrorMessageHandler(getCancelOfferMethod().getFullMethodName(), responseObserver, exceptionHandler, log);
|
||||
try {
|
||||
coreApi.cancelOffer(req.getId());
|
||||
var reply = CancelOfferReply.newBuilder().build();
|
||||
responseObserver.onNext(reply);
|
||||
responseObserver.onCompleted();
|
||||
coreApi.cancelOffer(req.getId(), () -> {
|
||||
var reply = CancelOfferReply.newBuilder().build();
|
||||
responseObserver.onNext(reply);
|
||||
responseObserver.onCompleted();
|
||||
}, errorMessage -> {
|
||||
if (!errorMessageHandler.isErrorHandled()) errorMessageHandler.handleErrorMessage(errorMessage);
|
||||
});
|
||||
} catch (Throwable cause) {
|
||||
exceptionHandler.handleException(log, cause, responseObserver);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user