mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Add toggle for filtering offers which can be taken with users accounts
This commit is contained in:
parent
c3c1f95cba
commit
9e275048f6
6 changed files with 134 additions and 24 deletions
|
@ -772,6 +772,11 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setShowOffersMatchingMyAccounts(boolean value) {
|
||||||
|
prefPayload.setShowOffersMatchingMyAccounts(value);
|
||||||
|
requestPersistence();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Getter
|
// Getter
|
||||||
|
@ -1081,5 +1086,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
void setAutoConfirmSettings(AutoConfirmSettings autoConfirmSettings);
|
void setAutoConfirmSettings(AutoConfirmSettings autoConfirmSettings);
|
||||||
|
|
||||||
void setHideNonAccountPaymentMethods(boolean hideNonAccountPaymentMethods);
|
void setHideNonAccountPaymentMethods(boolean hideNonAccountPaymentMethods);
|
||||||
|
|
||||||
|
void setShowOffersMatchingMyAccounts(boolean value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
|
||||||
|
|
||||||
// Added in 1.5.5
|
// Added in 1.5.5
|
||||||
private boolean hideNonAccountPaymentMethods;
|
private boolean hideNonAccountPaymentMethods;
|
||||||
|
private boolean showOffersMatchingMyAccounts;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -195,7 +197,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
|
||||||
.addAllAutoConfirmSettings(autoConfirmSettingsList.stream()
|
.addAllAutoConfirmSettings(autoConfirmSettingsList.stream()
|
||||||
.map(autoConfirmSettings -> ((protobuf.AutoConfirmSettings) autoConfirmSettings.toProtoMessage()))
|
.map(autoConfirmSettings -> ((protobuf.AutoConfirmSettings) autoConfirmSettings.toProtoMessage()))
|
||||||
.collect(Collectors.toList()))
|
.collect(Collectors.toList()))
|
||||||
.setHideNonAccountPaymentMethods(hideNonAccountPaymentMethods);
|
.setHideNonAccountPaymentMethods(hideNonAccountPaymentMethods)
|
||||||
|
.setShowOffersMatchingMyAccounts(showOffersMatchingMyAccounts);
|
||||||
|
|
||||||
Optional.ofNullable(backupDirectory).ifPresent(builder::setBackupDirectory);
|
Optional.ofNullable(backupDirectory).ifPresent(builder::setBackupDirectory);
|
||||||
Optional.ofNullable(preferredTradeCurrency).ifPresent(e -> builder.setPreferredTradeCurrency((protobuf.TradeCurrency) e.toProtoMessage()));
|
Optional.ofNullable(preferredTradeCurrency).ifPresent(e -> builder.setPreferredTradeCurrency((protobuf.TradeCurrency) e.toProtoMessage()));
|
||||||
|
@ -290,7 +293,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
|
||||||
new ArrayList<>(proto.getAutoConfirmSettingsList().stream()
|
new ArrayList<>(proto.getAutoConfirmSettingsList().stream()
|
||||||
.map(AutoConfirmSettings::fromProto)
|
.map(AutoConfirmSettings::fromProto)
|
||||||
.collect(Collectors.toList())),
|
.collect(Collectors.toList())),
|
||||||
proto.getHideNonAccountPaymentMethods()
|
proto.getHideNonAccountPaymentMethods(),
|
||||||
|
proto.getShowOffersMatchingMyAccounts()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,6 +342,7 @@ offerbook.offerersAcceptedBankSeats=Accepted seat of bank countries (taker):\n {
|
||||||
offerbook.availableOffers=Available offers
|
offerbook.availableOffers=Available offers
|
||||||
offerbook.filterByCurrency=Filter by currency
|
offerbook.filterByCurrency=Filter by currency
|
||||||
offerbook.filterByPaymentMethod=Filter by payment method
|
offerbook.filterByPaymentMethod=Filter by payment method
|
||||||
|
offerbook.matchingOffers=Offers matching my accounts
|
||||||
offerbook.timeSinceSigning=Account info
|
offerbook.timeSinceSigning=Account info
|
||||||
offerbook.timeSinceSigning.info=This account was verified and {0}
|
offerbook.timeSinceSigning.info=This account was verified and {0}
|
||||||
offerbook.timeSinceSigning.info.arbitrator=signed by an arbitrator and can sign peer accounts
|
offerbook.timeSinceSigning.info.arbitrator=signed by an arbitrator and can sign peer accounts
|
||||||
|
|
|
@ -22,6 +22,7 @@ import bisq.desktop.common.view.ActivatableViewAndModel;
|
||||||
import bisq.desktop.common.view.FxmlView;
|
import bisq.desktop.common.view.FxmlView;
|
||||||
import bisq.desktop.components.AutoTooltipButton;
|
import bisq.desktop.components.AutoTooltipButton;
|
||||||
import bisq.desktop.components.AutoTooltipLabel;
|
import bisq.desktop.components.AutoTooltipLabel;
|
||||||
|
import bisq.desktop.components.AutoTooltipSlideToggleButton;
|
||||||
import bisq.desktop.components.AutoTooltipTableColumn;
|
import bisq.desktop.components.AutoTooltipTableColumn;
|
||||||
import bisq.desktop.components.AutocompleteComboBox;
|
import bisq.desktop.components.AutocompleteComboBox;
|
||||||
import bisq.desktop.components.ColoredDecimalPlacesWithZerosText;
|
import bisq.desktop.components.ColoredDecimalPlacesWithZerosText;
|
||||||
|
@ -126,6 +127,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
private AutocompleteComboBox<TradeCurrency> currencyComboBox;
|
private AutocompleteComboBox<TradeCurrency> currencyComboBox;
|
||||||
private AutocompleteComboBox<PaymentMethod> paymentMethodComboBox;
|
private AutocompleteComboBox<PaymentMethod> paymentMethodComboBox;
|
||||||
private AutoTooltipButton createOfferButton;
|
private AutoTooltipButton createOfferButton;
|
||||||
|
private AutoTooltipSlideToggleButton matchingOffersToggle;
|
||||||
private AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> amountColumn, volumeColumn, marketColumn,
|
private AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> amountColumn, volumeColumn, marketColumn,
|
||||||
priceColumn, paymentMethodColumn, depositColumn, signingStateColumn, avatarColumn;
|
priceColumn, paymentMethodColumn, depositColumn, signingStateColumn, avatarColumn;
|
||||||
private TableView<OfferBookListItem> tableView;
|
private TableView<OfferBookListItem> tableView;
|
||||||
|
@ -174,10 +176,25 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
hBox.setSpacing(35);
|
hBox.setSpacing(35);
|
||||||
hBox.setPadding(new Insets(10, 0, 0, 0));
|
hBox.setPadding(new Insets(10, 0, 0, 0));
|
||||||
|
|
||||||
final Tuple3<VBox, Label, AutocompleteComboBox<TradeCurrency>> currencyBoxTuple = FormBuilder.addTopLabelAutocompleteComboBox(
|
Tuple3<VBox, Label, AutocompleteComboBox<TradeCurrency>> currencyBoxTuple = FormBuilder.addTopLabelAutocompleteComboBox(
|
||||||
Res.get("offerbook.filterByCurrency"));
|
Res.get("offerbook.filterByCurrency"));
|
||||||
final Tuple3<VBox, Label, AutocompleteComboBox<PaymentMethod>> paymentBoxTuple = FormBuilder.addTopLabelAutocompleteComboBox(
|
currencyComboBox = currencyBoxTuple.third;
|
||||||
|
currencyComboBox.setPrefWidth(270);
|
||||||
|
|
||||||
|
Tuple3<VBox, Label, AutocompleteComboBox<PaymentMethod>> paymentBoxTuple = FormBuilder.addTopLabelAutocompleteComboBox(
|
||||||
Res.get("offerbook.filterByPaymentMethod"));
|
Res.get("offerbook.filterByPaymentMethod"));
|
||||||
|
paymentMethodComboBox = paymentBoxTuple.third;
|
||||||
|
paymentMethodComboBox.setCellFactory(GUIUtil.getPaymentMethodCellFactory());
|
||||||
|
paymentMethodComboBox.setPrefWidth(270);
|
||||||
|
|
||||||
|
matchingOffersToggle = new AutoTooltipSlideToggleButton();
|
||||||
|
matchingOffersToggle.setText(Res.get("offerbook.matchingOffers"));
|
||||||
|
HBox.setMargin(matchingOffersToggle, new Insets(7, 0, -9, -15));
|
||||||
|
|
||||||
|
hBox.getChildren().addAll(currencyBoxTuple.first, paymentBoxTuple.first, matchingOffersToggle);
|
||||||
|
AnchorPane.setLeftAnchor(hBox, 0d);
|
||||||
|
AnchorPane.setTopAnchor(hBox, 0d);
|
||||||
|
AnchorPane.setBottomAnchor(hBox, 0d);
|
||||||
|
|
||||||
createOfferButton = new AutoTooltipButton();
|
createOfferButton = new AutoTooltipButton();
|
||||||
createOfferButton.setMinHeight(40);
|
createOfferButton.setMinHeight(40);
|
||||||
|
@ -185,11 +202,6 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
AnchorPane.setRightAnchor(createOfferButton, 0d);
|
AnchorPane.setRightAnchor(createOfferButton, 0d);
|
||||||
AnchorPane.setBottomAnchor(createOfferButton, 0d);
|
AnchorPane.setBottomAnchor(createOfferButton, 0d);
|
||||||
|
|
||||||
hBox.getChildren().addAll(currencyBoxTuple.first, paymentBoxTuple.first, createOfferButton);
|
|
||||||
AnchorPane.setLeftAnchor(hBox, 0d);
|
|
||||||
AnchorPane.setTopAnchor(hBox, 0d);
|
|
||||||
AnchorPane.setBottomAnchor(hBox, 0d);
|
|
||||||
|
|
||||||
AnchorPane anchorPane = new AnchorPane();
|
AnchorPane anchorPane = new AnchorPane();
|
||||||
anchorPane.getChildren().addAll(hBox, createOfferButton);
|
anchorPane.getChildren().addAll(hBox, createOfferButton);
|
||||||
|
|
||||||
|
@ -199,11 +211,6 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
GridPane.setMargin(anchorPane, new Insets(Layout.FIRST_ROW_DISTANCE, 0, 0, 0));
|
GridPane.setMargin(anchorPane, new Insets(Layout.FIRST_ROW_DISTANCE, 0, 0, 0));
|
||||||
root.getChildren().add(anchorPane);
|
root.getChildren().add(anchorPane);
|
||||||
|
|
||||||
currencyComboBox = currencyBoxTuple.third;
|
|
||||||
|
|
||||||
paymentMethodComboBox = paymentBoxTuple.third;
|
|
||||||
paymentMethodComboBox.setCellFactory(GUIUtil.getPaymentMethodCellFactory());
|
|
||||||
|
|
||||||
tableView = new TableView<>();
|
tableView = new TableView<>();
|
||||||
|
|
||||||
GridPane.setRowIndex(tableView, ++gridRow);
|
GridPane.setRowIndex(tableView, ++gridRow);
|
||||||
|
@ -328,6 +335,10 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
|
|
||||||
currencyComboBox.getEditor().setText(new CurrencyStringConverter(currencyComboBox).toString(currencyComboBox.getSelectionModel().getSelectedItem()));
|
currencyComboBox.getEditor().setText(new CurrencyStringConverter(currencyComboBox).toString(currencyComboBox.getSelectionModel().getSelectedItem()));
|
||||||
|
|
||||||
|
matchingOffersToggle.setSelected(model.useOffersMatchingMyAccountsFilter);
|
||||||
|
matchingOffersToggle.disableProperty().bind(model.disableMatchToggle);
|
||||||
|
matchingOffersToggle.setOnAction(e -> model.onShowOffersMatchingMyAccounts(matchingOffersToggle.isSelected()));
|
||||||
|
|
||||||
volumeColumn.sortableProperty().bind(model.showAllTradeCurrenciesProperty.not());
|
volumeColumn.sortableProperty().bind(model.showAllTradeCurrenciesProperty.not());
|
||||||
model.getOfferList().comparatorProperty().bind(tableView.comparatorProperty());
|
model.getOfferList().comparatorProperty().bind(tableView.comparatorProperty());
|
||||||
|
|
||||||
|
@ -424,6 +435,8 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
@Override
|
@Override
|
||||||
protected void deactivate() {
|
protected void deactivate() {
|
||||||
createOfferButton.setOnAction(null);
|
createOfferButton.setOnAction(null);
|
||||||
|
matchingOffersToggle.setOnAction(null);
|
||||||
|
matchingOffersToggle.disableProperty().unbind();
|
||||||
model.getOfferList().comparatorProperty().unbind();
|
model.getOfferList().comparatorProperty().unbind();
|
||||||
|
|
||||||
volumeColumn.sortableProperty().unbind();
|
volumeColumn.sortableProperty().unbind();
|
||||||
|
@ -1024,6 +1037,10 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
final Offer offer = item.getOffer();
|
final Offer offer = item.getOffer();
|
||||||
boolean myOffer = model.isMyOffer(offer);
|
boolean myOffer = model.isMyOffer(offer);
|
||||||
if (tableRow != null) {
|
if (tableRow != null) {
|
||||||
|
// this code is duplicated in model.getOffersMatchingMyAccountsPredicate but as
|
||||||
|
// we want to pass the results for displaying relevant info in popups we
|
||||||
|
// cannot simply replace it with the predicate. If there are any changes we
|
||||||
|
// need to maintain both.
|
||||||
isPaymentAccountValidForOffer = model.isAnyPaymentAccountValidForOffer(offer);
|
isPaymentAccountValidForOffer = model.isAnyPaymentAccountValidForOffer(offer);
|
||||||
isInsufficientCounterpartyTradeLimit = model.isInsufficientCounterpartyTradeLimit(offer);
|
isInsufficientCounterpartyTradeLimit = model.isInsufficientCounterpartyTradeLimit(offer);
|
||||||
hasSameProtocolVersion = model.hasSameProtocolVersion(offer);
|
hasSameProtocolVersion = model.hasSameProtocolVersion(offer);
|
||||||
|
|
|
@ -78,16 +78,19 @@ import javafx.beans.property.StringProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.collections.SetChangeListener;
|
||||||
import javafx.collections.transformation.FilteredList;
|
import javafx.collections.transformation.FilteredList;
|
||||||
import javafx.collections.transformation.SortedList;
|
import javafx.collections.transformation.SortedList;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -126,11 +129,15 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
|
|
||||||
private boolean isTabSelected;
|
private boolean isTabSelected;
|
||||||
final BooleanProperty showAllTradeCurrenciesProperty = new SimpleBooleanProperty(true);
|
final BooleanProperty showAllTradeCurrenciesProperty = new SimpleBooleanProperty(true);
|
||||||
|
final BooleanProperty disableMatchToggle = new SimpleBooleanProperty();
|
||||||
final IntegerProperty maxPlacesForAmount = new SimpleIntegerProperty();
|
final IntegerProperty maxPlacesForAmount = new SimpleIntegerProperty();
|
||||||
final IntegerProperty maxPlacesForVolume = new SimpleIntegerProperty();
|
final IntegerProperty maxPlacesForVolume = new SimpleIntegerProperty();
|
||||||
final IntegerProperty maxPlacesForPrice = new SimpleIntegerProperty();
|
final IntegerProperty maxPlacesForPrice = new SimpleIntegerProperty();
|
||||||
final IntegerProperty maxPlacesForMarketPriceMargin = new SimpleIntegerProperty();
|
final IntegerProperty maxPlacesForMarketPriceMargin = new SimpleIntegerProperty();
|
||||||
boolean showAllPaymentMethods = true;
|
boolean showAllPaymentMethods = true;
|
||||||
|
boolean useOffersMatchingMyAccountsFilter;
|
||||||
|
private final Map<String, Boolean> myInsufficientTradeLimitCache = new HashMap<>();
|
||||||
|
private final Map<String, Boolean> insufficientCounterpartyTradeLimitCache = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -206,6 +213,10 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
|
|
||||||
highestMarketPriceMarginOffer.ifPresent(offerBookListItem -> maxPlacesForMarketPriceMargin.set(formatMarketPriceMargin(offerBookListItem.getOffer(), false).length()));
|
highestMarketPriceMarginOffer.ifPresent(offerBookListItem -> maxPlacesForMarketPriceMargin.set(formatMarketPriceMargin(offerBookListItem.getOffer(), false).length()));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If our accounts have changed we reset our myInsufficientTradeLimitCache as it depends on account data
|
||||||
|
user.getPaymentAccountsAsObservable().addListener((SetChangeListener<PaymentAccount>) c ->
|
||||||
|
myInsufficientTradeLimitCache.clear());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -223,10 +234,13 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
}
|
}
|
||||||
tradeCurrencyCode.set(selectedTradeCurrency.getCode());
|
tradeCurrencyCode.set(selectedTradeCurrency.getCode());
|
||||||
|
|
||||||
|
disableMatchToggle.set(user.getPaymentAccounts() == null || user.getPaymentAccounts().isEmpty());
|
||||||
|
useOffersMatchingMyAccountsFilter = !disableMatchToggle.get() && isShowOffersMatchingMyAccounts();
|
||||||
|
|
||||||
fillAllTradeCurrencies();
|
fillAllTradeCurrencies();
|
||||||
preferences.getTradeCurrenciesAsObservable().addListener(tradeCurrencyListChangeListener);
|
preferences.getTradeCurrenciesAsObservable().addListener(tradeCurrencyListChangeListener);
|
||||||
offerBook.fillOfferBookListItems();
|
offerBook.fillOfferBookListItems();
|
||||||
applyFilterPredicate();
|
filterOffers();
|
||||||
setMarketPriceFeedCurrency();
|
setMarketPriceFeedCurrency();
|
||||||
|
|
||||||
priceUtil.recalculateBsq30DayAveragePrice();
|
priceUtil.recalculateBsq30DayAveragePrice();
|
||||||
|
@ -238,6 +252,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
preferences.getTradeCurrenciesAsObservable().removeListener(tradeCurrencyListChangeListener);
|
preferences.getTradeCurrenciesAsObservable().removeListener(tradeCurrencyListChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// API
|
// API
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -268,7 +283,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
setMarketPriceFeedCurrency();
|
setMarketPriceFeedCurrency();
|
||||||
applyFilterPredicate();
|
filterOffers();
|
||||||
|
|
||||||
if (direction == OfferPayload.Direction.BUY)
|
if (direction == OfferPayload.Direction.BUY)
|
||||||
preferences.setBuyScreenCurrencyCode(code);
|
preferences.setBuyScreenCurrencyCode(code);
|
||||||
|
@ -294,17 +309,28 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
this.selectedPaymentMethod = getShowAllEntryForPaymentMethod();
|
this.selectedPaymentMethod = getShowAllEntryForPaymentMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilterPredicate();
|
filterOffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRemoveOpenOffer(Offer offer, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
|
void onRemoveOpenOffer(Offer offer, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
|
||||||
openOfferManager.removeOffer(offer, resultHandler, errorMessageHandler);
|
openOfferManager.removeOffer(offer, resultHandler, errorMessageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onShowOffersMatchingMyAccounts(boolean isSelected) {
|
||||||
|
useOffersMatchingMyAccountsFilter = isSelected;
|
||||||
|
preferences.setShowOffersMatchingMyAccounts(useOffersMatchingMyAccountsFilter);
|
||||||
|
filterOffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Getters
|
// Getters
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
boolean isShowOffersMatchingMyAccounts() {
|
||||||
|
return preferences.isShowOffersMatchingMyAccounts();
|
||||||
|
}
|
||||||
|
|
||||||
SortedList<OfferBookListItem> getOfferList() {
|
SortedList<OfferBookListItem> getOfferList() {
|
||||||
return sortedItems;
|
return sortedItems;
|
||||||
}
|
}
|
||||||
|
@ -561,8 +587,15 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
// Filters
|
// Filters
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void applyFilterPredicate() {
|
private void filterOffers() {
|
||||||
filteredItems.setPredicate(offerBookListItem -> {
|
Predicate<OfferBookListItem> predicate = useOffersMatchingMyAccountsFilter ?
|
||||||
|
getCurrencyAndMethodPredicate().and(getOffersMatchingMyAccountsPredicate()) :
|
||||||
|
getCurrencyAndMethodPredicate();
|
||||||
|
filteredItems.setPredicate(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Predicate<OfferBookListItem> getCurrencyAndMethodPredicate() {
|
||||||
|
return offerBookListItem -> {
|
||||||
Offer offer = offerBookListItem.getOffer();
|
Offer offer = offerBookListItem.getOffer();
|
||||||
boolean directionResult = offer.getDirection() != direction;
|
boolean directionResult = offer.getDirection() != direction;
|
||||||
boolean currencyResult = (showAllTradeCurrenciesProperty.get()) ||
|
boolean currencyResult = (showAllTradeCurrenciesProperty.get()) ||
|
||||||
|
@ -571,7 +604,37 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
offer.getPaymentMethod().equals(selectedPaymentMethod);
|
offer.getPaymentMethod().equals(selectedPaymentMethod);
|
||||||
boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook();
|
boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook();
|
||||||
return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated;
|
return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated;
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Predicate<OfferBookListItem> getOffersMatchingMyAccountsPredicate() {
|
||||||
|
// This code duplicates code in the view at the button column. We need there the different results for
|
||||||
|
// display in popups so we cannot replace that with the predicate. Any change need to be applied in both
|
||||||
|
// places.
|
||||||
|
return offerBookListItem -> {
|
||||||
|
Offer offer = offerBookListItem.getOffer();
|
||||||
|
boolean isPaymentAccountValidForOffer = isAnyPaymentAccountValidForOffer(offer);
|
||||||
|
boolean isInsufficientCounterpartyTradeLimit = isInsufficientCounterpartyTradeLimit(offer);
|
||||||
|
boolean hasSameProtocolVersion = hasSameProtocolVersion(offer);
|
||||||
|
boolean isIgnored = isIgnored(offer);
|
||||||
|
boolean isOfferBanned = isOfferBanned(offer);
|
||||||
|
boolean isCurrencyBanned = isCurrencyBanned(offer);
|
||||||
|
boolean isPaymentMethodBanned = isPaymentMethodBanned(offer);
|
||||||
|
boolean isNodeAddressBanned = isNodeAddressBanned(offer);
|
||||||
|
boolean requireUpdateToNewVersion = requireUpdateToNewVersion();
|
||||||
|
boolean isMyInsufficientTradeLimit = isMyInsufficientTradeLimit(offer);
|
||||||
|
boolean isTradable = isPaymentAccountValidForOffer &&
|
||||||
|
!isInsufficientCounterpartyTradeLimit &&
|
||||||
|
hasSameProtocolVersion &&
|
||||||
|
!isIgnored &&
|
||||||
|
!isOfferBanned &&
|
||||||
|
!isCurrencyBanned &&
|
||||||
|
!isPaymentMethodBanned &&
|
||||||
|
!isNodeAddressBanned &&
|
||||||
|
!requireUpdateToNewVersion &&
|
||||||
|
!isMyInsufficientTradeLimit;
|
||||||
|
return isTradable;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isIgnored(Offer offer) {
|
boolean isIgnored(Offer offer) {
|
||||||
|
@ -599,13 +662,28 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
return filterManager.requireUpdateToNewVersionForTrading();
|
return filterManager.requireUpdateToNewVersionForTrading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This call is a bit expensive so we cache results
|
||||||
boolean isInsufficientCounterpartyTradeLimit(Offer offer) {
|
boolean isInsufficientCounterpartyTradeLimit(Offer offer) {
|
||||||
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) &&
|
String offerId = offer.getId();
|
||||||
!accountAgeWitnessService.verifyPeersTradeAmount(offer, offer.getAmount(), errorMessage -> {
|
if (insufficientCounterpartyTradeLimitCache.containsKey(offerId)) {
|
||||||
});
|
return insufficientCounterpartyTradeLimitCache.get(offerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) &&
|
||||||
|
!accountAgeWitnessService.verifyPeersTradeAmount(offer, offer.getAmount(),
|
||||||
|
errorMessage -> {
|
||||||
|
});
|
||||||
|
insufficientCounterpartyTradeLimitCache.put(offerId, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This call is a bit expensive so we cache results
|
||||||
boolean isMyInsufficientTradeLimit(Offer offer) {
|
boolean isMyInsufficientTradeLimit(Offer offer) {
|
||||||
|
String offerId = offer.getId();
|
||||||
|
if (myInsufficientTradeLimitCache.containsKey(offerId)) {
|
||||||
|
return myInsufficientTradeLimitCache.get(offerId);
|
||||||
|
}
|
||||||
|
|
||||||
Optional<PaymentAccount> accountOptional = getMostMaturePaymentAccountForOffer(offer);
|
Optional<PaymentAccount> accountOptional = getMostMaturePaymentAccountForOffer(offer);
|
||||||
long myTradeLimit = accountOptional
|
long myTradeLimit = accountOptional
|
||||||
.map(paymentAccount -> accountAgeWitnessService.getMyTradeLimit(paymentAccount,
|
.map(paymentAccount -> accountAgeWitnessService.getMyTradeLimit(paymentAccount,
|
||||||
|
@ -616,9 +694,11 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||||
accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null",
|
accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null",
|
||||||
Coin.valueOf(myTradeLimit).toFriendlyString(),
|
Coin.valueOf(myTradeLimit).toFriendlyString(),
|
||||||
Coin.valueOf(offerMinAmount).toFriendlyString());
|
Coin.valueOf(offerMinAmount).toFriendlyString());
|
||||||
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) &&
|
boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) &&
|
||||||
accountOptional.isPresent() &&
|
accountOptional.isPresent() &&
|
||||||
myTradeLimit < offerMinAmount;
|
myTradeLimit < offerMinAmount;
|
||||||
|
myInsufficientTradeLimitCache.put(offerId, result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasSameProtocolVersion(Offer offer) {
|
boolean hasSameProtocolVersion(Offer offer) {
|
||||||
|
|
|
@ -1615,6 +1615,7 @@ message PreferencesPayload {
|
||||||
repeated AutoConfirmSettings auto_confirm_settings = 56;
|
repeated AutoConfirmSettings auto_confirm_settings = 56;
|
||||||
double bsq_average_trim_threshold = 57;
|
double bsq_average_trim_threshold = 57;
|
||||||
bool hide_non_account_payment_methods = 58;
|
bool hide_non_account_payment_methods = 58;
|
||||||
|
bool show_offers_matching_my_accounts = 59;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AutoConfirmSettings {
|
message AutoConfirmSettings {
|
||||||
|
|
Loading…
Add table
Reference in a new issue