Skip to content

Commit

Permalink
Move Currency related helpers out of BSFormatter to CurrencyUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Carter committed Sep 18, 2019
1 parent ac5f9c1 commit 13fca56
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 47 deletions.
25 changes: 25 additions & 0 deletions core/src/main/java/bisq/core/locale/CurrencyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,29 @@ public static List<CryptoCurrency> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions core/src/main/java/bisq/core/util/BSFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -599,7 +599,7 @@ public TableCell<TradeStatistics2, TradeStatistics2> 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("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -726,7 +726,7 @@ public TableCell<Dispute, Dispute> call(TableColumn<Dispute, Dispute> 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("");
}
Expand Down

0 comments on commit 13fca56

Please sign in to comment.