Fix bug with total amount

This commit is contained in:
Manfred Karrer 2016-04-05 02:12:45 +02:00
parent b71ce2fc37
commit 530b15147c
2 changed files with 10 additions and 10 deletions

View File

@ -76,7 +76,6 @@ class MarketsStatisticViewModel extends ActivatableViewModel {
offersByCurrencyMap.get(currencyCode).add(offer);
}
marketStatisticItems.clear();
long totalAmount = 0;
for (String currencyCode : offersByCurrencyMap.keySet()) {
List<Offer> offers = offersByCurrencyMap.get(currencyCode);
List<Offer> buyOffers = offers
@ -105,14 +104,11 @@ class MarketsStatisticViewModel extends ActivatableViewModel {
Fiat bestSellOfferPrice = sellOffers.isEmpty() ? null : sellOffers.get(0).getPrice();
Fiat spread = null;
if (bestBuyOfferPrice != null && bestSellOfferPrice != null) {
if (bestBuyOfferPrice != null && bestSellOfferPrice != null)
spread = bestSellOfferPrice.subtract(bestBuyOfferPrice);
}
for (Offer offer : offers) {
totalAmount += offer.getAmount().getValue();
}
marketStatisticItems.add(new MarketStatisticItem(currencyCode, offers.size(), spread, Coin.valueOf(totalAmount)));
Coin totalAmount = Coin.valueOf(offers.stream().mapToLong(offer -> offer.getAmount().getValue()).sum());
marketStatisticItems.add(new MarketStatisticItem(currencyCode, offers.size(), spread, totalAmount));
}
}
}

View File

@ -206,10 +206,14 @@ public class MarketsStatisticsView extends ActivatableViewAndModel<GridPane, Mar
@Override
public void updateItem(final MarketStatisticItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty && item.spread != null)
setText(formatter.formatFiatWithCode(item.spread));
else
if (item != null && !empty) {
if (item.spread != null)
setText(formatter.formatFiatWithCode(item.spread));
else
setText("-");
} else {
setText("");
}
}
};
}