Add total volume text fields

This commit is contained in:
chimp1984 2021-02-10 01:41:45 -05:00
parent e91ed8a857
commit 683e768a00
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
6 changed files with 88 additions and 5 deletions

View file

@ -2434,6 +2434,8 @@ dao.factsAndFigures.dashboard.avgUSDPrice90=90 days volume weighted average BSQ/
dao.factsAndFigures.dashboard.avgUSDPrice30=30 days volume weighted average BSQ/USD price
dao.factsAndFigures.dashboard.marketCap=Market capitalisation (based on 30 days average BSQ/USD price)
dao.factsAndFigures.dashboard.availableAmount=Total available BSQ
dao.factsAndFigures.dashboard.volumeUsd=Total trade volume in USD
dao.factsAndFigures.dashboard.volumeBtc=Total trade volume in BTC
dao.factsAndFigures.supply.issuedVsBurnt=BSQ issued v. BSQ burnt

View file

@ -29,6 +29,7 @@ import bisq.core.dao.DaoFacade;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.model.blockchain.Block;
import bisq.core.dao.state.model.governance.IssuanceType;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res;
import bisq.core.monetary.Price;
import bisq.core.provider.price.PriceFeedService;
@ -38,6 +39,7 @@ import bisq.core.util.AveragePriceUtil;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.BsqFormatter;
import bisq.common.util.MathUtils;
import bisq.common.util.Tuple2;
import bisq.common.util.Tuple3;
@ -55,10 +57,13 @@ import javafx.scene.layout.VBox;
import javafx.geometry.Insets;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
import javafx.collections.ObservableList;
import java.text.DecimalFormat;
import java.util.Optional;
import static bisq.desktop.util.FormBuilder.addLabelWithSubText;
@ -78,7 +83,7 @@ public class BsqDashboardView extends ActivatableView<GridPane, Void> implements
private final Preferences preferences;
private final BsqFormatter bsqFormatter;
private TextField avgPrice90TextField, avgUSDPrice90TextField, marketCapTextField, availableAmountTextField;
private TextField avgPrice90TextField, avgUSDPrice90TextField, marketCapTextField, availableAmountTextField, usdVolumeTextField, btcVolumeTextField;
private TextFieldWithIcon avgPrice30TextField, avgUSDPrice30TextField;
private Label marketPriceLabel;
@ -133,6 +138,24 @@ public class BsqDashboardView extends ActivatableView<GridPane, Void> implements
updateAveragePriceFields(avgPrice90TextField, avgPrice30TextField, false);
updateAveragePriceFields(avgUSDPrice90TextField, avgUSDPrice30TextField, true);
updateMarketCap();
usdVolumeTextField.textProperty().bind(Bindings.createStringBinding(
() -> {
DecimalFormat volumeFormat = (DecimalFormat) DecimalFormat.getNumberInstance(GlobalSettings.getLocale());
volumeFormat.setMaximumFractionDigits(0);
double scaled = MathUtils.scaleDownByPowerOf10(volumeChartView.usdVolumeProperty().get(), 4);
return volumeFormat.format(scaled) + " USD";
},
volumeChartView.usdVolumeProperty()));
btcVolumeTextField.textProperty().bind(Bindings.createStringBinding(
() -> {
DecimalFormat volumeFormat = (DecimalFormat) DecimalFormat.getNumberInstance(GlobalSettings.getLocale());
volumeFormat.setMaximumFractionDigits(4);
double scaled = MathUtils.scaleDownByPowerOf10(volumeChartView.btcVolumeProperty().get(), 8);
return volumeFormat.format(scaled) + " BTC";
},
volumeChartView.btcVolumeProperty()));
}
@ -140,6 +163,9 @@ public class BsqDashboardView extends ActivatableView<GridPane, Void> implements
protected void deactivate() {
daoFacade.removeBsqStateListener(this);
priceFeedService.updateCounterProperty().removeListener(priceChangeListener);
usdVolumeTextField.textProperty().unbind();
btcVolumeTextField.textProperty().unbind();
}
@ -227,6 +253,11 @@ public class BsqDashboardView extends ActivatableView<GridPane, Void> implements
chartPane.getChildren().add(chartContainer);
root.getChildren().add(chartPane);
usdVolumeTextField = addTopLabelReadOnlyTextField(root, ++gridRow,
Res.get("dao.factsAndFigures.dashboard.volumeUsd")).second;
btcVolumeTextField = addTopLabelReadOnlyTextField(root, gridRow, 1,
Res.get("dao.factsAndFigures.dashboard.volumeBtc")).second;
}
private void updateWithBsqBlockChainData() {

View file

@ -54,6 +54,23 @@ public class VolumeChartDataModel extends ChartDataModel {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Total amounts
///////////////////////////////////////////////////////////////////////////////////////////
long getUsdVolume() {
return getUsdVolumeByInterval().values().stream()
.mapToLong(e -> e)
.sum();
}
long getBtcVolume() {
return getBtcVolumeByInterval().values().stream()
.mapToLong(e -> e)
.sum();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Data
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -25,6 +25,10 @@ import javax.inject.Inject;
import javafx.scene.chart.XYChart;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ReadOnlyLongProperty;
import javafx.beans.property.SimpleLongProperty;
import java.util.Collection;
import java.util.List;
@ -34,6 +38,9 @@ import lombok.extern.slf4j.Slf4j;
public class VolumeChartView extends ChartView<VolumeChartViewModel> {
private XYChart.Series<Number, Number> seriesUsdVolume, seriesBtcVolume;
private LongProperty usdVolumeProperty = new SimpleLongProperty();
private LongProperty btcVolumeProperty = new SimpleLongProperty();
@Inject
public VolumeChartView(VolumeChartViewModel model) {
super(model);
@ -121,5 +128,22 @@ public class VolumeChartView extends ChartView<VolumeChartViewModel> {
if (activeSeries.contains(seriesBtcVolume)) {
seriesBtcVolume.getData().setAll(model.getBtcVolumeChartData());
}
usdVolumeProperty.set(model.getUsdVolume());
btcVolumeProperty.set(model.getBtcVolume());
}
public ReadOnlyLongProperty usdVolumeProperty() {
if (usdVolumeProperty.get() == 0) {
usdVolumeProperty.set(model.getUsdVolume());
}
return usdVolumeProperty;
}
public ReadOnlyLongProperty btcVolumeProperty() {
if (btcVolumeProperty.get() == 0) {
btcVolumeProperty.set(model.getBtcVolume());
}
return btcVolumeProperty;
}
}

View file

@ -50,6 +50,19 @@ public class VolumeChartViewModel extends ChartViewModel<VolumeChartDataModel> {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Total amounts
///////////////////////////////////////////////////////////////////////////////////////////
long getUsdVolume() {
return dataModel.getUsdVolume();
}
long getBtcVolume() {
return dataModel.getBtcVolume();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Chart data
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -55,10 +55,6 @@ public class DaoChartView extends ChartView<DaoChartViewModel> {
// API Total amounts
///////////////////////////////////////////////////////////////////////////////////////////
public long getCompensationAmountProperty() {
return model.getCompensationAmount();
}
public ReadOnlyLongProperty compensationAmountProperty() {
if (compensationAmountProperty.get() == 0) {
compensationAmountProperty.set(model.getCompensationAmount());