mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
Merge pull request #1529 from ripcurlx/fix-spread-sorting
Fix spread sorting in spread view
This commit is contained in:
commit
1a1f8d7903
3 changed files with 13 additions and 11 deletions
|
@ -35,15 +35,18 @@ public class SpreadItem {
|
|||
@Nullable
|
||||
public final Price priceSpread;
|
||||
public final String percentage;
|
||||
public final double percentageValue;
|
||||
public final Coin totalAmount;
|
||||
|
||||
public SpreadItem(String currencyCode, int numberOfBuyOffers, int numberOfSellOffers, int numberOfOffers, @Nullable Price priceSpread, String percentage, Coin totalAmount) {
|
||||
public SpreadItem(String currencyCode, int numberOfBuyOffers, int numberOfSellOffers, int numberOfOffers,
|
||||
@Nullable Price priceSpread, String percentage, double percentageValue, Coin totalAmount) {
|
||||
this.currencyCode = currencyCode;
|
||||
this.numberOfBuyOffers = numberOfBuyOffers;
|
||||
this.numberOfSellOffers = numberOfSellOffers;
|
||||
this.numberOfOffers = numberOfOffers;
|
||||
this.priceSpread = priceSpread;
|
||||
this.percentage = percentage;
|
||||
this.percentageValue = percentageValue;
|
||||
this.totalAmount = totalAmount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ import javafx.collections.transformation.SortedList;
|
|||
|
||||
import javafx.util.Callback;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
@FxmlView
|
||||
public class SpreadView extends ActivatableViewAndModel<GridPane, SpreadViewModel> {
|
||||
private final BSFormatter formatter;
|
||||
|
@ -93,16 +95,12 @@ public class SpreadView extends ActivatableViewAndModel<GridPane, SpreadViewMode
|
|||
tableView.getColumns().add(spreadColumn);
|
||||
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
||||
|
||||
currencyColumn.setComparator((o1, o2) -> CurrencyUtil.getNameByCode(o1.currencyCode).compareTo(CurrencyUtil.getNameByCode(o2.currencyCode)));
|
||||
currencyColumn.setComparator(Comparator.comparing(o -> CurrencyUtil.getNameByCode(o.currencyCode)));
|
||||
numberOfOffersColumn.setComparator((o1, o2) -> Integer.valueOf(o1.numberOfOffers).compareTo(o2.numberOfOffers));
|
||||
numberOfBuyOffersColumn.setComparator((o1, o2) -> Integer.valueOf(o1.numberOfBuyOffers).compareTo(o2.numberOfBuyOffers));
|
||||
numberOfSellOffersColumn.setComparator((o1, o2) -> Integer.valueOf(o1.numberOfSellOffers).compareTo(o2.numberOfSellOffers));
|
||||
totalAmountColumn.setComparator((o1, o2) -> o1.totalAmount.compareTo(o2.totalAmount));
|
||||
spreadColumn.setComparator((o1, o2) -> {
|
||||
Long spreadO1 = o1.priceSpread != null ? o1.priceSpread.getValue() : 0;
|
||||
Long spreadO2 = o2.priceSpread != null ? o2.priceSpread.getValue() : 0;
|
||||
return spreadO1.compareTo(spreadO2);
|
||||
});
|
||||
totalAmountColumn.setComparator(Comparator.comparing(o -> o.totalAmount));
|
||||
spreadColumn.setComparator(Comparator.comparingDouble(o -> o.percentageValue));
|
||||
|
||||
numberOfOffersColumn.setSortType(TableColumn.SortType.DESCENDING);
|
||||
tableView.getSortOrder().add(numberOfOffersColumn);
|
||||
|
|
|
@ -154,6 +154,7 @@ class SpreadViewModel extends ActivatableViewModel {
|
|||
|
||||
Price spread = null;
|
||||
String percentage = "";
|
||||
double percentageValue = 0;
|
||||
Price bestSellOfferPrice = sellOffers.isEmpty() ? null : sellOffers.get(0).getPrice();
|
||||
Price bestBuyOfferPrice = buyOffers.isEmpty() ? null : buyOffers.get(0).getPrice();
|
||||
if (bestBuyOfferPrice != null && bestSellOfferPrice != null) {
|
||||
|
@ -180,11 +181,11 @@ class SpreadViewModel extends ActivatableViewModel {
|
|||
BigDecimal marketPriceAsBigDecimal = BigDecimal.valueOf(marketPriceAsDouble)
|
||||
.multiply(BigDecimal.valueOf(precision));
|
||||
// We multiply with 10000 because we use precision of 2 at % (100.00%)
|
||||
double result = BigDecimal.valueOf(spread.getValue())
|
||||
percentageValue = BigDecimal.valueOf(spread.getValue())
|
||||
.multiply(BigDecimal.valueOf(10000))
|
||||
.divide(marketPriceAsBigDecimal, RoundingMode.HALF_UP)
|
||||
.doubleValue() / 10000;
|
||||
percentage = formatter.formatPercentagePrice(result);
|
||||
percentage = formatter.formatPercentagePrice(percentageValue);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
try {
|
||||
|
@ -210,7 +211,7 @@ class SpreadViewModel extends ActivatableViewModel {
|
|||
|
||||
totalAmount = Coin.valueOf(offers.stream().mapToLong(offer -> offer.getAmount().getValue()).sum());
|
||||
spreadItems.add(new SpreadItem(currencyCode, buyOffers.size(), sellOffers.size(),
|
||||
uniqueOffers.size(), spread, percentage, totalAmount));
|
||||
uniqueOffers.size(), spread, percentage, percentageValue, totalAmount));
|
||||
}
|
||||
|
||||
maxPlacesForAmount.set(formatAmount(totalAmount, false).length());
|
||||
|
|
Loading…
Add table
Reference in a new issue