mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Add missing filtering on lists - adapt OpenOffersView to use FilterBox
This commit is contained in:
parent
752606d788
commit
caee12196d
@ -17,27 +17,150 @@
|
||||
|
||||
package bisq.desktop.main.portfolio.openoffer;
|
||||
|
||||
import bisq.desktop.util.DisplayUtils;
|
||||
import bisq.desktop.util.filtering.FilterableListItem;
|
||||
import bisq.desktop.util.filtering.FilteringUtils;
|
||||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
import bisq.core.offer.OpenOfferManager;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.PriceUtil;
|
||||
import bisq.core.util.VolumeUtil;
|
||||
import bisq.core.util.coin.BsqFormatter;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* We could remove that wrapper if it is not needed for additional UI only fields.
|
||||
*/
|
||||
class OpenOfferListItem {
|
||||
class OpenOfferListItem implements FilterableListItem {
|
||||
@Getter
|
||||
private final OpenOffer openOffer;
|
||||
private final PriceUtil priceUtil;
|
||||
private final CoinFormatter btcFormatter;
|
||||
private final BsqFormatter bsqFormatter;
|
||||
private final OpenOfferManager openOfferManager;
|
||||
|
||||
OpenOfferListItem(OpenOffer openOffer) {
|
||||
|
||||
OpenOfferListItem(OpenOffer openOffer, PriceUtil priceUtil, CoinFormatter btcFormatter, BsqFormatter bsqFormatter, OpenOfferManager openOfferManager) {
|
||||
this.openOffer = openOffer;
|
||||
}
|
||||
|
||||
OpenOfferListItem() {
|
||||
openOffer = null;
|
||||
this.priceUtil = priceUtil;
|
||||
this.btcFormatter = btcFormatter;
|
||||
this.bsqFormatter = bsqFormatter;
|
||||
this.openOfferManager = openOfferManager;
|
||||
}
|
||||
|
||||
public Offer getOffer() {
|
||||
return openOffer.getOffer();
|
||||
}
|
||||
|
||||
public String getDateAsString() {
|
||||
return DisplayUtils.formatDateTime(getOffer().getDate());
|
||||
}
|
||||
|
||||
public String getMarketDescription() {
|
||||
return CurrencyUtil.getCurrencyPair(getOffer().getCurrencyCode());
|
||||
}
|
||||
|
||||
public String getPriceAsString() {
|
||||
Price price = getOffer().getPrice();
|
||||
if (price != null) {
|
||||
return FormattingUtils.formatPrice(price);
|
||||
} else {
|
||||
return Res.get("shared.na");
|
||||
}
|
||||
}
|
||||
|
||||
public Double getPriceDeviationAsDouble() {
|
||||
Offer offer = getOffer();
|
||||
return priceUtil.getMarketBasedPrice(offer, offer.getMirroredDirection()).orElse(0d);
|
||||
}
|
||||
|
||||
public String getPriceDeviationAsString() {
|
||||
Offer offer = getOffer();
|
||||
return priceUtil.getMarketBasedPrice(offer, offer.getMirroredDirection())
|
||||
.map(FormattingUtils::formatPercentagePrice)
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
public String getPaymentMethodAsString() {
|
||||
return getOffer().getPaymentMethodNameWithCountryCode();
|
||||
}
|
||||
|
||||
public String getVolumeAsString() {
|
||||
return VolumeUtil.formatVolume(getOffer(), false, 0) + " " + getOffer().getCurrencyCode();
|
||||
}
|
||||
|
||||
public String getAmountAsString() {
|
||||
return DisplayUtils.formatAmount(getOffer(), btcFormatter);
|
||||
}
|
||||
|
||||
public String getDirectionLabel() {
|
||||
Offer offer = getOffer();
|
||||
OfferDirection direction = openOfferManager.isMyOffer(offer) ? offer.getDirection() : offer.getMirroredDirection();
|
||||
return DisplayUtils.getDirectionWithCode(direction, getOffer().getCurrencyCode());
|
||||
}
|
||||
|
||||
public boolean hasMakerFee() {
|
||||
return getOffer().getMakerFee().isPositive();
|
||||
}
|
||||
|
||||
public String getMakerFeeAsString() {
|
||||
Offer offer = getOffer();
|
||||
return offer.isCurrencyForMakerFeeBtc() ?
|
||||
btcFormatter.formatCoinWithCode(offer.getMakerFee()) :
|
||||
bsqFormatter.formatCoinWithCode(offer.getMakerFee());
|
||||
}
|
||||
|
||||
public boolean isNotPublished() {
|
||||
return openOffer.isDeactivated() || (getOffer().isBsqSwapOffer() && openOffer.isBsqSwapOfferHasMissingFunds());
|
||||
}
|
||||
|
||||
public String getTriggerPriceAsString() {
|
||||
Offer offer = getOffer();
|
||||
long triggerPrice = openOffer.getTriggerPrice();
|
||||
if (!offer.isUseMarketBasedPrice() || triggerPrice <= 0) {
|
||||
return Res.get("shared.na");
|
||||
} else {
|
||||
return PriceUtil.formatMarketPrice(triggerPrice, offer.getCurrencyCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(String filterString) {
|
||||
if (filterString.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (getDateAsString().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getMarketDescription().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getPriceAsString().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getPriceDeviationAsString().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getPaymentMethodAsString().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getVolumeAsString().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getAmountAsString().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (getDirectionLabel().contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
return FilteringUtils.match(getOffer(), filterString);
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,18 @@ import bisq.core.offer.OpenOfferManager;
|
||||
import bisq.core.offer.bisq_v1.TriggerPriceService;
|
||||
import bisq.core.offer.bsq_swap.OpenBsqSwapOfferService;
|
||||
import bisq.core.provider.price.PriceFeedService;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.PriceUtil;
|
||||
import bisq.core.util.coin.BsqFormatter;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
|
||||
import bisq.common.handlers.ErrorMessageHandler;
|
||||
import bisq.common.handlers.ResultHandler;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
@ -44,6 +50,9 @@ class OpenOffersDataModel extends ActivatableDataModel {
|
||||
private final OpenOfferManager openOfferManager;
|
||||
private final OpenBsqSwapOfferService openBsqSwapOfferService;
|
||||
private final PriceFeedService priceFeedService;
|
||||
private final PriceUtil priceUtil;
|
||||
private final CoinFormatter btcFormatter;
|
||||
private final BsqFormatter bsqFormatter;
|
||||
|
||||
private final ObservableList<OpenOfferListItem> list = FXCollections.observableArrayList();
|
||||
private final ListChangeListener<OpenOffer> tradesListChangeListener;
|
||||
@ -52,10 +61,16 @@ class OpenOffersDataModel extends ActivatableDataModel {
|
||||
@Inject
|
||||
public OpenOffersDataModel(OpenOfferManager openOfferManager,
|
||||
OpenBsqSwapOfferService openBsqSwapOfferService,
|
||||
PriceFeedService priceFeedService) {
|
||||
PriceFeedService priceFeedService,
|
||||
PriceUtil priceUtil,
|
||||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter,
|
||||
BsqFormatter bsqFormatter) {
|
||||
this.openOfferManager = openOfferManager;
|
||||
this.openBsqSwapOfferService = openBsqSwapOfferService;
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.priceUtil = priceUtil;
|
||||
this.btcFormatter = btcFormatter;
|
||||
this.bsqFormatter = bsqFormatter;
|
||||
|
||||
tradesListChangeListener = change -> applyList();
|
||||
currenciesUpdateFlagPropertyListener = (observable, oldValue, newValue) -> applyList();
|
||||
@ -106,7 +121,11 @@ class OpenOffersDataModel extends ActivatableDataModel {
|
||||
private void applyList() {
|
||||
list.clear();
|
||||
|
||||
list.addAll(openOfferManager.getObservableList().stream().map(OpenOfferListItem::new).collect(Collectors.toList()));
|
||||
list.addAll(
|
||||
openOfferManager.getObservableList().stream()
|
||||
.map(item -> new OpenOfferListItem(item, priceUtil, btcFormatter, bsqFormatter, openOfferManager))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
|
||||
// we sort by date, earliest first
|
||||
list.sort((o1, o2) -> o2.getOffer().getDate().compareTo(o1.getOffer().getDate()));
|
||||
|
@ -18,9 +18,8 @@
|
||||
-->
|
||||
|
||||
<?import bisq.desktop.components.AutoTooltipButton?>
|
||||
<?import bisq.desktop.components.AutoTooltipLabel?>
|
||||
<?import bisq.desktop.components.AutoTooltipSlideToggleButton?>
|
||||
<?import bisq.desktop.components.InputTextField?>
|
||||
<?import bisq.desktop.components.list.FilterBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
@ -34,9 +33,8 @@
|
||||
<padding>
|
||||
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>
|
||||
</padding>
|
||||
<HBox spacing="5.0">
|
||||
<AutoTooltipLabel fx:id="filterLabel"/>
|
||||
<InputTextField fx:id="filterTextField" minWidth="500"/>
|
||||
<HBox>
|
||||
<FilterBox fx:id="filterBox" />
|
||||
<Pane HBox.hgrow="ALWAYS"/>
|
||||
<AutoTooltipSlideToggleButton fx:id="selectToggleButton"/>
|
||||
</HBox>
|
||||
|
@ -25,7 +25,7 @@ import bisq.desktop.components.AutoTooltipLabel;
|
||||
import bisq.desktop.components.AutoTooltipSlideToggleButton;
|
||||
import bisq.desktop.components.AutoTooltipTableColumn;
|
||||
import bisq.desktop.components.HyperlinkWithIcon;
|
||||
import bisq.desktop.components.InputTextField;
|
||||
import bisq.desktop.components.list.FilterBox;
|
||||
import bisq.desktop.main.MainView;
|
||||
import bisq.desktop.main.funds.FundsView;
|
||||
import bisq.desktop.main.funds.withdrawal.WithdrawalView;
|
||||
@ -35,7 +35,6 @@ import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
|
||||
import bisq.desktop.main.portfolio.PortfolioView;
|
||||
import bisq.desktop.main.portfolio.presentation.PortfolioUtil;
|
||||
import bisq.desktop.util.GUIUtil;
|
||||
import bisq.desktop.util.filtering.FilteringUtils;
|
||||
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.Offer;
|
||||
@ -63,7 +62,6 @@ import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
@ -122,9 +120,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
marketColumn, directionColumn, dateColumn, offerIdColumn, deactivateItemColumn,
|
||||
removeItemColumn, editItemColumn, triggerPriceColumn, triggerIconColumn, paymentMethodColumn, duplicateItemColumn;
|
||||
@FXML
|
||||
AutoTooltipLabel filterLabel;
|
||||
@FXML
|
||||
InputTextField filterTextField;
|
||||
FilterBox filterBox;
|
||||
@FXML
|
||||
Label numItems;
|
||||
@FXML
|
||||
@ -138,8 +134,6 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
private final OfferDetailsWindow offerDetailsWindow;
|
||||
private final BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow;
|
||||
private SortedList<OpenOfferListItem> sortedList;
|
||||
private FilteredList<OpenOfferListItem> filteredList;
|
||||
private ChangeListener<String> filterTextFieldListener;
|
||||
private PortfolioView.OpenOfferActionHandler openOfferActionHandler;
|
||||
private ChangeListener<Number> widthListener;
|
||||
|
||||
@ -194,10 +188,10 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
|
||||
offerIdColumn.setComparator(Comparator.comparing(o -> o.getOffer().getId()));
|
||||
directionColumn.setComparator(Comparator.comparing(o -> o.getOffer().getDirection()));
|
||||
marketColumn.setComparator(Comparator.comparing(model::getMarketLabel));
|
||||
marketColumn.setComparator(Comparator.comparing(OpenOfferListItem::getMarketDescription));
|
||||
amountColumn.setComparator(Comparator.comparing(o -> o.getOffer().getAmount()));
|
||||
priceColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPrice(), Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
deviationColumn.setComparator(Comparator.comparing(model::getPriceDeviationAsDouble, Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
deviationColumn.setComparator(Comparator.comparing(OpenOfferListItem::getPriceDeviationAsDouble, Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
triggerPriceColumn.setComparator(Comparator.comparing(o -> o.getOpenOffer().getTriggerPrice(),
|
||||
Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
volumeColumn.setComparator(Comparator.comparing(o -> o.getOffer().getVolume(), Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
@ -221,10 +215,6 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
return row;
|
||||
});
|
||||
|
||||
filterLabel.setText(Res.get("shared.filter"));
|
||||
HBox.setMargin(filterLabel, new Insets(5, 0, 0, 10));
|
||||
filterTextFieldListener = (observable, oldValue, newValue) -> applyFilteredListPredicate(filterTextField.getText());
|
||||
|
||||
selectToggleButton.setPadding(new Insets(0, 90, -20, 0));
|
||||
selectToggleButton.setText(Res.get("shared.enabled"));
|
||||
selectToggleButton.setDisable(true);
|
||||
@ -238,11 +228,14 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
|
||||
@Override
|
||||
protected void activate() {
|
||||
filteredList = new FilteredList<>(model.getList());
|
||||
FilteredList<OpenOfferListItem> filteredList = new FilteredList<>(model.dataModel.getList());
|
||||
sortedList = new SortedList<>(filteredList);
|
||||
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
|
||||
tableView.setItems(sortedList);
|
||||
|
||||
filterBox.initialize(filteredList, tableView); // here because filteredList is instantiated here
|
||||
filterBox.activate();
|
||||
|
||||
updateSelectToggleButtonState();
|
||||
|
||||
selectToggleButton.setOnAction(event -> {
|
||||
@ -267,16 +260,16 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
};
|
||||
CSVEntryConverter<OpenOfferListItem> contentConverter = item -> {
|
||||
String[] columns = new String[ColumnNames.values().length];
|
||||
columns[ColumnNames.OFFER_ID.ordinal()] = model.getOfferId(item);
|
||||
columns[ColumnNames.DATE.ordinal()] = model.getDate(item);
|
||||
columns[ColumnNames.MARKET.ordinal()] = model.getMarketLabel(item);
|
||||
columns[ColumnNames.PRICE.ordinal()] = model.getPrice(item);
|
||||
columns[ColumnNames.DEVIATION.ordinal()] = model.getPriceDeviation(item);
|
||||
columns[ColumnNames.TRIGGER_PRICE.ordinal()] = model.getTriggerPrice(item);
|
||||
columns[ColumnNames.AMOUNT.ordinal()] = model.getAmount(item);
|
||||
columns[ColumnNames.VOLUME.ordinal()] = model.getVolume(item);
|
||||
columns[ColumnNames.PAYMENT_METHOD.ordinal()] = model.getPaymentMethod(item);
|
||||
columns[ColumnNames.DIRECTION.ordinal()] = model.getDirectionLabel(item);
|
||||
columns[ColumnNames.OFFER_ID.ordinal()] = item.getOffer().getShortId();
|
||||
columns[ColumnNames.DATE.ordinal()] = item.getDateAsString();
|
||||
columns[ColumnNames.MARKET.ordinal()] = item.getMarketDescription();
|
||||
columns[ColumnNames.PRICE.ordinal()] = item.getPriceAsString();
|
||||
columns[ColumnNames.DEVIATION.ordinal()] = item.getPriceDeviationAsString();
|
||||
columns[ColumnNames.TRIGGER_PRICE.ordinal()] = item.getTriggerPriceAsString();
|
||||
columns[ColumnNames.AMOUNT.ordinal()] = item.getAmountAsString();
|
||||
columns[ColumnNames.VOLUME.ordinal()] = item.getVolumeAsString();
|
||||
columns[ColumnNames.PAYMENT_METHOD.ordinal()] = item.getPaymentMethodAsString();
|
||||
columns[ColumnNames.DIRECTION.ordinal()] = item.getDirectionLabel();
|
||||
columns[ColumnNames.STATUS.ordinal()] = String.valueOf(!item.getOpenOffer().isDeactivated());
|
||||
return columns;
|
||||
};
|
||||
@ -284,14 +277,11 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
GUIUtil.exportCSV("openOffers.csv",
|
||||
headerConverter,
|
||||
contentConverter,
|
||||
new OpenOfferListItem(),
|
||||
new OpenOfferListItem(null, null, null, null, null),
|
||||
sortedList,
|
||||
(Stage) root.getScene().getWindow());
|
||||
});
|
||||
|
||||
filterTextField.textProperty().addListener(filterTextFieldListener);
|
||||
applyFilteredListPredicate(filterTextField.getText());
|
||||
|
||||
root.widthProperty().addListener(widthListener);
|
||||
onWidthChange(root.getWidth());
|
||||
}
|
||||
@ -301,7 +291,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
sortedList.comparatorProperty().unbind();
|
||||
exportButton.setOnAction(null);
|
||||
|
||||
filterTextField.textProperty().removeListener(filterTextFieldListener);
|
||||
filterBox.deactivate();
|
||||
root.widthProperty().removeListener(widthListener);
|
||||
}
|
||||
|
||||
@ -322,39 +312,6 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
}
|
||||
}
|
||||
|
||||
private void applyFilteredListPredicate(String filterString) {
|
||||
filteredList.setPredicate(item -> {
|
||||
if (filterString.isEmpty())
|
||||
return true;
|
||||
|
||||
if (model.getDate(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (model.getMarketLabel(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (model.getPrice(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (model.getPriceDeviation(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (model.getPaymentMethod(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (model.getVolume(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (model.getAmount(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
if (model.getDirectionLabel(item).contains(filterString)) {
|
||||
return true;
|
||||
}
|
||||
return FilteringUtils.match(item.getOpenOffer().getOffer(), filterString);
|
||||
});
|
||||
}
|
||||
|
||||
private void onWidthChange(double width) {
|
||||
triggerPriceColumn.setVisible(width > 1200);
|
||||
}
|
||||
@ -383,12 +340,13 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
}
|
||||
}
|
||||
|
||||
private void onRemoveOpenOffer(OpenOffer openOffer) {
|
||||
private void onRemoveOpenOffer(OpenOfferListItem item) {
|
||||
OpenOffer openOffer = item.getOpenOffer();
|
||||
if (model.isBootstrappedOrShowPopup()) {
|
||||
String key = "RemoveOfferWarning";
|
||||
if (DontShowAgainLookup.showAgain(key)) {
|
||||
String message = model.hasMakerFee(openOffer) ?
|
||||
Res.get("popup.warning.removeOffer", model.getMakerFeeAsString(openOffer)) :
|
||||
String message = item.hasMakerFee() ?
|
||||
Res.get("popup.warning.removeOffer", item.getMakerFeeAsString()) :
|
||||
Res.get("popup.warning.removeNoFeeOffer");
|
||||
new Popup().warning(message)
|
||||
.actionButtonText(Res.get("shared.removeOffer"))
|
||||
@ -458,7 +416,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
public void updateItem(final OpenOfferListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty) {
|
||||
field = new HyperlinkWithIcon(model.getOfferId(item));
|
||||
field = new HyperlinkWithIcon(item.getOffer().getShortId());
|
||||
field.setOnAction(event -> {
|
||||
if (item.getOffer().isBsqSwapOffer()) {
|
||||
bsqSwapOfferDetailsWindow.show(item.getOffer());
|
||||
@ -493,8 +451,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
super.updateItem(item, empty);
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getDate(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getDateAsString()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -518,8 +476,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getAmount(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getAmountAsString()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -543,8 +501,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getPrice(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getPriceAsString()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -568,8 +526,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
AutoTooltipLabel autoTooltipLabel = new AutoTooltipLabel(model.getPriceDeviation(item));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
AutoTooltipLabel autoTooltipLabel = new AutoTooltipLabel(item.getPriceDeviationAsString());
|
||||
autoTooltipLabel.setOpacity(item.getOffer().isUseMarketBasedPrice() ? 1 : 0.4);
|
||||
setGraphic(autoTooltipLabel);
|
||||
} else {
|
||||
@ -594,8 +552,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
super.updateItem(item, empty);
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getTriggerPrice(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getTriggerPriceAsString()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -619,8 +577,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getVolume(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getVolumeAsString()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -644,8 +602,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getPaymentMethodAsString()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -669,8 +627,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getDirectionLabel(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getDirectionLabel()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -694,8 +652,8 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
getStyleClass().removeAll("offer-disabled");
|
||||
|
||||
if (item != null) {
|
||||
if (model.isNotPublished(item)) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(model.getMarketLabel(item)));
|
||||
if (item.isNotPublished()) getStyleClass().add("offer-disabled");
|
||||
setGraphic(new AutoTooltipLabel(item.getMarketDescription()));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
@ -775,7 +733,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
button.setTooltip(new Tooltip(Res.get("shared.removeOffer")));
|
||||
setGraphic(button);
|
||||
}
|
||||
button.setOnAction(event -> onRemoveOpenOffer(item.getOpenOffer()));
|
||||
button.setOnAction(event -> onRemoveOpenOffer(item));
|
||||
} else {
|
||||
setGraphic(null);
|
||||
if (button != null) {
|
||||
@ -847,7 +805,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
button.setTooltip(new Tooltip(Res.get("openOffer.triggered")));
|
||||
} else {
|
||||
button.getGraphic().getStyleClass().remove("warning");
|
||||
button.setTooltip(new Tooltip(Res.get("openOffer.triggerPrice", model.getTriggerPrice(item))));
|
||||
button.setTooltip(new Tooltip(Res.get("openOffer.triggerPrice", item.getTriggerPriceAsString())));
|
||||
}
|
||||
setGraphic(button);
|
||||
}
|
||||
|
@ -19,54 +19,31 @@ package bisq.desktop.main.portfolio.openoffer;
|
||||
|
||||
import bisq.desktop.common.model.ActivatableWithDataModel;
|
||||
import bisq.desktop.common.model.ViewModel;
|
||||
import bisq.desktop.util.DisplayUtils;
|
||||
import bisq.desktop.util.GUIUtil;
|
||||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.PriceUtil;
|
||||
import bisq.core.util.VolumeUtil;
|
||||
import bisq.core.util.coin.BsqFormatter;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
|
||||
import bisq.network.p2p.P2PService;
|
||||
|
||||
import bisq.common.handlers.ErrorMessageHandler;
|
||||
import bisq.common.handlers.ResultHandler;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
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 PriceUtil priceUtil;
|
||||
private final CoinFormatter btcFormatter;
|
||||
private final BsqFormatter bsqFormatter;
|
||||
|
||||
|
||||
@Inject
|
||||
public OpenOffersViewModel(OpenOffersDataModel dataModel,
|
||||
P2PService p2PService,
|
||||
PriceUtil priceUtil,
|
||||
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter,
|
||||
BsqFormatter bsqFormatter) {
|
||||
PriceUtil priceUtil) {
|
||||
super(dataModel);
|
||||
|
||||
this.p2PService = p2PService;
|
||||
this.priceUtil = priceUtil;
|
||||
this.btcFormatter = btcFormatter;
|
||||
this.bsqFormatter = bsqFormatter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,122 +67,7 @@ class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel>
|
||||
dataModel.onRemoveOpenOffer(openOffer, resultHandler, errorMessageHandler);
|
||||
}
|
||||
|
||||
public ObservableList<OpenOfferListItem> getList() {
|
||||
return dataModel.getList();
|
||||
}
|
||||
|
||||
String getOfferId(OpenOfferListItem item) {
|
||||
return item.getOffer().getShortId();
|
||||
}
|
||||
|
||||
String getAmount(OpenOfferListItem item) {
|
||||
return (item != null) ? DisplayUtils.formatAmount(item.getOffer(), btcFormatter) : "";
|
||||
}
|
||||
|
||||
String getPrice(OpenOfferListItem item) {
|
||||
if ((item == null))
|
||||
return "";
|
||||
|
||||
Offer offer = item.getOffer();
|
||||
Price price = offer.getPrice();
|
||||
if (price != null) {
|
||||
return FormattingUtils.formatPrice(price);
|
||||
} else {
|
||||
return Res.get("shared.na");
|
||||
}
|
||||
}
|
||||
|
||||
String getPriceDeviation(OpenOfferListItem item) {
|
||||
Offer offer = item.getOffer();
|
||||
return priceUtil.getMarketBasedPrice(offer, offer.getMirroredDirection())
|
||||
.map(FormattingUtils::formatPercentagePrice)
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
Double getPriceDeviationAsDouble(OpenOfferListItem item) {
|
||||
Offer offer = item.getOffer();
|
||||
return priceUtil.getMarketBasedPrice(offer, offer.getMirroredDirection()).orElse(0d);
|
||||
}
|
||||
|
||||
String getVolume(OpenOfferListItem item) {
|
||||
return (item != null)
|
||||
? VolumeUtil.formatVolume(item.getOffer(), false, 0) + " " + item.getOffer().getCurrencyCode()
|
||||
: "";
|
||||
}
|
||||
|
||||
String getDirectionLabel(OpenOfferListItem item) {
|
||||
if ((item == null))
|
||||
return "";
|
||||
|
||||
return DisplayUtils.getDirectionWithCode(dataModel.getDirection(item.getOffer()), item.getOffer().getCurrencyCode());
|
||||
}
|
||||
|
||||
String getMarketLabel(OpenOfferListItem item) {
|
||||
if ((item == null))
|
||||
return "";
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
boolean isNotPublished(OpenOfferListItem item) {
|
||||
return isDeactivated(item) || isBsqSwapOfferHasMissingFunds(item);
|
||||
}
|
||||
|
||||
boolean isDeactivated(OpenOfferListItem item) {
|
||||
return item != null &&
|
||||
item.getOpenOffer() != null &&
|
||||
item.getOpenOffer().isDeactivated();
|
||||
}
|
||||
|
||||
boolean isBsqSwapOfferHasMissingFunds(OpenOfferListItem item) {
|
||||
return item != null &&
|
||||
item.getOpenOffer() != null &&
|
||||
item.getOpenOffer().getOffer().isBsqSwapOffer() &&
|
||||
item.getOpenOffer().isBsqSwapOfferHasMissingFunds();
|
||||
}
|
||||
|
||||
boolean isBootstrappedOrShowPopup() {
|
||||
return GUIUtil.isBootstrappedOrShowPopup(p2PService);
|
||||
}
|
||||
|
||||
public boolean hasMakerFee(OpenOffer openOffer) {
|
||||
Coin makerFee = openOffer.getOffer().getMakerFee();
|
||||
return makerFee.isPositive();
|
||||
}
|
||||
|
||||
public String getMakerFeeAsString(OpenOffer openOffer) {
|
||||
Offer offer = openOffer.getOffer();
|
||||
return offer.isCurrencyForMakerFeeBtc() ?
|
||||
btcFormatter.formatCoinWithCode(offer.getMakerFee()) :
|
||||
bsqFormatter.formatCoinWithCode(offer.getMakerFee());
|
||||
}
|
||||
|
||||
String getTriggerPrice(OpenOfferListItem item) {
|
||||
if ((item == null)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Offer offer = item.getOffer();
|
||||
long triggerPrice = item.getOpenOffer().getTriggerPrice();
|
||||
if (!offer.isUseMarketBasedPrice() || triggerPrice <= 0) {
|
||||
return Res.get("shared.na");
|
||||
} else {
|
||||
return PriceUtil.formatMarketPrice(triggerPrice, offer.getCurrencyCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user