From fd985b0c9aeb23b2ab999b81d034daf663862faf Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 29 Oct 2025 09:19:03 -0400 Subject: [PATCH] show number of offers in payment method pulldown (#2032) --- .../desktop/main/offer/offerbook/OfferBook.java | 7 +++++++ .../main/offer/offerbook/OfferBookView.java | 5 ++++- .../src/main/java/haveno/desktop/util/GUIUtil.java | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBook.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBook.java index 6f5424a843..4c9cb7eb00 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBook.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBook.java @@ -232,15 +232,22 @@ public class OfferBook { buyOfferCountMap.clear(); sellOfferCountMap.clear(); final String[] ccyCode = new String[1]; + final String[] paymentMethod = new String[1]; final int[] offerCount = new int[1]; + final int[] paymentMethodOfferCount = new int[1]; offerBookListItems.forEach(o -> { + paymentMethod[0] = o.getOffer().getPaymentMethod().getId(); ccyCode[0] = o.getOffer().getCounterCurrencyCode(); if (o.getOffer().getDirection() == BUY) { offerCount[0] = buyOfferCountMap.getOrDefault(ccyCode[0], 0) + 1; + paymentMethodOfferCount[0] = buyOfferCountMap.getOrDefault(paymentMethod[0], 0) + 1; buyOfferCountMap.put(ccyCode[0], offerCount[0]); + buyOfferCountMap.put(paymentMethod[0], paymentMethodOfferCount[0]); } else { offerCount[0] = sellOfferCountMap.getOrDefault(ccyCode[0], 0) + 1; + paymentMethodOfferCount[0] = sellOfferCountMap.getOrDefault(paymentMethod[0], 0) + 1; sellOfferCountMap.put(ccyCode[0], offerCount[0]); + sellOfferCountMap.put(paymentMethod[0], paymentMethodOfferCount[0]); } }); log.debug("buyOfferCountMap.size {} sellOfferCountMap.size {}", diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java index b2ce32149b..f5dc2a69a0 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java @@ -183,7 +183,6 @@ abstract public class OfferBookView> paymentBoxTuple = FormBuilder.addTopLabelAutocompleteComboBox( Res.get("offerbook.filterByPaymentMethod")); paymentMethodComboBox = paymentBoxTuple.third; - paymentMethodComboBox.setCellFactory(GUIUtil.getPaymentMethodCellFactory()); paymentMethodComboBox.setPrefWidth(250); paymentMethodComboBox.getStyleClass().add("input-with-border"); @@ -383,6 +382,10 @@ abstract public class OfferBookView, ListCell> getPaymentMethodCellFactory() { + public static Callback, ListCell> getPaymentMethodCellFactory(String postFixSingle, + String postFixMulti, + Map offerCounts) { return p -> new ListCell<>() { @Override protected void updateItem(PaymentMethod method, boolean empty) { @@ -572,16 +574,24 @@ public class GUIUtil { HBox box = new HBox(); box.setSpacing(20); + box.setAlignment(Pos.CENTER_LEFT); Label paymentType = new AutoTooltipLabel(getCurrencyType(method)); paymentType.getStyleClass().add("currency-label-small"); Label paymentMethod = new AutoTooltipLabel(Res.get(id)); paymentMethod.getStyleClass().add("currency-label"); - box.getChildren().addAll(paymentType, paymentMethod); + Label numOffersLabel = new AutoTooltipLabel(); + box.getChildren().addAll(paymentType, paymentMethod, numOffersLabel); if (id.equals(GUIUtil.SHOW_ALL_FLAG)) { paymentType.setText(Res.get("shared.all")); paymentMethod.setText(Res.get("list.currency.showAll")); } + Optional offerCountOptional = Optional.ofNullable(offerCounts.get(id)); + offerCountOptional.ifPresent(numOffers -> { + HBox.setMargin(numOffersLabel, new Insets(0, 0, 0, NUM_OFFERS_TRANSLATE_X)); + numOffersLabel.getStyleClass().add("offer-label"); + numOffersLabel.setText(numOffers + " " + (numOffers == 1 ? postFixSingle : postFixMulti)); + }); setGraphic(box);