Merge pull request #5740 from ghubstan/mv-volfmt-code-to-volutil

Move volume formatting from DisplayUtils to VolumeUtil
This commit is contained in:
Christoph Atteneder 2021-10-04 10:27:41 +02:00 committed by GitHub
commit 55ab0d412e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 278 additions and 196 deletions

View file

@ -17,17 +17,28 @@
package bisq.core.util; package bisq.core.util;
import bisq.core.locale.Res;
import bisq.core.monetary.Altcoin; import bisq.core.monetary.Altcoin;
import bisq.core.monetary.AltcoinExchangeRate; import bisq.core.monetary.AltcoinExchangeRate;
import bisq.core.monetary.Price; import bisq.core.monetary.Price;
import bisq.core.monetary.Volume; import bisq.core.monetary.Volume;
import bisq.core.offer.Offer;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.ExchangeRate; import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat; import org.bitcoinj.utils.Fiat;
import org.bitcoinj.utils.MonetaryFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
public class VolumeUtil { public class VolumeUtil {
private static final MonetaryFormat FIAT_VOLUME_FORMAT = new MonetaryFormat().shift(0).minDecimals(0).repeatOptionalDecimals(0, 0);
public static Volume getRoundedFiatVolume(Volume volumeByAmount) { public static Volume getRoundedFiatVolume(Volume volumeByAmount) {
// We want to get rounded to 1 unit of the fiat currency, e.g. 1 EUR. // We want to get rounded to 1 unit of the fiat currency, e.g. 1 EUR.
return getAdjustedFiatVolume(volumeByAmount, 1); return getAdjustedFiatVolume(volumeByAmount, 1);
@ -62,4 +73,76 @@ public class VolumeUtil {
return new Volume(new ExchangeRate((Fiat) price.getMonetary()).coinToFiat(amount)); return new Volume(new ExchangeRate((Fiat) price.getMonetary()).coinToFiat(amount));
} }
} }
public static String formatVolume(Offer offer, Boolean decimalAligned, int maxNumberOfDigits) {
return formatVolume(offer, decimalAligned, maxNumberOfDigits, true);
}
public static String formatVolume(Offer offer, Boolean decimalAligned, int maxNumberOfDigits, boolean showRange) {
String formattedVolume = offer.isRange() && showRange
? formatVolume(offer.getMinVolume()) + FormattingUtils.RANGE_SEPARATOR + formatVolume(offer.getVolume())
: formatVolume(offer.getVolume());
if (decimalAligned) {
formattedVolume = FormattingUtils.fillUpPlacesWithEmptyStrings(formattedVolume, maxNumberOfDigits);
}
return formattedVolume;
}
public static String formatLargeFiat(double value, String currency) {
if (value <= 0) {
return "0";
}
NumberFormat numberFormat = DecimalFormat.getInstance(Locale.US);
numberFormat.setGroupingUsed(true);
return numberFormat.format(value) + " " + currency;
}
public static String formatLargeFiatWithUnitPostFix(double value, String currency) {
if (value <= 0) {
return "0";
}
String[] units = new String[]{"", "K", "M", "B"};
int digitGroups = (int) (Math.log10(value) / Math.log10(1000));
return new DecimalFormat("#,##0.###")
.format(value / Math.pow(1000, digitGroups)) + units[digitGroups] + " " + currency;
}
public static String formatVolume(Volume volume) {
return formatVolume(volume, FIAT_VOLUME_FORMAT, false);
}
private static String formatVolume(Volume volume, MonetaryFormat fiatVolumeFormat, boolean appendCurrencyCode) {
if (volume != null) {
Monetary monetary = volume.getMonetary();
if (monetary instanceof Fiat)
return FormattingUtils.formatFiat((Fiat) monetary, fiatVolumeFormat, appendCurrencyCode);
else
return FormattingUtils.formatAltcoinVolume((Altcoin) monetary, appendCurrencyCode);
} else {
return "";
}
}
public static String formatVolumeWithCode(Volume volume) {
return formatVolume(volume, true);
}
public static String formatVolume(Volume volume, boolean appendCode) {
return formatVolume(volume, FIAT_VOLUME_FORMAT, appendCode);
}
public static String formatAverageVolumeWithCode(Volume volume) {
return formatVolume(volume, FIAT_VOLUME_FORMAT.minDecimals(2), true);
}
public static String formatVolumeLabel(String currencyCode) {
return formatVolumeLabel(currencyCode, "");
}
public static String formatVolumeLabel(String currencyCode, String postFix) {
return Res.get("formatter.formatVolumeLabel",
currencyCode, postFix);
}
} }

View file

