From 82b4fe8c6d18554c69ba0b2b5f9cd8056dc3b365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Louck=C3=BD?= Date: Mon, 17 May 2021 23:59:52 +0200 Subject: [PATCH] Close current SELL offer tab TODO: fix bug with currency combobox --- .../desktop/main/offer/MutableOfferView.java | 16 +++++++++++++++- .../bisq/desktop/main/offer/OfferViewUtil.java | 17 +++++++++++++++-- .../main/offer/takeoffer/TakeOfferView.java | 3 ++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java index 24e7c7e7543..32273c39a3d 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java @@ -163,6 +163,7 @@ public abstract class MutableOfferView> exten private ChangeListener tradeCurrencyCodeListener, errorMessageListener, marketPriceMarginListener, volumeListener, buyerSecurityDepositInBTCListener; private ChangeListener marketPriceAvailableListener; + private Navigation.Listener navigationWithCloseListener; private EventHandler currencyComboBoxSelectionHandler, paymentAccountsComboBoxSelectionHandler; private OfferView.CloseHandler closeHandler; @@ -875,6 +876,14 @@ private void createListeners() { buyerSecurityDepositInputTextField.setDisable(false); } }); + + navigationWithCloseListener = (path, data) -> { + log.warn("*** target path={}, data={}, dir={}", path, data, model.getDataModel().getDirection()); + if ("closeOfferView".equals(data)) { + log.warn("*** WILL CLOSE"); + close(); + } + }; } private void setIsCurrencyForMakerFeeBtc(boolean isCurrencyForMakerFeeBtc) { @@ -931,6 +940,8 @@ private void addListeners() { // UI actions paymentAccountsComboBox.setOnAction(paymentAccountsComboBoxSelectionHandler); currencyComboBox.setOnAction(currencyComboBoxSelectionHandler); + + navigation.addListener(navigationWithCloseListener); } private void removeListeners() { @@ -966,6 +977,8 @@ private void removeListeners() { // UI actions paymentAccountsComboBox.setOnAction(null); currencyComboBox.setOnAction(null); + + navigation.removeListener(navigationWithCloseListener); } @@ -1077,7 +1090,8 @@ private void addOptionsGroup() { GridPane.setMargin(advancedOptionsBox, new Insets(Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE, 0, 0, 0)); gridPane.getChildren().add(advancedOptionsBox); - Tuple2 buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(navigation, preferences); + Tuple2 buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox( + navigation, preferences, model.dataModel::getDirection); buyBsqButton = buyBsqButtonBox.first; buyBsqButton.setVisible(false); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java index 38ab915c0a3..e40533b9456 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java @@ -24,6 +24,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; +import bisq.core.offer.OfferPayload; import bisq.core.user.Preferences; import bisq.common.util.Tuple2; @@ -35,9 +36,12 @@ import javafx.geometry.Insets; import javafx.geometry.Pos; +import lombok.extern.slf4j.Slf4j; + /** * Reusable methods for CreateOfferView, TakeOfferView or other related views */ +@Slf4j public class OfferViewUtil { public static Label createPopOverLabel(String text) { final Label label = new Label(text); @@ -48,7 +52,13 @@ public static Label createPopOverLabel(String text) { return label; } - public static Tuple2 createBuyBsqButtonBox(Navigation navigation, Preferences preferences) { + public interface DirectionClosure { + OfferPayload.Direction getDirection(); + } + + public static Tuple2 createBuyBsqButtonBox(Navigation navigation, + Preferences preferences, + DirectionClosure directionClosure) { String buyBsqText = Res.get("shared.buyCurrency", "BSQ"); var buyBsqButton = new AutoTooltipButton(buyBsqText); buyBsqButton.getStyleClass().add("action-button"); @@ -59,7 +69,10 @@ public static Tuple2 createBuyBsqButtonBox(Navigation n .buttonAlignment(HPos.CENTER) .onAction(() -> { preferences.setSellScreenCurrencyCode("BSQ"); - navigation.navigateTo(MainView.class, SellOfferView.class, OfferBookView.class); + navigation.navigateToWithData( + // FIXME: replace "closeOfferView" with a more unique object? + directionClosure.getDirection() == OfferPayload.Direction.SELL ? "closeOfferView" : null, + MainView.class, SellOfferView.class, OfferBookView.class); }).show()); final VBox buyBsqButtonVBox = new VBox(buyBsqButton); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java index 33291610ca7..dac8cc0d4d9 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java @@ -880,7 +880,8 @@ private void addOptionsGroup() { GridPane.setMargin(advancedOptionsBox, new Insets(Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE, 0, 0, 0)); gridPane.getChildren().add(advancedOptionsBox); - Tuple2 buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(navigation, model.dataModel.preferences); + Tuple2 buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox( + navigation, model.dataModel.preferences, model.dataModel::getDirection); advancedOptionsBox.getChildren().addAll(getTradeFeeFieldsBox(), buyBsqButtonBox.second); }