Column sorting - fix string comparators

This commit is contained in:
xyzmaker123 2022-02-02 08:47:45 +01:00
parent 44b02b3cbb
commit 2ad384dcca
No known key found for this signature in database
GPG Key ID: 47689699B7B0AAFC
6 changed files with 42 additions and 7 deletions

View File

@ -26,6 +26,7 @@ import bisq.desktop.util.filtering.FilteringUtils;
import bisq.core.btc.listeners.TxConfidenceListener;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.locale.CurrencyUtil;
import bisq.core.monetary.Price;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferDirection;
import bisq.core.trade.ClosedTradableManager;
@ -109,10 +110,18 @@ class UnconfirmedBsqSwapsListItem implements FilterableListItem {
return bsqSwapTrade.getShortId();
}
public Coin getAmount() {
return bsqSwapTrade.getAmount();
}
public String getAmountAsString() {
return btcFormatter.formatCoin(bsqSwapTrade.getAmount());
}
public Price getPrice() {
return bsqSwapTrade.getPrice();
}
public String getPriceAsString() {
return FormattingUtils.formatPrice(bsqSwapTrade.getPrice());
}
@ -121,6 +130,10 @@ class UnconfirmedBsqSwapsListItem implements FilterableListItem {
return VolumeUtil.formatVolumeWithCode(bsqSwapTrade.getVolume());
}
public Coin getTxFee() {
return Coin.valueOf(bsqSwapTrade.getBsqSwapProtocolModel().getTxFee());
}
public String getTxFeeAsString() {
return btcFormatter.formatCoinWithCode(Coin.valueOf(bsqSwapTrade.getBsqSwapProtocolModel().getTxFee()));
}

View File

@ -179,12 +179,12 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel<VBox, Uncon
dateColumn.setComparator(Comparator.comparing(o -> o.getBsqSwapTrade().getDate()));
directionColumn.setComparator(Comparator.comparing(o -> o.getBsqSwapTrade().getOffer().getDirection()));
marketColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getMarketLabel));
priceColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getPriceAsString, Comparator.nullsFirst(Comparator.naturalOrder())));
priceColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getPrice, Comparator.nullsFirst(Comparator.naturalOrder())));
volumeColumn.setComparator(nullsFirstComparingAsTrade(BsqSwapTrade::getVolume));
amountColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getAmountAsString, Comparator.nullsFirst(Comparator.naturalOrder())));
amountColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getAmount, Comparator.nullsFirst(Comparator.naturalOrder())));
avatarColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getNumPastTrades, Comparator.nullsFirst(Comparator.naturalOrder())));
txFeeColumn.setComparator(nullsFirstComparing(BsqSwapTrade::getTxFeePerVbyte));
txFeeColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getTxFeeAsString, Comparator.nullsFirst(Comparator.naturalOrder())));
txFeeColumn.setComparator(Comparator.comparing(UnconfirmedBsqSwapsListItem::getTxFee, Comparator.nullsFirst(Comparator.naturalOrder())));
//
tradeFeeColumn.setComparator(Comparator.comparing(item -> {

View File

@ -22,6 +22,7 @@ import bisq.desktop.util.filtering.FilterableListItem;
import bisq.desktop.util.filtering.FilteringUtils;
import bisq.core.locale.CurrencyUtil;
import bisq.core.monetary.Price;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferDirection;
import bisq.core.trade.ClosedTradableFormatter;
@ -30,8 +31,12 @@ import bisq.core.trade.model.Tradable;
import bisq.core.trade.model.bisq_v1.Trade;
import bisq.core.trade.model.bsq_swap.BsqSwapTrade;
import org.bitcoinj.core.Coin;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
import lombok.Getter;
public class ClosedTradesListItem implements FilterableListItem {
@ -54,10 +59,18 @@ public class ClosedTradesListItem implements FilterableListItem {
return tradable.getShortId();
}
public Coin getAmount() {
return tradable.getOptionalAmount().orElse(null);
}
public String getAmountAsString() {
return closedTradableFormatter.getAmountAsString(tradable);
}
public Price getPrice() {
return tradable.getOptionalPrice().orElse(null);
}
public String getPriceAsString() {
return closedTradableFormatter.getPriceAsString(tradable);
}
@ -99,6 +112,10 @@ public class ClosedTradesListItem implements FilterableListItem {
return DisplayUtils.getDirectionWithCode(direction, currencyCode);
}
public Date getDate() {
return tradable.getDate();
}
public String getDateAsString() {
return DisplayUtils.formatDateTime(tradable.getDate());
}

View File

@ -215,15 +215,15 @@ public class ClosedTradesView extends ActivatableViewAndModel<VBox, ClosedTrades
setAvatarColumnCellFactory();
tradeIdColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getTradeId));
dateColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getDateAsString));
dateColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getDate));
directionColumn.setComparator(Comparator.comparing(o -> o.getTradable().getOffer().getDirection()));
marketColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getMarketLabel));
priceColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getPriceAsString, Comparator.nullsFirst(Comparator.naturalOrder())));
priceColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getPrice, Comparator.nullsFirst(Comparator.naturalOrder())));
deviationColumn.setComparator(Comparator.comparing(o ->
o.getTradable().getOffer().isUseMarketBasedPrice() ? o.getTradable().getOffer().getMarketPriceMargin() : 1,
Comparator.nullsFirst(Comparator.naturalOrder())));
volumeColumn.setComparator(nullsFirstComparingAsTrade(TradeModel::getVolume));
amountColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getAmountAsString, Comparator.nullsFirst(Comparator.naturalOrder())));
amountColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getAmount, Comparator.nullsFirst(Comparator.naturalOrder())));
avatarColumn.setComparator(Comparator.comparing(ClosedTradesListItem::getNumPastTrades, Comparator.nullsFirst(Comparator.naturalOrder())));
txFeeColumn.setComparator(nullsFirstComparing(o ->
o.getTradable() instanceof TradeModel ? ((TradeModel) o.getTradable()).getTxFee() : o.getTradable().getOffer().getTxFee()

View File

@ -19,6 +19,7 @@ package bisq.desktop.main.portfolio.pendingtrades;
import bisq.desktop.util.filtering.FilterableListItem;
import bisq.core.monetary.Price;
import bisq.core.trade.model.bisq_v1.Trade;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;
@ -47,6 +48,10 @@ public class PendingTradesListItem implements FilterableListItem {
return trade;
}
public Price getPrice() {
return trade.getPrice();
}
public String getPriceAsString() {
return FormattingUtils.formatPrice(trade.getPrice());
}

View File

@ -211,7 +211,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
dateColumn.setComparator(Comparator.comparing(o -> o.getTrade().getDate()));
volumeColumn.setComparator(Comparator.comparing(o -> o.getTrade().getVolume(), Comparator.nullsFirst(Comparator.naturalOrder())));
amountColumn.setComparator(Comparator.comparing(o -> o.getTrade().getAmount(), Comparator.nullsFirst(Comparator.naturalOrder())));
priceColumn.setComparator(Comparator.comparing(PendingTradesListItem::getPriceAsString));
priceColumn.setComparator(Comparator.comparing(PendingTradesListItem::getPrice));
paymentMethodColumn.setComparator(Comparator.comparing(
item -> item.getTrade().getOffer() != null ?
Res.get(item.getTrade().getOffer().getPaymentMethod().getId()) :