Add formatPrice, formatVoluem and formatAmount methods. Apply inverted price to popups statistics and tables

This commit is contained in:
Manfred Karrer 2016-08-19 21:56:22 +02:00
parent a51fa4850d
commit 57e3c19b89
16 changed files with 78 additions and 46 deletions

View file

@ -197,7 +197,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offer != null && offer.getPrice() != null) {
setText(formatter.formatFiat(offer.getPrice()));
setText(formatter.formatPrice(offer.getPrice()));
model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
}
}
@ -212,7 +212,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
model.priceFeedService.currenciesUpdateFlagProperty().addListener(listener);
setText("N/A");
} else {
setText(formatter.formatFiat(offer.getPrice()));
setText(formatter.formatPrice(offer.getPrice()));
}
} else {
if (listener != null)
@ -268,7 +268,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offer != null && offer.getPrice() != null) {
setText(formatter.formatFiat(offer.getOfferVolume()));
setText(formatter.formatVolume(offer.getOfferVolume()));
model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
}
}
@ -283,7 +283,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
model.priceFeedService.currenciesUpdateFlagProperty().addListener(listener);
setText("N/A");
} else {
setText(formatter.formatFiat(offer.getOfferVolume()));
setText(formatter.formatVolume(offer.getOfferVolume()));
}
} else {
if (listener != null)

View file

@ -93,7 +93,7 @@ public class SpreadView extends ActivatableViewAndModel<GridPane, SpreadViewMode
numberOfBuyOffersColumn.setComparator((o1, o2) -> Integer.valueOf(o1.numberOfBuyOffers).compareTo(o2.numberOfBuyOffers));
numberOfSellOffersColumn.setComparator((o1, o2) -> Integer.valueOf(o1.numberOfSellOffers).compareTo(o2.numberOfSellOffers));
totalAmountColumn.setComparator((o1, o2) -> o1.totalAmount.compareTo(o2.totalAmount));
spreadColumn.setComparator((o1, o2) -> o1.spread != null && o2.spread != null ? formatter.formatFiatWithCode(o1.spread).compareTo(formatter.formatFiatWithCode(o2.spread)) : 0);
spreadColumn.setComparator((o1, o2) -> o1.spread != null && o2.spread != null ? formatter.formatVolumeWithCode(o1.spread).compareTo(formatter.formatVolumeWithCode(o2.spread)) : 0);
numberOfOffersColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(numberOfOffersColumn);
@ -286,7 +286,7 @@ public class SpreadView extends ActivatableViewAndModel<GridPane, SpreadViewMode
super.updateItem(item, empty);
if (item != null && !empty) {
if (item.spread != null)
setText(formatter.formatFiatWithCode(item.spread));
setText(formatter.formatVolumeWithCode(item.spread));
else
setText("-");
} else {

View file

@ -233,7 +233,7 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
priceAxisY.setTickLabelFormatter(new StringConverter<Number>() {
@Override
public String toString(Number object) {
return formatter.formatFiat(Fiat.valueOf(model.getCurrencyCode(), new Double((double) object).longValue()));
return formatter.formatPrice(Fiat.valueOf(model.getCurrencyCode(), new Double((double) object).longValue()));
}
@Override
@ -245,7 +245,7 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
priceChart = new CandleStickChart(priceAxisX, priceAxisY, new StringConverter<Number>() {
@Override
public String toString(Number object) {
return formatter.formatFiatWithCode(Fiat.valueOf(model.getCurrencyCode(), (long) object));
return formatter.formatPriceWithCode(Fiat.valueOf(model.getCurrencyCode(), (long) object));
}
@Override
@ -461,8 +461,8 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
super.updateItem(item, empty);
if (item != null)
setText(model.showAllTradeCurrenciesProperty.get() ?
formatter.formatFiatWithCode(item.getTradePrice()) :
formatter.formatFiat(item.getTradePrice()));
formatter.formatPriceWithCode(item.getTradePrice()) :
formatter.formatPrice(item.getTradePrice()));
else
setText("");
}
@ -487,8 +487,8 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
super.updateItem(item, empty);
if (item != null)
setText(model.showAllTradeCurrenciesProperty.get() ?
formatter.formatFiatWithCode(item.getTradeVolume()) :
formatter.formatFiat(item.getTradeVolume()));
formatter.formatVolumeWithCode(item.getTradeVolume()) :
formatter.formatVolume(item.getTradeVolume()));
else
setText("");
}

View file

@ -286,9 +286,9 @@ class OfferBookViewModel extends ActivatableViewModel {
Fiat minOfferVolume = item.getOffer().getMinOfferVolume();
if (offerVolume != null && minOfferVolume != null) {
if (showAllTradeCurrenciesProperty.get())
return formatter.formatFiatWithCode(offerVolume) + " (" + formatter.formatFiatWithCode(minOfferVolume) + ")";
return formatter.formatVolumeWithCode(offerVolume) + " (" + formatter.formatVolumeWithCode(minOfferVolume) + ")";
else
return formatter.formatFiat(offerVolume) + " (" + formatter.formatFiat(minOfferVolume) + ")";
return formatter.formatVolume(offerVolume) + " (" + formatter.formatVolume(minOfferVolume) + ")";
} else {
return "N/A";
}

View file

@ -163,7 +163,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
}
amountRange = formatter.formatCoin(offer.getMinAmount()) + " - " + formatter.formatCoin(offer.getAmount());
price = formatter.formatFiat(dataModel.tradePrice);
price = formatter.formatPrice(dataModel.tradePrice);
marketPriceMargin = formatter.formatPercentagePrice(offer.getMarketPriceMargin());
paymentLabel = BSResources.get("takeOffer.fundsBox.paymentLabel", offer.getShortId());
@ -399,8 +399,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
///////////////////////////////////////////////////////////////////////////////////////////
private void addBindings() {
volume.bind(createStringBinding(() -> formatter.formatFiat(dataModel.volumeAsFiat.get()), dataModel.volumeAsFiat));
volume.bind(createStringBinding(() -> formatter.formatVolume(dataModel.volumeAsFiat.get()), dataModel.volumeAsFiat));
if (dataModel.getDirection() == Offer.Direction.SELL) {
volumeDescriptionLabel.set(BSResources.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getCurrencyCode()));

View file

@ -25,7 +25,6 @@ import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.Layout;
import io.bitsquare.locale.BSResources;
import io.bitsquare.locale.CountryUtil;
import io.bitsquare.locale.CurrencyUtil;
import io.bitsquare.payment.PaymentAccountContractData;
import io.bitsquare.payment.PaymentMethod;
import io.bitsquare.trade.Contract;
@ -118,9 +117,10 @@ public class ContractWindow extends Overlay<ContractWindow> {
addLabelTextField(gridPane, ++rowIndex, "Offer date:", formatter.formatDateTime(offer.getDate()));
addLabelTextField(gridPane, ++rowIndex, "Trade date:", formatter.formatDateTime(dispute.getTradeDate()));
addLabelTextField(gridPane, ++rowIndex, "Trade type:", formatter.getDirectionBothSides(offer.getDirection()));
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatFiat(contract.getTradePrice()) + " " + offer.getCurrencyCode());
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPriceWithCode(contract.getTradePrice()));
addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
addLabelTextField(gridPane, ++rowIndex, CurrencyUtil.getNameByCode(offer.getCurrencyCode()) + " amount:", formatter.formatFiatWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(offer.getCurrencyCode(), ":"),
formatter.formatVolumeWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Buyer bitcoin address:",
contract.getBuyerPayoutAddressString()).second.setMouseTransparent(false);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Seller bitcoin address:",

View file

@ -243,8 +243,8 @@ public class DisputeSummaryWindow extends Overlay<DisputeSummaryWindow> {
}
addLabelTextField(gridPane, ++rowIndex, "Traders role:", role);
addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatFiatWithCode(contract.getTradePrice()));
addLabelTextField(gridPane, ++rowIndex, "Trade volume:", formatter.formatFiatWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPriceWithCode(contract.getTradePrice()));
addLabelTextField(gridPane, ++rowIndex, "Trade volume:", formatter.formatVolumeWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
}
private void addCheckboxes() {

View file

@ -34,7 +34,6 @@ import io.bitsquare.gui.util.Layout;
import io.bitsquare.locale.BSResources;
import io.bitsquare.locale.BankUtil;
import io.bitsquare.locale.CountryUtil;
import io.bitsquare.locale.CurrencyUtil;
import io.bitsquare.payment.PaymentAccount;
import io.bitsquare.payment.PaymentMethod;
import io.bitsquare.trade.offer.Offer;
@ -174,19 +173,20 @@ public class OfferDetailsWindow extends Overlay<OfferDetailsWindow> {
}
if (takeOfferHandlerOptional.isPresent()) {
addLabelTextField(gridPane, ++rowIndex, "Bitcoin amount" + btcDirectionInfo, formatter.formatCoinWithCode(tradeAmount));
addLabelTextField(gridPane, ++rowIndex, CurrencyUtil.getNameByCode(offer.getCurrencyCode()) + " amount" + fiatDirectionInfo, formatter.formatFiatWithCode(offer.getVolumeByAmount(tradeAmount)));
addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(offer.getCurrencyCode()) + fiatDirectionInfo,
formatter.formatVolumeWithCode(offer.getVolumeByAmount(tradeAmount)));
} else {
addLabelTextField(gridPane, ++rowIndex, "Bitcoin amount" + btcDirectionInfo, formatter.formatCoinWithCode(offer.getAmount()));
addLabelTextField(gridPane, ++rowIndex, "Min. bitcoin amount:", formatter.formatCoinWithCode(offer.getMinAmount()));
String amount = formatter.formatFiatWithCode(offer.getOfferVolume());
String amount = formatter.formatAmountWithCode(offer.getOfferVolume());
String minVolume = "";
if (!offer.getAmount().equals(offer.getMinAmount()))
minVolume = " (min. " + formatter.formatFiatWithCode(offer.getMinOfferVolume()) + ")";
addLabelTextField(gridPane, ++rowIndex, CurrencyUtil.getNameByCode(offer.getCurrencyCode()) + " amount" + fiatDirectionInfo, amount + minVolume);
minVolume = " (min. " + formatter.formatVolumeWithCode(offer.getMinOfferVolume()) + ")";
addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(offer.getCurrencyCode()) + fiatDirectionInfo, amount + minVolume);
}
if (takeOfferHandlerOptional.isPresent()) {
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatFiat(tradePrice) + " " + offer.getCurrencyCode() + "/" + "BTC");
addLabelTextField(gridPane, ++rowIndex, "Price:", formatter.formatPriceWithCode(tradePrice));
} else {
Fiat price = offer.getPrice();
if (offer.getUseMarketBasedPrice()) {

View file

@ -25,7 +25,6 @@ import io.bitsquare.gui.main.overlays.Overlay;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.Layout;
import io.bitsquare.locale.BSResources;
import io.bitsquare.locale.CurrencyUtil;
import io.bitsquare.payment.PaymentAccountContractData;
import io.bitsquare.trade.Contract;
import io.bitsquare.trade.Trade;
@ -127,7 +126,7 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
}
addLabelTextField(gridPane, ++rowIndex, "Bitcoin amount" + btcDirectionInfo, formatter.formatCoinWithCode(trade.getTradeAmount()));
addLabelTextField(gridPane, ++rowIndex, CurrencyUtil.getNameByCode(offer.getCurrencyCode()) + " amount" + fiatDirectionInfo, formatter.formatFiatWithCode(trade.getTradeVolume()));
addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(offer.getCurrencyCode()) + fiatDirectionInfo, formatter.formatVolumeWithCode(trade.getTradeVolume()));
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPriceWithCode(trade.getTradePrice()));
addLabelTextField(gridPane, ++rowIndex, "Payment method:", BSResources.get(offer.getPaymentMethod().getId()));

