From 9af723f910a35d6099ae91f4212787ad3f77f95a Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 6 Sep 2019 03:00:08 +0200 Subject: [PATCH 1/3] Remove not used fields --- .../main/dao/economy/dashboard/BsqDashboardView.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java index 0de2e7e6252..8263372bc13 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java @@ -23,7 +23,6 @@ import bisq.core.dao.DaoFacade; import bisq.core.dao.state.DaoStateListener; -import bisq.core.dao.state.DaoStateService; import bisq.core.dao.state.model.blockchain.Block; import bisq.core.dao.state.model.governance.IssuanceType; import bisq.core.locale.Res; @@ -32,7 +31,6 @@ import bisq.core.trade.statistics.TradeStatistics2; import bisq.core.trade.statistics.TradeStatisticsManager; import bisq.core.user.Preferences; -import bisq.core.util.BSFormatter; import bisq.core.util.BsqFormatter; import bisq.common.util.Tuple3; @@ -90,15 +88,12 @@ public class BsqDashboardView extends ActivatableView implements private final DaoFacade daoFacade; private final TradeStatisticsManager tradeStatisticsManager; private final PriceFeedService priceFeedService; - private final DaoStateService daoStateService; private final Preferences preferences; private final BsqFormatter bsqFormatter; - private final BSFormatter btcFormatter; private ChangeListener priceChangeListener; private AreaChart bsqPriceChart; - private XYChart.Series seriesBSQAdded, seriesBSQBurnt; private XYChart.Series seriesBSQPrice; private TextField marketCapTextField, availableAmountTextField; @@ -116,17 +111,13 @@ public class BsqDashboardView extends ActivatableView implements private BsqDashboardView(DaoFacade daoFacade, TradeStatisticsManager tradeStatisticsManager, PriceFeedService priceFeedService, - DaoStateService daoStateService, Preferences preferences, - BsqFormatter bsqFormatter, - BSFormatter btcFormatter) { + BsqFormatter bsqFormatter) { this.daoFacade = daoFacade; this.tradeStatisticsManager = tradeStatisticsManager; this.priceFeedService = priceFeedService; - this.daoStateService = daoStateService; this.preferences = preferences; this.bsqFormatter = bsqFormatter; - this.btcFormatter = btcFormatter; } @Override From 5d4f9afa715df1d784e5bfacd07b5c3aa0b88799 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 6 Sep 2019 04:43:30 +0200 Subject: [PATCH 2/3] Add 90 days average and median BSQ price --- .../main/java/bisq/common/util/MathUtils.java | 11 +++ .../main/java/bisq/core/offer/OfferUtil.java | 27 +++++- .../resources/i18n/displayStrings.properties | 2 + .../economy/dashboard/BsqDashboardView.java | 95 +++++++++++++++---- .../market/trades/TradesChartsViewModel.java | 13 +-- .../main/java/bisq/desktop/util/GUIUtil.java | 66 +++++++++++-- 6 files changed, 171 insertions(+), 43 deletions(-) diff --git a/common/src/main/java/bisq/common/util/MathUtils.java b/common/src/main/java/bisq/common/util/MathUtils.java index 56685137629..78b787843a5 100644 --- a/common/src/main/java/bisq/common/util/MathUtils.java +++ b/common/src/main/java/bisq/common/util/MathUtils.java @@ -92,4 +92,15 @@ public static double scaleDownByPowerOf10(long value, int exponent) { public static double exactMultiply(double value1, double value2) { return BigDecimal.valueOf(value1).multiply(BigDecimal.valueOf(value2)).doubleValue(); } + + public static Long getMedian(Long[] list) { + int middle = list.length / 2; + long median; + if (list.length % 2 == 1) { + median = list[middle]; + } else { + median = MathUtils.roundDoubleToLong((list[middle - 1] + list[middle]) / 2.0); + } + return median; + } } diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index 7d26b6cad39..24c4222c8d3 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -116,7 +116,9 @@ public static Coin getMakerFee(boolean isCurrencyForMakerFeeBtc, @Nullable Coin * @param amount * @return */ - public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount) { + public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, + BsqWalletService bsqWalletService, + Coin amount) { boolean payFeeInBtc = preferences.getPayFeeInBtc(); boolean bsqForFeeAvailable = isBsqForMakerFeeAvailable(bsqWalletService, amount); return payFeeInBtc || !bsqForFeeAvailable; @@ -152,7 +154,9 @@ public static Coin getTakerFee(boolean isCurrencyForTakerFeeBtc, @Nullable Coin } } - public static boolean isCurrencyForTakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount) { + public static boolean isCurrencyForTakerFeeBtc(Preferences preferences, + BsqWalletService bsqWalletService, + Coin amount) { boolean payFeeInBtc = preferences.getPayFeeInBtc(); boolean bsqForFeeAvailable = isBsqForTakerFeeAvailable(bsqWalletService, amount); return payFeeInBtc || !bsqForFeeAvailable; @@ -278,10 +282,21 @@ static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, int public static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean isCurrencyForMakerFeeBtc, Preferences preferences, PriceFeedService priceFeedService, BsqFormatter bsqFormatter) { - // We use the users currency derived from his selected country. - // We don't use the preferredTradeCurrency from preferences as that can be also set to an altcoin. String countryCode = preferences.getUserCountry().code; String userCurrencyCode = CurrencyUtil.getCurrencyByCountryCode(countryCode).getCode(); + return getFeeInUserFiatCurrency(makerFee, + isCurrencyForMakerFeeBtc, + userCurrencyCode, + priceFeedService, + bsqFormatter); + } + + public static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean isCurrencyForMakerFeeBtc, + String userCurrencyCode, PriceFeedService priceFeedService, + BsqFormatter bsqFormatter) { + // We use the users currency derived from his selected country. + // We don't use the preferredTradeCurrency from preferences as that can be also set to an altcoin. + MarketPrice marketPrice = priceFeedService.getMarketPrice(userCurrencyCode); if (marketPrice != null && makerFee != null) { long marketPriceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(marketPrice.getPrice(), Fiat.SMALLEST_UNIT_EXPONENT)); @@ -306,7 +321,9 @@ public static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean i } } - public static String getFeeWithFiatAmount(Coin makerFeeAsCoin, Optional optionalFeeInFiat, BSFormatter formatter) { + public static String getFeeWithFiatAmount(Coin makerFeeAsCoin, + Optional optionalFeeInFiat, + BSFormatter formatter) { String fee = makerFeeAsCoin != null ? formatter.formatCoinWithCode(makerFeeAsCoin) : Res.get("shared.na"); String feeInFiatAsString; if (optionalFeeInFiat != null && optionalFeeInFiat.isPresent()) { diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index c534f009849..1d134691339 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -2055,6 +2055,8 @@ dao.factsAndFigures.menuItem.transactions=BSQ Transactions dao.factsAndFigures.dashboard.marketPrice=Market data dao.factsAndFigures.dashboard.price=Latest BSQ/BTC trade price (in Bisq) +dao.factsAndFigures.dashboard.avgPrice90=90 days average BSQ/BTC trade price +dao.factsAndFigures.dashboard.medianPrice90=90 days median BSQ/BTC trade price dao.factsAndFigures.dashboard.marketCap=Market capitalisation (based on trade price) dao.factsAndFigures.dashboard.availableAmount=Total available BSQ diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java index 8263372bc13..147ad3edd5a 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java @@ -20,12 +20,14 @@ import bisq.desktop.common.view.ActivatableView; import bisq.desktop.common.view.FxmlView; import bisq.desktop.util.FormBuilder; +import bisq.desktop.util.GUIUtil; import bisq.core.dao.DaoFacade; import bisq.core.dao.state.DaoStateListener; import bisq.core.dao.state.model.blockchain.Block; import bisq.core.dao.state.model.governance.IssuanceType; import bisq.core.locale.Res; +import bisq.core.monetary.Altcoin; import bisq.core.monetary.Price; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.statistics.TradeStatistics2; @@ -33,6 +35,8 @@ import bisq.core.user.Preferences; import bisq.core.util.BsqFormatter; +import bisq.common.util.MathUtils; +import bisq.common.util.Tuple2; import bisq.common.util.Tuple3; import org.bitcoinj.core.Coin; @@ -65,7 +69,12 @@ import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAdjusters; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; import java.util.Comparator; +import java.util.Date; +import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -76,9 +85,6 @@ import static bisq.desktop.util.FormBuilder.addTopLabelReadOnlyTextField; - -import java.sql.Date; - @FxmlView public class BsqDashboardView extends ActivatableView implements DaoStateListener { @@ -96,13 +102,13 @@ public class BsqDashboardView extends ActivatableView implements private AreaChart bsqPriceChart; private XYChart.Series seriesBSQPrice; - private TextField marketCapTextField, availableAmountTextField; + private TextField avgPrice90TextField, medianPrice90TextField, marketCapTextField, availableAmountTextField; private Label marketPriceLabel; private Coin availableAmount; - private int gridRow = 0; + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle /////////////////////////////////////////////////////////////////////////////////////////// @@ -122,32 +128,37 @@ private BsqDashboardView(DaoFacade daoFacade, @Override public void initialize() { - ADJUSTERS.put(DAY, TemporalAdjusters.ofDateAdjuster(d -> d)); createKPIs(); createChart(); - priceChangeListener = (observable, oldValue, newValue) -> updatePrice(); + priceChangeListener = (observable, oldValue, newValue) -> { + updatePrice(); + updateAverageAndMedianPrice(); + }; } private void createKPIs() { - Tuple3 marketPriceBox = addLabelWithSubText(root, gridRow++, "0.004000 BSQ/BTC", "Latest BSQ/BTC trade price (in Bisq)"); marketPriceLabel = marketPriceBox.first; marketPriceLabel.getStyleClass().add("dao-kpi-big"); marketPriceBox.second.getStyleClass().add("dao-kpi-subtext"); + avgPrice90TextField = addTopLabelReadOnlyTextField(root, ++gridRow, + Res.get("dao.factsAndFigures.dashboard.avgPrice90")).second; + + medianPrice90TextField = addTopLabelReadOnlyTextField(root, gridRow, 1, + Res.get("dao.factsAndFigures.dashboard.medianPrice90")).second; + marketCapTextField = addTopLabelReadOnlyTextField(root, ++gridRow, Res.get("dao.factsAndFigures.dashboard.marketCap")).second; availableAmountTextField = FormBuilder.addTopLabelReadOnlyTextField(root, gridRow, 1, Res.get("dao.factsAndFigures.dashboard.availableAmount")).second; - } - @Override protected void activate() { daoFacade.addBsqStateListener(this); @@ -156,15 +167,16 @@ protected void activate() { updateWithBsqBlockChainData(); updatePrice(); updateChartData(); + updateAverageAndMedianPrice(); } - @Override protected void deactivate() { daoFacade.removeBsqStateListener(this); priceFeedService.updateCounterProperty().removeListener(priceChangeListener); } + /////////////////////////////////////////////////////////////////////////////////////////// // DaoStateListener /////////////////////////////////////////////////////////////////////////////////////////// @@ -227,8 +239,8 @@ public Number fromString(String string) { bsqPriceChart.setLegendVisible(false); bsqPriceChart.setAnimated(false); bsqPriceChart.setId("charts-dao"); - bsqPriceChart.setMinHeight(385); - bsqPriceChart.setPrefHeight(385); + bsqPriceChart.setMinHeight(335); + bsqPriceChart.setPrefHeight(bsqPriceChart.getMinHeight()); bsqPriceChart.setCreateSymbols(true); bsqPriceChart.setPadding(new Insets(0)); bsqPriceChart.getData().addAll(seriesBSQPrice); @@ -251,16 +263,16 @@ public Number fromString(String string) { } private void updateChartData() { - updateBSQPriceData(); + updateBsqPriceData(); } - private void updateBSQPriceData() { + private void updateBsqPriceData() { seriesBSQPrice.getData().clear(); Map> bsqPriceByDate = tradeStatisticsManager.getObservableTradeStatisticsSet().stream() .filter(e -> e.getCurrencyCode().equals("BSQ")) .sorted(Comparator.comparing(TradeStatistics2::getTradeDate)) - .collect(Collectors.groupingBy(item -> new Date(item.getTradeDate().getTime()).toLocalDate() + .collect(Collectors.groupingBy(item -> new java.sql.Date(item.getTradeDate().getTime()).toLocalDate() .with(ADJUSTERS.get(DAY)))); List> updatedBSQPrice = bsqPriceByDate.keySet().stream() @@ -312,5 +324,56 @@ private void updatePrice() { marketCapTextField.setText(Res.get("shared.na")); } } + + private void updateAverageAndMedianPrice() { + Date past90 = getPastDate(90); + List bsqTradePast90Days = tradeStatisticsManager.getObservableTradeStatisticsSet().stream() + .filter(e -> e.getCurrencyCode().equals("BSQ")) + .filter(e -> e.getTradeDate().after(past90)) + .collect(Collectors.toList()); + Tuple2 averageAndMedian = getAverageAndMedian(bsqTradePast90Days); + Coin oneBsq = Coin.valueOf(100); + + Price avgPrice = Price.valueOf("BSQ", averageAndMedian.first); + String avg = bsqFormatter.formatPrice(avgPrice); + String bsqInUsdAvg = GUIUtil.getBsqInUsd(avgPrice, oneBsq, priceFeedService, bsqFormatter); + avgPrice90TextField.setText(avg + " BSQ/BTC (" + "1 BSQ = " + bsqInUsdAvg + ")"); + + Price medianPrice = Price.valueOf("BSQ", averageAndMedian.second); + String median = bsqFormatter.formatPrice(medianPrice); + String bsqInUsdMedian = GUIUtil.getBsqInUsd(medianPrice, oneBsq, priceFeedService, bsqFormatter); + medianPrice90TextField.setText(median + " BSQ/BTC (" + "1 BSQ = " + bsqInUsdMedian + ")"); + } + + private Tuple2 getAverageAndMedian(List list) { + long accumulatedVolume = 0; + long accumulatedAmount = 0; + List tradePrices = new ArrayList<>(list.size()); + + for (TradeStatistics2 item : list) { + item.getTradeVolume(); + accumulatedVolume += item.getTradeVolume().getValue(); + accumulatedAmount += item.getTradeAmount().getValue(); + tradePrices.add(item.getTradePrice().getValue()); + } + Collections.sort(tradePrices); + list.sort(Comparator.comparingLong(o -> o.getTradeDate().getTime())); + + long averagePrice; + Long[] prices = new Long[tradePrices.size()]; + tradePrices.toArray(prices); + long medianPrice = MathUtils.getMedian(prices); + double accumulatedAmountAsDouble = MathUtils.scaleUpByPowerOf10((double) accumulatedAmount, Altcoin.SMALLEST_UNIT_EXPONENT); + averagePrice = MathUtils.roundDoubleToLong(accumulatedAmountAsDouble / (double) accumulatedVolume); + + return new Tuple2<>(averagePrice, medianPrice); + } + + private Date getPastDate(int days) { + Calendar cal = new GregorianCalendar(); + cal.setTime(new Date()); + cal.add(Calendar.DAY_OF_MONTH, -1 * days); + return cal.getTime(); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java index c9da02597ec..3dfe37b9683 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsViewModel.java @@ -330,7 +330,7 @@ CandleData getCandleData(long tick, Set set) { long averagePrice; Long[] prices = new Long[tradePrices.size()]; tradePrices.toArray(prices); - long medianPrice = findMedian(prices); + long medianPrice = MathUtils.getMedian(prices); boolean isBullish; if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) { isBullish = close < open; @@ -350,17 +350,6 @@ CandleData getCandleData(long tick, Set set) { return new CandleData(tick, open, close, high, low, averagePrice, medianPrice, accumulatedAmount, accumulatedVolume, numTrades, isBullish, dateString); } - - Long findMedian(Long[] prices) { - int middle = prices.length / 2; - long median; - if (prices.length % 2 == 1) { - median = prices[middle]; - } else { - median = MathUtils.roundDoubleToLong((prices[middle - 1] + prices[middle]) / 2.0); - } - return median; - } Date roundToTick(Date time, TickUnit tickUnit) { ZonedDateTime zdt = time.toInstant().atZone(ZoneId.systemDefault()); diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index aa772f2c531..09d950369e4 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -31,10 +31,14 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; +import bisq.core.monetary.Price; +import bisq.core.monetary.Volume; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PaymentAccountList; import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.fee.FeeService; +import bisq.core.provider.price.MarketPrice; +import bisq.core.provider.price.PriceFeedService; import bisq.core.user.DontShowAgainLookup; import bisq.core.user.Preferences; import bisq.core.user.User; @@ -51,6 +55,7 @@ import bisq.common.storage.CorruptedDatabaseFilesHandler; import bisq.common.storage.FileUtil; import bisq.common.storage.Storage; +import bisq.common.util.MathUtils; import bisq.common.util.Tuple2; import bisq.common.util.Tuple3; import bisq.common.util.Utilities; @@ -59,6 +64,7 @@ import org.bitcoinj.core.Coin; import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.uri.BitcoinURI; +import org.bitcoinj.utils.Fiat; import org.bitcoinj.wallet.DeterministicSeed; import com.googlecode.jcsv.CSVStrategy; @@ -189,8 +195,12 @@ public static void showFeeInfoBeforeExecute(Runnable runnable) { } } - public static void exportAccounts(ArrayList accounts, String fileName, - Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { + public static void exportAccounts(ArrayList accounts, + String fileName, + Preferences preferences, + Stage stage, + PersistenceProtoResolver persistenceProtoResolver, + CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { if (!accounts.isEmpty()) { String directory = getDirectoryFromChooser(preferences, stage); if (directory != null && !directory.isEmpty()) { @@ -204,8 +214,12 @@ public static void exportAccounts(ArrayList accounts, String fil } } - public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage, - PersistenceProtoResolver persistenceProtoResolver, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { + public static void importAccounts(User user, + String fileName, + Preferences preferences, + Stage stage, + PersistenceProtoResolver persistenceProtoResolver, + CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { FileChooser fileChooser = new FileChooser(); File initDir = new File(preferences.getDirectoryChooserPath()); if (initDir.isDirectory()) { @@ -351,7 +365,8 @@ protected void updateItem(CurrencyListItem item, boolean empty) { }; } - public static Callback, ListCell> getCurrencyListItemCellFactory(String postFixSingle, String postFixMulti, + public static Callback, ListCell> getCurrencyListItemCellFactory(String postFixSingle, + String postFixMulti, Preferences preferences) { return p -> new ListCell<>() { @Override @@ -583,7 +598,9 @@ protected void updateItem(PaymentMethod method, boolean empty) { }; } - public static void updateConfidence(TransactionConfidence confidence, Tooltip tooltip, TxConfidenceIndicator txConfidenceIndicator) { + public static void updateConfidence(TransactionConfidence confidence, + Tooltip tooltip, + TxConfidenceIndicator txConfidenceIndicator) { if (confidence != null) { switch (confidence.getConfidenceType()) { case UNKNOWN: @@ -855,8 +872,13 @@ public static void removeChildrenFromGridPaneRows(GridPane gridPane, int start, } } - public static void showBsqFeeInfoPopup(Coin fee, Coin miningFee, Coin btcForIssuance, int txSize, BsqFormatter bsqFormatter, - BSFormatter btcFormatter, String type, + public static void showBsqFeeInfoPopup(Coin fee, + Coin miningFee, + Coin btcForIssuance, + int txSize, + BsqFormatter bsqFormatter, + BSFormatter btcFormatter, + String type, Runnable actionHandler) { String confirmationMessage; @@ -893,7 +915,11 @@ public static void showBsqFeeInfoPopup(Coin fee, Coin miningFee, int txSize, Bsq showBsqFeeInfoPopup(fee, miningFee, null, txSize, bsqFormatter, btcFormatter, type, actionHandler); } - public static void setFitToRowsForTableView(TableView tableView, int rowHeight, int headerHeight, int minNumRows, int maxNumRows) { + public static void setFitToRowsForTableView(TableView tableView, + int rowHeight, + int headerHeight, + int minNumRows, + int maxNumRows) { int size = tableView.getItems().size(); int minHeight = rowHeight * minNumRows + headerHeight; int maxHeight = rowHeight * maxNumRows + headerHeight; @@ -999,7 +1025,9 @@ public static ListCell getComboBoxButtonCell(String title, ComboBox co } @NotNull - public static ListCell getComboBoxButtonCell(String title, ComboBox comboBox, Boolean hideOriginalPrompt) { + public static ListCell getComboBoxButtonCell(String title, + ComboBox comboBox, + Boolean hideOriginalPrompt) { return new ListCell<>() { @Override protected void updateItem(T item, boolean empty) { @@ -1022,4 +1050,22 @@ public static void openTxInBsqBlockExplorer(String txId, Preferences preferences if (txId != null) GUIUtil.openWebPage(preferences.getBsqBlockChainExplorer().txUrl + txId, false); } + + public static String getBsqInUsd(Price bsqPrice, + Coin bsqAmount, + PriceFeedService priceFeedService, + BsqFormatter bsqFormatter) { + MarketPrice usdMarketPrice = priceFeedService.getMarketPrice("USD"); + if (usdMarketPrice == null) { + return Res.get("shared.na"); + } + long usdMarketPriceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(usdMarketPrice.getPrice(), + Fiat.SMALLEST_UNIT_EXPONENT)); + Price usdPrice = Price.valueOf("USD", usdMarketPriceAsLong); + String bsqAmountAsString = bsqFormatter.formatCoin(bsqAmount); + Volume bsqAmountAsVolume = Volume.parse(bsqAmountAsString, "BSQ"); + Coin requiredBtc = bsqPrice.getAmountByVolume(bsqAmountAsVolume); + Volume volumeByAmount = usdPrice.getVolumeByAmount(requiredBtc); + return bsqFormatter.formatVolumeWithCode(volumeByAmount); + } } From 69d70f386e38003975262bb06cdc330a81606a6b Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Fri, 6 Sep 2019 16:21:22 +0200 Subject: [PATCH 3/3] Revert non-changes --- .../main/java/bisq/core/offer/OfferUtil.java | 12 ++---- .../economy/dashboard/BsqDashboardView.java | 8 +++- .../main/java/bisq/desktop/util/GUIUtil.java | 42 +++++-------------- 3 files changed, 19 insertions(+), 43 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index 24c4222c8d3..1e5f9b491f0 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -116,9 +116,7 @@ public static Coin getMakerFee(boolean isCurrencyForMakerFeeBtc, @Nullable Coin * @param amount * @return */ - public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, - BsqWalletService bsqWalletService, - Coin amount) { + public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount) { boolean payFeeInBtc = preferences.getPayFeeInBtc(); boolean bsqForFeeAvailable = isBsqForMakerFeeAvailable(bsqWalletService, amount); return payFeeInBtc || !bsqForFeeAvailable; @@ -154,9 +152,7 @@ public static Coin getTakerFee(boolean isCurrencyForTakerFeeBtc, @Nullable Coin } } - public static boolean isCurrencyForTakerFeeBtc(Preferences preferences, - BsqWalletService bsqWalletService, - Coin amount) { + public static boolean isCurrencyForTakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount) { boolean payFeeInBtc = preferences.getPayFeeInBtc(); boolean bsqForFeeAvailable = isBsqForTakerFeeAvailable(bsqWalletService, amount); return payFeeInBtc || !bsqForFeeAvailable; @@ -321,9 +317,7 @@ public static Optional getFeeInUserFiatCurrency(Coin makerFee, boolean i } } - public static String getFeeWithFiatAmount(Coin makerFeeAsCoin, - Optional optionalFeeInFiat, - BSFormatter formatter) { + public static String getFeeWithFiatAmount(Coin makerFeeAsCoin, Optional optionalFeeInFiat, BSFormatter formatter) { String fee = makerFeeAsCoin != null ? formatter.formatCoinWithCode(makerFeeAsCoin) : Res.get("shared.na"); String feeInFiatAsString; if (optionalFeeInFiat != null && optionalFeeInFiat.isPresent()) { diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java index 147ad3edd5a..34b21b7cffd 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/dashboard/BsqDashboardView.java @@ -106,8 +106,8 @@ public class BsqDashboardView extends ActivatableView implements private Label marketPriceLabel; private Coin availableAmount; - private int gridRow = 0; + private int gridRow = 0; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -128,6 +128,7 @@ private BsqDashboardView(DaoFacade daoFacade, @Override public void initialize() { + ADJUSTERS.put(DAY, TemporalAdjusters.ofDateAdjuster(d -> d)); createKPIs(); @@ -140,6 +141,7 @@ public void initialize() { } private void createKPIs() { + Tuple3 marketPriceBox = addLabelWithSubText(root, gridRow++, "0.004000 BSQ/BTC", "Latest BSQ/BTC trade price (in Bisq)"); marketPriceLabel = marketPriceBox.first; marketPriceLabel.getStyleClass().add("dao-kpi-big"); @@ -157,8 +159,10 @@ private void createKPIs() { availableAmountTextField = FormBuilder.addTopLabelReadOnlyTextField(root, gridRow, 1, Res.get("dao.factsAndFigures.dashboard.availableAmount")).second; + } + @Override protected void activate() { daoFacade.addBsqStateListener(this); @@ -170,13 +174,13 @@ protected void activate() { updateAverageAndMedianPrice(); } + @Override protected void deactivate() { daoFacade.removeBsqStateListener(this); priceFeedService.updateCounterProperty().removeListener(priceChangeListener); } - /////////////////////////////////////////////////////////////////////////////////////////// // DaoStateListener /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index 09d950369e4..1afbc534333 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -195,12 +195,8 @@ public static void showFeeInfoBeforeExecute(Runnable runnable) { } } - public static void exportAccounts(ArrayList accounts, - String fileName, - Preferences preferences, - Stage stage, - PersistenceProtoResolver persistenceProtoResolver, - CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { + public static void exportAccounts(ArrayList accounts, String fileName, + Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { if (!accounts.isEmpty()) { String directory = getDirectoryFromChooser(preferences, stage); if (directory != null && !directory.isEmpty()) { @@ -214,12 +210,8 @@ public static void exportAccounts(ArrayList accounts, } } - public static void importAccounts(User user, - String fileName, - Preferences preferences, - Stage stage, - PersistenceProtoResolver persistenceProtoResolver, - CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { + public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage, + PersistenceProtoResolver persistenceProtoResolver, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { FileChooser fileChooser = new FileChooser(); File initDir = new File(preferences.getDirectoryChooserPath()); if (initDir.isDirectory()) { @@ -365,8 +357,7 @@ protected void updateItem(CurrencyListItem item, boolean empty) { }; } - public static Callback, ListCell> getCurrencyListItemCellFactory(String postFixSingle, - String postFixMulti, + public static Callback, ListCell> getCurrencyListItemCellFactory(String postFixSingle, String postFixMulti, Preferences preferences) { return p -> new ListCell<>() { @Override @@ -598,9 +589,7 @@ protected void updateItem(PaymentMethod method, boolean empty) { }; } - public static void updateConfidence(TransactionConfidence confidence, - Tooltip tooltip, - TxConfidenceIndicator txConfidenceIndicator) { + public static void updateConfidence(TransactionConfidence confidence, Tooltip tooltip, TxConfidenceIndicator txConfidenceIndicator) { if (confidence != null) { switch (confidence.getConfidenceType()) { case UNKNOWN: @@ -872,13 +861,8 @@ public static void removeChildrenFromGridPaneRows(GridPane gridPane, int start, } } - public static void showBsqFeeInfoPopup(Coin fee, - Coin miningFee, - Coin btcForIssuance, - int txSize, - BsqFormatter bsqFormatter, - BSFormatter btcFormatter, - String type, + public static void showBsqFeeInfoPopup(Coin fee, Coin miningFee, Coin btcForIssuance, int txSize, BsqFormatter bsqFormatter, + BSFormatter btcFormatter, String type, Runnable actionHandler) { String confirmationMessage; @@ -915,11 +899,7 @@ public static void showBsqFeeInfoPopup(Coin fee, Coin miningFee, int txSize, Bsq showBsqFeeInfoPopup(fee, miningFee, null, txSize, bsqFormatter, btcFormatter, type, actionHandler); } - public static void setFitToRowsForTableView(TableView tableView, - int rowHeight, - int headerHeight, - int minNumRows, - int maxNumRows) { + public static void setFitToRowsForTableView(TableView tableView, int rowHeight, int headerHeight, int minNumRows, int maxNumRows) { int size = tableView.getItems().size(); int minHeight = rowHeight * minNumRows + headerHeight; int maxHeight = rowHeight * maxNumRows + headerHeight; @@ -1025,9 +1005,7 @@ public static ListCell getComboBoxButtonCell(String title, ComboBox co } @NotNull - public static ListCell getComboBoxButtonCell(String title, - ComboBox comboBox, - Boolean hideOriginalPrompt) { + public static ListCell getComboBoxButtonCell(String title, ComboBox comboBox, Boolean hideOriginalPrompt) { return new ListCell<>() { @Override protected void updateItem(T item, boolean empty) {