From 0a38aebdf8595529da673453ff191d20a05266d7 Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Wed, 27 Jan 2021 20:42:52 +0000 Subject: [PATCH] Fix stale trade stats list view when new entries arrive Ensure the trade statistics list in TradesChartsView doesn't go stale upon new stats arrivals, by moving a fillList() call from the currency combobox onChangeConfirmed event handler to the selectedTradeStatistics (TradesChartsViewModel field) listener. Also avoid unnecessary use of an ObservableList as a temporary variable. --- .../main/market/trades/TradesChartsView.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java index b42e2c3a435..4c02dfab715 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/trades/TradesChartsView.java @@ -240,8 +240,10 @@ public void initialize() { volumeAxisYWidth = (double) newValue; layoutChart(); }; - tradeStatisticsByCurrencyListener = c -> nrOfTradeStatisticsLabel.setText(Res.get("market.trades.nrOfTrades", - model.selectedTradeStatistics.size())); + tradeStatisticsByCurrencyListener = c -> { + nrOfTradeStatisticsLabel.setText(Res.get("market.trades.nrOfTrades", model.selectedTradeStatistics.size())); + fillList(); + }; parentHeightListener = (observable, oldValue, newValue) -> layout(); priceColumnLabelListener = (o, oldVal, newVal) -> priceColumn.setGraphic(new AutoTooltipLabel(newVal)); @@ -308,7 +310,6 @@ else if (model.getSelectedCurrencyListItem().isPresent()) CurrencyListItem selectedItem = currencyComboBox.getSelectionModel().getSelectedItem(); if (selectedItem != null) { model.onSetTradeCurrency(selectedItem.tradeCurrency); - fillList(); } }); @@ -396,14 +397,12 @@ private void showVolumeAsUsd(Boolean showUsd) { } private void fillList() { - ObservableList tradeStatistics3ListItems = FXCollections.observableList( - model.selectedTradeStatistics.stream() - .map(tradeStatistics -> new TradeStatistics3ListItem(tradeStatistics, - coinFormatter, - model.showAllTradeCurrenciesProperty.get())) - .collect(Collectors.toList())); - listItems.clear(); - listItems.addAll(tradeStatistics3ListItems); + List tradeStatistics3ListItems = model.selectedTradeStatistics.stream() + .map(tradeStatistics -> new TradeStatistics3ListItem(tradeStatistics, + coinFormatter, + model.showAllTradeCurrenciesProperty.get())) + .collect(Collectors.toList()); + listItems.setAll(tradeStatistics3ListItems); } private void exportToCsv() {