mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Make buildUsdPricesPerTickUnit async using CompletableFuture
This commit is contained in:
parent
deeb912f9b
commit
ea66a510dc
@ -33,13 +33,14 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ChartCalculations {
|
||||
static final ZoneId ZONE_ID = ZoneId.systemDefault();
|
||||
|
||||
static void buildUsdPricesPerTickUnit(Map<TradesChartsViewModel.TickUnit, Map<Long, Long>> usdAveragePriceMapsPerTickUnit,
|
||||
Set<TradeStatistics3> tradeStatisticsSet) {
|
||||
if (usdAveragePriceMapsPerTickUnit.isEmpty()) {
|
||||
static CompletableFuture<Map<TradesChartsViewModel.TickUnit, Map<Long, Long>>> buildUsdPricesPerTickUnit(Set<TradeStatistics3> tradeStatisticsSet) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Map<TradesChartsViewModel.TickUnit, Map<Long, Long>> usdAveragePriceMapsPerTickUnit = new HashMap<>();
|
||||
Map<TradesChartsViewModel.TickUnit, Map<Long, List<TradeStatistics3>>> dateMapsPerTickUnit = new HashMap<>();
|
||||
for (TradesChartsViewModel.TickUnit tick : TradesChartsViewModel.TickUnit.values()) {
|
||||
dateMapsPerTickUnit.put(tick, new HashMap<>());
|
||||
@ -61,7 +62,8 @@ public class ChartCalculations {
|
||||
map.forEach((date, tradeStatisticsList) -> priceMap.put(date, getAveragePrice(tradeStatisticsList)));
|
||||
usdAveragePriceMapsPerTickUnit.put(tick, priceMap);
|
||||
});
|
||||
}
|
||||
return usdAveragePriceMapsPerTickUnit;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,6 +38,7 @@ import bisq.core.trade.statistics.TradeStatistics3;
|
||||
import bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import bisq.core.user.Preferences;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.util.MathUtils;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
@ -154,10 +155,21 @@ class TradesChartsViewModel extends ActivatableViewModel {
|
||||
syncPriceFeedCurrency();
|
||||
setMarketPriceFeedCurrency();
|
||||
|
||||
ChartCalculations.buildUsdPricesPerTickUnit(usdAveragePriceMapsPerTickUnit, tradeStatisticsManager.getObservableTradeStatisticsSet());
|
||||
ChartCalculations.buildUsdPricesPerTickUnit(tradeStatisticsManager.getObservableTradeStatisticsSet())
|
||||
.whenComplete((usdAveragePriceMapsPerTickUnit, throwable) -> {
|
||||
if (throwable != null) {
|
||||
log.error(throwable.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
updateSelectedTradeStatistics(getCurrencyCode());
|
||||
updateChartData();
|
||||
UserThread.execute(() -> {
|
||||
this.usdAveragePriceMapsPerTickUnit.clear();
|
||||
this.usdAveragePriceMapsPerTickUnit.putAll(usdAveragePriceMapsPerTickUnit);
|
||||
|
||||
updateSelectedTradeStatistics(getCurrencyCode());
|
||||
updateChartData();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user