From d516ba4a5983dc6377e008fff13b1b25e1b64f7c Mon Sep 17 00:00:00 2001
From: jmacxx <47253594+jmacxx@users.noreply.github.com>
Date: Thu, 23 Apr 2020 16:14:20 -0500
Subject: [PATCH] Display payment method column in Open Offers view
Adjust widths of existing columns to fit in a column for payment method.
Fixes #3902
Fixes #4125
---
core/src/main/java/bisq/core/offer/Offer.java | 8 +++++
.../core/payment/payload/PaymentMethod.java | 6 ++++
.../portfolio/openoffer/OpenOffersView.fxml | 15 +++++-----
.../portfolio/openoffer/OpenOffersView.java | 30 ++++++++++++++++++-
.../openoffer/OpenOffersViewModel.java | 13 ++++++++
.../pendingtrades/PendingTradesViewModel.java | 8 +----
6 files changed, 65 insertions(+), 15 deletions(-)
diff --git a/core/src/main/java/bisq/core/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java
index d52bd9471e7..6b9ded1eeb6 100644
--- a/core/src/main/java/bisq/core/offer/Offer.java
+++ b/core/src/main/java/bisq/core/offer/Offer.java
@@ -365,6 +365,14 @@ public String getF2FExtraInfo() {
return "";
}
+ public String getPaymentMethodNameWithCountryCode() {
+ String method = this.getPaymentMethod().getShortName();
+ String methodCountryCode = this.getCountryCode();
+ if (methodCountryCode != null)
+ method = method + " (" + methodCountryCode + ")";
+ return method;
+ }
+
// domain properties
public Offer.State getState() {
return stateProperty.get();
diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java
index 0b77c461d90..eecbb0f730d 100644
--- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java
+++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java
@@ -313,6 +313,12 @@ else if (maxTradeLimit == DEFAULT_TRADE_LIMIT_HIGH_RISK.value)
return Coin.valueOf(tradeLimits.getRoundedRiskBasedTradeLimit(maxTradeLimit, riskFactor));
}
+ public String getShortName() {
+ // in cases where translation is not found, Res.get() simply returns the key string
+ // so no need for special error-handling code.
+ return Res.get(this.id + "_SHORT");
+ }
+
@Override
public int compareTo(@NotNull PaymentMethod other) {
return id.compareTo(other.id);
diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.fxml b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.fxml
index ade8c1656d8..250cc4d8073 100644
--- a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.fxml
+++ b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.fxml
@@ -31,14 +31,15 @@
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java
index 6c5da5f7c13..ecdee3ca5e2 100644
--- a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java
+++ b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java
@@ -69,7 +69,7 @@ public class OpenOffersView extends ActivatableViewAndModel priceColumn, amountColumn, volumeColumn,
marketColumn, directionColumn, dateColumn, offerIdColumn, deactivateItemColumn,
- removeItemColumn, editItemColumn;
+ removeItemColumn, editItemColumn, paymentMethodColumn;
private final Navigation navigation;
private final OfferDetailsWindow offerDetailsWindow;
private SortedList sortedList;
@@ -84,6 +84,7 @@ public OpenOffersView(OpenOffersViewModel model, Navigation navigation, OfferDet
@Override
public void initialize() {
+ paymentMethodColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.paymentMethod")));
priceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.price")));
amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.BTCMinMax")));
volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountMinMax")));
@@ -101,6 +102,7 @@ public void initialize() {
setPriceColumnCellFactory();
setAmountColumnCellFactory();
setVolumeColumnCellFactory();
+ setPaymentMethodColumnCellFactory();
setDateColumnCellFactory();
setDeactivateColumnCellFactory();
setEditColumnCellFactory();
@@ -116,6 +118,7 @@ public void initialize() {
priceColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPrice(), Comparator.nullsFirst(Comparator.naturalOrder())));
volumeColumn.setComparator(Comparator.comparing(o -> o.getOffer().getVolume(), Comparator.nullsFirst(Comparator.naturalOrder())));
dateColumn.setComparator(Comparator.comparing(o -> o.getOffer().getDate()));
+ paymentMethodColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPaymentMethod().getId()));
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);
@@ -330,6 +333,31 @@ public void updateItem(final OpenOfferListItem item, boolean empty) {
});
}
+ private void setPaymentMethodColumnCellFactory() {
+ paymentMethodColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
+ paymentMethodColumn.setCellFactory(
+ new Callback<>() {
+ @Override
+ public TableCell call(
+ TableColumn column) {
+ return new TableCell<>() {
+ @Override
+ public void updateItem(final OpenOfferListItem item, boolean empty) {
+ super.updateItem(item, empty);
+ getStyleClass().removeAll("offer-disabled");
+
+ if (item != null) {
+ if (model.isDeactivated(item)) getStyleClass().add("offer-disabled");
+ setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item)));
+ } else {
+ setGraphic(null);
+ }
+ }
+ };
+ }
+ });
+ }
+
private void setDirectionColumnCellFactory() {
directionColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
directionColumn.setCellFactory(
diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java
index 00db47c31c3..1e3b2884f0c 100644
--- a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java
+++ b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersViewModel.java
@@ -42,6 +42,8 @@
import javafx.collections.ObservableList;
+import static com.google.common.base.Preconditions.checkNotNull;
+
class OpenOffersViewModel extends ActivatableWithDataModel implements ViewModel {
private final P2PService p2PService;
private final CoinFormatter btcFormatter;
@@ -118,6 +120,17 @@ String getMarketLabel(OpenOfferListItem item) {
return CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode());
}
+ String getPaymentMethod(OpenOfferListItem item) {
+ String result = "";
+ if (item != null) {
+ Offer offer = item.getOffer();
+ checkNotNull(offer);
+ checkNotNull(offer.getPaymentMethod());
+ result = offer.getPaymentMethodNameWithCountryCode();
+ }
+ return result;
+ }
+
String getDate(OpenOfferListItem item) {
return DisplayUtils.formatDateTime(item.getOffer().getDate());
}
diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java
index cefeb458b66..ca871232c49 100644
--- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java
+++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java
@@ -276,13 +276,7 @@ String getPaymentMethod(PendingTradesListItem item) {
Offer offer = item.getTrade().getOffer();
checkNotNull(offer);
checkNotNull(offer.getPaymentMethod());
- String method = Res.get(offer.getPaymentMethod().getId() + "_SHORT");
- String methodCountryCode = offer.getCountryCode();
-
- if (methodCountryCode != null)
- result = method + " (" + methodCountryCode + ")";
- else
- result = method;
+ result = offer.getPaymentMethodNameWithCountryCode();
}
return result;
}