View file

@ -61,14 +61,14 @@ class ClosedTradesViewModel extends ActivatableWithDataModel<ClosedTradesDataMod
return "";
Tradable tradable = item.getTradable();
if (tradable instanceof Trade)
return formatter.formatFiat(((Trade) tradable).getTradePrice());
return formatter.formatPrice(((Trade) tradable).getTradePrice());
else
return formatter.formatFiat(tradable.getOffer().getPrice());
return formatter.formatPrice(tradable.getOffer().getPrice());
}
String getVolume(ClosedTradableListItem item) {
if (item != null && item.getTradable() instanceof Trade)
return formatter.formatFiatWithCode(((Trade) item.getTradable()).getTradeVolume());
return formatter.formatVolumeWithCode(((Trade) item.getTradable()).getTradeVolume());
else if (item != null && item.getTradable() instanceof OpenOffer)
return "-";
else

View file

@ -51,12 +51,12 @@ class FailedTradesViewModel extends ActivatableWithDataModel<FailedTradesDataMod
}
String getPrice(FailedTradesListItem item) {
return (item != null) ? formatter.formatFiat(item.getTrade().getTradePrice()) : "";
return (item != null) ? formatter.formatPrice(item.getTrade().getTradePrice()) : "";
}
String getVolume(FailedTradesListItem item) {
if (item != null && item.getTrade() != null)
return formatter.formatFiatWithCode(item.getTrade().getTradeVolume());
return formatter.formatVolumeWithCode(item.getTrade().getTradeVolume());
else
return "";
}

