From 2d3269a07a120f5ea0b49ba54c0d5048a71c25b3 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 30 Oct 2018 20:46:26 -0500 Subject: [PATCH] Add getBsqPrice method to PriceFeedService --- .../src/main/java/bisq/core/offer/OfferUtil.java | 8 +++----- .../core/provider/price/PriceFeedService.java | 11 +++++++++++ .../dao/wallet/dashboard/BsqDashboardView.java | 16 ++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index 3c7d340822..ad91bbc7dd 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -22,7 +22,6 @@ import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.Restrictions; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; -import bisq.core.monetary.Altcoin; import bisq.core.monetary.Price; import bisq.core.monetary.Volume; import bisq.core.provider.fee.FeeService; @@ -308,10 +307,9 @@ public class OfferUtil { if (isCurrencyForMakerFeeBtc) { return Optional.of(userCurrencyPrice.getVolumeByAmount(makerFee)); } else { - MarketPrice bsqMarketPrice = priceFeedService.getMarketPrice("BSQ"); - if (bsqMarketPrice != null) { - long bsqPriceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(bsqMarketPrice.getPrice(), Altcoin.SMALLEST_UNIT_EXPONENT)); - Price bsqPrice = Price.valueOf("BSQ", bsqPriceAsLong); + Optional optionalBsqPrice = priceFeedService.getBsqPrice(); + if (optionalBsqPrice.isPresent()) { + Price bsqPrice = optionalBsqPrice.get(); String inputValue = bsqFormatter.formatCoin(makerFee); Volume makerFeeAsVolume = Volume.parse(inputValue, "BSQ"); Coin requiredBtc = bsqPrice.getAmountByVolume(makerFeeAsVolume); diff --git a/core/src/main/java/bisq/core/provider/price/PriceFeedService.java b/core/src/main/java/bisq/core/provider/price/PriceFeedService.java index 76e646792f..852cd3a219 100644 --- a/core/src/main/java/bisq/core/provider/price/PriceFeedService.java +++ b/core/src/main/java/bisq/core/provider/price/PriceFeedService.java @@ -19,6 +19,7 @@ package bisq.core.provider.price; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; +import bisq.core.monetary.Altcoin; import bisq.core.monetary.Price; import bisq.core.provider.PriceNodeHttpClient; import bisq.core.provider.ProvidersRepository; @@ -53,6 +54,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.Set; import java.util.function.Consumer; @@ -323,6 +325,15 @@ public class PriceFeedService { }); } + public Optional getBsqPrice() { + MarketPrice bsqMarketPrice = getMarketPrice("BSQ"); + if (bsqMarketPrice != null) { + long bsqPriceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(bsqMarketPrice.getPrice(), Altcoin.SMALLEST_UNIT_EXPONENT)); + return Optional.of(Price.valueOf("BSQ", bsqPriceAsLong)); + } else { + return Optional.empty(); + } + } /////////////////////////////////////////////////////////////////////////////////////////// // Private diff --git a/desktop/src/main/java/bisq/desktop/main/dao/wallet/dashboard/BsqDashboardView.java b/desktop/src/main/java/bisq/desktop/main/dao/wallet/dashboard/BsqDashboardView.java index 31f04c6c56..19717b280c 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/wallet/dashboard/BsqDashboardView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/wallet/dashboard/BsqDashboardView.java @@ -29,14 +29,11 @@ import bisq.core.dao.state.DaoStateListener; import bisq.core.dao.state.blockchain.Block; import bisq.core.dao.state.governance.IssuanceType; import bisq.core.locale.Res; -import bisq.core.monetary.Altcoin; import bisq.core.monetary.Price; -import bisq.core.provider.price.MarketPrice; import bisq.core.provider.price.PriceFeedService; import bisq.core.user.Preferences; import bisq.core.util.BsqFormatter; -import bisq.common.util.MathUtils; import bisq.common.util.Tuple3; import org.bitcoinj.core.Coin; @@ -51,6 +48,8 @@ import javafx.scene.layout.VBox; import javafx.beans.value.ChangeListener; +import java.util.Optional; + import static bisq.desktop.util.FormBuilder.addTitledGroupBg; import static bisq.desktop.util.FormBuilder.addTopLabelReadOnlyTextField; @@ -219,12 +218,13 @@ public class BsqDashboardView extends ActivatableView implements private void updatePrice() { Coin issuedAmount = daoFacade.getGenesisTotalSupply(); - MarketPrice bsqMarketPrice = priceFeedService.getMarketPrice("BSQ"); - if (bsqMarketPrice != null) { - long bsqPrice = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(bsqMarketPrice.getPrice(), Altcoin.SMALLEST_UNIT_EXPONENT)); - priceTextField.setText(bsqFormatter.formatPrice(Price.valueOf("BSQ", bsqPrice)) + " BSQ/BTC"); + Optional optionalBsqPrice = priceFeedService.getBsqPrice(); + if (optionalBsqPrice.isPresent()) { + Price bsqPrice = optionalBsqPrice.get(); + priceTextField.setText(bsqFormatter.formatPrice(bsqPrice) + " BSQ/BTC"); - marketCapTextField.setText(bsqFormatter.formatMarketCap(bsqMarketPrice, priceFeedService.getMarketPrice("USD"), issuedAmount)); + marketCapTextField.setText(bsqFormatter.formatMarketCap(priceFeedService.getMarketPrice("BSQ"), + priceFeedService.getMarketPrice("USD"), issuedAmount)); } else { priceTextField.setText(Res.get("shared.na")); marketCapTextField.setText(Res.get("shared.na"));