diff --git a/core/src/main/java/bisq/core/trade/ClosedTradableManager.java b/core/src/main/java/bisq/core/trade/ClosedTradableManager.java index 38c2a9a27a0..ab533462232 100644 --- a/core/src/main/java/bisq/core/trade/ClosedTradableManager.java +++ b/core/src/main/java/bisq/core/trade/ClosedTradableManager.java @@ -52,6 +52,7 @@ import java.time.Instant; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -149,6 +150,10 @@ public ObservableList getObservableList() { return closedTradables.getObservableList(); } + public List getTradableList() { + return ImmutableList.copyOf(new ArrayList<>(getObservableList())); + } + public List getClosedTrades() { return ImmutableList.copyOf(getObservableList().stream() .filter(e -> e instanceof Trade) diff --git a/core/src/main/java/bisq/core/trade/bsq_swap/BsqSwapTradeManager.java b/core/src/main/java/bisq/core/trade/bsq_swap/BsqSwapTradeManager.java index f5b9a9f6805..6ea6774a13b 100644 --- a/core/src/main/java/bisq/core/trade/bsq_swap/BsqSwapTradeManager.java +++ b/core/src/main/java/bisq/core/trade/bsq_swap/BsqSwapTradeManager.java @@ -20,6 +20,7 @@ import bisq.core.btc.wallet.BsqWalletService; import bisq.core.offer.Offer; import bisq.core.provider.price.PriceFeedService; +import bisq.core.trade.model.Tradable; import bisq.core.trade.model.TradableList; import bisq.core.trade.model.bsq_swap.BsqSwapTrade; @@ -116,6 +117,10 @@ public List getBsqSwapTrades() { return ImmutableList.copyOf(new ArrayList<>(getObservableList())); } + public List getTradableList() { + return ImmutableList.copyOf(new ArrayList<>(getObservableList())); + } + public Optional findBsqSwapTradeById(String id) { return bsqSwapTrades.stream().filter(e -> e.getId().equals(id)).findFirst(); } diff --git a/core/src/main/java/bisq/core/trade/model/Tradable.java b/core/src/main/java/bisq/core/trade/model/Tradable.java index 96739a4aa19..bf7fa7f908a 100644 --- a/core/src/main/java/bisq/core/trade/model/Tradable.java +++ b/core/src/main/java/bisq/core/trade/model/Tradable.java @@ -21,6 +21,8 @@ import bisq.core.monetary.Volume; import bisq.core.offer.Offer; +import bisq.network.p2p.NodeAddress; + import bisq.common.proto.persistable.PersistablePayload; import org.bitcoinj.core.Coin; @@ -72,4 +74,8 @@ default Optional getOptionalTakerFee() { default Optional getOptionalMakerFee() { return asTradeModel().map(TradeModel::getMakerFee).or(() -> Optional.ofNullable(getOffer().getMakerFee())); } + + default Optional getOptionalTradingPeerNodeAddress() { + return asTradeModel().map(TradeModel::getTradingPeerNodeAddress); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index beaa0b6ca9c..df3ff85659b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -49,7 +49,9 @@ import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.ClosedTradableManager; +import bisq.core.trade.bsq_swap.BsqSwapTradeManager; import bisq.core.trade.model.bisq_v1.Trade; +import bisq.core.trade.model.bsq_swap.BsqSwapTrade; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.FormattingUtils; @@ -94,6 +96,7 @@ import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -108,6 +111,7 @@ class OfferBookViewModel extends ActivatableViewModel { private final P2PService p2PService; final PriceFeedService priceFeedService; private final ClosedTradableManager closedTradableManager; + private final BsqSwapTradeManager bsqSwapTradeManager; final AccountAgeWitnessService accountAgeWitnessService; private final Navigation navigation; private final PriceUtil priceUtil; @@ -161,6 +165,7 @@ public OfferBookViewModel(User user, P2PService p2PService, PriceFeedService priceFeedService, ClosedTradableManager closedTradableManager, + BsqSwapTradeManager bsqSwapTradeManager, AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, PriceUtil priceUtil, @@ -179,6 +184,7 @@ public OfferBookViewModel(User user, this.p2PService = p2PService; this.priceFeedService = priceFeedService; this.closedTradableManager = closedTradableManager; + this.bsqSwapTradeManager = bsqSwapTradeManager; this.accountAgeWitnessService = accountAgeWitnessService; this.navigation = navigation; this.priceUtil = priceUtil; @@ -626,11 +632,12 @@ private boolean isEditEntry(String id) { } int getNumTrades(Offer offer) { - return closedTradableManager.getObservableList().stream() + return Stream.concat(closedTradableManager.getTradableList().stream(), bsqSwapTradeManager.getTradableList().stream()) + .filter(e -> e instanceof Trade || e instanceof BsqSwapTrade) // weed out canceled offers .filter(e -> { - final NodeAddress tradingPeerNodeAddress = e instanceof Trade ? ((Trade) e).getTradingPeerNodeAddress() : null; - return tradingPeerNodeAddress != null && - tradingPeerNodeAddress.getFullAddress().equals(offer.getMakerNodeAddress().getFullAddress()); + final Optional tradingPeerNodeAddress = e.getOptionalTradingPeerNodeAddress(); + return tradingPeerNodeAddress.isPresent() && + tradingPeerNodeAddress.get().getFullAddress().equals(offer.getMakerNodeAddress().getFullAddress()); }) .collect(Collectors.toSet()) .size(); diff --git a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java index 5e5e25cb8fa..cffe57e297a 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java @@ -239,7 +239,7 @@ public void testMaxCharactersForAmountWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForAmount.intValue()); } @@ -253,7 +253,7 @@ public void testMaxCharactersForAmount() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(6, model.maxPlacesForAmount.intValue()); @@ -271,7 +271,7 @@ public void testMaxCharactersForAmountRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(15, model.maxPlacesForAmount.intValue()); @@ -290,7 +290,7 @@ public void testMaxCharactersForVolumeWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForVolume.intValue()); } @@ -304,7 +304,7 @@ public void testMaxCharactersForVolume() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(5, model.maxPlacesForVolume.intValue()); @@ -322,7 +322,7 @@ public void testMaxCharactersForVolumeRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(9, model.maxPlacesForVolume.intValue()); @@ -341,7 +341,7 @@ public void testMaxCharactersForPriceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForPrice.intValue()); } @@ -355,7 +355,7 @@ public void testMaxCharactersForPrice() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(7, model.maxPlacesForPrice.intValue()); @@ -373,7 +373,7 @@ public void testMaxCharactersForPriceDistanceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue()); } @@ -408,7 +408,7 @@ public void testMaxCharactersForPriceDistance() { offerBookListItems.addAll(item1, item2); final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue()); //" (1.97%)" @@ -429,7 +429,7 @@ public void testGetPrice() { when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true)); final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); final OfferBookListItem item = make(btcBuyItem.but( with(useMarketBasedPrice, true), @@ -634,3 +634,4 @@ private Offer getOffer(String tradeCurrencyCode, 1)); } } +