@ -30,7 +30,6 @@ import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.TxDetailsBsq; import bisq.desktop.main.overlays.windows.TxDetailsBsq;
import bisq.desktop.main.overlays.windows.TxInputSelectionWindow; import bisq.desktop.main.overlays.windows.TxInputSelectionWindow;
import bisq.desktop.main.overlays.windows.WalletPasswordWindow; import bisq.desktop.main.overlays.windows.WalletPasswordWindow;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.FormBuilder; import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.GUIUtil; import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.Layout; import bisq.desktop.util.Layout;
@ -54,6 +53,7 @@ import bisq.core.user.DontShowAgainLookup;
import bisq.core.user.Preferences; import bisq.core.user.Preferences;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.ParsingUtils; import bisq.core.util.ParsingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.CoinUtil; import bisq.core.util.coin.CoinUtil;
@ -256,7 +256,7 @@ public class BsqSendView extends ActivatableView<GridPane, Void> implements BsqB
} }
public void fillFromTradeData(Tuple2<Volume, String> tuple) { public void fillFromTradeData(Tuple2<Volume, String> tuple) {
amountInputTextField.setText(DisplayUtils.formatVolume(tuple.first)); amountInputTextField.setText(VolumeUtil.formatVolume(tuple.first));
receiversAddressInputTextField.setText(tuple.second); receiversAddressInputTextField.setText(tuple.second);
} }
@ -528,7 +528,7 @@ public class BsqSendView extends ActivatableView<GridPane, Void> implements BsqB
private void doWithdraw(Transaction txWithBtcFee, TxType txType, TxBroadcaster.Callback callback) { private void doWithdraw(Transaction txWithBtcFee, TxType txType, TxBroadcaster.Callback callback) {
if (btcWalletService.isEncrypted()) { if (btcWalletService.isEncrypted()) {
UserThread.runAfter(() -> walletPasswordWindow.onAesKey(aesKey -> UserThread.runAfter(() -> walletPasswordWindow.onAesKey(aesKey ->
sendFunds(txWithBtcFee, txType, callback)) sendFunds(txWithBtcFee, txType, callback))
.show(), 300, TimeUnit.MILLISECONDS); .show(), 300, TimeUnit.MILLISECONDS);
} else { } else {
sendFunds(txWithBtcFee, txType, callback); sendFunds(txWithBtcFee, txType, callback);

View file

@ -39,6 +39,7 @@ import bisq.core.offer.OfferPayload;
import bisq.core.trade.statistics.TradeStatistics3; import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.trade.statistics.TradeStatistics3StorageService; import bisq.core.trade.statistics.TradeStatistics3StorageService;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.common.util.Utilities; import bisq.common.util.Utilities;
@ -198,7 +199,7 @@ public class MarketView extends ActivatableView<TabPane, Void> {
.append("Market: ").append(CurrencyUtil.getCurrencyPair(tradeStatistics3.getCurrency())).append("\n") .append("Market: ").append(CurrencyUtil.getCurrencyPair(tradeStatistics3.getCurrency())).append("\n")
.append("Price: ").append(FormattingUtils.formatPrice(tradeStatistics3.getTradePrice())).append("\n") .append("Price: ").append(FormattingUtils.formatPrice(tradeStatistics3.getTradePrice())).append("\n")
.append("Amount: ").append(formatter.formatCoin(tradeStatistics3.getTradeAmount())).append("\n") .append("Amount: ").append(formatter.formatCoin(tradeStatistics3.getTradeAmount())).append("\n")
.append("Volume: ").append(DisplayUtils.formatVolume(tradeStatistics3.getTradeVolume())).append("\n") .append("Volume: ").append(VolumeUtil.formatVolume(tradeStatistics3.getTradeVolume())).append("\n")
.append("Payment method: ").append(Res.get(tradeStatistics3.getPaymentMethod())).append("\n") .append("Payment method: ").append(Res.get(tradeStatistics3.getPaymentMethod())).append("\n")
.append("ReferralID: ").append(tradeStatistics3.getExtraDataMap().get(OfferPayload.REFERRAL_ID)); .append("ReferralID: ").append(tradeStatistics3.getExtraDataMap().get(OfferPayload.REFERRAL_ID));
return sb.toString(); return sb.toString();

View file

@ -39,6 +39,7 @@ import bisq.core.locale.Res;
import bisq.core.offer.Offer; import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload; import bisq.core.offer.OfferPayload;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.network.p2p.NodeAddress; import bisq.network.p2p.NodeAddress;
@ -88,11 +89,11 @@ import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import java.text.DecimalFormat;
import javafx.util.Callback; import javafx.util.Callback;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import java.text.DecimalFormat;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
@ -140,7 +141,9 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Inject @Inject
public OfferBookChartView(OfferBookChartViewModel model, Navigation navigation, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, public OfferBookChartView(OfferBookChartViewModel model,
Navigation navigation,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter,
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) { @Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
super(model); super(model);
this.navigation = navigation; this.navigation = navigation;
@ -230,7 +233,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
final double doubleValue = (double) object; final double doubleValue = (double) object;
if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) { if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
final String withCryptoPrecision = FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, cryptoPrecision); final String withCryptoPrecision = FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, cryptoPrecision);
if (withCryptoPrecision.substring(0,3).equals("0.0")) { if (withCryptoPrecision.substring(0, 3).equals("0.0")) {
return FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, 8).replaceFirst("0+$", ""); return FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, 8).replaceFirst("0+$", "");
} else { } else {
return withCryptoPrecision.replaceFirst("0+$", ""); return withCryptoPrecision.replaceFirst("0+$", "");
@ -398,7 +401,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
List<XYChart.Data<Number, Number>> filterOutliersBuy(List<XYChart.Data<Number, Number>> buy, boolean isCrypto) { List<XYChart.Data<Number, Number>> filterOutliersBuy(List<XYChart.Data<Number, Number>> buy, boolean isCrypto) {
List<Double> mnmx = isCrypto ? minMaxFilterRight(buy) : minMaxFilterLeft(buy); List<Double> mnmx = isCrypto ? minMaxFilterRight(buy) : minMaxFilterLeft(buy);
if (mnmx.get(0).doubleValue() == Double.MAX_VALUE || if (mnmx.get(0).doubleValue() == Double.MAX_VALUE ||
mnmx.get(1).doubleValue() == Double.MIN_VALUE) { // no filtering mnmx.get(1).doubleValue() == Double.MIN_VALUE) { // no filtering
return buy; return buy;
} }
// apply filtering // apply filtering
@ -408,7 +411,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
List<XYChart.Data<Number, Number>> filterOutliersSell(List<XYChart.Data<Number, Number>> sell, boolean isCrypto) { List<XYChart.Data<Number, Number>> filterOutliersSell(List<XYChart.Data<Number, Number>> sell, boolean isCrypto) {
List<Double> mnmx = isCrypto ? minMaxFilterLeft(sell) : minMaxFilterRight(sell); List<Double> mnmx = isCrypto ? minMaxFilterLeft(sell) : minMaxFilterRight(sell);
if (mnmx.get(0).doubleValue() == Double.MAX_VALUE || if (mnmx.get(0).doubleValue() == Double.MAX_VALUE ||
mnmx.get(1).doubleValue() == Double.MIN_VALUE) { // no filtering mnmx.get(1).doubleValue() == Double.MIN_VALUE) { // no filtering
return sell; return sell;
} }
// apply filtering // apply filtering
@ -417,43 +420,43 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
private List<Double> minMaxFilterLeft(List<XYChart.Data<Number, Number>> data) { private List<Double> minMaxFilterLeft(List<XYChart.Data<Number, Number>> data) {
double maxValue = data.stream() double maxValue = data.stream()
.mapToDouble(o -> o.getXValue().doubleValue()) .mapToDouble(o -> o.getXValue().doubleValue())
.max() .max()
.orElse(Double.MIN_VALUE); .orElse(Double.MIN_VALUE);
// Hide offers less than a div-factor of dataLimitFactor lower than the highest offer. // Hide offers less than a div-factor of dataLimitFactor lower than the highest offer.
double minValue = data.stream() double minValue = data.stream()
.mapToDouble(o -> o.getXValue().doubleValue()) .mapToDouble(o -> o.getXValue().doubleValue())
.filter(o -> o > maxValue / dataLimitFactor) .filter(o -> o > maxValue / dataLimitFactor)
.min() .min()
.orElse(Double.MAX_VALUE); .orElse(Double.MAX_VALUE);
return List.of(minValue, maxValue); return List.of(minValue, maxValue);
} }
private List<Double> minMaxFilterRight(List<XYChart.Data<Number, Number>> data) { private List<Double> minMaxFilterRight(List<XYChart.Data<Number, Number>> data) {
double minValue = data.stream() double minValue = data.stream()
.mapToDouble(o -> o.getXValue().doubleValue()) .mapToDouble(o -> o.getXValue().doubleValue())
.min() .min()
.orElse(Double.MAX_VALUE); .orElse(Double.MAX_VALUE);
// Hide offers a dataLimitFactor factor higher than the lowest offer // Hide offers a dataLimitFactor factor higher than the lowest offer
double maxValue = data.stream() double maxValue = data.stream()
.mapToDouble(o -> o.getXValue().doubleValue()) .mapToDouble(o -> o.getXValue().doubleValue())
.filter(o -> o < minValue * dataLimitFactor) .filter(o -> o < minValue * dataLimitFactor)
.max() .max()
.orElse(Double.MIN_VALUE); .orElse(Double.MIN_VALUE);
return List.of(minValue, maxValue); return List.of(minValue, maxValue);
} }
private List<XYChart.Data<Number, Number>> filterLeft(List<XYChart.Data<Number, Number>> data, double maxValue) { private List<XYChart.Data<Number, Number>> filterLeft(List<XYChart.Data<Number, Number>> data, double maxValue) {
return data.stream() return data.stream()
.filter(o -> o.getXValue().doubleValue() > maxValue / dataLimitFactor) .filter(o -> o.getXValue().doubleValue() > maxValue / dataLimitFactor)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private List<XYChart.Data<Number, Number>> filterRight(List<XYChart.Data<Number, Number>> data, double minValue) { private List<XYChart.Data<Number, Number>> filterRight(List<XYChart.Data<Number, Number>> data, double minValue) {
return data.stream() return data.stream()
.filter(o -> o.getXValue().doubleValue() < minValue * dataLimitFactor) .filter(o -> o.getXValue().doubleValue() < minValue * dataLimitFactor)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(OfferPayload.Direction direction) { private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(OfferPayload.Direction direction) {
@ -479,7 +482,9 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
private Offer offer; private Offer offer;
final ChangeListener<Number> listener = new ChangeListener<>() { final ChangeListener<Number> listener = new ChangeListener<>() {
@Override @Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { public void changed(ObservableValue<? extends Number> observable,
Number oldValue,
Number newValue) {
if (offer != null && offer.getPrice() != null) { if (offer != null && offer.getPrice() != null) {
setText(""); setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer),
@ -529,7 +534,9 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
private Offer offer; private Offer offer;
final ChangeListener<Number> listener = new ChangeListener<>() { final ChangeListener<Number> listener = new ChangeListener<>() {
@Override @Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { public void changed(ObservableValue<? extends Number> observable,
Number oldValue,
Number newValue) {
if (offer != null && offer.getPrice() != null) { if (offer != null && offer.getPrice() != null) {
renderCellContentRange(); renderCellContentRange();
model.priceFeedService.updateCounterProperty().removeListener(listener); model.priceFeedService.updateCounterProperty().removeListener(listener);
@ -562,7 +569,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
* Should not be called for empty cells * Should not be called for empty cells
*/ */
private void renderCellContentRange() { private void renderCellContentRange() {
String volumeRange = DisplayUtils.formatVolume(offer, true, 2); String volumeRange = VolumeUtil.formatVolume(offer, true, 2);
setText(""); setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(volumeRange, setGraphic(new ColoredDecimalPlacesWithZerosText(volumeRange,
@ -711,8 +718,8 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
if (buyOfferTableView.getHeight() != newTableViewHeight) { if (buyOfferTableView.getHeight() != newTableViewHeight) {
buyOfferTableView.setMinHeight(newTableViewHeight); buyOfferTableView.setMinHeight(newTableViewHeight);
sellOfferTableView.setMinHeight(newTableViewHeight); sellOfferTableView.setMinHeight(newTableViewHeight);
} }
} }
}, 100, TimeUnit.MILLISECONDS); }, 100, TimeUnit.MILLISECONDS);
} }
} }

View file

@ -38,6 +38,7 @@ import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload; import bisq.core.offer.OfferPayload;
import bisq.core.provider.price.PriceFeedService; import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.Preferences; import bisq.core.user.Preferences;
import bisq.core.util.VolumeUtil;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -232,15 +233,20 @@ class OfferBookChartViewModel extends ActivatableViewModel {
} }
public Optional<CurrencyListItem> getSelectedCurrencyListItem() { public Optional<CurrencyListItem> getSelectedCurrencyListItem() {
return currencyListItems.getObservableList().stream().filter(e -> e.tradeCurrency.equals(selectedTradeCurrencyProperty.get())).findAny(); return currencyListItems.getObservableList().stream()
.filter(e -> e.tradeCurrency.equals(selectedTradeCurrencyProperty.get())).findAny();
} }
public int getMaxNumberOfPriceZeroDecimalsToColorize(Offer offer) { public int getMaxNumberOfPriceZeroDecimalsToColorize(Offer offer) {
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? GUIUtil.FIAT_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS; return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())
? GUIUtil.FIAT_DECIMALS_WITH_ZEROS
: GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS;
} }
public int getZeroDecimalsForPrice(Offer offer) { public int getZeroDecimalsForPrice(Offer offer) {
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? GUIUtil.FIAT_PRICE_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS; return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())
? GUIUtil.FIAT_PRICE_DECIMALS_WITH_ZEROS
: GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS;
} }
public String getPrice(Offer offer) { public String getPrice(Offer offer) {
@ -248,7 +254,9 @@ class OfferBookChartViewModel extends ActivatableViewModel {
} }
private String formatPrice(Offer offer, boolean decimalAligned) { private String formatPrice(Offer offer, boolean decimalAligned) {
return DisplayUtils.formatPrice(offer.getPrice(), decimalAligned, offer.isBuyOffer() ? maxPlacesForBuyPrice.get() : maxPlacesForSellPrice.get()); return DisplayUtils.formatPrice(offer.getPrice(), decimalAligned, offer.isBuyOffer()
? maxPlacesForBuyPrice.get()
: maxPlacesForSellPrice.get());
} }
public String getVolume(Offer offer) { public String getVolume(Offer offer) {
@ -256,7 +264,10 @@ class OfferBookChartViewModel extends ActivatableViewModel {
} }
private String formatVolume(Offer offer, boolean decimalAligned) { private String formatVolume(Offer offer, boolean decimalAligned) {
return DisplayUtils.formatVolume(offer, decimalAligned, offer.isBuyOffer() ? maxPlacesForBuyVolume.get() : maxPlacesForSellVolume.get(), false); return VolumeUtil.formatVolume(offer,
decimalAligned,
offer.isBuyOffer() ? maxPlacesForBuyVolume.get() : maxPlacesForSellVolume.get(),
false);
} }
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -23,6 +23,7 @@ import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.trade.statistics.TradeStatistics3; import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import lombok.experimental.Delegate; import lombok.experimental.Delegate;
@ -73,8 +74,8 @@ public class TradeStatistics3ListItem {
public String getVolumeString() { public String getVolumeString() {
if (volumeString == null) { if (volumeString == null) {
volumeString = tradeStatistics3 != null ? showAllTradeCurrencies ? volumeString = tradeStatistics3 != null ? showAllTradeCurrencies ?
DisplayUtils.formatVolumeWithCode(tradeStatistics3.getTradeVolume()) : VolumeUtil.formatVolumeWithCode(tradeStatistics3.getTradeVolume()) :
DisplayUtils.formatVolume(tradeStatistics3.getTradeVolume()) VolumeUtil.formatVolume(tradeStatistics3.getTradeVolume())
: ""; : "";
} }
return volumeString; return volumeString;

View file

@ -38,6 +38,7 @@ import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.user.CookieKey; import bisq.core.user.CookieKey;
import bisq.core.user.User; import bisq.core.user.User;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.common.UserThread; import bisq.common.UserThread;
@ -570,7 +571,7 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
public String toString(Number volume) { public String toString(Number volume) {
return currency.equals("BTC") ? return currency.equals("BTC") ?
coinFormatter.formatCoin(Coin.valueOf(MathUtils.doubleToLong((double) volume))) : coinFormatter.formatCoin(Coin.valueOf(MathUtils.doubleToLong((double) volume))) :
DisplayUtils.formatLargeFiatWithUnitPostFix((double) volume, "USD"); VolumeUtil.formatLargeFiatWithUnitPostFix((double) volume, "USD");
} }
@Override @Override

View file

@ -18,9 +18,9 @@
package bisq.desktop.main.market.trades.charts.volume; package bisq.desktop.main.market.trades.charts.volume;
import bisq.desktop.main.market.trades.charts.CandleData; import bisq.desktop.main.market.trades.charts.CandleData;
import bisq.desktop.util.DisplayUtils;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.util.VolumeUtil;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
@ -57,7 +57,7 @@ public class VolumeBar extends Group {
public void update(double height, double candleWidth, CandleData candleData) { public void update(double height, double candleWidth, CandleData candleData) {
bar.resizeRelocate(-candleWidth / 2, 0, candleWidth, height); bar.resizeRelocate(-candleWidth / 2, 0, candleWidth, height);
String volumeInBtc = volumeStringConverter.toString(candleData.accumulatedAmount); String volumeInBtc = volumeStringConverter.toString(candleData.accumulatedAmount);
String volumeInUsd = DisplayUtils.formatLargeFiat(candleData.volumeInUsd, "USD"); String volumeInUsd = VolumeUtil.formatLargeFiat(candleData.volumeInUsd, "USD");
tooltip.setText(Res.get("market.trades.tooltip.volumeBar", volumeInBtc, volumeInUsd, candleData.numTrades, candleData.date)); tooltip.setText(Res.get("market.trades.tooltip.volumeBar", volumeInBtc, volumeInUsd, candleData.numTrades, candleData.date));
} }

View file

@ -23,6 +23,7 @@ import bisq.desktop.util.GUIUtil;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.monetary.Volume; import bisq.core.monetary.Volume;
import bisq.core.offer.OfferUtil; import bisq.core.offer.OfferUtil;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.common.app.DevEnv; import bisq.common.app.DevEnv;
@ -65,9 +66,9 @@ public class FeeUtil {
" " + Res.get("guiUtil.ofTradeAmount"); " " + Res.get("guiUtil.ofTradeAmount");
} }
return offerUtil.getFeeInUserFiatCurrency(tradeFee, return offerUtil.getFeeInUserFiatCurrency(tradeFee,
isCurrencyForMakerFeeBtc, isCurrencyForMakerFeeBtc,
formatter) formatter)
.map(DisplayUtils::formatAverageVolumeWithCode) .map(VolumeUtil::formatAverageVolumeWithCode)
.map(feeInFiat -> Res.get("feeOptionWindow.btcFeeWithFiatAndPercentage", feeAsBtc, feeInFiat, percentage)) .map(feeInFiat -> Res.get("feeOptionWindow.btcFeeWithFiatAndPercentage", feeAsBtc, feeInFiat, percentage))
.orElseGet(() -> Res.get("feeOptionWindow.btcFeeWithPercentage", feeAsBtc, percentage)); .orElseGet(() -> Res.get("feeOptionWindow.btcFeeWithPercentage", feeAsBtc, percentage));
} else { } else {

View file

@ -471,7 +471,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
volumeListener = (ov, oldValue, newValue) -> { volumeListener = (ov, oldValue, newValue) -> {
ignoreVolumeStringListener = true; ignoreVolumeStringListener = true;
if (newValue != null) if (newValue != null)
volume.set(DisplayUtils.formatVolume(newValue)); volume.set(VolumeUtil.formatVolume(newValue));
else else
volume.set(""); volume.set("");
@ -758,7 +758,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
if (dataModel.getMinVolume().get() != null) { if (dataModel.getMinVolume().get() != null) {
InputValidator.ValidationResult minVolumeResult = isVolumeInputValid( InputValidator.ValidationResult minVolumeResult = isVolumeInputValid(
DisplayUtils.formatVolume(dataModel.getMinVolume().get())); VolumeUtil.formatVolume(dataModel.getMinVolume().get()));
volumeValidationResult.set(minVolumeResult); volumeValidationResult.set(minVolumeResult);
@ -883,7 +883,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
else if (CurrencyUtil.isFiatCurrency(tradeCurrencyCode.get())) else if (CurrencyUtil.isFiatCurrency(tradeCurrencyCode.get()))
volume = VolumeUtil.getRoundedFiatVolume(volume); volume = VolumeUtil.getRoundedFiatVolume(volume);
this.volume.set(DisplayUtils.formatVolume(volume)); this.volume.set(VolumeUtil.formatVolume(volume));
} }
ignoreVolumeStringListener = false; ignoreVolumeStringListener = false;
@ -1303,7 +1303,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
dataModel.getPrice().get() != null && dataModel.getPrice().get() != null &&
dataModel.getPrice().get().getValue() != 0 && dataModel.getPrice().get().getValue() != 0 &&
isVolumeInputValid(volume.get()).isValid && isVolumeInputValid(volume.get()).isValid &&
isVolumeInputValid(DisplayUtils.formatVolume(dataModel.getMinVolume().get())).isValid && isVolumeInputValid(VolumeUtil.formatVolume(dataModel.getMinVolume().get())).isValid &&
dataModel.isMinAmountLessOrEqualAmount(); dataModel.isMinAmountLessOrEqualAmount();
if (dataModel.useMarketBasedPrice.get() && dataModel.isMarketPriceAvailable()) { if (dataModel.useMarketBasedPrice.get() && dataModel.isMarketPriceAvailable()) {

View file

@ -50,6 +50,7 @@ import bisq.core.trade.closed.ClosedTradableManager;
import bisq.core.user.Preferences; import bisq.core.user.Preferences;
import bisq.core.user.User; import bisq.core.user.User;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
@ -435,7 +436,7 @@ class OfferBookViewModel extends ActivatableViewModel {
if (offerVolume != null && minOfferVolume != null) { if (offerVolume != null && minOfferVolume != null) {
String postFix = showAllTradeCurrenciesProperty.get() ? " " + offer.getCurrencyCode() : ""; String postFix = showAllTradeCurrenciesProperty.get() ? " " + offer.getCurrencyCode() : "";
decimalAligned = decimalAligned && !showAllTradeCurrenciesProperty.get(); decimalAligned = decimalAligned && !showAllTradeCurrenciesProperty.get();
return DisplayUtils.formatVolume(offer, decimalAligned, maxPlacesForVolume.get()) + postFix; return VolumeUtil.formatVolume(offer, decimalAligned, maxPlacesForVolume.get()) + postFix;
} else { } else {
return Res.get("shared.na"); return Res.get("shared.na");
} }

View file

@ -43,6 +43,7 @@ import bisq.core.payment.payload.PaymentMethod;
import bisq.core.provider.fee.FeeService; import bisq.core.provider.fee.FeeService;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.CoinUtil; import bisq.core.util.coin.CoinUtil;
@ -475,7 +476,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void addBindings() { private void addBindings() {
volume.bind(createStringBinding(() -> DisplayUtils.formatVolume(dataModel.volume.get()), dataModel.volume)); volume.bind(createStringBinding(() -> VolumeUtil.formatVolume(dataModel.volume.get()), dataModel.volume));
if (dataModel.getDirection() == OfferPayload.Direction.SELL) { if (dataModel.getDirection() == OfferPayload.Direction.SELL) {
volumeDescriptionLabel.set(Res.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getCurrencyCode())); volumeDescriptionLabel.set(Res.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getCurrencyCode()));

View file

@ -39,6 +39,7 @@ import bisq.core.support.dispute.mediation.MediationManager;
import bisq.core.support.dispute.refund.RefundManager; import bisq.core.support.dispute.refund.RefundManager;
import bisq.core.trade.Contract; import bisq.core.trade.Contract;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.network.p2p.NodeAddress; import bisq.network.p2p.NodeAddress;
@ -162,8 +163,10 @@ public class ContractWindow extends Overlay<ContractWindow> {
FormattingUtils.formatPrice(contract.getTradePrice())); FormattingUtils.formatPrice(contract.getTradePrice()));
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradeAmount"), addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradeAmount"),
formatter.formatCoinWithCode(contract.getTradeAmount())); formatter.formatCoinWithCode(contract.getTradeAmount()));
addConfirmationLabelLabel(gridPane, ++rowIndex, DisplayUtils.formatVolumeLabel(currencyCode, ":"), addConfirmationLabelLabel(gridPane,
DisplayUtils.formatVolumeWithCode(contract.getTradeVolume())); ++rowIndex,
VolumeUtil.formatVolumeLabel(currencyCode, ":"),
VolumeUtil.formatVolumeWithCode(contract.getTradeVolume()));
String securityDeposit = Res.getWithColAndCap("shared.buyer") + String securityDeposit = Res.getWithColAndCap("shared.buyer") +
" " + " " +
formatter.formatCoinWithCode(offer.getBuyerSecurityDeposit()) + formatter.formatCoinWithCode(offer.getBuyerSecurityDeposit()) +
@ -172,28 +175,43 @@ public class ContractWindow extends Overlay<ContractWindow> {
" " + " " +
formatter.formatCoinWithCode(offer.getSellerSecurityDeposit()); formatter.formatCoinWithCode(offer.getSellerSecurityDeposit());
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.securityDeposit"), securityDeposit); addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.securityDeposit"), securityDeposit);
addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.btcAddresses"), addConfirmationLabelTextFieldWithCopyIcon(gridPane,
contract.getBuyerPayoutAddressString() + " / " + ++rowIndex,
contract.getSellerPayoutAddressString()).second.setMouseTransparent(false); Res.get("contractWindow.btcAddresses"),
addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.onions"), contract.getBuyerPayoutAddressString() + " / " + contract.getSellerPayoutAddressString()).second.setMouseTransparent(false);
addConfirmationLabelTextFieldWithCopyIcon(gridPane,
++rowIndex,
Res.get("contractWindow.onions"),
contract.getBuyerNodeAddress().getFullAddress() + " / " + contract.getSellerNodeAddress().getFullAddress()); contract.getBuyerNodeAddress().getFullAddress() + " / " + contract.getSellerNodeAddress().getFullAddress());
addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.accountAge"), addConfirmationLabelTextFieldWithCopyIcon(gridPane,
getAccountAge(contract.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing(), offer.getCurrencyCode()) + " / " + ++rowIndex,
getAccountAge(contract.getSellerPaymentAccountPayload(), contract.getSellerPubKeyRing(), offer.getCurrencyCode())); Res.get("contractWindow.accountAge"),
getAccountAge(contract.getBuyerPaymentAccountPayload(),
contract.getBuyerPubKeyRing(),
offer.getCurrencyCode()) + " / " + getAccountAge(contract.getSellerPaymentAccountPayload(), contract.getSellerPubKeyRing(), offer.getCurrencyCode()));
DisputeManager<? extends DisputeList<Dispute>> disputeManager = getDisputeManager(dispute); DisputeManager<? extends DisputeList<Dispute>> disputeManager = getDisputeManager(dispute);
String nrOfDisputesAsBuyer = disputeManager != null ? disputeManager.getNrOfDisputes(true, contract) : ""; String nrOfDisputesAsBuyer = disputeManager != null ? disputeManager.getNrOfDisputes(true, contract) : "";
String nrOfDisputesAsSeller = disputeManager != null ? disputeManager.getNrOfDisputes(false, contract) : ""; String nrOfDisputesAsSeller = disputeManager != null ? disputeManager.getNrOfDisputes(false, contract) : "";
addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.numDisputes"), addConfirmationLabelTextFieldWithCopyIcon(gridPane,
++rowIndex,
Res.get("contractWindow.numDisputes"),
nrOfDisputesAsBuyer + " / " + nrOfDisputesAsSeller); nrOfDisputesAsBuyer + " / " + nrOfDisputesAsSeller);
addConfirmationLabelTextFieldWithCopyIcon(gridPane,
addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.buyer")), ++rowIndex,
contract.getBuyerPaymentAccountPayload() != null ? Res.get("shared.paymentDetails", Res.get("shared.buyer")),
contract.getBuyerPaymentAccountPayload().getPaymentDetails() : "NA").second.setMouseTransparent(false); contract.getBuyerPaymentAccountPayload() != null
addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.seller")), ? contract.getBuyerPaymentAccountPayload().getPaymentDetails()
sellerPaymentAccountPayload != null ? : "NA")
sellerPaymentAccountPayload.getPaymentDetails() : "NA").second.setMouseTransparent(false); .second.setMouseTransparent(false);
addConfirmationLabelTextFieldWithCopyIcon(gridPane,
++rowIndex,
Res.get("shared.paymentDetails", Res.get("shared.seller")),
sellerPaymentAccountPayload != null
? sellerPaymentAccountPayload.getPaymentDetails()
: "NA")
.second.setMouseTransparent(false);
String title = ""; String title = "";
String agentKeyBaseUserName = ""; String agentKeyBaseUserName = "";
@ -232,7 +250,10 @@ public class ContractWindow extends Overlay<ContractWindow> {
countries = CountryUtil.getCodesString(acceptedCountryCodes); countries = CountryUtil.getCodesString(acceptedCountryCodes);
tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes)); tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes));
} }
Label acceptedCountries = addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.acceptedTakerCountries"), countries).second; Label acceptedCountries = addConfirmationLabelLabel(gridPane,
++rowIndex,
Res.get("shared.acceptedTakerCountries"),
countries).second;
if (tooltip != null) acceptedCountries.setTooltip(new Tooltip()); if (tooltip != null) acceptedCountries.setTooltip(new Tooltip());
} }
@ -242,7 +263,10 @@ public class ContractWindow extends Overlay<ContractWindow> {
} else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS)) { } else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS)) {
String value = Joiner.on(", ").join(acceptedBanks); String value = Joiner.on(", ").join(acceptedBanks);
Tooltip tooltip = new Tooltip(Res.get("shared.acceptedBanks") + value); Tooltip tooltip = new Tooltip(Res.get("shared.acceptedBanks") + value);
Label acceptedBanksTextField = addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.acceptedBanks"), value).second; Label acceptedBanksTextField = addConfirmationLabelLabel(gridPane,
++rowIndex,
Res.get("shared.acceptedBanks"),
value).second;
acceptedBanksTextField.setMouseTransparent(false); acceptedBanksTextField.setMouseTransparent(false);
acceptedBanksTextField.setTooltip(tooltip); acceptedBanksTextField.setTooltip(tooltip);
} }

View file

@ -50,6 +50,7 @@ import bisq.core.trade.Contract;
import bisq.core.trade.TradeDataValidation; import bisq.core.trade.TradeDataValidation;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.ParsingUtils; import bisq.core.util.ParsingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.CoinUtil; import bisq.core.util.coin.CoinUtil;
@ -295,7 +296,7 @@ public class DisputeSummaryWindow extends Overlay<DisputeSummaryWindow> {
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradePrice"), addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradePrice"),
FormattingUtils.formatPrice(contract.getTradePrice())); FormattingUtils.formatPrice(contract.getTradePrice()));
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradeVolume"), addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradeVolume"),
DisplayUtils.formatVolumeWithCode(contract.getTradeVolume())); VolumeUtil.formatVolumeWithCode(contract.getTradeVolume()));
String securityDeposit = Res.getWithColAndCap("shared.buyer") + String securityDeposit = Res.getWithColAndCap("shared.buyer") +
" " + " " +
formatter.formatCoinWithCode(contract.getOfferPayload().getBuyerSecurityDeposit()) + formatter.formatCoinWithCode(contract.getOfferPayload().getBuyerSecurityDeposit()) +

