Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display "Payment Method" column in Open Offers view #4193

Merged
merged 1 commit into from Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/src/main/java/bisq/core/offer/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
<columns>
<TableColumn fx:id="offerIdColumn" minWidth="110" maxWidth="130"/>
<TableColumn fx:id="dateColumn" minWidth="180"/>
<TableColumn fx:id="marketColumn" minWidth="90"/>
<TableColumn fx:id="priceColumn" minWidth="150"/>
<TableColumn fx:id="amountColumn" minWidth="150"/>
<TableColumn fx:id="volumeColumn" minWidth="170"/>
<TableColumn fx:id="marketColumn" minWidth="75"/>
<TableColumn fx:id="priceColumn" minWidth="110"/>
<TableColumn fx:id="amountColumn" minWidth="100"/>
<TableColumn fx:id="volumeColumn" minWidth="150"/>
<TableColumn fx:id="paymentMethodColumn" minWidth="120" maxWidth="170"/>
<TableColumn fx:id="directionColumn" minWidth="80"/>
<TableColumn fx:id="deactivateItemColumn" minWidth="100" maxWidth="100" sortable="false"/>
<TableColumn fx:id="editItemColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn fx:id="removeItemColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn fx:id="deactivateItemColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn fx:id="editItemColumn" minWidth="50" maxWidth="60" sortable="false"/>
<TableColumn fx:id="removeItemColumn" minWidth="50" maxWidth="60" sortable="false"/>
</columns>
</TableView>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
@FXML
TableColumn<OpenOfferListItem, OpenOfferListItem> priceColumn, amountColumn, volumeColumn,
marketColumn, directionColumn, dateColumn, offerIdColumn, deactivateItemColumn,
removeItemColumn, editItemColumn;
removeItemColumn, editItemColumn, paymentMethodColumn;
private final Navigation navigation;
private final OfferDetailsWindow offerDetailsWindow;
private SortedList<OpenOfferListItem> sortedList;
Expand All @@ -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")));
Expand All @@ -101,6 +102,7 @@ public void initialize() {
setPriceColumnCellFactory();
setAmountColumnCellFactory();
setVolumeColumnCellFactory();
setPaymentMethodColumnCellFactory();
setDateColumnCellFactory();
setDeactivateColumnCellFactory();
setEditColumnCellFactory();
Expand All @@ -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);
Expand Down Expand Up @@ -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<OpenOfferListItem, OpenOfferListItem> call(
TableColumn<OpenOfferListItem, OpenOfferListItem> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

import javafx.collections.ObservableList;

import static com.google.common.base.Preconditions.checkNotNull;

class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel> implements ViewModel {
private final P2PService p2PService;
private final CoinFormatter btcFormatter;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down