set offer trigger price and state from open offer

This commit is contained in:
woodser 2022-05-23 18:24:10 -04:00
parent e33d93eee8
commit ca9bdf7c29
5 changed files with 23 additions and 19 deletions

View File

@ -18,7 +18,7 @@
package bisq.core.api.model;
import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer;
import bisq.common.Payload;
import bisq.common.proto.ProtoUtil;
import java.util.Objects;
@ -94,10 +94,13 @@ public class OfferInfo implements Payload {
return getOfferInfoBuilder(offer).build();
}
public static OfferInfo toOfferInfo(Offer offer, long triggerPrice) {
// The Offer does not have a triggerPrice attribute, so we get
// the base OfferInfoBuilder, then add the OpenOffer's triggerPrice.
return getOfferInfoBuilder(offer).withTriggerPrice(triggerPrice).build();
public static OfferInfo toOfferInfo(Offer offer, OpenOffer openOffer) {
OfferInfoBuilder builder = getOfferInfoBuilder(offer);
if (openOffer != null) {
builder.withState(openOffer.getState().name());
builder.withTriggerPrice(openOffer.getTriggerPrice());
}
return builder.build();
}
private static OfferInfoBuilder getOfferInfoBuilder(Offer offer) {

View File

@ -82,7 +82,6 @@ public class Offer implements NetworkPayload, PersistablePayload {
public enum State {
UNKNOWN,
SCHEDULED,
OFFER_FEE_RESERVED,
AVAILABLE,
NOT_AVAILABLE,

View File

@ -696,7 +696,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
// schedule txs
openOffer.setScheduledTxHashes(scheduledTxHashes);
openOffer.setScheduledAmount(scheduledAmount.toString());
openOffer.getOffer().setState(Offer.State.SCHEDULED);
openOffer.setState(OpenOffer.State.SCHEDULED);
}
// handle result

View File

@ -39,7 +39,7 @@ import io.grpc.ServerInterceptor;
import io.grpc.stub.StreamObserver;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
@ -91,7 +91,7 @@ class GrpcOffersService extends OffersImplBase {
Offer offer = coreApi.getMyOffer(req.getId());
OpenOffer openOffer = coreApi.getMyOpenOffer(req.getId());
var reply = GetMyOfferReply.newBuilder()
.setOffer(toOfferInfo(offer, openOffer.getTriggerPrice()).toProtoMessage())
.setOffer(toOfferInfo(offer, openOffer).toProtoMessage())
.build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
@ -123,9 +123,11 @@ class GrpcOffersService extends OffersImplBase {
public void getMyOffers(GetMyOffersRequest req,
StreamObserver<GetMyOffersReply> responseObserver) {
try {
List<OfferInfo> result = coreApi.getMyOffers(req.getDirection(), req.getCurrencyCode())
.stream().map(OfferInfo::toOfferInfo)
.collect(Collectors.toList());
List<OfferInfo> result = new ArrayList<OfferInfo>();
for (Offer offer : coreApi.getMyOffers(req.getDirection(), req.getCurrencyCode())) {
OpenOffer openOffer = coreApi.getMyOpenOffer(offer.getId());
result.add(toOfferInfo(offer, openOffer));
}
var reply = GetMyOffersReply.newBuilder()
.addAllOffers(result.stream()
.map(OfferInfo::toProtoMessage)
@ -161,7 +163,8 @@ class GrpcOffersService extends OffersImplBase {
offer -> {
// This result handling consumer's accept operation will return
// the new offer to the gRPC client after async placement is done.
OfferInfo offerInfo = toOfferInfo(offer);
OpenOffer openOffer = coreApi.getMyOpenOffer(offer.getId());
OfferInfo offerInfo = toOfferInfo(offer, openOffer);
CreateOfferReply reply = CreateOfferReply.newBuilder()
.setOffer(offerInfo.toProtoMessage())
.build();

View File

@ -1450,12 +1450,11 @@ message Offer {
enum State {
PB_ERROR = 0;
UNKNOWN = 1;
SCHEDULED = 2;
OFFER_FEE_RESERVED = 3;
AVAILABLE = 4;
NOT_AVAILABLE = 5;
REMOVED = 6;
MAKER_OFFLINE = 7;
OFFER_FEE_RESERVED = 2;
AVAILABLE = 3;
NOT_AVAILABLE = 4;
REMOVED = 5;
MAKER_OFFLINE = 6;
}
OfferPayload offer_payload = 1;