View file

@ -28,7 +28,6 @@ import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.Layout; import bisq.desktop.util.Layout;
import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.locale.BankUtil;
import bisq.core.locale.CountryUtil; import bisq.core.locale.CountryUtil;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.monetary.Price; import bisq.core.monetary.Price;
@ -39,6 +38,7 @@ import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PaymentMethod;
import bisq.core.user.User; import bisq.core.user.User;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.common.crypto.KeyRing; import bisq.common.crypto.KeyRing;
@ -208,20 +208,25 @@ public class OfferDetailsWindow extends Overlay<OfferDetailsWindow> {
if (takeOfferHandlerOptional.isPresent()) { if (takeOfferHandlerOptional.isPresent()) {
addConfirmationLabelLabel(gridPane, ++rowIndex, btcAmount + btcDirectionInfo, addConfirmationLabelLabel(gridPane, ++rowIndex, btcAmount + btcDirectionInfo,
formatter.formatCoinWithCode(tradeAmount)); formatter.formatCoinWithCode(tradeAmount));
addConfirmationLabelLabel(gridPane, ++rowIndex, DisplayUtils.formatVolumeLabel(currencyCode) + fiatDirectionInfo, addConfirmationLabelLabel(gridPane,
DisplayUtils.formatVolumeWithCode(offer.getVolumeByAmount(tradeAmount))); ++rowIndex,
VolumeUtil.formatVolumeLabel(currencyCode) + fiatDirectionInfo,
VolumeUtil.formatVolumeWithCode(offer.getVolumeByAmount(tradeAmount)));
} else { } else {
addConfirmationLabelLabel(gridPane, ++rowIndex, btcAmount + btcDirectionInfo, addConfirmationLabelLabel(gridPane, ++rowIndex, btcAmount + btcDirectionInfo,
formatter.formatCoinWithCode(offer.getAmount())); formatter.formatCoinWithCode(offer.getAmount()));
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("offerDetailsWindow.minBtcAmount"), addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("offerDetailsWindow.minBtcAmount"),
formatter.formatCoinWithCode(offer.getMinAmount())); formatter.formatCoinWithCode(offer.getMinAmount()));
String volume = DisplayUtils.formatVolumeWithCode(offer.getVolume()); String volume = VolumeUtil.formatVolumeWithCode(offer.getVolume());
String minVolume = ""; String minVolume = "";
if (offer.getVolume() != null && offer.getMinVolume() != null && if (offer.getVolume() != null && offer.getMinVolume() != null &&
!offer.getVolume().equals(offer.getMinVolume())) !offer.getVolume().equals(offer.getMinVolume()))
minVolume = " " + Res.get("offerDetailsWindow.min", DisplayUtils.formatVolumeWithCode(offer.getMinVolume())); minVolume = " " + Res.get("offerDetailsWindow.min",
addConfirmationLabelLabel(gridPane, ++rowIndex, VolumeUtil.formatVolumeWithCode(offer.getMinVolume()));
DisplayUtils.formatVolumeLabel(currencyCode) + fiatDirectionInfo, volume + minVolume); addConfirmationLabelLabel(gridPane,
++rowIndex,
VolumeUtil.formatVolumeLabel(currencyCode) + fiatDirectionInfo,
volume + minVolume);
} }
String priceLabel = Res.get("shared.price"); String priceLabel = Res.get("shared.price");

