From 7610d65d385650facb5e7187f95580230f81450c Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 30 Oct 2023 07:14:46 -0400 Subject: [PATCH] fix inverted offer direction for non-fiat trades --- .../haveno/desktop/main/offer/OfferView.java | 7 +++- .../desktop/main/offer/OfferViewUtil.java | 38 +------------------ .../offer/createoffer/CreateOfferView.java | 5 +-- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/offer/OfferView.java b/desktop/src/main/java/haveno/desktop/main/offer/OfferView.java index 1e5b8a478d..0fb25210da 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/OfferView.java @@ -264,7 +264,12 @@ public abstract class OfferView extends ActivatableView { // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times // in different graphs view = viewLoader.load(childViewClass); - ((CreateOfferView) view).initWithData(direction, tradeCurrency, offerActionHandler); + + // Invert direction for non-Fiat trade currencies -> BUY BCH is to SELL Monero + OfferDirection offerDirection = CurrencyUtil.isFiatCurrency(tradeCurrency.getCode()) ? direction : + direction == OfferDirection.BUY ? OfferDirection.SELL : OfferDirection.BUY; + + ((CreateOfferView) view).initWithData(offerDirection, tradeCurrency, offerActionHandler); ((SelectableView) view).onTabSelected(true); diff --git a/desktop/src/main/java/haveno/desktop/main/offer/OfferViewUtil.java b/desktop/src/main/java/haveno/desktop/main/offer/OfferViewUtil.java index f62f001323..00fec8bb0e 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/OfferViewUtil.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/OfferViewUtil.java @@ -18,7 +18,6 @@ package haveno.desktop.main.offer; import haveno.common.UserThread; -import haveno.common.util.Tuple2; import haveno.core.locale.CryptoCurrency; import haveno.core.locale.CurrencyUtil; import haveno.core.locale.Res; @@ -26,10 +25,7 @@ import haveno.core.locale.TradeCurrency; import haveno.core.offer.Offer; import haveno.core.offer.OfferDirection; import haveno.core.xmr.wallet.XmrWalletService; -import haveno.desktop.Navigation; -import haveno.desktop.components.AutoTooltipButton; import haveno.desktop.components.AutoTooltipLabel; -import haveno.desktop.components.HyperlinkWithIcon; import haveno.desktop.main.offer.offerbook.XmrOfferBookView; import haveno.desktop.main.offer.offerbook.OfferBookView; import haveno.desktop.main.offer.offerbook.OtherOfferBookView; @@ -38,13 +34,11 @@ import haveno.desktop.main.overlays.popups.Popup; import haveno.desktop.util.GUIUtil; import javafx.geometry.HPos; import javafx.geometry.Insets; -import javafx.geometry.Pos; import javafx.geometry.VPos; import javafx.scene.control.Label; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; -import javafx.scene.layout.HBox; import lombok.extern.slf4j.Slf4j; import monero.daemon.model.MoneroSubmitTxResult; import org.jetbrains.annotations.NotNull; @@ -94,36 +88,6 @@ public class OfferViewUtil { infoGridPane.getChildren().addAll(label, textField); } - public static Tuple2 createBuyBsqButtonBox(Navigation navigation) { - String buyBsqText = Res.get("shared.buyCurrency", "BSQ"); - var buyBsqButton = new AutoTooltipButton(buyBsqText); - buyBsqButton.getStyleClass().add("action-button"); - buyBsqButton.getStyleClass().add("tiny-button"); - buyBsqButton.setMinWidth(60); - buyBsqButton.setOnAction(e -> openBuyBsqOfferBook(navigation) - ); - - var info = new AutoTooltipLabel("BSQ is colored BTC that helps fund Haveno developers."); - var learnMore = new HyperlinkWithIcon("Learn More"); - learnMore.setOnAction(e -> new Popup().headLine(buyBsqText) - .information(Res.get("createOffer.buyBsq.popupMessage")) - .actionButtonText(buyBsqText) - .buttonAlignment(HPos.CENTER) - .onAction(() -> openBuyBsqOfferBook(navigation)).show()); - learnMore.setMinWidth(100); - - HBox buyBsqBox = new HBox(buyBsqButton, info, learnMore); - buyBsqBox.setAlignment(Pos.BOTTOM_LEFT); - buyBsqBox.setSpacing(10); - buyBsqBox.setPadding(new Insets(0, 0, 4, -20)); - - return new Tuple2<>(buyBsqButton, buyBsqBox); - } - - private static void openBuyBsqOfferBook(Navigation navigation) { - throw new Error("BSQ not supported"); - } - public static Class> getOfferBookViewClass(String currencyCode) { Class> offerBookViewClazz; if (CurrencyUtil.isTraditionalCurrency(currencyCode)) { @@ -145,7 +109,7 @@ public class OfferViewUtil { } public static boolean isShownAsSellOffer(String currencyCode, OfferDirection direction) { - return CurrencyUtil.isTraditionalCurrency(currencyCode) == (direction == OfferDirection.SELL); + return CurrencyUtil.isFiatCurrency(currencyCode) == (direction == OfferDirection.SELL); } public static boolean isShownAsBuyOffer(Offer offer) { diff --git a/desktop/src/main/java/haveno/desktop/main/offer/createoffer/CreateOfferView.java b/desktop/src/main/java/haveno/desktop/main/offer/createoffer/CreateOfferView.java index 6dace11d42..8cde03a07b 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/createoffer/CreateOfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/createoffer/CreateOfferView.java @@ -54,10 +54,7 @@ public class CreateOfferView extends MutableOfferView { public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency, OfferView.OfferActionHandler offerActionHandler) { - // Invert direction for non-Fiat trade currencies -> BUY BSQ is to SELL Bitcoin - OfferDirection offerDirection = CurrencyUtil.isFiatCurrency(tradeCurrency.getCode()) ? direction : - direction == OfferDirection.BUY ? OfferDirection.SELL : OfferDirection.BUY; - super.initWithData(offerDirection, tradeCurrency, offerActionHandler); + super.initWithData(direction, tradeCurrency, offerActionHandler); } @Override