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

Add filter to trade history #2752

Merged
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
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/offer/OfferPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.security.PublicKey;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -378,7 +379,7 @@ public String getCurrencyCode() {
public String toString() {
return "OfferPayload{" +
"\n id='" + id + '\'' +
",\n date=" + date +
",\n date=" + new Date(date) +
",\n ownerNodeAddress=" + ownerNodeAddress +
",\n pubKeyRing=" + pubKeyRing +
",\n direction=" + direction +
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ support.tab.support=Support tickets
support.tab.ArbitratorsSupportTickets=Arbitrator's support tickets
support.tab.TradersSupportTickets=Trader's support tickets
support.filter=Filter list
support.filter.prompt=Enter trade ID, date, onion address or account data
support.noTickets=There are no open tickets
support.sendingMessage=Sending Message...
support.receiverNotOnline=Receiver is not online. Message is saved to his mailbox.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
-->

<?import bisq.desktop.components.AutoTooltipButton?>
<?import bisq.desktop.components.AutoTooltipLabel?>
<?import bisq.desktop.components.InputTextField?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<VBox fx:id="root" fx:controller="bisq.desktop.main.portfolio.closedtrades.ClosedTradesView"
Expand All @@ -41,5 +45,10 @@
<TableColumn fx:id="avatarColumn" minWidth="40" maxWidth="40"/>
</columns>
</TableView>
<AutoTooltipButton fx:id="exportButton"/>
<HBox fx:id="footerBox">
<AutoTooltipLabel fx:id="filterLabel"/>
<InputTextField fx:id="filterTextField" minWidth="300"/>
<Pane fx:id="spacer"/>
<AutoTooltipButton fx:id="exportButton"/>
</HBox>
</VBox>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.components.InputTextField;
import bisq.desktop.components.PeerInfoIcon;
import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
import bisq.desktop.main.overlays.windows.TradeDetailsWindow;
Expand All @@ -34,6 +35,7 @@
import bisq.core.monetary.Volume;
import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer;
import bisq.core.trade.Contract;
import bisq.core.trade.Tradable;
import bisq.core.trade.Trade;
import bisq.core.user.Preferences;
Expand All @@ -60,13 +62,18 @@
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

import javafx.geometry.Insets;

import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;

import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;

import javafx.util.Callback;
Expand All @@ -76,19 +83,31 @@
@FxmlView
public class ClosedTradesView extends ActivatableViewAndModel<VBox, ClosedTradesViewModel> {
private final boolean useDevPrivilegeKeys;

@FXML
TableView<ClosedTradableListItem> tableView;
@FXML
TableColumn<ClosedTradableListItem, ClosedTradableListItem> priceColumn, amountColumn, volumeColumn,
marketColumn, directionColumn, dateColumn, tradeIdColumn, stateColumn, avatarColumn;
@FXML
HBox footerBox;
@FXML
AutoTooltipLabel filterLabel;
@FXML
InputTextField filterTextField;
@FXML
Pane spacer;
@FXML
AutoTooltipButton exportButton;

private final OfferDetailsWindow offerDetailsWindow;
private Preferences preferences;
private final BSFormatter formatter;
private final TradeDetailsWindow tradeDetailsWindow;
private final PrivateNotificationManager privateNotificationManager;
private SortedList<ClosedTradableListItem> sortedList;
private FilteredList<ClosedTradableListItem> filteredList;
private ChangeListener<String> filterTextFieldListener;

@Inject
public ClosedTradesView(ClosedTradesViewModel model,
Expand Down Expand Up @@ -178,13 +197,24 @@ public void initialize() {

dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);

filterLabel.setText(Res.getWithCol("support.filter"));
filterTextField.setPromptText(Res.get("support.filter.prompt"));
HBox.setMargin(filterLabel, new Insets(5, 0, 0, 10));
filterTextFieldListener = (observable, oldValue, newValue) -> applyFilteredListPredicate(filterTextField.getText());
footerBox.setSpacing(5);
HBox.setHgrow(spacer, Priority.ALWAYS);
exportButton.updateText(Res.get("shared.exportCSV"));
HBox.setMargin(exportButton, new Insets(0, 10, 0, 0));
}

@Override
protected void activate() {
sortedList = new SortedList<>(model.getList());
filteredList = new FilteredList<>(model.getList());

sortedList = new SortedList<>(filteredList);
sortedList.comparatorProperty().bind(tableView.comparatorProperty());

tableView.setItems(sortedList);

exportButton.setOnAction(event -> {
Expand All @@ -211,14 +241,52 @@ protected void activate() {
GUIUtil.exportCSV("tradeHistory.csv", headerConverter, contentConverter,
new ClosedTradableListItem(null), sortedList, (Stage) root.getScene().getWindow());
});

filterTextField.textProperty().addListener(filterTextFieldListener);
applyFilteredListPredicate(filterTextField.getText());
}

@Override
protected void deactivate() {
sortedList.comparatorProperty().unbind();
exportButton.setOnAction(null);

filterTextField.textProperty().removeListener(filterTextFieldListener);
}

private void applyFilteredListPredicate(String filterString) {
filteredList.setPredicate(item -> {
if (filterString.isEmpty())
return true;

Offer offer = item.getTradable().getOffer();
boolean matchesId = offer.getId().contains(filterString);
boolean matchesOfferDate = formatter.formatDate(offer.getDate()).contains(filterString);
boolean isMakerOnion = offer.getMakerNodeAddress().getFullAddress().contains(filterString);

if (item.getTradable() instanceof Trade) {
boolean isBuyerOnion = false;
boolean isSellerOnion = false;
boolean matchesBuyersPaymentAccountData = false;
boolean matchesSellersPaymentAccountData = false;

Trade trade = (Trade) item.getTradable();
boolean matchesTradeDate = formatter.formatDate(trade.getTakeOfferDate()).contains(filterString);
Contract contract = trade.getContract();
if (contract != null) {
isBuyerOnion = contract.getBuyerNodeAddress().getFullAddress().contains(filterString);
isSellerOnion = contract.getSellerNodeAddress().getFullAddress().contains(filterString);
matchesBuyersPaymentAccountData = contract.getBuyerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesSellersPaymentAccountData = contract.getSellerPaymentAccountPayload().getPaymentDetails().contains(filterString);
}
return matchesId || matchesOfferDate || isMakerOnion ||
matchesTradeDate || isBuyerOnion || isSellerOnion ||
matchesBuyersPaymentAccountData || matchesSellersPaymentAccountData;
} else {
return matchesId || matchesOfferDate || isMakerOnion;
}
});
}

private void setTradeIdColumnCellFactory() {
tradeIdColumn.getStyleClass().add("first-column");
Expand Down