View file

@ -18,14 +18,15 @@
package bisq.desktop.main.overlays.windows; package bisq.desktop.main.overlays.windows;
import bisq.desktop.main.overlays.Overlay; import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.util.DisplayUtils;
import bisq.core.locale.CountryUtil; import bisq.core.locale.CountryUtil;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.payment.payload.SwiftAccountPayload; import bisq.core.payment.payload.SwiftAccountPayload;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.util.VolumeUtil;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import java.util.ArrayList; import java.util.ArrayList;
@ -72,7 +73,8 @@ public class SwiftPaymentDetails extends Overlay<SwiftPaymentDetails> {
addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("payment.swift.headline")); addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("payment.swift.headline"));
gridPane.add(new Label(""), 0, ++rowIndex); // spacer gridPane.add(new Label(""), 0, ++rowIndex); // spacer
addLabelsAndCopy(Res.get("portfolio.pending.step2_buyer.amountToTransfer"), DisplayUtils.formatVolumeWithCode(trade.getTradeVolume())); addLabelsAndCopy(Res.get("portfolio.pending.step2_buyer.amountToTransfer"),
VolumeUtil.formatVolumeWithCode(trade.getTradeVolume()));
addLabelsAndCopy(Res.get(SWIFT_CODE + BANKPOSTFIX), payload.getBankSwiftCode()); addLabelsAndCopy(Res.get(SWIFT_CODE + BANKPOSTFIX), payload.getBankSwiftCode());
addLabelsAndCopy(Res.get(SNAME + BANKPOSTFIX), payload.getBankName()); addLabelsAndCopy(Res.get(SNAME + BANKPOSTFIX), payload.getBankName());
addLabelsAndCopy(Res.get(BRANCH + BANKPOSTFIX), payload.getBankBranch()); addLabelsAndCopy(Res.get(BRANCH + BANKPOSTFIX), payload.getBankBranch());
@ -85,7 +87,8 @@ public class SwiftPaymentDetails extends Overlay<SwiftPaymentDetails> {
addLabelsAndCopy(Res.get(SNAME + INTERMEDIARYPOSTFIX), payload.getIntermediaryName()); addLabelsAndCopy(Res.get(SNAME + INTERMEDIARYPOSTFIX), payload.getIntermediaryName());
addLabelsAndCopy(Res.get(BRANCH + INTERMEDIARYPOSTFIX), payload.getIntermediaryBranch()); addLabelsAndCopy(Res.get(BRANCH + INTERMEDIARYPOSTFIX), payload.getIntermediaryBranch());
addLabelsAndCopy(Res.get(ADDRESS + INTERMEDIARYPOSTFIX), cleanString(payload.getIntermediaryAddress())); addLabelsAndCopy(Res.get(ADDRESS + INTERMEDIARYPOSTFIX), cleanString(payload.getIntermediaryAddress()));
addLabelsAndCopy(Res.get(COUNTRY + INTERMEDIARYPOSTFIX), CountryUtil.getNameAndCode(payload.getIntermediaryCountryCode())); addLabelsAndCopy(Res.get(COUNTRY + INTERMEDIARYPOSTFIX),
CountryUtil.getNameAndCode(payload.getIntermediaryCountryCode()));
} }
gridPane.add(new Label(""), 0, ++rowIndex); // spacer gridPane.add(new Label(""), 0, ++rowIndex); // spacer

