Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce bs formatter interface #3253

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/app/WalletAppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bisq.core.locale.Res;
import bisq.core.user.Preferences;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;

import org.bitcoinj.core.VersionMessage;
import org.bitcoinj.store.BlockStoreException;
Expand Down Expand Up @@ -123,7 +124,7 @@ void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,
result = Res.get("mainView.footer.btcInfo",
peers,
Res.get("mainView.footer.btcInfo.synchronizingWith"),
getBtcNetworkAsString() + ": " + BSFormatter.formatToPercentWithSymbol(percentage));
getBtcNetworkAsString() + ": " + FormattingUtils.formatToPercentWithSymbol(percentage));
} else {
result = Res.get("mainView.footer.btcInfo",
peers,
Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/bisq/core/dao/presentation/DaoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bisq.core.dao.state.model.governance.DaoPhase;
import bisq.core.locale.Res;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;

import java.text.SimpleDateFormat;

Expand All @@ -40,8 +41,8 @@ public static String getNextPhaseDuration(int height, DaoPhase.Phase phase, DaoF
long now = new Date().getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd MMM", Locale.getDefault());
SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm", Locale.getDefault());
String startDateTime = BSFormatter.formatDateTime(new Date(now + (start - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);
String endDateTime = BSFormatter.formatDateTime(new Date(now + (end - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);
String startDateTime = FormattingUtils.formatDateTime(new Date(now + (start - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);
String endDateTime = FormattingUtils.formatDateTime(new Date(now + (end - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);

return Res.get("dao.cycle.phaseDurationWithoutBlocks", start, end, startDateTime, endDateTime);
}
Expand All @@ -53,9 +54,9 @@ public static String getPhaseDuration(int height, DaoPhase.Phase phase, DaoFacad
long now = new Date().getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd MMM", Locale.getDefault());
SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm", Locale.getDefault());
String startDateTime = BSFormatter.formatDateTime(new Date(now + (start - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);
String endDateTime = BSFormatter.formatDateTime(new Date(now + (end - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);
String durationTime = BSFormatter.formatDurationAsWords(duration * 10 * 60 * 1000, false, false);
String startDateTime = FormattingUtils.formatDateTime(new Date(now + (start - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);
String endDateTime = FormattingUtils.formatDateTime(new Date(now + (end - height) * 10 * 60 * 1000L), dateFormatter, timeFormatter);
String durationTime = FormattingUtils.formatDurationAsWords(duration * 10 * 60 * 1000, false, false);
return Res.get("dao.cycle.phaseDuration", duration, durationTime, start, end, startDateTime, endDateTime);
}
}
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 @@ -31,6 +31,7 @@
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;

import bisq.common.crypto.KeyRing;
import bisq.common.util.MathUtils;
Expand Down Expand Up @@ -180,9 +181,9 @@ else if (!isFiatCurrency && !isSellOffer)
ratio = Math.abs(ratio);
String msg = Res.get("account.notifications.marketAlert.message.msg",
direction,
BSFormatter.getCurrencyPair(currencyCode),
BSFormatter.formatPrice(offerPrice),
BSFormatter.formatToPercentWithSymbol(ratio / 10000d),
CurrencyUtil.getCurrencyPair(currencyCode),
FormattingUtils.formatPrice(offerPrice),
FormattingUtils.formatToPercentWithSymbol(ratio / 10000d),
marketDir,
Res.get(offer.getPaymentMethod().getId()),
shortOfferId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;

import bisq.common.util.MathUtils;

Expand Down Expand Up @@ -70,8 +71,8 @@ private void update() {
if (priceAsLong > filter.getHigh() || priceAsLong < filter.getLow()) {
String msg = Res.get("account.notifications.priceAlert.message.msg",
currencyName,
BSFormatter.formatMarketPrice(priceAsDouble, currencyCode),
BSFormatter.getCurrencyPair(currencyCode));
FormattingUtils.formatMarketPrice(priceAsDouble, currencyCode),
CurrencyUtil.getCurrencyPair(currencyCode));
MobileMessage message = new MobileMessage(Res.get("account.notifications.priceAlert.message.title", currencyName),
msg,
MobileMessageType.PRICE);
Expand Down
Loading