From 1ba2b6ca18c31c6aa5c4a1ee8d55337293c0cabe Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 7 Mar 2022 20:46:27 -0300 Subject: [PATCH 1/2] Fix API OfferInfo.isActivated setting for bsqswaps I think this bug was introduced when deprecating GrpcOffersService .getMyOffer(id), in favor of using only getOffer(id) for 'my' and 'available' offers. This change explicitly sets the proto's isActivated flag in the OfferInfo factory methods, and adds checks to api offer test cases. Based on branch `2-improve-grpc-exception-status-code-mapping`, PR https://github.com/bisq-network/bisq/pull/6088 --- .../method/offer/BsqSwapOfferTest.java | 5 ++++- .../method/offer/CreateBSQOffersTest.java | 8 +++++++ .../offer/CreateOfferUsingFixedPriceTest.java | 6 ++++++ ...CreateOfferUsingMarketPriceMarginTest.java | 10 +++++++++ .../method/offer/CreateXMROffersTest.java | 8 +++++++ .../core/api/model/CanceledTradeInfo.java | 4 ++-- .../java/bisq/core/api/model/OfferInfo.java | 21 ++++++++++++------- .../java/bisq/core/api/model/TradeInfo.java | 4 ++-- .../bisq/daemon/grpc/GrpcOffersService.java | 14 ++++++++----- 9 files changed, 63 insertions(+), 17 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java index 5006ab3b301..e1824f8c91a 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java @@ -35,6 +35,7 @@ import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static protobuf.OfferDirection.BUY; @@ -45,7 +46,7 @@ public class BsqSwapOfferTest extends AbstractOfferTest { @BeforeAll public static void setUp() { - AbstractOfferTest.setUp(); + AbstractOfferTest.setUp(false); } @BeforeEach @@ -137,6 +138,7 @@ private void testGetMyBsqSwapOffer(OfferInfo bsqSwapOffer) { numFetchAttempts++; var fetchedBsqSwapOffer = aliceClient.getOffer(bsqSwapOffer.getId()); assertEquals(bsqSwapOffer.getId(), fetchedBsqSwapOffer.getId()); + assertTrue(fetchedBsqSwapOffer.getIsActivated()); log.debug("Alice found her (my) new bsq swap offer on attempt # {}.", numFetchAttempts); break; } catch (Exception ex) { @@ -159,6 +161,7 @@ private void testGetBsqSwapOffer(OfferInfo bsqSwapOffer) { numFetchAttempts++; var fetchedBsqSwapOffer = bobClient.getOffer(bsqSwapOffer.getId()); assertEquals(bsqSwapOffer.getId(), fetchedBsqSwapOffer.getId()); + assertTrue(fetchedBsqSwapOffer.getIsActivated()); log.debug("Bob found new available bsq swap offer on attempt # {}.", numFetchAttempts); break; } catch (Exception ex) { diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java index efa832b9a2a..66819852bff 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java @@ -68,6 +68,7 @@ public void testCreateBuy1BTCFor20KBSQOffer() { log.debug("Sell BSQ (Buy BTC) Offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -89,6 +90,7 @@ public void testCreateBuy1BTCFor20KBSQOffer() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); @@ -119,6 +121,7 @@ public void testCreateSell1BTCFor20KBSQOffer() { log.debug("SELL 20K BSQ Offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -140,6 +143,7 @@ public void testCreateSell1BTCFor20KBSQOffer() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); @@ -170,6 +174,7 @@ public void testCreateBuyBTCWith1To2KBSQOffer() { log.debug("BUY 1-2K BSQ Offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -191,6 +196,7 @@ public void testCreateBuyBTCWith1To2KBSQOffer() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); @@ -221,6 +227,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() { log.debug("SELL 5-10K BSQ Offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -242,6 +249,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java index 7691a5e26d4..913d5fc1697 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java @@ -60,6 +60,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() { log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -79,6 +80,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); @@ -109,6 +111,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() { log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -128,6 +131,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); @@ -158,6 +162,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() { log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -177,6 +182,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java index fc61b5699dc..8f58e845eaf 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java @@ -77,6 +77,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() { log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -94,6 +95,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); @@ -126,6 +128,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() { log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -143,6 +146,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); @@ -175,6 +179,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() { log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -192,6 +197,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); @@ -224,6 +230,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() { log.debug("Offer #4:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -241,6 +248,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); @@ -273,12 +281,14 @@ public void testCreateUSDBTCBuyOfferWithTriggerPrice() { triggerPrice); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); genBtcBlocksThenWait(1, 4000); // give time to add to offer book newOffer = aliceClient.getOffer(newOffer.getId()); log.debug("Offer #5:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(triggerPrice, newOffer.getTriggerPrice()); } diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java index 615eda0d160..b9337051535 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java @@ -71,6 +71,7 @@ public void testCreateFixedPriceBuy1BTCFor200KXMROffer() { log.debug("Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -90,6 +91,7 @@ public void testCreateFixedPriceBuy1BTCFor200KXMROffer() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); @@ -118,6 +120,7 @@ public void testCreateFixedPriceSell1BTCFor200KXMROffer() { log.debug("Buy XMR (Sell BTC) offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -137,6 +140,7 @@ public void testCreateFixedPriceSell1BTCFor200KXMROffer() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertFalse(newOffer.getUseMarketBasedPrice()); @@ -168,6 +172,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() { log.debug("Pending Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -191,6 +196,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() { log.debug("Available Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); @@ -224,6 +230,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() { log.debug("Buy XMR (Sell BTC) offer:\n{}", toOfferTable.apply(newOffer)); assertTrue(newOffer.getIsMyOffer()); assertTrue(newOffer.getIsMyPendingOffer()); + assertFalse(newOffer.getIsActivated()); String newOfferId = newOffer.getId(); assertNotEquals("", newOfferId); @@ -242,6 +249,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() { newOffer = aliceClient.getOffer(newOfferId); assertTrue(newOffer.getIsMyOffer()); assertFalse(newOffer.getIsMyPendingOffer()); + assertTrue(newOffer.getIsActivated()); assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); diff --git a/core/src/main/java/bisq/core/api/model/CanceledTradeInfo.java b/core/src/main/java/bisq/core/api/model/CanceledTradeInfo.java index d1bb85ff80d..14bffe34c12 100644 --- a/core/src/main/java/bisq/core/api/model/CanceledTradeInfo.java +++ b/core/src/main/java/bisq/core/api/model/CanceledTradeInfo.java @@ -22,7 +22,7 @@ import bisq.core.offer.OpenOffer; import static bisq.core.api.model.ContractInfo.emptyContract; -import static bisq.core.api.model.OfferInfo.toMyOfferInfo; +import static bisq.core.api.model.OfferInfo.toMyInactiveOfferInfo; import static bisq.core.offer.OpenOffer.State.CANCELED; import static java.lang.String.format; import static org.apache.commons.lang3.StringUtils.capitalize; @@ -37,7 +37,7 @@ public static TradeInfo toCanceledTradeInfo(OpenOffer myCanceledOpenOffer) { throw new IllegalArgumentException(format("offer '%s' is not canceled", myCanceledOpenOffer.getId())); Offer offer = myCanceledOpenOffer.getOffer(); - OfferInfo offerInfo = toMyOfferInfo(offer); + OfferInfo offerInfo = toMyInactiveOfferInfo(offer); return new TradeInfoV1Builder() .withOffer(offerInfo) diff --git a/core/src/main/java/bisq/core/api/model/OfferInfo.java b/core/src/main/java/bisq/core/api/model/OfferInfo.java index de155b86291..444d0fe1aa1 100644 --- a/core/src/main/java/bisq/core/api/model/OfferInfo.java +++ b/core/src/main/java/bisq/core/api/model/OfferInfo.java @@ -113,14 +113,18 @@ public OfferInfo(OfferInfoBuilder builder) { this.protocolVersion = builder.getProtocolVersion(); } - public static OfferInfo toMyOfferInfo(Offer offer) { - return getBuilder(offer, true).build(); + public static OfferInfo toMyInactiveOfferInfo(Offer offer) { + return getBuilder(offer, true) + .withIsActivated(false) + .build(); } public static OfferInfo toOfferInfo(Offer offer) { // Assume the offer is not mine, but isMyOffer can be reset to true, i.e., when // calling TradeInfo toTradeInfo(Trade trade, String role, boolean isMyOffer); - return getBuilder(offer, false).build(); + return getBuilder(offer, false) + .withIsActivated(true) + .build(); } public static OfferInfo toMyPendingOfferInfo(Offer myNewOffer) { @@ -130,21 +134,24 @@ public static OfferInfo toMyPendingOfferInfo(Offer myNewOffer) { // column that will show a PENDING value when this.isMyPendingOffer = true. return getBuilder(myNewOffer, true) .withIsMyPendingOffer(true) + .withIsActivated(false) .build(); } public static OfferInfo toMyOfferInfo(OpenOffer openOffer) { // An OpenOffer is always my offer. - var currencyCode = openOffer.getOffer().getCurrencyCode(); - Optional optionalTriggerPrice = openOffer.getTriggerPrice() > 0 + var offer = openOffer.getOffer(); + var currencyCode = offer.getCurrencyCode(); + var isActivated = !openOffer.isDeactivated(); + Optional optionalTriggerPrice = (!offer.isBsqSwapOffer() && openOffer.getTriggerPrice() > 0) ? Optional.of(Price.valueOf(currencyCode, openOffer.getTriggerPrice())) : Optional.empty(); var preciseTriggerPrice = optionalTriggerPrice .map(value -> reformatMarketPrice(value.toPlainString(), currencyCode)) .orElse("0"); - return getBuilder(openOffer.getOffer(), true) + return getBuilder(offer, true) .withTriggerPrice(preciseTriggerPrice) - .withIsActivated(!openOffer.isDeactivated()) + .withIsActivated(isActivated) .build(); } diff --git a/core/src/main/java/bisq/core/api/model/TradeInfo.java b/core/src/main/java/bisq/core/api/model/TradeInfo.java index f150bcaac2c..cf65cf77999 100644 --- a/core/src/main/java/bisq/core/api/model/TradeInfo.java +++ b/core/src/main/java/bisq/core/api/model/TradeInfo.java @@ -32,7 +32,7 @@ import lombok.Getter; import static bisq.core.api.model.BsqSwapTradeInfo.toBsqSwapTradeInfo; -import static bisq.core.api.model.OfferInfo.toMyOfferInfo; +import static bisq.core.api.model.OfferInfo.toMyInactiveOfferInfo; import static bisq.core.api.model.OfferInfo.toOfferInfo; import static bisq.core.api.model.PaymentAccountPayloadInfo.toPaymentAccountPayloadInfo; import static bisq.core.offer.OfferDirection.BUY; @@ -50,7 +50,7 @@ public class TradeInfo implements Payload { // view and interact with trades. private static final BiFunction toOfferInfo = (tradeModel, isMyOffer) -> - isMyOffer ? toMyOfferInfo(tradeModel.getOffer()) : toOfferInfo(tradeModel.getOffer()); + isMyOffer ? toMyInactiveOfferInfo(tradeModel.getOffer()) : toOfferInfo(tradeModel.getOffer()); private static final Function toPeerNodeAddress = (tradeModel) -> tradeModel.getTradingPeerNodeAddress() == null diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java index 18bb17bf048..665569181b3 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java @@ -125,8 +125,8 @@ public void getOffer(GetOfferRequest req, try { String offerId = req.getId(); Optional myOpenOffer = coreApi.findMyOpenOffer(offerId); - OfferInfo offerInfo = myOpenOffer.map(OfferInfo::toMyOfferInfo) - .orElseGet(() -> toOfferInfo(coreApi.getOffer(offerId))); + Offer offer = myOpenOffer.map(OpenOffer::getOffer).orElseGet(() -> coreApi.getOffer(offerId)); + OfferInfo offerInfo = myOpenOffer.map(OfferInfo::toMyOfferInfo).orElseGet(() -> OfferInfo.toOfferInfo(offer)); var reply = GetOfferReply.newBuilder() .setOffer(offerInfo.toProtoMessage()) .build(); @@ -174,7 +174,8 @@ public void getBsqSwapOffers(GetBsqSwapOffersRequest req, StreamObserver responseObserver) { try { List result = coreApi.getBsqSwapOffers(req.getDirection()) - .stream().map(OfferInfo::toOfferInfo) + .stream() + .map(OfferInfo::toOfferInfo) .collect(Collectors.toList()); var reply = GetBsqSwapOffersReply.newBuilder() .addAllBsqSwapOffers(result.stream() @@ -193,7 +194,8 @@ public void getOffers(GetOffersRequest req, StreamObserver responseObserver) { try { List result = coreApi.getOffers(req.getDirection(), req.getCurrencyCode()) - .stream().map(OfferInfo::toOfferInfo) + .stream() + .map(OfferInfo::toOfferInfo) .collect(Collectors.toList()); var reply = GetOffersReply.newBuilder() .addAllOffers(result.stream() @@ -212,7 +214,9 @@ public void getMyBsqSwapOffers(GetBsqSwapOffersRequest req, StreamObserver responseObserver) { try { List result = coreApi.getMyBsqSwapOffers(req.getDirection()) - .stream().map(OfferInfo::toOfferInfo) + .stream() + .map(o -> coreApi.getMyOpenBsqSwapOffer(o.getId())) + .map(OfferInfo::toMyOfferInfo) .collect(Collectors.toList()); var reply = GetMyBsqSwapOffersReply.newBuilder() .addAllBsqSwapOffers(result.stream() From 4c2649b118ea1e9aaf57a26acf52e24f1985125a Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 7 Mar 2022 21:02:13 -0300 Subject: [PATCH 2/2] Fix 'unnecessary use of fully qualified name' --- .../src/main/java/bisq/daemon/grpc/GrpcOffersService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java index 665569181b3..cfb6cc34973 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java @@ -125,8 +125,10 @@ public void getOffer(GetOfferRequest req, try { String offerId = req.getId(); Optional myOpenOffer = coreApi.findMyOpenOffer(offerId); - Offer offer = myOpenOffer.map(OpenOffer::getOffer).orElseGet(() -> coreApi.getOffer(offerId)); - OfferInfo offerInfo = myOpenOffer.map(OfferInfo::toMyOfferInfo).orElseGet(() -> OfferInfo.toOfferInfo(offer)); + Offer offer = myOpenOffer.map(OpenOffer::getOffer) + .orElseGet(() -> coreApi.getOffer(offerId)); + OfferInfo offerInfo = myOpenOffer.map(OfferInfo::toMyOfferInfo) + .orElseGet(() -> toOfferInfo(offer)); var reply = GetOfferReply.newBuilder() .setOffer(offerInfo.toProtoMessage()) .build();