View file

@ -39,6 +39,7 @@ import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager; import bisq.core.trade.TradeManager;
import bisq.core.trade.txproof.AssetTxProofResult; import bisq.core.trade.txproof.AssetTxProofResult;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.network.p2p.NodeAddress; import bisq.network.p2p.NodeAddress;
@ -168,8 +169,8 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.btcAmount") + btcDirectionInfo, addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.btcAmount") + btcDirectionInfo,
formatter.formatCoinWithCode(trade.getTradeAmount())); formatter.formatCoinWithCode(trade.getTradeAmount()));
addConfirmationLabelLabel(gridPane, ++rowIndex, addConfirmationLabelLabel(gridPane, ++rowIndex,
DisplayUtils.formatVolumeLabel(offer.getCurrencyCode()) + fiatDirectionInfo, VolumeUtil.formatVolumeLabel(offer.getCurrencyCode()) + fiatDirectionInfo,
DisplayUtils.formatVolumeWithCode(trade.getTradeVolume())); VolumeUtil.formatVolumeWithCode(trade.getTradeVolume()));
addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradePrice"), addConfirmationLabelLabel(gridPane, ++rowIndex, Res.get("shared.tradePrice"),
FormattingUtils.formatPrice(trade.getTradePrice())); FormattingUtils.formatPrice(trade.getTradePrice()));
String paymentMethodText = Res.get(offer.getPaymentMethod().getId()); String paymentMethodText = Res.get(offer.getPaymentMethod().getId());

