From 89edd67ddc20532ea27afe54cd98ec319b9ff200 Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Fri, 1 Nov 2019 00:51:05 -0700 Subject: [PATCH] Fix BTC valuation popups When hovering over the BTC balances, the popup was using the market price based on the locale combined with the preferred currency as its units. This lead to the situation where it could show a mismatch between value and units. Instead, use the market price based on the preferred currency. Fixes #3515 --- .../src/main/java/bisq/desktop/main/MainView.java | 15 +++++++++------ .../java/bisq/desktop/main/MainViewModel.java | 4 ++++ .../presentation/MarketPricePresentation.java | 10 ++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/MainView.java b/desktop/src/main/java/bisq/desktop/main/MainView.java index ff09adc716a..9dfcd6325e6 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainView.java +++ b/desktop/src/main/java/bisq/desktop/main/MainView.java @@ -254,11 +254,12 @@ protected void initialize() { protected Tooltip computeValue() { String tooltipText = Res.get("mainView.balance.available"); try { + String preferredTradeCurrency = model.getPreferences().getPreferredTradeCurrency().getCode(); double availableBalance = Double.parseDouble( model.getAvailableBalance().getValue().replace("BTC", "")); - double marketPrice = Double.parseDouble(model.getMarketPrice().getValue()); + double marketPrice = Double.parseDouble(model.getMarketPrice(preferredTradeCurrency).getValue()); tooltipText += "\n" + currencyFormat.format(availableBalance * marketPrice) + - " " + model.getPreferences().getPreferredTradeCurrency().getCode(); + " " + preferredTradeCurrency; } catch (NullPointerException | NumberFormatException e) { // Either the balance or market price is not available yet } @@ -278,11 +279,12 @@ protected Tooltip computeValue() { protected Tooltip computeValue() { String tooltipText = Res.get("mainView.balance.reserved"); try { + String preferredTradeCurrency = model.getPreferences().getPreferredTradeCurrency().getCode(); double reservedBalance = Double.parseDouble( model.getReservedBalance().getValue().replace("BTC", "")); - double marketPrice = Double.parseDouble(model.getMarketPrice().getValue()); + double marketPrice = Double.parseDouble(model.getMarketPrice(preferredTradeCurrency).getValue()); tooltipText += "\n" + currencyFormat.format(reservedBalance * marketPrice) + - " " + model.getPreferences().getPreferredTradeCurrency().getCode(); + " " + preferredTradeCurrency; } catch (NullPointerException | NumberFormatException e) { // Either the balance or market price is not available yet } @@ -302,11 +304,12 @@ protected Tooltip computeValue() { protected Tooltip computeValue() { String tooltipText = Res.get("mainView.balance.locked"); try { + String preferredTradeCurrency = model.getPreferences().getPreferredTradeCurrency().getCode(); double lockedBalance = Double.parseDouble( model.getLockedBalance().getValue().replace("BTC", "")); - double marketPrice = Double.parseDouble(model.getMarketPrice().getValue()); + double marketPrice = Double.parseDouble(model.getMarketPrice(preferredTradeCurrency).getValue()); tooltipText += "\n" + currencyFormat.format(lockedBalance * marketPrice) + - " " + model.getPreferences().getPreferredTradeCurrency().getCode(); + " " + preferredTradeCurrency; } catch (NullPointerException | NumberFormatException e) { // Either the balance or market price is not available yet } diff --git a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index 70726c52ac7..786d955134c 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -613,6 +613,10 @@ StringProperty getMarketPrice() { return marketPricePresentation.getMarketPrice(); } + StringProperty getMarketPrice(String currencyCode) { + return marketPricePresentation.getMarketPrice(currencyCode); + } + public ObservableList getPriceFeedComboBoxItems() { return marketPricePresentation.getPriceFeedComboBoxItems(); } diff --git a/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java b/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java index 3c1c864ed60..d6e4f6f5627 100644 --- a/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java @@ -242,4 +242,14 @@ public IntegerProperty getMarketPriceUpdated() { public StringProperty getMarketPrice() { return marketPrice; } + + public StringProperty getMarketPrice(String currencyCode) { + SimpleStringProperty marketPrice = new SimpleStringProperty(Res.get("shared.na")); + try { + marketPrice.set(String.valueOf(priceFeedService.getMarketPrice(currencyCode).getPrice())); + } catch (NullPointerException e) { + // Market price is not available yet + } + return marketPrice; + } }