From c6b1d032830ca11a48eee8fdbc83f9546dc5efd9 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 29 Dec 2023 05:58:43 -0500 Subject: [PATCH] set price feed state in UserThread --- .../core/provider/price/PriceFeedService.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/haveno/core/provider/price/PriceFeedService.java b/core/src/main/java/haveno/core/provider/price/PriceFeedService.java index 0765c8ce..4d2c4e08 100644 --- a/core/src/main/java/haveno/core/provider/price/PriceFeedService.java +++ b/core/src/main/java/haveno/core/provider/price/PriceFeedService.java @@ -284,13 +284,15 @@ public class PriceFeedService { } private void setHavenoMarketPrice(String currencyCode, Price price) { - if (!cache.containsKey(currencyCode) || !cache.get(currencyCode).isExternallyProvidedPrice()) { - cache.put(currencyCode, new MarketPrice(currencyCode, - MathUtils.scaleDownByPowerOf10(price.getValue(), CurrencyUtil.isCryptoCurrency(currencyCode) ? CryptoMoney.SMALLEST_UNIT_EXPONENT : TraditionalMoney.SMALLEST_UNIT_EXPONENT), - 0, - false)); - updateCounter.set(updateCounter.get() + 1); - } + UserThread.await(() -> { + if (!cache.containsKey(currencyCode) || !cache.get(currencyCode).isExternallyProvidedPrice()) { + cache.put(currencyCode, new MarketPrice(currencyCode, + MathUtils.scaleDownByPowerOf10(price.getValue(), CurrencyUtil.isCryptoCurrency(currencyCode) ? CryptoMoney.SMALLEST_UNIT_EXPONENT : TraditionalMoney.SMALLEST_UNIT_EXPONENT), + 0, + false)); + updateCounter.set(updateCounter.get() + 1); + } + }); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -298,12 +300,13 @@ public class PriceFeedService { /////////////////////////////////////////////////////////////////////////////////////////// public void setCurrencyCode(String currencyCode) { - if (this.currencyCode == null || !this.currencyCode.equals(currencyCode)) { - this.currencyCode = currencyCode; - currencyCodeProperty.set(currencyCode); - if (priceConsumer != null) - applyPriceToConsumer(); - } + UserThread.await(() -> { + if (this.currencyCode == null || !this.currencyCode.equals(currencyCode)) { + this.currencyCode = currencyCode; + currencyCodeProperty.set(currencyCode); + if (priceConsumer != null) applyPriceToConsumer(); + } + }); } @@ -428,7 +431,7 @@ public class PriceFeedService { faultHandler.handleFault(errorMessage, new PriceRequestException(errorMessage)); } - updateCounter.set(updateCounter.get() + 1); + UserThread.await(() -> updateCounter.set(updateCounter.get() + 1)); return result; }