From 13fca56198d31ab965b1ac58ca386b14312a9f6c Mon Sep 17 00:00:00 2001 From: Justin Carter Date: Fri, 13 Sep 2019 08:27:56 +0200 Subject: [PATCH] Move Currency related helpers out of BSFormatter to CurrencyUtils --- .../java/bisq/core/locale/CurrencyUtil.java | 25 +++++++++++++++++++ .../alerts/market/MarketAlerts.java | 2 +- .../alerts/price/PriceAlert.java | 2 +- .../main/java/bisq/core/util/BSFormatter.java | 24 ------------------ .../bisq/desktop/main/market/MarketView.java | 5 ++-- .../market/offerbook/OfferBookChartView.java | 2 +- .../main/market/trades/TradesChartsView.java | 4 +-- .../desktop/main/offer/MutableOfferView.java | 4 +-- .../main/offer/offerbook/OfferBookView.java | 8 +++--- .../main/offer/takeoffer/TakeOfferView.java | 4 +-- .../closedtrades/ClosedTradesViewModel.java | 3 ++- .../failedtrades/FailedTradesViewModel.java | 3 ++- .../openoffer/OpenOffersViewModel.java | 3 ++- .../pendingtrades/PendingTradesViewModel.java | 3 ++- .../presentation/MarketPricePresentation.java | 4 +-- .../main/support/dispute/DisputeView.java | 4 +-- 16 files changed, 53 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index ac8a8350174..b98b5b3d893 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -507,4 +507,29 @@ public static List getActiveSortedCryptoCurrencies(AssetService .filter(e -> !filterManager.isCurrencyBanned(e.getCode())) .collect(Collectors.toList()); } + + public static String getCurrencyPair(String currencyCode) { + if (isFiatCurrency(currencyCode)) + return Res.getBaseCurrencyCode() + "/" + currencyCode; + else + return currencyCode + "/" + Res.getBaseCurrencyCode(); + } + + public static String getCounterCurrency(String currencyCode) { + if (isFiatCurrency(currencyCode)) + return currencyCode; + else + return Res.getBaseCurrencyCode(); + } + + public static String getPriceWithCurrencyCode(String currencyCode) { + return getPriceWithCurrencyCode(currencyCode, "shared.priceInCurForCur"); + } + + public static String getPriceWithCurrencyCode(String currencyCode, String translationKey) { + if (isCryptoCurrency(currencyCode)) + return Res.get(translationKey, Res.getBaseCurrencyCode(), currencyCode); + else + return Res.get(translationKey, currencyCode, Res.getBaseCurrencyCode()); + } } diff --git a/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java b/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java index b6b892beb0c..5ab49fbb2e4 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java +++ b/core/src/main/java/bisq/core/notifications/alerts/market/MarketAlerts.java @@ -181,7 +181,7 @@ else if (!isFiatCurrency && !isSellOffer) ratio = Math.abs(ratio); String msg = Res.get("account.notifications.marketAlert.message.msg", direction, - BSFormatter.getCurrencyPair(currencyCode), + CurrencyUtil.getCurrencyPair(currencyCode), FormattingUtils.formatPrice(offerPrice), FormattingUtils.formatToPercentWithSymbol(ratio / 10000d), marketDir, diff --git a/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java b/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java index 3f75f0fe56d..4d57f4dad65 100644 --- a/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java +++ b/core/src/main/java/bisq/core/notifications/alerts/price/PriceAlert.java @@ -72,7 +72,7 @@ private void update() { String msg = Res.get("account.notifications.priceAlert.message.msg", currencyName, FormattingUtils.formatMarketPrice(priceAsDouble, currencyCode), - BSFormatter.getCurrencyPair(currencyCode)); + CurrencyUtil.getCurrencyPair(currencyCode)); MobileMessage message = new MobileMessage(Res.get("account.notifications.priceAlert.message.title", currencyName), msg, MobileMessageType.PRICE); diff --git a/core/src/main/java/bisq/core/util/BSFormatter.java b/core/src/main/java/bisq/core/util/BSFormatter.java index 92703ec5c16..1b8211dd366 100644 --- a/core/src/main/java/bisq/core/util/BSFormatter.java +++ b/core/src/main/java/bisq/core/util/BSFormatter.java @@ -138,28 +138,4 @@ public static String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker } - public static String getCurrencyPair(String currencyCode) { - if (CurrencyUtil.isFiatCurrency(currencyCode)) - return Res.getBaseCurrencyCode() + "/" + currencyCode; - else - return currencyCode + "/" + Res.getBaseCurrencyCode(); - } - - public static String getCounterCurrency(String currencyCode) { - if (CurrencyUtil.isFiatCurrency(currencyCode)) - return currencyCode; - else - return Res.getBaseCurrencyCode(); - } - - public static String getPriceWithCurrencyCode(String currencyCode) { - return getPriceWithCurrencyCode(currencyCode, "shared.priceInCurForCur"); - } - - public static String getPriceWithCurrencyCode(String currencyCode, String translationKey) { - if (CurrencyUtil.isCryptoCurrency(currencyCode)) - return Res.get(translationKey, Res.getBaseCurrencyCode(), currencyCode); - else - return Res.get(translationKey, currencyCode, Res.getBaseCurrencyCode()); - } } diff --git a/desktop/src/main/java/bisq/desktop/main/market/MarketView.java b/desktop/src/main/java/bisq/desktop/main/market/MarketView.java index 5899a00bf96..7c3531ca51e 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/MarketView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/MarketView.java @@ -33,6 +33,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.util.DisplayUtils; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.offer.OfferPayload; import bisq.core.trade.statistics.TradeStatistics2; @@ -186,7 +187,7 @@ private String getAllTradesWithReferralId() { StringBuilder sb = new StringBuilder(); sb.append("Trade ID: ").append(trade.getOfferId()).append("\n") .append("Date: ").append(DisplayUtils.formatDateTime(trade.getTradeDate())).append("\n") - .append("Market: ").append(BSFormatter.getCurrencyPair(trade.getCurrencyCode())).append("\n") + .append("Market: ").append(CurrencyUtil.getCurrencyPair(trade.getCurrencyCode())).append("\n") .append("Price: ").append(FormattingUtils.formatPrice(trade.getTradePrice())).append("\n") .append("Amount: ").append(formatter.formatCoin(trade.getTradeAmount())).append("\n") .append("Volume: ").append(DisplayUtils.formatVolume(trade.getTradeVolume())).append("\n") @@ -207,7 +208,7 @@ private String getAllOffersWithReferralId() { StringBuilder sb = new StringBuilder(); sb.append("Offer ID: ").append(offer.getId()).append("\n") .append("Type: ").append(offer.getDirection().name()).append("\n") - .append("Market: ").append(BSFormatter.getCurrencyPair(offer.getCurrencyCode())).append("\n") + .append("Market: ").append(CurrencyUtil.getCurrencyPair(offer.getCurrencyCode())).append("\n") .append("Price: ").append(FormattingUtils.formatPrice(offer.getPrice())).append("\n") .append("Amount: ").append(DisplayUtils.formatAmount(offer, formatter)).append(" BTC\n") .append("Payment method: ").append(Res.get(offer.getPaymentMethod().getId())).append("\n") diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index 68d2173135b..e716f275b6f 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -269,7 +269,7 @@ public Number fromString(String string) { priceColumnLabel.set(Res.get("shared.priceWithCur", code)); } - xAxis.setLabel(BSFormatter.getPriceWithCurrencyCode(code)); + xAxis.setLabel(CurrencyUtil.getPriceWithCurrencyCode(code)); seriesBuy.setName(leftHeaderLabel.getText() + " "); seriesSell.setName(rightHeaderLabel.getText()); diff --git a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java index c7b01b39c06..70c143ba56a 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java @@ -241,7 +241,7 @@ else if (model.getSelectedCurrencyListItem().isPresent()) String code = selectedTradeCurrency.getCode(); volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", code))); - priceColumnLabel.set(BSFormatter.getPriceWithCurrencyCode(code)); + priceColumnLabel.set(CurrencyUtil.getPriceWithCurrencyCode(code)); tableView.getColumns().remove(marketColumn); } @@ -599,7 +599,7 @@ public TableCell call( public void updateItem(final TradeStatistics2 item, boolean empty) { super.updateItem(item, empty); if (item != null) - setText(BSFormatter.getCurrencyPair(item.getCurrencyCode())); + setText(CurrencyUtil.getCurrencyPair(item.getCurrencyCode())); else setText(""); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java index 66ed1be692d..8ce86042308 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java @@ -565,11 +565,11 @@ protected void close() { /////////////////////////////////////////////////////////////////////////////////////////// private void addBindings() { - priceCurrencyLabel.textProperty().bind(createStringBinding(() -> BSFormatter.getCounterCurrency(model.tradeCurrencyCode.get()), model.tradeCurrencyCode)); + priceCurrencyLabel.textProperty().bind(createStringBinding(() -> CurrencyUtil.getCounterCurrency(model.tradeCurrencyCode.get()), model.tradeCurrencyCode)); marketBasedPriceLabel.prefWidthProperty().bind(priceCurrencyLabel.widthProperty()); volumeCurrencyLabel.textProperty().bind(model.tradeCurrencyCode); - priceDescriptionLabel.textProperty().bind(createStringBinding(() -> BSFormatter.getPriceWithCurrencyCode(model.tradeCurrencyCode.get(), "shared.fixedPriceInCurForCur"), model.tradeCurrencyCode)); + priceDescriptionLabel.textProperty().bind(createStringBinding(() -> CurrencyUtil.getPriceWithCurrencyCode(model.tradeCurrencyCode.get(), "shared.fixedPriceInCurForCur"), model.tradeCurrencyCode)); volumeDescriptionLabel.textProperty().bind(createStringBinding(model.volumeDescriptionLabel::get, model.tradeCurrencyCode, model.volumeDescriptionLabel)); amountTextField.textProperty().bindBidirectional(model.amount); minAmountTextField.textProperty().bindBidirectional(model.minAmount); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index 26eb7e603b7..968da3a3cf8 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -227,8 +227,8 @@ public void initialize() { tableView.setPlaceholder(placeholder); marketColumn.setComparator((o1, o2) -> { - String str1 = BSFormatter.getCurrencyPair(o1.getOffer().getCurrencyCode()); - String str2 = BSFormatter.getCurrencyPair(o2.getOffer().getCurrencyCode()); + String str1 = CurrencyUtil.getCurrencyPair(o1.getOffer().getCurrencyCode()); + String str2 = CurrencyUtil.getCurrencyPair(o2.getOffer().getCurrencyCode()); return str1 != null && str2 != null ? str1.compareTo(str2) : 0; }); priceColumn.setComparator((o1, o2) -> { @@ -325,7 +325,7 @@ protected void activate() { tableView.getColumns().add(0, marketColumn); } else { volumeColumn.setTitleWithHelpText(Res.get("offerbook.volume", code), Res.get("shared.amountHelp")); - priceColumn.setTitle(BSFormatter.getPriceWithCurrencyCode(code)); + priceColumn.setTitle(CurrencyUtil.getPriceWithCurrencyCode(code)); priceColumn.getStyleClass().add("first-column"); tableView.getColumns().remove(marketColumn); @@ -688,7 +688,7 @@ public void updateItem(final OfferBookListItem item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) - setText(BSFormatter.getCurrencyPair(item.getOffer().getCurrencyCode())); + setText(CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode())); else setText(""); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java index 6f4393db85e..5d528cd7d9d 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java @@ -278,7 +278,7 @@ protected void activate() { String currencyCode = model.dataModel.getCurrencyCode(); volumeCurrencyLabel.setText(currencyCode); - priceDescriptionLabel.setText(BSFormatter.getPriceWithCurrencyCode(currencyCode)); + priceDescriptionLabel.setText(CurrencyUtil.getPriceWithCurrencyCode(currencyCode)); volumeDescriptionLabel.setText(model.volumeDescriptionLabel.get()); if (model.getPossiblePaymentAccounts().size() > 1) { @@ -606,7 +606,7 @@ private void addBindings() { totalToPayTextField.textProperty().bind(model.totalToPay); addressTextField.amountAsCoinProperty().bind(model.dataModel.getMissingCoin()); amountTextField.validationResultProperty().bind(model.amountValidationResult); - priceCurrencyLabel.textProperty().bind(createStringBinding(() -> BSFormatter.getCounterCurrency(model.dataModel.getCurrencyCode()))); + priceCurrencyLabel.textProperty().bind(createStringBinding(() -> CurrencyUtil.getCounterCurrency(model.dataModel.getCurrencyCode()))); priceAsPercentageLabel.prefWidthProperty().bind(priceCurrencyLabel.widthProperty()); nextButton.disableProperty().bind(model.isNextButtonDisabled); tradeFeeInBtcLabel.textProperty().bind(model.tradeFeeInBtcWithFiat); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java index 8b675ebe6ed..efc5ec06808 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java @@ -22,6 +22,7 @@ import bisq.desktop.util.DisplayUtils; import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.offer.OpenOffer; import bisq.core.trade.Tradable; @@ -136,7 +137,7 @@ String getMarketLabel(ClosedTradableListItem item) { if ((item == null)) return ""; - return BSFormatter.getCurrencyPair(item.getTradable().getOffer().getCurrencyCode()); + return CurrencyUtil.getCurrencyPair(item.getTradable().getOffer().getCurrencyCode()); } String getState(ClosedTradableListItem item) { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesViewModel.java index 1b3d9d7e19d..a3937f9c63c 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesViewModel.java @@ -21,6 +21,7 @@ import bisq.desktop.common.model.ViewModel; import bisq.desktop.util.DisplayUtils; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.util.BSFormatter; import bisq.core.util.FormattingUtils; @@ -74,7 +75,7 @@ String getMarketLabel(FailedTradesListItem item) { if ((item == null)) return ""; - return BSFormatter.getCurrencyPair(item.getTrade().getOffer().getCurrencyCode()); + return CurrencyUtil.getCurrencyPair(item.getTrade().getOffer().getCurrencyCode()); } String getDate(FailedTradesListItem item) { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java index be3d8139490..9b92cef057f 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java @@ -22,6 +22,7 @@ import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.monetary.Price; import bisq.core.offer.Offer; @@ -108,7 +109,7 @@ String getMarketLabel(OpenOfferListItem item) { if ((item == null)) return ""; - return BSFormatter.getCurrencyPair(item.getOffer().getCurrencyCode()); + return CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode()); } String getDate(OpenOfferListItem item) { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java index d8511f2a5f4..69530c0a4ac 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -23,6 +23,7 @@ import bisq.desktop.util.GUIUtil; import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.network.MessageState; import bisq.core.offer.Offer; @@ -200,7 +201,7 @@ String getMarketLabel(PendingTradesListItem item) { if ((item == null)) return ""; - return BSFormatter.getCurrencyPair(item.getTrade().getOffer().getCurrencyCode()); + return CurrencyUtil.getCurrencyPair(item.getTrade().getOffer().getCurrencyCode()); } private long getMaxTradePeriod() { 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 df7eeaa85e2..3e5fb12b2d9 100644 --- a/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/presentation/MarketPricePresentation.java @@ -143,7 +143,7 @@ private void setupMarketPriceFeed() { marketPriceBinding = EasyBind.combine( marketPriceCurrencyCode, marketPrice, - (currencyCode, price) -> BSFormatter.getCurrencyPair(currencyCode) + ": " + price); + (currencyCode, price) -> CurrencyUtil.getCurrencyPair(currencyCode) + ": " + price); marketPriceBinding.subscribe((observable, oldValue, newValue) -> { if (newValue != null && !newValue.equals(oldValue)) { @@ -202,7 +202,7 @@ private void setMarketPriceInItems() { priceString = Res.get("shared.na"); item.setPriceAvailable(false); } - item.setDisplayString(BSFormatter.getCurrencyPair(currencyCode) + ": " + priceString); + item.setDisplayString(CurrencyUtil.getCurrencyPair(currencyCode) + ": " + priceString); final String code = item.currencyCode; if (selectedPriceFeedComboBoxItemProperty.get() != null && diff --git a/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java b/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java index 6922b560560..7e1268e7d01 100644 --- a/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java +++ b/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java @@ -216,7 +216,7 @@ public void initialize() { dateColumn.setComparator(Comparator.comparing(Dispute::getOpeningDate)); buyerOnionAddressColumn.setComparator(Comparator.comparing(this::getBuyerOnionAddressColumnLabel)); sellerOnionAddressColumn.setComparator(Comparator.comparing(this::getSellerOnionAddressColumnLabel)); - marketColumn.setComparator((o1, o2) -> BSFormatter.getCurrencyPair(o1.getContract().getOfferPayload().getCurrencyCode()).compareTo(o2.getContract().getOfferPayload().getCurrencyCode())); + marketColumn.setComparator((o1, o2) -> CurrencyUtil.getCurrencyPair(o1.getContract().getOfferPayload().getCurrencyCode()).compareTo(o2.getContract().getOfferPayload().getCurrencyCode())); dateColumn.setSortType(TableColumn.SortType.DESCENDING); tableView.getSortOrder().add(dateColumn); @@ -726,7 +726,7 @@ public TableCell call(TableColumn column) { public void updateItem(final Dispute item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) - setText(BSFormatter.getCurrencyPair(item.getContract().getOfferPayload().getCurrencyCode())); + setText(CurrencyUtil.getCurrencyPair(item.getContract().getOfferPayload().getCurrencyCode())); else setText(""); }