Skip to content

Commit

Permalink
Close current SELL offer tab
Browse files Browse the repository at this point in the history
TODO: fix bug with currency combobox
  • Loading branch information
Jakub-CZ committed May 23, 2021
1 parent 57a1bf1 commit 82b4fe8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Expand Up @@ -163,6 +163,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
private ChangeListener<String> tradeCurrencyCodeListener, errorMessageListener,
marketPriceMarginListener, volumeListener, buyerSecurityDepositInBTCListener;
private ChangeListener<Number> marketPriceAvailableListener;
private Navigation.Listener navigationWithCloseListener;
private EventHandler<ActionEvent> currencyComboBoxSelectionHandler, paymentAccountsComboBoxSelectionHandler;
private OfferView.CloseHandler closeHandler;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -931,6 +940,8 @@ private void addListeners() {
// UI actions
paymentAccountsComboBox.setOnAction(paymentAccountsComboBoxSelectionHandler);
currencyComboBox.setOnAction(currencyComboBoxSelectionHandler);

navigation.addListener(navigationWithCloseListener);
}

private void removeListeners() {
Expand Down Expand Up @@ -966,6 +977,8 @@ private void removeListeners() {
// UI actions
paymentAccountsComboBox.setOnAction(null);
currencyComboBox.setOnAction(null);

navigation.removeListener(navigationWithCloseListener);
}


Expand Down Expand Up @@ -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<AutoTooltipButton, VBox> buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(navigation, preferences);
Tuple2<AutoTooltipButton, VBox> buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(
navigation, preferences, model.dataModel::getDirection);
buyBsqButton = buyBsqButtonBox.first;
buyBsqButton.setVisible(false);

Expand Down
17 changes: 15 additions & 2 deletions desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -48,7 +52,13 @@ public static Label createPopOverLabel(String text) {
return label;
}

public static Tuple2<AutoTooltipButton, VBox> createBuyBsqButtonBox(Navigation navigation, Preferences preferences) {
public interface DirectionClosure {
OfferPayload.Direction getDirection();
}

public static Tuple2<AutoTooltipButton, VBox> createBuyBsqButtonBox(Navigation navigation,
Preferences preferences,
DirectionClosure directionClosure) {
String buyBsqText = Res.get("shared.buyCurrency", "BSQ");
var buyBsqButton = new AutoTooltipButton(buyBsqText);
buyBsqButton.getStyleClass().add("action-button");
Expand All @@ -59,7 +69,10 @@ public static Tuple2<AutoTooltipButton, VBox> 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);
Expand Down
Expand Up @@ -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<AutoTooltipButton, VBox> buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(navigation, model.dataModel.preferences);
Tuple2<AutoTooltipButton, VBox> buyBsqButtonBox = OfferViewUtil.createBuyBsqButtonBox(
navigation, model.dataModel.preferences, model.dataModel::getDirection);

advancedOptionsBox.getChildren().addAll(getTradeFeeFieldsBox(), buyBsqButtonBox.second);
}
Expand Down

0 comments on commit 82b4fe8

Please sign in to comment.