View file

@ -32,6 +32,7 @@ import bisq.core.offer.OpenOffer;
import bisq.core.trade.Tradable; import bisq.core.trade.Tradable;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
@ -115,7 +116,7 @@ public class ClosedTradesViewModel extends ActivatableWithDataModel<ClosedTrades
} }
Trade trade = (Trade) item.getTradable(); Trade trade = (Trade) item.getTradable();
return DisplayUtils.formatVolume(trade.getTradeVolume(), appendCode); return VolumeUtil.formatVolume(trade.getTradeVolume(), appendCode);
} }
String getVolumeCurrency(ClosedTradableListItem item) { String getVolumeCurrency(ClosedTradableListItem item) {
@ -289,7 +290,7 @@ public class ClosedTradesViewModel extends ActivatableWithDataModel<ClosedTrades
.map(volume -> { .map(volume -> {
return Res.get("closedTradesSummaryWindow.totalAmount.value", return Res.get("closedTradesSummaryWindow.totalAmount.value",
btcFormatter.formatCoin(totalTradeAmount, true), btcFormatter.formatCoin(totalTradeAmount, true),
DisplayUtils.formatVolumeWithCode(volume)); VolumeUtil.formatVolumeWithCode(volume));
}) })
.orElse(""); .orElse("");
} }
@ -305,7 +306,7 @@ public class ClosedTradesViewModel extends ActivatableWithDataModel<ClosedTrades
} else { } else {
monetary = Fiat.valueOf(currencyCode, entry.getValue()); monetary = Fiat.valueOf(currencyCode, entry.getValue());
} }
return DisplayUtils.formatVolumeWithCode(new Volume(monetary)); return VolumeUtil.formatVolumeWithCode(new Volume(monetary));
} }
)); ));
} }

View file

