Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add toggle for displaying volume in tradestatistics chart in USD #5066

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;

import java.time.LocalDateTime;
import java.time.ZoneId;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -71,6 +74,8 @@
public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload,
CapabilityRequiringPayload, DateSortedTruncatablePayload {

@JsonExclude
private transient static final ZoneId ZONE_ID = ZoneId.systemDefault();

public static TradeStatistics3 from(Trade trade,
@Nullable String referralId,
Expand Down Expand Up @@ -186,6 +191,11 @@ private enum PaymentMethodMapper {
@JsonExclude
private transient final Date dateObj;

@JsonExclude
private transient Volume volume = null;
@JsonExclude
private transient LocalDateTime localDateTime;

public TradeStatistics3(String currency,
long price,
long amount,
Expand Down Expand Up @@ -328,6 +338,13 @@ public Date getDate() {
return dateObj;
}

public LocalDateTime getLocalDateTime() {
if (localDateTime == null) {
localDateTime = dateObj.toInstant().atZone(ZONE_ID).toLocalDateTime();
}
return localDateTime;
}

public long getDateAsLong() {
return date;
}
Expand All @@ -350,21 +367,29 @@ public String getPaymentMethod() {
}
}

private transient Price priceObj;

public Price getTradePrice() {
return Price.valueOf(currency, price);
if (priceObj == null) {
priceObj = Price.valueOf(currency, price);
}
return priceObj;
}

public Coin getTradeAmount() {
return Coin.valueOf(amount);
}

public Volume getTradeVolume() {
if (getTradePrice().getMonetary() instanceof Altcoin) {
return new Volume(new AltcoinExchangeRate((Altcoin) getTradePrice().getMonetary()).coinToAltcoin(getTradeAmount()));
} else {
Volume volume = new Volume(new ExchangeRate((Fiat) getTradePrice().getMonetary()).coinToFiat(getTradeAmount()));
return VolumeUtil.getRoundedFiatVolume(volume);
if (volume == null) {
if (getTradePrice().getMonetary() instanceof Altcoin) {
volume = new Volume(new AltcoinExchangeRate((Altcoin) getTradePrice().getMonetary()).coinToAltcoin(getTradeAmount()));
} else {
Volume exactVolume = new Volume(new ExchangeRate((Fiat) getTradePrice().getMonetary()).coinToFiat(getTradeAmount()));
volume = VolumeUtil.getRoundedFiatVolume(exactVolume);
}
}
return volume;
}

public boolean isValid() {
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/bisq/core/user/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public Optional<Double> getAsOptionalDouble(CookieKey key) {
}
}

public void putAsBoolean(CookieKey key, boolean value) {
put(key, value ? "1" : "0");
}

public Optional<Boolean> getAsOptionalBoolean(CookieKey key) {
return containsKey(key) ?
Optional.of(get(key).equals("1")) :
Optional.empty();
}

public Map<String, String> toProtoMessage() {
Map<String, String> protoMap = new HashMap<>();
this.forEach((key, value) -> protoMap.put(key.name(), value));
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/user/CookieKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public enum CookieKey {
STAGE_X,
STAGE_Y,
STAGE_W,
STAGE_H
STAGE_H,
TRADE_STAT_CHART_USE_USD
}
3 changes: 2 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,15 @@ market.spread.expanded=Expanded view

# TradesChartsView
market.trades.nrOfTrades=Trades: {0}
market.trades.tooltip.volumeBar=Volume: {0}\nNo. of trades: {1}\nDate: {2}
market.trades.tooltip.volumeBar=Volume: {0} / {1}\nNo. of trades: {2}\nDate: {3}
market.trades.tooltip.candle.open=Open:
market.trades.tooltip.candle.close=Close:
market.trades.tooltip.candle.high=High:
market.trades.tooltip.candle.low=Low:
market.trades.tooltip.candle.average=Average:
market.trades.tooltip.candle.median=Median:
market.trades.tooltip.candle.date=Date:
market.trades.showVolumeInUSD=Show volume in USD

####################################################################
# OfferView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class TradeStatistics3ListItem {
private final TradeStatistics3 tradeStatistics3;
private final CoinFormatter coinFormatter;
private final boolean showAllTradeCurrencies;
private String dateString;
private String market;
private String priceString;
private String volumeString;
private String paymentMethodString;
private String amountString;

public TradeStatistics3ListItem(@Nullable TradeStatistics3 tradeStatistics3,
CoinFormatter coinFormatter,
Expand All @@ -44,31 +50,47 @@ public TradeStatistics3ListItem(@Nullable TradeStatistics3 tradeStatistics3,
}

public String getDateString() {
return tradeStatistics3 != null ? DisplayUtils.formatDateTime(tradeStatistics3.getDate()) : "";
if (dateString == null) {
dateString = tradeStatistics3 != null ? DisplayUtils.formatDateTime(tradeStatistics3.getDate()) : "";
}
return dateString;
}

public String getMarket() {
return tradeStatistics3 != null ? CurrencyUtil.getCurrencyPair(tradeStatistics3.getCurrency()) : "";
if (market == null) {
market = tradeStatistics3 != null ? CurrencyUtil.getCurrencyPair(tradeStatistics3.getCurrency()) : "";
}
return market;
}

public String getPriceString() {
return tradeStatistics3 != null ? FormattingUtils.formatPrice(tradeStatistics3.getTradePrice()) : "";
if (priceString == null) {
priceString = tradeStatistics3 != null ? FormattingUtils.formatPrice(tradeStatistics3.getTradePrice()) : "";
}
return priceString;
}

public String getVolumeString() {
if (tradeStatistics3 == null) {
return "";
if (volumeString == null) {
volumeString = tradeStatistics3 != null ? showAllTradeCurrencies ?
DisplayUtils.formatVolumeWithCode(tradeStatistics3.getTradeVolume()) :
DisplayUtils.formatVolume(tradeStatistics3.getTradeVolume())
: "";
}
return showAllTradeCurrencies ?
DisplayUtils.formatVolumeWithCode(tradeStatistics3.getTradeVolume()) :
DisplayUtils.formatVolume(tradeStatistics3.getTradeVolume());
return volumeString;
}

public String getPaymentMethodString() {
return tradeStatistics3 != null ? Res.get(tradeStatistics3.getPaymentMethod()) : "";
if (paymentMethodString == null) {
paymentMethodString = tradeStatistics3 != null ? Res.get(tradeStatistics3.getPaymentMethod()) : "";
}
return paymentMethodString;
}

public String getAmountString() {
return tradeStatistics3 != null ? coinFormatter.formatCoin(tradeStatistics3.getTradeAmount(), 4) : "";
if (amountString == null) {
amountString = tradeStatistics3 != null ? coinFormatter.formatCoin(tradeStatistics3.getTradeAmount(), 4) : "";
}
return amountString;
}
}
Loading