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