@ -24,6 +24,7 @@ import bisq.desktop.util.DisplayUtils;
import bisq.core.locale.CurrencyUtil; import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -37,7 +38,8 @@ class FailedTradesViewModel extends ActivatableWithDataModel<FailedTradesDataMod
@Inject @Inject
public FailedTradesViewModel(FailedTradesDataModel dataModel, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) { public FailedTradesViewModel(FailedTradesDataModel dataModel,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) {
super(dataModel); super(dataModel);
this.formatter = formatter; this.formatter = formatter;
@ -64,7 +66,7 @@ class FailedTradesViewModel extends ActivatableWithDataModel<FailedTradesDataMod
String getVolume(FailedTradesListItem item) { String getVolume(FailedTradesListItem item) {
if (item != null && item.getTrade() != null) if (item != null && item.getTrade() != null)
return DisplayUtils.formatVolumeWithCode(item.getTrade().getTradeVolume()); return VolumeUtil.formatVolumeWithCode(item.getTrade().getTradeVolume());
else else
return ""; return "";
} }

View file

@ -29,6 +29,7 @@ import bisq.core.monetary.Price;
import bisq.core.offer.Offer; import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer; import bisq.core.offer.OpenOffer;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
@ -125,7 +126,9 @@ class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel>
} }
String getVolume(OpenOfferListItem item) { String getVolume(OpenOfferListItem item) {
return (item != null) ? DisplayUtils.formatVolume(item.getOffer(), false, 0) + " " + item.getOffer().getCurrencyCode() : ""; return (item != null)
? VolumeUtil.formatVolume(item.getOffer(), false, 0) + " " + item.getOffer().getCurrencyCode()
: "";
} }
String getDirectionLabel(OpenOfferListItem item) { String getDirectionLabel(OpenOfferListItem item) {

View file

@ -44,6 +44,7 @@ import bisq.core.trade.Contract;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.user.Preferences; import bisq.core.user.Preferences;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.network.p2p.NodeAddress; import bisq.network.p2p.NodeAddress;
@ -388,7 +389,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
private void onShowInfoForInvalidTrade(Trade trade) { private void onShowInfoForInvalidTrade(Trade trade) {
new Popup().width(900).attention(Res.get("portfolio.pending.failedTrade.info.popup", new Popup().width(900).attention(Res.get("portfolio.pending.failedTrade.info.popup",
getInvalidTradeDetails(trade))) getInvalidTradeDetails(trade)))
.show(); .show();
} }
@ -736,7 +737,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
super.updateItem(item, empty); super.updateItem(item, empty);
if (item != null && !empty) { if (item != null && !empty) {
try { try {
String volume = DisplayUtils.formatVolumeWithCode(item.getTrade().getTradeVolume()); String volume = VolumeUtil.formatVolumeWithCode(item.getTrade().getTradeVolume());
setGraphic(new AutoTooltipLabel(volume)); setGraphic(new AutoTooltipLabel(volume));
} catch (Throwable ignore) { } catch (Throwable ignore) {
log.debug(ignore.toString()); // Stupidity to make Codacy happy log.debug(ignore.toString()); // Stupidity to make Codacy happy

View file

@ -38,6 +38,7 @@ import bisq.core.trade.TradeUtil;
import bisq.core.trade.closed.ClosedTradableManager; import bisq.core.trade.closed.ClosedTradableManager;
import bisq.core.user.User; import bisq.core.user.User;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.validation.BtcAddressValidator; import bisq.core.util.validation.BtcAddressValidator;
@ -309,7 +310,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
public String getFiatVolume() { public String getFiatVolume() {
return dataModel.getTrade() != null return dataModel.getTrade() != null
? DisplayUtils.formatVolumeWithCode(dataModel.getTrade().getTradeVolume()) ? VolumeUtil.formatVolumeWithCode(dataModel.getTrade().getTradeVolume())
: ""; : "";
} }

View file

@ -70,7 +70,6 @@ import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.SetXmrTxKeyWindow; import bisq.desktop.main.overlays.windows.SetXmrTxKeyWindow;
import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel;
import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.Layout; import bisq.desktop.util.Layout;
import bisq.desktop.util.Transitions; import bisq.desktop.util.Transitions;
@ -95,6 +94,7 @@ import bisq.core.payment.payload.WesternUnionAccountPayload;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.trade.TradeDataValidation; import bisq.core.trade.TradeDataValidation;
import bisq.core.user.DontShowAgainLookup; import bisq.core.user.DontShowAgainLookup;
import bisq.core.util.VolumeUtil;
import bisq.common.Timer; import bisq.common.Timer;
import bisq.common.UserThread; import bisq.common.UserThread;
@ -601,7 +601,7 @@ public class BuyerStep2View extends TradeStepView {
String refTextWarn = Res.get("portfolio.pending.step2_buyer.refTextWarn"); String refTextWarn = Res.get("portfolio.pending.step2_buyer.refTextWarn");
String fees = Res.get("portfolio.pending.step2_buyer.fees"); String fees = Res.get("portfolio.pending.step2_buyer.fees");
String id = trade.getShortId(); String id = trade.getShortId();
String amount = DisplayUtils.formatVolumeWithCode(trade.getTradeVolume()); String amount = VolumeUtil.formatVolumeWithCode(trade.getTradeVolume());
if (paymentAccountPayload instanceof AssetsAccountPayload) { if (paymentAccountPayload instanceof AssetsAccountPayload) {
message += Res.get("portfolio.pending.step2_buyer.altcoin", message += Res.get("portfolio.pending.step2_buyer.altcoin",
getCurrencyName(trade), getCurrencyName(trade),

View file

@ -24,9 +24,7 @@ import bisq.desktop.components.indicator.TxConfidenceIndicator;
import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel;
import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.GUIUtil; import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.Layout;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.payment.PaymentAccount; import bisq.core.payment.PaymentAccount;
@ -48,6 +46,7 @@ import bisq.core.trade.Contract;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.trade.txproof.AssetTxProofResult; import bisq.core.trade.txproof.AssetTxProofResult;
import bisq.core.user.DontShowAgainLookup; import bisq.core.user.DontShowAgainLookup;
import bisq.core.util.VolumeUtil;
import bisq.common.Timer; import bisq.common.Timer;
import bisq.common.UserThread; import bisq.common.UserThread;
@ -75,6 +74,9 @@ import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static bisq.desktop.util.FormBuilder.*; import static bisq.desktop.util.FormBuilder.*;
import static bisq.desktop.util.Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE;
import static bisq.desktop.util.Layout.COMPACT_GROUP_DISTANCE;
import static bisq.desktop.util.Layout.FLOATING_LABEL_DISTANCE;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
public class SellerStep3View extends TradeStepView { public class SellerStep3View extends TradeStepView {
@ -195,11 +197,11 @@ public class SellerStep3View extends TradeStepView {
addTradeInfoBlock(); addTradeInfoBlock();
addTitledGroupBg(gridPane, ++gridRow, 3, addTitledGroupBg(gridPane, ++gridRow, 3,
Res.get("portfolio.pending.step3_seller.confirmPaymentReceipt"), Layout.COMPACT_GROUP_DISTANCE); Res.get("portfolio.pending.step3_seller.confirmPaymentReceipt"), COMPACT_GROUP_DISTANCE);
TextFieldWithCopyIcon field = addTopLabelTextFieldWithCopyIcon(gridPane, gridRow, TextFieldWithCopyIcon field = addTopLabelTextFieldWithCopyIcon(gridPane, gridRow,
Res.get("portfolio.pending.step3_seller.amountToReceive"), Res.get("portfolio.pending.step3_seller.amountToReceive"),
model.getFiatVolume(), Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE).second; model.getFiatVolume(), COMPACT_FIRST_ROW_AND_GROUP_DISTANCE).second;
field.setCopyWithoutCurrencyPostFix(true); field.setCopyWithoutCurrencyPostFix(true);
String myPaymentDetails = ""; String myPaymentDetails = "";
@ -250,7 +252,7 @@ public class SellerStep3View extends TradeStepView {
assetTxConfidenceIndicator.setTooltip(new Tooltip()); assetTxConfidenceIndicator.setTooltip(new Tooltip());
assetTxProofResultField.setContentForInfoPopOver(createPopoverLabel(Res.get("setting.info.msg"))); assetTxProofResultField.setContentForInfoPopOver(createPopoverLabel(Res.get("setting.info.msg")));
HBox.setMargin(assetTxConfidenceIndicator, new Insets(Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0)); HBox.setMargin(assetTxConfidenceIndicator, new Insets(FLOATING_LABEL_DISTANCE, 0, 0, 0));
HBox hBox = new HBox(); HBox hBox = new HBox();
HBox.setHgrow(vBox, Priority.ALWAYS); HBox.setHgrow(vBox, Priority.ALWAYS);
@ -259,7 +261,10 @@ public class SellerStep3View extends TradeStepView {
GridPane.setRowIndex(hBox, gridRow); GridPane.setRowIndex(hBox, gridRow);
GridPane.setColumnIndex(hBox, 1); GridPane.setColumnIndex(hBox, 1);
GridPane.setMargin(hBox, new Insets(Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0)); GridPane.setMargin(hBox, new Insets(COMPACT_FIRST_ROW_AND_GROUP_DISTANCE + FLOATING_LABEL_DISTANCE,
0,
0,
0));
gridPane.getChildren().add(hBox); gridPane.getChildren().add(hBox);
} }
@ -397,7 +402,7 @@ public class SellerStep3View extends TradeStepView {
PaymentAccountPayload paymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload(); PaymentAccountPayload paymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload();
String key = "confirmPayment" + trade.getId(); String key = "confirmPayment" + trade.getId();
String message = ""; String message = "";
String tradeVolumeWithCode = DisplayUtils.formatVolumeWithCode(trade.getTradeVolume()); String tradeVolumeWithCode = VolumeUtil.formatVolumeWithCode(trade.getTradeVolume());
String currencyName = getCurrencyName(trade); String currencyName = getCurrencyName(trade);
String part1 = Res.get("portfolio.pending.step3_seller.part", currencyName); String part1 = Res.get("portfolio.pending.step3_seller.part", currencyName);
if (paymentAccountPayload instanceof AssetsAccountPayload) { if (paymentAccountPayload instanceof AssetsAccountPayload) {
@ -405,12 +410,17 @@ public class SellerStep3View extends TradeStepView {
String explorerOrWalletString = isXmrTrade() ? String explorerOrWalletString = isXmrTrade() ?
Res.get("portfolio.pending.step3_seller.altcoin.wallet", currencyName) : Res.get("portfolio.pending.step3_seller.altcoin.wallet", currencyName) :
Res.get("portfolio.pending.step3_seller.altcoin.explorer", currencyName); Res.get("portfolio.pending.step3_seller.altcoin.explorer", currencyName);
message = Res.get("portfolio.pending.step3_seller.altcoin", part1, explorerOrWalletString, address, tradeVolumeWithCode, currencyName); message = Res.get("portfolio.pending.step3_seller.altcoin",
part1,
explorerOrWalletString,
address,
tradeVolumeWithCode,
currencyName);
} else { } else {
if (paymentAccountPayload instanceof USPostalMoneyOrderAccountPayload) { if (paymentAccountPayload instanceof USPostalMoneyOrderAccountPayload) {
message = Res.get("portfolio.pending.step3_seller.postal", part1, tradeVolumeWithCode); message = Res.get("portfolio.pending.step3_seller.postal", part1, tradeVolumeWithCode);
} else if (paymentAccountPayload instanceof CashByMailAccountPayload) { } else if (paymentAccountPayload instanceof CashByMailAccountPayload) {
message = Res.get("portfolio.pending.step3_seller.cashByMail", part1, tradeVolumeWithCode); message = Res.get("portfolio.pending.step3_seller.cashByMail", part1, tradeVolumeWithCode);
} else if (!(paymentAccountPayload instanceof WesternUnionAccountPayload) && } else if (!(paymentAccountPayload instanceof WesternUnionAccountPayload) &&
!(paymentAccountPayload instanceof HalCashAccountPayload) && !(paymentAccountPayload instanceof HalCashAccountPayload) &&
!(paymentAccountPayload instanceof F2FAccountPayload) && !(paymentAccountPayload instanceof F2FAccountPayload) &&

View file

@ -3,33 +3,27 @@ package bisq.desktop.util;
import bisq.core.locale.CurrencyUtil; import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.GlobalSettings; import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.monetary.Altcoin;
import bisq.core.monetary.Price; import bisq.core.monetary.Price;
import bisq.core.monetary.Volume; import bisq.core.monetary.Volume;
import bisq.core.offer.Offer; import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload; import bisq.core.offer.OfferPayload;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.ParsingUtils; import bisq.core.util.ParsingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.Fiat;
import org.bitcoinj.utils.MonetaryFormat;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.lang3.time.DurationFormatUtils;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.Date; import java.util.Date;
import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -37,7 +31,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class DisplayUtils { public class DisplayUtils {
private static final int SCALE = 3; private static final int SCALE = 3;
private static final MonetaryFormat FIAT_VOLUME_FORMAT = new MonetaryFormat().shift(0).minDecimals(0).repeatOptionalDecimals(0, 0);
public static String formatDateTime(Date date) { public static String formatDateTime(Date date) {
return FormattingUtils.formatDateTime(date, true); return FormattingUtils.formatDateTime(date, true);
@ -92,78 +85,6 @@ public class DisplayUtils {
return value ? Res.get("shared.yes") : Res.get("shared.no"); return value ? Res.get("shared.yes") : Res.get("shared.no");
} }
///////////////////////////////////////////////////////////////////////////////////////////
// Volume
///////////////////////////////////////////////////////////////////////////////////////////
public static String formatVolume(Offer offer, Boolean decimalAligned, int maxNumberOfDigits) {
return formatVolume(offer, decimalAligned, maxNumberOfDigits, true);
}
public static String formatVolume(Offer offer, Boolean decimalAligned, int maxNumberOfDigits, boolean showRange) {
String formattedVolume = offer.isRange() && showRange ? formatVolume(offer.getMinVolume()) + FormattingUtils.RANGE_SEPARATOR + formatVolume(offer.getVolume()) : formatVolume(offer.getVolume());
if (decimalAligned) {
formattedVolume = FormattingUtils.fillUpPlacesWithEmptyStrings(formattedVolume, maxNumberOfDigits);
}
return formattedVolume;
}
public static String formatLargeFiat(double value, String currency) {
if (value <= 0) {
return "0";
}
NumberFormat numberFormat = DecimalFormat.getInstance(Locale.US);
numberFormat.setGroupingUsed(true);
return numberFormat.format(value) + " " + currency;
}
public static String formatLargeFiatWithUnitPostFix(double value, String currency) {
if (value <= 0) {
return "0";
}
String[] units = new String[]{"", "K", "M", "B"};
int digitGroups = (int) (Math.log10(value) / Math.log10(1000));
return new DecimalFormat("#,##0.###").format(value / Math.pow(1000, digitGroups)) + units[digitGroups] + " " + currency;
}
public static String formatVolume(Volume volume) {
return formatVolume(volume, FIAT_VOLUME_FORMAT, false);
}
private static String formatVolume(Volume volume, MonetaryFormat fiatVolumeFormat, boolean appendCurrencyCode) {
if (volume != null) {
Monetary monetary = volume.getMonetary();
if (monetary instanceof Fiat)
return FormattingUtils.formatFiat((Fiat) monetary, fiatVolumeFormat, appendCurrencyCode);
else
return FormattingUtils.formatAltcoinVolume((Altcoin) monetary, appendCurrencyCode);
} else {
return "";
}
}
public static String formatVolumeWithCode(Volume volume) {
return formatVolume(volume, true);
}
public static String formatVolume(Volume volume, boolean appendCode) {
return formatVolume(volume, FIAT_VOLUME_FORMAT, appendCode);
}
public static String formatAverageVolumeWithCode(Volume volume) {
return formatVolume(volume, FIAT_VOLUME_FORMAT.minDecimals(2), true);
}
public static String formatVolumeLabel(String currencyCode) {
return formatVolumeLabel(currencyCode, "");
}
public static String formatVolumeLabel(String currencyCode, String postFix) {
return Res.get("formatter.formatVolumeLabel",
currencyCode, postFix);
}
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Offer direction // Offer direction
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -284,7 +205,7 @@ public class DisplayUtils {
CoinFormatter formatter) { CoinFormatter formatter) {
String feeInBtc = makerFeeAsCoin != null ? formatter.formatCoinWithCode(makerFeeAsCoin) : Res.get("shared.na"); String feeInBtc = makerFeeAsCoin != null ? formatter.formatCoinWithCode(makerFeeAsCoin) : Res.get("shared.na");
if (optionalFeeInFiat != null && optionalFeeInFiat.isPresent()) { if (optionalFeeInFiat != null && optionalFeeInFiat.isPresent()) {
String feeInFiat = formatAverageVolumeWithCode(optionalFeeInFiat.get()); String feeInFiat = VolumeUtil.formatAverageVolumeWithCode(optionalFeeInFiat.get());
return Res.get("feeOptionWindow.fee", feeInBtc, feeInFiat); return Res.get("feeOptionWindow.fee", feeInBtc, feeInFiat);
} else { } else {
return feeInBtc; return feeInBtc;

View file

@ -54,6 +54,7 @@ import bisq.core.user.Preferences;
import bisq.core.user.User; import bisq.core.user.User;
import bisq.core.user.UserPayload; import bisq.core.user.UserPayload;
import bisq.core.util.FormattingUtils; import bisq.core.util.FormattingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.CoinUtil; import bisq.core.util.coin.CoinUtil;
@ -224,7 +225,7 @@ public class GUIUtil {
persistenceManager.persistNow(() -> { persistenceManager.persistNow(() -> {
persistenceManager.shutdown(); persistenceManager.shutdown();
new Popup().feedback(Res.get("guiUtil.accountExport.savedToPath", new Popup().feedback(Res.get("guiUtil.accountExport.savedToPath",
Paths.get(directory, fileName).toAbsolutePath())) Paths.get(directory, fileName).toAbsolutePath()))
.show(); .show();
}); });
} }
@ -801,7 +802,7 @@ public class GUIUtil {
.dontShowAgainId(key) .dontShowAgainId(key)
.actionButtonTextWithGoTo("navigation.dao.networkMonitor") .actionButtonTextWithGoTo("navigation.dao.networkMonitor")
.onAction(() -> { .onAction(() -> {
navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class); navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class);
}) })
.show(), 5, TimeUnit.SECONDS); .show(), 5, TimeUnit.SECONDS);
} }
@ -1172,7 +1173,7 @@ public class GUIUtil {
Volume bsqAmountAsVolume = Volume.parse(bsqAmountAsString, "BSQ"); Volume bsqAmountAsVolume = Volume.parse(bsqAmountAsString, "BSQ");
Coin requiredBtc = bsqPrice.getAmountByVolume(bsqAmountAsVolume); Coin requiredBtc = bsqPrice.getAmountByVolume(bsqAmountAsVolume);
Volume volumeByAmount = usdPrice.getVolumeByAmount(requiredBtc); Volume volumeByAmount = usdPrice.getVolumeByAmount(requiredBtc);
return DisplayUtils.formatAverageVolumeWithCode(volumeByAmount); return VolumeUtil.formatAverageVolumeWithCode(volumeByAmount);
} }
public static MaterialDesignIcon getIconForSignState(AccountAgeWitnessService.SignState state) { public static MaterialDesignIcon getIconForSignState(AccountAgeWitnessService.SignState state) {

View file

@ -4,8 +4,9 @@ import bisq.core.locale.Res;
import bisq.core.monetary.Volume; import bisq.core.monetary.Volume;
import bisq.core.offer.Offer; import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload; import bisq.core.offer.OfferPayload;
import bisq.core.util.coin.ImmutableCoinFormatter; import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter; import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.ImmutableCoinFormatter;
import bisq.common.config.Config; import bisq.common.config.Config;
@ -49,9 +50,9 @@ public class DisplayUtilsTest {
@Test @Test
public void testFormatVolume() { public void testFormatVolume() {
assertEquals("1", DisplayUtils.formatVolume(make(btcUsdOffer), true, 4)); assertEquals("1", VolumeUtil.formatVolume(make(btcUsdOffer), true, 4));
assertEquals("100", DisplayUtils.formatVolume(make(usdVolume))); assertEquals("100", VolumeUtil.formatVolume(make(usdVolume)));
assertEquals("1775", DisplayUtils.formatVolume(make(usdVolume.but(with(volumeString, "1774.62"))))); assertEquals("1775", VolumeUtil.formatVolume(make(usdVolume.but(with(volumeString, "1774.62")))));
} }
@Test @Test
@ -61,7 +62,7 @@ public class DisplayUtilsTest {
when(offer.getMinVolume()).thenReturn(btc); when(offer.getMinVolume()).thenReturn(btc);
when(offer.getVolume()).thenReturn(btc); when(offer.getVolume()).thenReturn(btc);
assertEquals("0.10000000", DisplayUtils.formatVolume(offer.getVolume())); assertEquals("0.10000000", VolumeUtil.formatVolume(offer.getVolume()));
} }
@Test @Test
@ -73,7 +74,7 @@ public class DisplayUtilsTest {
when(offer.getMinVolume()).thenReturn(btcMin); when(offer.getMinVolume()).thenReturn(btcMin);
when(offer.getVolume()).thenReturn(btcMax); when(offer.getVolume()).thenReturn(btcMax);
assertEquals("0.10000000 - 0.25000000", DisplayUtils.formatVolume(offer, false, 0)); assertEquals("0.10000000 - 0.25000000", VolumeUtil.formatVolume(offer, false, 0));
} }
@Test @Test
@ -82,7 +83,7 @@ public class DisplayUtilsTest {
when(offer.getMinVolume()).thenReturn(null); when(offer.getMinVolume()).thenReturn(null);
when(offer.getVolume()).thenReturn(null); when(offer.getVolume()).thenReturn(null);
assertEquals("", DisplayUtils.formatVolume(offer.getVolume())); assertEquals("", VolumeUtil.formatVolume(offer.getVolume()));
} }
@Test @Test