From 07769fd8d9dd04ca2add4fdb3ac472c521bbfeba Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 10 Dec 2023 08:11:14 -0500 Subject: [PATCH] fix updating display of current price --- .../java/haveno/desktop/main/MainView.java | 14 +++--- .../presentation/MarketPricePresentation.java | 44 ++++++++++--------- .../main/shared/PriceFeedComboBoxItem.java | 3 +- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/MainView.java b/desktop/src/main/java/haveno/desktop/main/MainView.java index fe64223a..adabe6f7 100644 --- a/desktop/src/main/java/haveno/desktop/main/MainView.java +++ b/desktop/src/main/java/haveno/desktop/main/MainView.java @@ -429,14 +429,12 @@ public class MainView extends InitializableView { return new ListCell<>() { @Override protected void updateItem(PriceFeedComboBoxItem item, boolean empty) { - UserThread.execute(() -> { - super.updateItem(item, empty); - if (!empty && item != null) { - textProperty().bind(item.displayStringProperty); - } else { - textProperty().unbind(); - } - }); + super.updateItem(item, empty); + if (!empty && item != null) { + textProperty().bind(item.displayStringProperty); + } else { + textProperty().unbind(); + } } }; } diff --git a/desktop/src/main/java/haveno/desktop/main/presentation/MarketPricePresentation.java b/desktop/src/main/java/haveno/desktop/main/presentation/MarketPricePresentation.java index f33e4b81..7325428f 100644 --- a/desktop/src/main/java/haveno/desktop/main/presentation/MarketPricePresentation.java +++ b/desktop/src/main/java/haveno/desktop/main/presentation/MarketPricePresentation.java @@ -131,31 +131,33 @@ public class MarketPricePresentation { }); marketPriceBinding.subscribe((observable, oldValue, newValue) -> { - if (newValue != null && !newValue.equals(oldValue)) { - setMarketPriceInItems(); + UserThread.execute(() -> { + if (newValue != null && !newValue.equals(oldValue)) { + setMarketPriceInItems(); - String code = priceFeedService.currencyCodeProperty().get(); - Optional itemOptional = findPriceFeedComboBoxItem(code); - if (itemOptional.isPresent()) { - itemOptional.get().setDisplayString(newValue); - selectedPriceFeedComboBoxItemProperty.set(itemOptional.get()); - } else { - if (CurrencyUtil.isCryptoCurrency(code)) { - CurrencyUtil.getCryptoCurrency(code).ifPresent(cryptoCurrency -> { - preferences.addCryptoCurrency(cryptoCurrency); - fillPriceFeedComboBoxItems(); - }); + String code = priceFeedService.currencyCodeProperty().get(); + Optional itemOptional = findPriceFeedComboBoxItem(code); + if (itemOptional.isPresent()) { + itemOptional.get().setDisplayString(newValue); + selectedPriceFeedComboBoxItemProperty.set(itemOptional.get()); } else { - CurrencyUtil.getTraditionalCurrency(code).ifPresent(traditionalCurrency -> { - preferences.addTraditionalCurrency(traditionalCurrency); - fillPriceFeedComboBoxItems(); - }); + if (CurrencyUtil.isCryptoCurrency(code)) { + CurrencyUtil.getCryptoCurrency(code).ifPresent(cryptoCurrency -> { + preferences.addCryptoCurrency(cryptoCurrency); + fillPriceFeedComboBoxItems(); + }); + } else { + CurrencyUtil.getTraditionalCurrency(code).ifPresent(traditionalCurrency -> { + preferences.addTraditionalCurrency(traditionalCurrency); + fillPriceFeedComboBoxItems(); + }); + } } - } - if (selectedPriceFeedComboBoxItemProperty.get() != null) - selectedPriceFeedComboBoxItemProperty.get().setDisplayString(newValue); - } + if (selectedPriceFeedComboBoxItemProperty.get() != null) + selectedPriceFeedComboBoxItemProperty.get().setDisplayString(newValue); + } + }); }); marketPriceCurrencyCode.bind(priceFeedService.currencyCodeProperty()); diff --git a/desktop/src/main/java/haveno/desktop/main/shared/PriceFeedComboBoxItem.java b/desktop/src/main/java/haveno/desktop/main/shared/PriceFeedComboBoxItem.java index 64f5cb49..7014dc7b 100644 --- a/desktop/src/main/java/haveno/desktop/main/shared/PriceFeedComboBoxItem.java +++ b/desktop/src/main/java/haveno/desktop/main/shared/PriceFeedComboBoxItem.java @@ -17,7 +17,6 @@ package haveno.desktop.main.shared; -import haveno.common.UserThread; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import lombok.Getter; @@ -38,6 +37,6 @@ public class PriceFeedComboBoxItem { } public void setDisplayString(String displayString) { - UserThread.execute(() -> this.displayStringProperty.set(displayString)); + this.displayStringProperty.set(displayString); } }