View file

@ -384,7 +384,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
public void updateItem(final PendingTradesListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty)
setText(formatter.formatFiatWithCode(item.getTrade().getTradeVolume()));
setText(formatter.formatVolumeWithCode(item.getTrade().getTradeVolume()));
else
setText(null);
}

View file

@ -247,7 +247,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
}
public String getFiatAmount() {
return dataModel.getTrade() != null ? formatter.formatFiatWithCode(dataModel.getTrade().getTradeVolume()) : "";
return dataModel.getTrade() != null ? formatter.formatAmountWithCode(dataModel.getTrade().getTradeVolume()) : "";
}
// summary
@ -256,7 +256,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
}
public String getFiatVolume() {
return dataModel.getTrade() != null ? formatter.formatFiatWithCode(dataModel.getTrade().getTradeVolume()) : "";
return dataModel.getTrade() != null ? formatter.formatVolumeWithCode(dataModel.getTrade().getTradeVolume()) : "";
}
public String getTotalFees() {

View file

@ -72,7 +72,7 @@ public class BuyerStep2View extends TradeStepView {
"(You can wait for more confirmations if you want - 6 confirmations are considered as very secure.)\n\n" +
"Please transfer from your external " +
CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode()) + " wallet\n" +
model.formatter.formatFiatWithCode(trade.getTradeVolume()) + " to the bitcoin seller.\n\n" +
model.formatter.formatVolumeWithCode(trade.getTradeVolume()) + " to the bitcoin seller.\n\n" +
"Here are the payment account details of the bitcoin seller:\n" +
"" + paymentAccountContractData.getPaymentDetailsForTradePopup() + ".\n\n" +
"(You can copy & paste the values from the main screen after closing that popup.)";
@ -80,7 +80,7 @@ public class BuyerStep2View extends TradeStepView {
message = "Your trade has reached at least one blockchain confirmation.\n" +
"(You can wait for more confirmations if you want - 6 confirmations are considered as very secure.)\n\n" +
"Please go to your online banking web page and pay " +
model.formatter.formatFiatWithCode(trade.getTradeVolume()) + " to the bitcoin seller.\n\n" +
model.formatter.formatVolumeWithCode(trade.getTradeVolume()) + " to the bitcoin seller.\n\n" +
"Here are the payment account details of the bitcoin seller:\n" +
"" + paymentAccountContractData.getPaymentDetailsForTradePopup() + ".\n" +
"(You can copy & paste the values from the main screen after closing that popup.)\n\n" +

View file

@ -70,7 +70,7 @@ public class SellerStep3View extends TradeStepView {
PaymentAccountContractData paymentAccountContractData = model.dataModel.getSellersPaymentAccountContractData();
String key = "confirmPayment" + trade.getId();
String message;
String tradeAmountWithCode = model.formatter.formatFiatWithCode(trade.getTradeVolume());
String tradeVolumeWithCode = model.formatter.formatVolumeWithCode(trade.getTradeVolume());
String currencyName = CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode());
if (paymentAccountContractData instanceof CryptoCurrencyAccountContractData) {
String address = ((CryptoCurrencyAccountContractData) paymentAccountContractData).getAddress();
@ -79,13 +79,13 @@ public class SellerStep3View extends TradeStepView {
" blockchain explorer if the transaction to your receiving address\n" +
"" + address + "\n" +
"has already sufficient blockchain confirmations.\n" +
"The payment amount has to be " + tradeAmountWithCode + "\n\n" +
"The payment amount has to be " + tradeVolumeWithCode + "\n\n" +
"You can copy & paste your " + currencyName + " address from the main screen after " +
"closing that popup.";
} else {
message = "Your trading partner has confirmed that he initiated the " + currencyName + " payment.\n\n" +
"Please go to your online banking web page and check if you have received " +
tradeAmountWithCode + " from the bitcoin buyer.\n\n" +
tradeVolumeWithCode + " from the bitcoin buyer.\n\n" +
"The trade ID (\"reason for payment\" text) of the transaction is: \"" + trade.getShortId() + "\"";
Optional<String> optionalHolderName = getOptionalHolderName();
if (optionalHolderName.isPresent()) {

View file

@ -204,7 +204,7 @@ public class BSFormatter {
}
}
public String formatFiatWithCode(Fiat fiat) {
private String formatFiatWithCode(Fiat fiat) {
if (fiat != null) {
try {
return fiatFormat.noCode().format(fiat).toString() + " " + fiat.getCurrencyCode();
@ -258,6 +258,40 @@ public class BSFormatter {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Amount
///////////////////////////////////////////////////////////////////////////////////////////
public String formatAmount(Fiat fiat) {
return formatFiat(fiat);
}
public String formatAmountWithCode(Fiat fiat) {
return formatFiatWithCode(fiat);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Volume
///////////////////////////////////////////////////////////////////////////////////////////
public String formatVolume(Fiat fiat) {
return formatFiat(fiat);
}
public String formatVolumeWithCode(Fiat fiat) {
return formatFiatWithCode(fiat);
}
public String formatVolumeLabel(String currencyCode) {
return formatVolumeLabel(currencyCode, "");
}
public String formatVolumeLabel(String currencyCode, String postFix) {
return CurrencyUtil.getNameByCode(currencyCode) + " amount" + postFix;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Price
///////////////////////////////////////////////////////////////////////////////////////////
@ -267,9 +301,9 @@ public class BSFormatter {
final String currencyCode = fiat.getCurrencyCode();
if (CurrencyUtil.isCryptoCurrency(currencyCode)) {
final double value = fiat.value != 0 ? 10000D / fiat.value : 0;
return MathUtils.roundDouble(value, 8) + " " + getCurrencyPair(currencyCode);
return String.valueOf(MathUtils.roundDouble(value, 8));
} else
return formatFiat(fiat) + " " + getCurrencyPair(currencyCode);
return formatFiat(fiat);
} else {
return "N/A";
}