diff --git a/core/src/main/java/haveno/core/locale/CurrencyUtil.java b/core/src/main/java/haveno/core/locale/CurrencyUtil.java index b482ea4f..45371225 100644 --- a/core/src/main/java/haveno/core/locale/CurrencyUtil.java +++ b/core/src/main/java/haveno/core/locale/CurrencyUtil.java @@ -73,14 +73,6 @@ public class CurrencyUtil { private static String baseCurrencyCode = "XMR"; - private static List getTraditionalNonFiatCurrencies() { - return Arrays.asList( - new TraditionalCurrency("XAG", "Silver"), - new TraditionalCurrency("XAU", "Gold"), - new TraditionalCurrency("XGB", "Goldback") - ); - } - // Calls to isTraditionalCurrency and isCryptoCurrency are very frequent so we use a cache of the results. // The main improvement was already achieved with using memoize for the source maps, but // the caching still reduces performance costs by about 20% for isCryptoCurrency (1752 ms vs 2121 ms) and about 50% @@ -124,6 +116,14 @@ public class CurrencyUtil { return new ArrayList<>(traditionalCurrencyMapSupplier.get().values()); } + public static List getTraditionalNonFiatCurrencies() { + return Arrays.asList( + new TraditionalCurrency("XAG", "Silver"), + new TraditionalCurrency("XAU", "Gold"), + new TraditionalCurrency("XGB", "Goldback") + ); + } + public static Collection getAllSortedTraditionalCurrencies(Comparator comparator) { return (List) getAllSortedTraditionalCurrencies().stream() .sorted(comparator) diff --git a/core/src/main/java/haveno/core/payment/PaymentAccount.java b/core/src/main/java/haveno/core/payment/PaymentAccount.java index 6a293b34..a9e03d80 100644 --- a/core/src/main/java/haveno/core/payment/PaymentAccount.java +++ b/core/src/main/java/haveno/core/payment/PaymentAccount.java @@ -139,6 +139,10 @@ public abstract class PaymentAccount implements PersistablePayload { return getSingleTradeCurrency() == null || CurrencyUtil.isFiatCurrency(getSingleTradeCurrency().getCode()); // TODO: check if trade currencies contain fiat } + public boolean isCryptoCurrency() { + return getSingleTradeCurrency() != null && CurrencyUtil.isCryptoCurrency(getSingleTradeCurrency().getCode()); + } + /////////////////////////////////////////////////////////////////////////////////////////// // PROTO BUFFER diff --git a/core/src/main/java/haveno/core/user/Preferences.java b/core/src/main/java/haveno/core/user/Preferences.java index 209dc7fb..3c09126c 100644 --- a/core/src/main/java/haveno/core/user/Preferences.java +++ b/core/src/main/java/haveno/core/user/Preferences.java @@ -566,6 +566,16 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid requestPersistence(); } + public void setBuyScreenOtherCurrencyCode(String buyScreenCurrencyCode) { + prefPayload.setBuyScreenOtherCurrencyCode(buyScreenCurrencyCode); + requestPersistence(); + } + + public void setSellScreenOtherCurrencyCode(String sellScreenCurrencyCode) { + prefPayload.setSellScreenOtherCurrencyCode(sellScreenCurrencyCode); + requestPersistence(); + } + public void setIgnoreTradersList(List ignoreTradersList) { prefPayload.setIgnoreTradersList(ignoreTradersList); requestPersistence(); diff --git a/core/src/main/java/haveno/core/user/PreferencesPayload.java b/core/src/main/java/haveno/core/user/PreferencesPayload.java index e45f1282..6d3d41f3 100644 --- a/core/src/main/java/haveno/core/user/PreferencesPayload.java +++ b/core/src/main/java/haveno/core/user/PreferencesPayload.java @@ -77,6 +77,10 @@ public final class PreferencesPayload implements PersistableEnvelope { private String buyScreenCryptoCurrencyCode; @Nullable private String sellScreenCryptoCurrencyCode; + @Nullable + private String buyScreenOtherCurrencyCode; + @Nullable + private String sellScreenOtherCurrencyCode; private int tradeStatisticsTickUnitIndex = 3; private boolean resyncSpvRequested; private boolean sortMarketCurrenciesNumerically = true; @@ -212,6 +216,8 @@ public final class PreferencesPayload implements PersistableEnvelope { Optional.ofNullable(sellScreenCurrencyCode).ifPresent(builder::setSellScreenCurrencyCode); Optional.ofNullable(buyScreenCryptoCurrencyCode).ifPresent(builder::setBuyScreenCryptoCurrencyCode); Optional.ofNullable(sellScreenCryptoCurrencyCode).ifPresent(builder::setSellScreenCryptoCurrencyCode); + Optional.ofNullable(buyScreenOtherCurrencyCode).ifPresent(builder::setBuyScreenOtherCurrencyCode); + Optional.ofNullable(sellScreenOtherCurrencyCode).ifPresent(builder::setSellScreenOtherCurrencyCode); Optional.ofNullable(selectedPaymentAccountForCreateOffer).ifPresent( account -> builder.setSelectedPaymentAccountForCreateOffer(selectedPaymentAccountForCreateOffer.toProtoMessage())); Optional.ofNullable(bridgeAddresses).ifPresent(builder::addAllBridgeAddresses); @@ -260,6 +266,8 @@ public final class PreferencesPayload implements PersistableEnvelope { ProtoUtil.stringOrNullFromProto(proto.getSellScreenCurrencyCode()), ProtoUtil.stringOrNullFromProto(proto.getBuyScreenCryptoCurrencyCode()), ProtoUtil.stringOrNullFromProto(proto.getSellScreenCryptoCurrencyCode()), + ProtoUtil.stringOrNullFromProto(proto.getBuyScreenOtherCurrencyCode()), + ProtoUtil.stringOrNullFromProto(proto.getSellScreenOtherCurrencyCode()), proto.getTradeStatisticsTickUnitIndex(), proto.getResyncSpvRequested(), proto.getSortMarketCurrenciesNumerically(), diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 45e07111..c0e99107 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -207,6 +207,7 @@ shared.crypto=Crypto shared.traditional=Traditional shared.otherAssets=other assets shared.other=Other +shared.preciousMetals=Precious Metals shared.all=All shared.edit=Edit shared.advancedOptions=Advanced options @@ -245,8 +246,8 @@ shared.taker=Taker #################################################################### mainView.menu.market=Market -mainView.menu.buy=Buy -mainView.menu.sell=Sell +mainView.menu.buyXmr=Buy XMR +mainView.menu.sellXmr=Sell XMR mainView.menu.portfolio=Portfolio mainView.menu.funds=Funds mainView.menu.support=Support diff --git a/core/src/main/resources/i18n/displayStrings_tr.properties b/core/src/main/resources/i18n/displayStrings_tr.properties index a9b123b4..a9e7e49a 100644 --- a/core/src/main/resources/i18n/displayStrings_tr.properties +++ b/core/src/main/resources/i18n/displayStrings_tr.properties @@ -245,8 +245,8 @@ shared.taker=Alıcı #################################################################### mainView.menu.market=Piyasa -mainView.menu.buy=Satın Al -mainView.menu.sell=Sat +mainView.menu.buyXmr=XMR Satın Al +mainView.menu.sellXmr=XMR Sat mainView.menu.portfolio=Portföy mainView.menu.funds=Fonlar mainView.menu.support=Destek diff --git a/desktop/src/main/java/haveno/desktop/main/MainView.java b/desktop/src/main/java/haveno/desktop/main/MainView.java index fe18d711..7290f768 100644 --- a/desktop/src/main/java/haveno/desktop/main/MainView.java +++ b/desktop/src/main/java/haveno/desktop/main/MainView.java @@ -165,8 +165,8 @@ public class MainView extends InitializableView { MainView.rootContainer.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); ToggleButton marketButton = new NavButton(MarketView.class, Res.get("mainView.menu.market").toUpperCase()); - ToggleButton buyButton = new NavButton(BuyOfferView.class, Res.get("mainView.menu.buy").toUpperCase()); - ToggleButton sellButton = new NavButton(SellOfferView.class, Res.get("mainView.menu.sell").toUpperCase()); + ToggleButton buyButton = new NavButton(BuyOfferView.class, Res.get("mainView.menu.buyXmr").toUpperCase()); + ToggleButton sellButton = new NavButton(SellOfferView.class, Res.get("mainView.menu.sellXmr").toUpperCase()); ToggleButton portfolioButton = new NavButton(PortfolioView.class, Res.get("mainView.menu.portfolio").toUpperCase()); ToggleButton fundsButton = new NavButton(FundsView.class, Res.get("mainView.menu.funds").toUpperCase()); diff --git a/desktop/src/main/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModel.java b/desktop/src/main/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModel.java index fa0bcbd0..59c90088 100644 --- a/desktop/src/main/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModel.java +++ b/desktop/src/main/java/haveno/desktop/main/market/offerbook/OfferBookChartViewModel.java @@ -425,14 +425,10 @@ class OfferBookChartViewModel extends ActivatableViewModel { if (isSellOffer(direction)) { if (CurrencyUtil.isTraditionalCurrency(getCurrencyCode())) { preferences.setBuyScreenCurrencyCode(getCurrencyCode()); - } else if (!getCurrencyCode().equals(GUIUtil.TOP_CRYPTO.getCode())) { - preferences.setBuyScreenCryptoCurrencyCode(getCurrencyCode()); } } else { if (CurrencyUtil.isTraditionalCurrency(getCurrencyCode())) { preferences.setSellScreenCurrencyCode(getCurrencyCode()); - } else if (!getCurrencyCode().equals(GUIUtil.TOP_CRYPTO.getCode())) { - preferences.setSellScreenCryptoCurrencyCode(getCurrencyCode()); } } } diff --git a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java index d48a1d2e..10ecb181 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java @@ -57,7 +57,6 @@ import java.util.Comparator; import static java.util.Comparator.comparing; import java.util.Date; import java.util.HashSet; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Predicate; @@ -257,10 +256,10 @@ public abstract class MutableOfferDataModel extends OfferDataModel { private Optional getAnyPaymentAccount() { if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) { return paymentAccounts.stream().filter(paymentAccount1 -> paymentAccount1.isFiat()).findAny(); + } else if (CurrencyUtil.isCryptoCurrency(tradeCurrency.getCode())) { + return paymentAccounts.stream().filter(paymentAccount1 -> paymentAccount1.isCryptoCurrency()).findAny(); } else { - return paymentAccounts.stream().filter(paymentAccount1 -> !paymentAccount1.isFiat() && - paymentAccount1.getTradeCurrency().isPresent() && - !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), GUIUtil.TOP_CRYPTO.getCode())).findAny(); + return paymentAccounts.stream().filter(paymentAccount1 -> paymentAccount1.getTradeCurrency().isPresent()).findAny(); } } 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 6ba827f0..fc7c0561 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/OfferView.java @@ -33,10 +33,10 @@ import haveno.desktop.common.view.View; import haveno.desktop.common.view.ViewLoader; import haveno.desktop.main.MainView; import haveno.desktop.main.offer.createoffer.CreateOfferView; -import haveno.desktop.main.offer.offerbook.XmrOfferBookView; +import haveno.desktop.main.offer.offerbook.FiatOfferBookView; import haveno.desktop.main.offer.offerbook.OfferBookView; +import haveno.desktop.main.offer.offerbook.CryptoOfferBookView; import haveno.desktop.main.offer.offerbook.OtherOfferBookView; -import haveno.desktop.main.offer.offerbook.TopCryptoOfferBookView; import haveno.desktop.main.offer.takeoffer.TakeOfferView; import haveno.desktop.util.GUIUtil; import haveno.network.p2p.P2PService; @@ -50,9 +50,9 @@ import java.util.Optional; public abstract class OfferView extends ActivatableView { - private OfferBookView xmrOfferBookView, topCryptoOfferBookView, otherOfferBookView; + private OfferBookView fiatOfferBookView, cryptoOfferBookView, otherOfferBookView; - private Tab xmrOfferBookTab, topCryptoOfferBookTab, otherOfferBookTab; + private Tab fiatOfferBookTab, cryptoOfferBookTab, otherOfferBookTab; private final ViewLoader viewLoader; private final Navigation navigation; @@ -95,17 +95,17 @@ public abstract class OfferView extends ActivatableView { tabChangeListener = (observableValue, oldValue, newValue) -> { UserThread.execute(() -> { if (newValue != null) { - if (newValue.equals(xmrOfferBookTab)) { - if (xmrOfferBookView != null) { - xmrOfferBookView.onTabSelected(true); + if (newValue.equals(fiatOfferBookTab)) { + if (fiatOfferBookView != null) { + fiatOfferBookView.onTabSelected(true); } else { - loadView(XmrOfferBookView.class, null, null); + loadView(FiatOfferBookView.class, null, null); } - } else if (newValue.equals(topCryptoOfferBookTab)) { - if (topCryptoOfferBookView != null) { - topCryptoOfferBookView.onTabSelected(true); + } else if (newValue.equals(cryptoOfferBookTab)) { + if (cryptoOfferBookView != null) { + cryptoOfferBookView.onTabSelected(true); } else { - loadView(TopCryptoOfferBookView.class, null, null); + loadView(CryptoOfferBookView.class, null, null); } } else if (newValue.equals(otherOfferBookTab)) { if (otherOfferBookView != null) { @@ -116,10 +116,10 @@ public abstract class OfferView extends ActivatableView { } } if (oldValue != null) { - if (oldValue.equals(xmrOfferBookTab) && xmrOfferBookView != null) { - xmrOfferBookView.onTabSelected(false); - } else if (oldValue.equals(topCryptoOfferBookTab) && topCryptoOfferBookView != null) { - topCryptoOfferBookView.onTabSelected(false); + if (oldValue.equals(fiatOfferBookTab) && fiatOfferBookView != null) { + fiatOfferBookView.onTabSelected(false); + } else if (oldValue.equals(cryptoOfferBookTab) && cryptoOfferBookView != null) { + cryptoOfferBookView.onTabSelected(false); } else if (oldValue.equals(otherOfferBookTab) && otherOfferBookView != null) { otherOfferBookView.onTabSelected(false); } @@ -154,14 +154,8 @@ public abstract class OfferView extends ActivatableView { root.getSelectionModel().selectedItemProperty().addListener(tabChangeListener); navigation.addListener(navigationListener); - if (xmrOfferBookView == null) { - navigation.navigateTo(MainView.class, this.getClass(), XmrOfferBookView.class); - } - - GUIUtil.updateTopCrypto(preferences); - - if (topCryptoOfferBookTab != null) { - topCryptoOfferBookTab.setText(GUIUtil.TOP_CRYPTO.getName().toUpperCase()); + if (fiatOfferBookView == null) { + navigation.navigateTo(MainView.class, this.getClass(), FiatOfferBookView.class); } } @@ -179,66 +173,65 @@ public abstract class OfferView extends ActivatableView { if (OfferBookView.class.isAssignableFrom(viewClass)) { - if (viewClass == XmrOfferBookView.class && xmrOfferBookTab != null && xmrOfferBookView != null) { + if (viewClass == FiatOfferBookView.class && fiatOfferBookTab != null && fiatOfferBookView != null) { if (childViewClass == null) { - xmrOfferBookTab.setContent(xmrOfferBookView.getRoot()); + fiatOfferBookTab.setContent(fiatOfferBookView.getRoot()); } else if (childViewClass == TakeOfferView.class) { - loadTakeViewClass(viewClass, childViewClass, xmrOfferBookTab); + loadTakeViewClass(viewClass, childViewClass, fiatOfferBookTab); } else { - loadCreateViewClass(xmrOfferBookView, viewClass, childViewClass, xmrOfferBookTab, (PaymentMethod) data); + loadCreateViewClass(fiatOfferBookView, viewClass, childViewClass, fiatOfferBookTab, (PaymentMethod) data); } - tabPane.getSelectionModel().select(xmrOfferBookTab); - } else if (viewClass == TopCryptoOfferBookView.class && topCryptoOfferBookTab != null && topCryptoOfferBookView != null) { + tabPane.getSelectionModel().select(fiatOfferBookTab); + } else if (viewClass == CryptoOfferBookView.class && cryptoOfferBookTab != null && cryptoOfferBookView != null) { if (childViewClass == null) { - topCryptoOfferBookTab.setContent(topCryptoOfferBookView.getRoot()); + cryptoOfferBookTab.setContent(cryptoOfferBookView.getRoot()); } else if (childViewClass == TakeOfferView.class) { - loadTakeViewClass(viewClass, childViewClass, topCryptoOfferBookTab); + loadTakeViewClass(viewClass, childViewClass, cryptoOfferBookTab); } else { - tradeCurrency = GUIUtil.TOP_CRYPTO; - loadCreateViewClass(topCryptoOfferBookView, viewClass, childViewClass, topCryptoOfferBookTab, (PaymentMethod) data); - } - tabPane.getSelectionModel().select(topCryptoOfferBookTab); - } else if (viewClass == OtherOfferBookView.class && otherOfferBookTab != null && otherOfferBookView != null) { - if (childViewClass == null) { - otherOfferBookTab.setContent(otherOfferBookView.getRoot()); - } else if (childViewClass == TakeOfferView.class) { - loadTakeViewClass(viewClass, childViewClass, otherOfferBookTab); - } else { - //add sanity check in case of app restart + // add sanity check in case of app restart if (CurrencyUtil.isTraditionalCurrency(tradeCurrency.getCode())) { Optional tradeCurrencyOptional = (this.direction == OfferDirection.SELL) ? CurrencyUtil.getTradeCurrency(preferences.getSellScreenCryptoCurrencyCode()) : CurrencyUtil.getTradeCurrency(preferences.getBuyScreenCryptoCurrencyCode()); tradeCurrency = tradeCurrencyOptional.isEmpty() ? OfferViewUtil.getAnyOfMainCryptoCurrencies() : tradeCurrencyOptional.get(); } + loadCreateViewClass(cryptoOfferBookView, viewClass, childViewClass, cryptoOfferBookTab, (PaymentMethod) data); + } + tabPane.getSelectionModel().select(cryptoOfferBookTab); + } else if (viewClass == OtherOfferBookView.class && otherOfferBookTab != null && otherOfferBookView != null) { + if (childViewClass == null) { + otherOfferBookTab.setContent(otherOfferBookView.getRoot()); + } else if (childViewClass == TakeOfferView.class) { + loadTakeViewClass(viewClass, childViewClass, otherOfferBookTab); + } else { loadCreateViewClass(otherOfferBookView, viewClass, childViewClass, otherOfferBookTab, (PaymentMethod) data); } tabPane.getSelectionModel().select(otherOfferBookTab); } else { - if (xmrOfferBookTab == null) { - xmrOfferBookTab = new Tab(Res.getBaseCurrencyName().toUpperCase()); - xmrOfferBookTab.setClosable(false); - topCryptoOfferBookTab = new Tab(GUIUtil.TOP_CRYPTO.getName().toUpperCase()); - topCryptoOfferBookTab.setClosable(false); - otherOfferBookTab = new Tab(Res.get("shared.other").toUpperCase()); + if (fiatOfferBookTab == null) { + fiatOfferBookTab = new Tab(Res.get("shared.fiat").toUpperCase()); + fiatOfferBookTab.setClosable(false); + cryptoOfferBookTab = new Tab(Res.get("shared.crypto").toUpperCase()); + cryptoOfferBookTab.setClosable(false); + otherOfferBookTab = new Tab(Res.get("shared.preciousMetals").toUpperCase()); otherOfferBookTab.setClosable(false); - tabPane.getTabs().addAll(xmrOfferBookTab, topCryptoOfferBookTab, otherOfferBookTab); + tabPane.getTabs().addAll(fiatOfferBookTab, cryptoOfferBookTab, otherOfferBookTab); } - if (viewClass == XmrOfferBookView.class) { - xmrOfferBookView = (XmrOfferBookView) viewLoader.load(XmrOfferBookView.class); - xmrOfferBookView.setOfferActionHandler(offerActionHandler); - xmrOfferBookView.setDirection(direction); - xmrOfferBookView.onTabSelected(true); - tabPane.getSelectionModel().select(xmrOfferBookTab); - xmrOfferBookTab.setContent(xmrOfferBookView.getRoot()); - } else if (viewClass == TopCryptoOfferBookView.class) { - topCryptoOfferBookView = (TopCryptoOfferBookView) viewLoader.load(TopCryptoOfferBookView.class); - topCryptoOfferBookView.setOfferActionHandler(offerActionHandler); - topCryptoOfferBookView.setDirection(direction); - topCryptoOfferBookView.onTabSelected(true); - tabPane.getSelectionModel().select(topCryptoOfferBookTab); - topCryptoOfferBookTab.setContent(topCryptoOfferBookView.getRoot()); + if (viewClass == FiatOfferBookView.class) { + fiatOfferBookView = (FiatOfferBookView) viewLoader.load(FiatOfferBookView.class); + fiatOfferBookView.setOfferActionHandler(offerActionHandler); + fiatOfferBookView.setDirection(direction); + fiatOfferBookView.onTabSelected(true); + tabPane.getSelectionModel().select(fiatOfferBookTab); + fiatOfferBookTab.setContent(fiatOfferBookView.getRoot()); + } else if (viewClass == CryptoOfferBookView.class) { + cryptoOfferBookView = (CryptoOfferBookView) viewLoader.load(CryptoOfferBookView.class); + cryptoOfferBookView.setOfferActionHandler(offerActionHandler); + cryptoOfferBookView.setDirection(direction); + cryptoOfferBookView.onTabSelected(true); + tabPane.getSelectionModel().select(cryptoOfferBookTab); + cryptoOfferBookTab.setContent(cryptoOfferBookView.getRoot()); } else if (viewClass == OtherOfferBookView.class) { otherOfferBookView = (OtherOfferBookView) viewLoader.load(OtherOfferBookView.class); otherOfferBookView.setOfferActionHandler(offerActionHandler); @@ -265,11 +258,7 @@ public abstract class OfferView extends ActivatableView { // in different graphs view = viewLoader.load(childViewClass); - // 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); + ((CreateOfferView) view).initWithData(direction, tradeCurrency, offerActionHandler); ((SelectableView) view).onTabSelected(true); @@ -329,9 +318,9 @@ public abstract class OfferView extends ActivatableView { private Class> getOfferBookViewClassFor(String currencyCode) { Class> offerBookViewClass; if (CurrencyUtil.isFiatCurrency(currencyCode)) { - offerBookViewClass = XmrOfferBookView.class; - } else if (currencyCode.equals(GUIUtil.TOP_CRYPTO.getCode())) { - offerBookViewClass = TopCryptoOfferBookView.class; + offerBookViewClass = FiatOfferBookView.class; + } else if (CurrencyUtil.isCryptoCurrency(currencyCode)) { + offerBookViewClass = CryptoOfferBookView.class; } else { offerBookViewClass = OtherOfferBookView.class; } 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 4f18294d..a01f2f3e 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/OfferViewUtil.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/OfferViewUtil.java @@ -22,16 +22,16 @@ import haveno.core.locale.CryptoCurrency; import haveno.core.locale.CurrencyUtil; import haveno.core.locale.Res; import haveno.core.locale.TradeCurrency; +import haveno.core.locale.TraditionalCurrency; import haveno.core.offer.Offer; import haveno.core.offer.OfferDirection; import haveno.core.xmr.wallet.XmrWalletService; import haveno.desktop.components.AutoTooltipLabel; -import haveno.desktop.main.offer.offerbook.XmrOfferBookView; +import haveno.desktop.main.offer.offerbook.FiatOfferBookView; import haveno.desktop.main.offer.offerbook.OfferBookView; +import haveno.desktop.main.offer.offerbook.CryptoOfferBookView; import haveno.desktop.main.offer.offerbook.OtherOfferBookView; -import haveno.desktop.main.offer.offerbook.TopCryptoOfferBookView; import haveno.desktop.main.overlays.popups.Popup; -import haveno.desktop.util.GUIUtil; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.VPos; @@ -44,7 +44,6 @@ import monero.daemon.model.MoneroSubmitTxResult; import org.jetbrains.annotations.NotNull; import java.util.HashMap; -import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; @@ -90,10 +89,10 @@ public class OfferViewUtil { public static Class> getOfferBookViewClass(String currencyCode) { Class> offerBookViewClazz; - if (CurrencyUtil.isTraditionalCurrency(currencyCode)) { - offerBookViewClazz = XmrOfferBookView.class; - } else if (currencyCode.equals(GUIUtil.TOP_CRYPTO.getCode())) { - offerBookViewClazz = TopCryptoOfferBookView.class; + if (CurrencyUtil.isFiatCurrency(currencyCode)) { + offerBookViewClazz = FiatOfferBookView.class; + } else if (CurrencyUtil.isCryptoCurrency(currencyCode)) { + offerBookViewClazz = CryptoOfferBookView.class; } else { offerBookViewClazz = OtherOfferBookView.class; } @@ -109,7 +108,7 @@ public class OfferViewUtil { } public static boolean isShownAsSellOffer(String currencyCode, OfferDirection direction) { - return CurrencyUtil.isFiatCurrency(currencyCode) == (direction == OfferDirection.SELL); + return direction == OfferDirection.SELL; } public static boolean isShownAsBuyOffer(Offer offer) { @@ -124,10 +123,18 @@ public class OfferViewUtil { return getMainCryptoCurrencies().findAny().get(); } + public static TradeCurrency getAnyOfOtherCurrencies() { + return getOtherCurrencies().findAny().get(); + } + @NotNull public static Stream getMainCryptoCurrencies() { - return CurrencyUtil.getMainCryptoCurrencies().stream().filter(cryptoCurrency -> - !Objects.equals(cryptoCurrency.getCode(), GUIUtil.TOP_CRYPTO.getCode())); + return CurrencyUtil.getMainCryptoCurrencies().stream(); + } + + @NotNull + public static Stream getOtherCurrencies() { + return CurrencyUtil.getTraditionalNonFiatCurrencies().stream(); } public static void submitTransactionHex(XmrWalletService xmrWalletService, 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 e30d53fd..ba9f3d31 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 @@ -31,8 +31,6 @@ import haveno.desktop.common.view.FxmlView; import haveno.desktop.main.offer.MutableOfferView; import haveno.desktop.main.offer.OfferView; import haveno.desktop.main.overlays.windows.OfferDetailsWindow; -import haveno.desktop.util.GUIUtil; -import java.util.Objects; import java.util.stream.Collectors; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -60,12 +58,12 @@ public class CreateOfferView extends MutableOfferView { protected ObservableList filterPaymentAccounts(ObservableList paymentAccounts) { return FXCollections.observableArrayList( paymentAccounts.stream().filter(paymentAccount -> { - if (model.getTradeCurrency().equals(GUIUtil.TOP_CRYPTO)) { - return Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.TOP_CRYPTO); - } else if (CurrencyUtil.isFiatCurrency(model.getTradeCurrency().getCode())) { + if (CurrencyUtil.isFiatCurrency(model.getTradeCurrency().getCode())) { return paymentAccount.isFiat(); + } else if (CurrencyUtil.isCryptoCurrency(model.getTradeCurrency().getCode())) { + return paymentAccount.isCryptoCurrency(); } else { - return !paymentAccount.isFiat() && !Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.TOP_CRYPTO); + return !paymentAccount.isFiat() && !paymentAccount.isCryptoCurrency(); } }).collect(Collectors.toList())); } diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookView.fxml b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookView.fxml similarity index 97% rename from desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookView.fxml rename to desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookView.fxml index 45a46ca7..658f138c 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookView.fxml +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookView.fxml @@ -19,7 +19,7 @@ - diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookView.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookView.java similarity index 56% rename from desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookView.java rename to desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookView.java index a6904d96..8dfdc686 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookView.java @@ -33,39 +33,29 @@ import haveno.desktop.main.overlays.windows.OfferDetailsWindow; import javafx.scene.layout.GridPane; @FxmlView -public class TopCryptoOfferBookView extends OfferBookView { +public class CryptoOfferBookView extends OfferBookView { @Inject - TopCryptoOfferBookView(TopCryptoOfferBookViewModel model, - Navigation navigation, - OfferDetailsWindow offerDetailsWindow, - @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, - PrivateNotificationManager privateNotificationManager, - @Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys, - AccountAgeWitnessService accountAgeWitnessService, - SignedWitnessService signedWitnessService) { + CryptoOfferBookView(CryptoOfferBookViewModel model, + Navigation navigation, + OfferDetailsWindow offerDetailsWindow, + @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, + PrivateNotificationManager privateNotificationManager, + @Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys, + AccountAgeWitnessService accountAgeWitnessService, + SignedWitnessService signedWitnessService) { super(model, navigation, offerDetailsWindow, formatter, privateNotificationManager, useDevPrivilegeKeys, accountAgeWitnessService, signedWitnessService); } @Override protected String getMarketTitle() { return model.getDirection().equals(OfferDirection.BUY) ? - Res.get("offerbook.availableOffersToBuy", TopCryptoOfferBookViewModel.TOP_CRYPTO.getCode(), Res.getBaseCurrencyCode()) : - Res.get("offerbook.availableOffersToSell", TopCryptoOfferBookViewModel.TOP_CRYPTO.getCode(), Res.getBaseCurrencyCode()); - } - - @Override - protected void activate() { - model.onSetTradeCurrency(TopCryptoOfferBookViewModel.TOP_CRYPTO); - - super.activate(); - - currencyComboBoxContainer.setVisible(false); - currencyComboBoxContainer.setManaged(false); + Res.get("offerbook.availableOffersToBuy", Res.getBaseCurrencyCode(), Res.get("shared.crypto")) : + Res.get("offerbook.availableOffersToSell", Res.getBaseCurrencyCode(), Res.get("shared.crypto")); } @Override String getTradeCurrencyCode() { - return TopCryptoOfferBookViewModel.TOP_CRYPTO.getCode(); + return Res.getBaseCurrencyCode(); } } diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookViewModel.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookViewModel.java new file mode 100644 index 00000000..e97c0855 --- /dev/null +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/CryptoOfferBookViewModel.java @@ -0,0 +1,148 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package haveno.desktop.main.offer.offerbook; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import haveno.core.account.witness.AccountAgeWitnessService; +import haveno.core.api.CoreApi; +import haveno.core.locale.CryptoCurrency; +import haveno.core.locale.CurrencyUtil; +import haveno.core.locale.GlobalSettings; +import haveno.core.locale.TradeCurrency; +import haveno.core.offer.Offer; +import haveno.core.offer.OfferDirection; +import haveno.core.offer.OfferFilterService; +import haveno.core.offer.OpenOfferManager; +import haveno.core.payment.payload.PaymentMethod; +import haveno.core.provider.price.PriceFeedService; +import haveno.core.trade.ClosedTradableManager; +import haveno.core.user.Preferences; +import haveno.core.user.User; +import haveno.core.util.FormattingUtils; +import haveno.core.util.PriceUtil; +import haveno.core.util.coin.CoinFormatter; +import haveno.core.xmr.setup.WalletsSetup; +import haveno.desktop.Navigation; +import haveno.desktop.main.offer.OfferViewUtil; +import haveno.desktop.util.GUIUtil; +import haveno.network.p2p.P2PService; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +public class CryptoOfferBookViewModel extends OfferBookViewModel { + + @Inject + public CryptoOfferBookViewModel(User user, + OpenOfferManager openOfferManager, + OfferBook offerBook, + Preferences preferences, + WalletsSetup walletsSetup, + P2PService p2PService, + PriceFeedService priceFeedService, + ClosedTradableManager closedTradableManager, + AccountAgeWitnessService accountAgeWitnessService, + Navigation navigation, + PriceUtil priceUtil, + OfferFilterService offerFilterService, + @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, + CoreApi coreApi) { + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, coreApi); + } + + @Override + void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) { + if (direction == OfferDirection.BUY) { + preferences.setBuyScreenCryptoCurrencyCode(code); + } else { + preferences.setSellScreenCryptoCurrencyCode(code); + } + } + + @Override + protected ObservableList filterPaymentMethods(ObservableList list, + TradeCurrency selectedTradeCurrency) { + return FXCollections.observableArrayList(list.stream().filter(paymentMethod -> { + return paymentMethod.isBlockchain(); + }).collect(Collectors.toList())); + } + + @Override + void fillCurrencies(ObservableList tradeCurrencies, + ObservableList allCurrencies) { + + tradeCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); + tradeCurrencies.addAll(preferences.getCryptoCurrenciesAsObservable().stream() + .collect(Collectors.toList())); + tradeCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); + + allCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); + allCurrencies.addAll(CurrencyUtil.getAllSortedCryptoCurrencies().stream() + .collect(Collectors.toList())); + allCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); + } + + @Override + Predicate getCurrencyAndMethodPredicate(OfferDirection direction, + TradeCurrency selectedTradeCurrency) { + return offerBookListItem -> { + Offer offer = offerBookListItem.getOffer(); + boolean directionResult = offer.getDirection() != direction; // offer to buy xmr appears as offer to sell in peer's offer book and vice versa + boolean currencyResult = CurrencyUtil.isCryptoCurrency(offer.getCurrencyCode()) && + (showAllTradeCurrenciesProperty.get() || + offer.getCurrencyCode().equals(selectedTradeCurrency.getCode())); + boolean paymentMethodResult = showAllPaymentMethods || + offer.getPaymentMethod().equals(selectedPaymentMethod); + boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook(); + return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated; + }; + } + + @Override + TradeCurrency getDefaultTradeCurrency() { + TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency(); + + if (CurrencyUtil.isCryptoCurrency(defaultTradeCurrency.getCode()) && + hasPaymentAccountForCurrency(defaultTradeCurrency)) { + return defaultTradeCurrency; + } + + ObservableList tradeCurrencies = FXCollections.observableArrayList(getTradeCurrencies()); + if (!tradeCurrencies.isEmpty()) { + // drop show all entry and select first currency with payment account available + tradeCurrencies.remove(0); + List sortedList = tradeCurrencies.stream().sorted((o1, o2) -> + Boolean.compare(!hasPaymentAccountForCurrency(o1), + !hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()); + return sortedList.get(0); + } else { + return OfferViewUtil.getMainCryptoCurrencies().sorted((o1, o2) -> + Boolean.compare(!hasPaymentAccountForCurrency(o1), + !hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()).get(0); + } + } + + @Override + String getCurrencyCodeFromPreferences(OfferDirection direction) { + return direction == OfferDirection.BUY ? preferences.getBuyScreenCryptoCurrencyCode() : + preferences.getSellScreenCryptoCurrencyCode(); + } +} \ No newline at end of file diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookView.fxml b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookView.fxml similarity index 97% rename from desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookView.fxml rename to desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookView.fxml index e5bad7e7..2f2b6602 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookView.fxml +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookView.fxml @@ -19,7 +19,7 @@ - diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookView.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookView.java similarity index 75% rename from desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookView.java rename to desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookView.java index 07b4c561..9112ea9a 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookView.java @@ -33,17 +33,17 @@ import haveno.desktop.main.overlays.windows.OfferDetailsWindow; import javafx.scene.layout.GridPane; @FxmlView -public class XmrOfferBookView extends OfferBookView { +public class FiatOfferBookView extends OfferBookView { @Inject - XmrOfferBookView(XmrOfferBookViewModel model, - Navigation navigation, - OfferDetailsWindow offerDetailsWindow, - @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, - PrivateNotificationManager privateNotificationManager, - @Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys, - AccountAgeWitnessService accountAgeWitnessService, - SignedWitnessService signedWitnessService) { + FiatOfferBookView(FiatOfferBookViewModel model, + Navigation navigation, + OfferDetailsWindow offerDetailsWindow, + @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, + PrivateNotificationManager privateNotificationManager, + @Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys, + AccountAgeWitnessService accountAgeWitnessService, + SignedWitnessService signedWitnessService) { super(model, navigation, offerDetailsWindow, formatter, privateNotificationManager, useDevPrivilegeKeys, accountAgeWitnessService, signedWitnessService); } diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookViewModel.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookViewModel.java similarity index 84% rename from desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookViewModel.java rename to desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookViewModel.java index 38702cde..bea41743 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/XmrOfferBookViewModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/FiatOfferBookViewModel.java @@ -49,23 +49,23 @@ import java.util.stream.Collectors; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -public class XmrOfferBookViewModel extends OfferBookViewModel { +public class FiatOfferBookViewModel extends OfferBookViewModel { @Inject - public XmrOfferBookViewModel(User user, - OpenOfferManager openOfferManager, - OfferBook offerBook, - Preferences preferences, - WalletsSetup walletsSetup, - P2PService p2PService, - PriceFeedService priceFeedService, - ClosedTradableManager closedTradableManager, - AccountAgeWitnessService accountAgeWitnessService, - Navigation navigation, - PriceUtil priceUtil, - OfferFilterService offerFilterService, - @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, - CoreApi coreApi) { + public FiatOfferBookViewModel(User user, + OpenOfferManager openOfferManager, + OfferBook offerBook, + Preferences preferences, + WalletsSetup walletsSetup, + P2PService p2PService, + PriceFeedService priceFeedService, + ClosedTradableManager closedTradableManager, + AccountAgeWitnessService accountAgeWitnessService, + Navigation navigation, + PriceUtil priceUtil, + OfferFilterService offerFilterService, + @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, + CoreApi coreApi) { super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, coreApi); } @@ -141,9 +141,10 @@ public class XmrOfferBookViewModel extends OfferBookViewModel { !hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()); return sortedList.get(0); } else { - return CurrencyUtil.getMainTraditionalCurrencies().stream().sorted((o1, o2) -> - Boolean.compare(!hasPaymentAccountForCurrency(o1), - !hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()).get(0); + return CurrencyUtil.getMainTraditionalCurrencies().stream() + .filter(withFiatCurrency()) + .sorted((o1, o2) -> Boolean.compare(!hasPaymentAccountForCurrency(o1), !hasPaymentAccountForCurrency(o2))) + .collect(Collectors.toList()).get(0); } } diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OtherOfferBookView.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OtherOfferBookView.java index 71d18d50..14d1f835 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OtherOfferBookView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OtherOfferBookView.java @@ -37,25 +37,25 @@ public class OtherOfferBookView extends OfferBookView filterPaymentMethods(ObservableList list, TradeCurrency selectedTradeCurrency) { return FXCollections.observableArrayList(list.stream().filter(paymentMethod -> { - if (paymentMethod.isBlockchain()) return true; if (paymentMethod.getSupportedAssetCodes() == null) return true; for (String assetCode : paymentMethod.getSupportedAssetCodes()) { if (!CurrencyUtil.isFiatCurrency(assetCode)) return true; @@ -95,20 +93,13 @@ public class OtherOfferBookViewModel extends OfferBookViewModel { @Override void fillCurrencies(ObservableList tradeCurrencies, ObservableList allCurrencies) { - tradeCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); - tradeCurrencies.addAll(preferences.getCryptoCurrenciesAsObservable().stream() - .filter(withoutTopCrypto()) - .collect(Collectors.toList())); tradeCurrencies.addAll(CurrencyUtil.getMainTraditionalCurrencies().stream() .filter(withoutFiatCurrency()) .collect(Collectors.toList())); tradeCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); allCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); - allCurrencies.addAll(CurrencyUtil.getAllSortedCryptoCurrencies().stream() - .filter(withoutTopCrypto()) - .collect(Collectors.toList())); allCurrencies.addAll(CurrencyUtil.getMainTraditionalCurrencies().stream() .filter(withoutFiatCurrency()) .collect(Collectors.toList())); @@ -120,12 +111,9 @@ public class OtherOfferBookViewModel extends OfferBookViewModel { TradeCurrency selectedTradeCurrency) { return offerBookListItem -> { Offer offer = offerBookListItem.getOffer(); - // BUY Crypto is actually SELL Monero - boolean directionResult = offer.getDirection() == direction; - boolean currencyResult = !CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) && - ((showAllTradeCurrenciesProperty.get() && - !offer.getCurrencyCode().equals(GUIUtil.TOP_CRYPTO.getCode())) || - offer.getCurrencyCode().equals(selectedTradeCurrency.getCode())); + boolean directionResult = offer.getDirection() != direction; + boolean currencyResult = CurrencyUtil.isTraditionalCurrency(offer.getCurrencyCode()) && !CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) && + (showAllTradeCurrenciesProperty.get() || offer.getCurrencyCode().equals(selectedTradeCurrency.getCode())); boolean paymentMethodResult = showAllPaymentMethods || offer.getPaymentMethod().equals(selectedPaymentMethod); boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook(); @@ -137,8 +125,8 @@ public class OtherOfferBookViewModel extends OfferBookViewModel { TradeCurrency getDefaultTradeCurrency() { TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency(); - if (!CurrencyUtil.isTraditionalCurrency(defaultTradeCurrency.getCode()) && - !defaultTradeCurrency.equals(GUIUtil.TOP_CRYPTO) && + if (CurrencyUtil.isTraditionalCurrency(defaultTradeCurrency.getCode()) && + !CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode()) && hasPaymentAccountForCurrency(defaultTradeCurrency)) { return defaultTradeCurrency; } @@ -152,22 +140,19 @@ public class OtherOfferBookViewModel extends OfferBookViewModel { !hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()); return sortedList.get(0); } else { - return OfferViewUtil.getMainCryptoCurrencies().sorted((o1, o2) -> - Boolean.compare(!hasPaymentAccountForCurrency(o1), - !hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()).get(0); + return CurrencyUtil.getMainTraditionalCurrencies().stream() + .filter(withoutFiatCurrency()) + .sorted((o1, o2) -> Boolean.compare(!hasPaymentAccountForCurrency(o1), !hasPaymentAccountForCurrency(o2))) + .collect(Collectors.toList()).get(0); } } @Override String getCurrencyCodeFromPreferences(OfferDirection direction) { - return direction == OfferDirection.BUY ? preferences.getBuyScreenCryptoCurrencyCode() : - preferences.getSellScreenCryptoCurrencyCode(); - } + // validate if previous stored currencies are Traditional ones + String currencyCode = direction == OfferDirection.BUY ? preferences.getBuyScreenOtherCurrencyCode() : preferences.getSellScreenOtherCurrencyCode(); - @NotNull - private Predicate withoutTopCrypto() { - return cryptoCurrency -> - !cryptoCurrency.equals(GUIUtil.TOP_CRYPTO); + return CurrencyUtil.isTraditionalCurrency(currencyCode) ? currencyCode : null; } @NotNull diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookViewModel.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookViewModel.java deleted file mode 100644 index 37cdaa12..00000000 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/TopCryptoOfferBookViewModel.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package haveno.desktop.main.offer.offerbook; - -import com.google.inject.Inject; -import com.google.inject.name.Named; -import haveno.core.account.witness.AccountAgeWitnessService; -import haveno.core.api.CoreApi; -import haveno.core.locale.TradeCurrency; -import haveno.core.offer.Offer; -import haveno.core.offer.OfferDirection; -import haveno.core.offer.OfferFilterService; -import haveno.core.offer.OpenOfferManager; -import haveno.core.payment.payload.PaymentMethod; -import haveno.core.provider.price.PriceFeedService; -import haveno.core.trade.ClosedTradableManager; -import haveno.core.user.Preferences; -import haveno.core.user.User; -import haveno.core.util.FormattingUtils; -import haveno.core.util.PriceUtil; -import haveno.core.util.coin.CoinFormatter; -import haveno.core.xmr.setup.WalletsSetup; -import haveno.desktop.Navigation; -import haveno.desktop.util.GUIUtil; -import haveno.network.p2p.P2PService; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; - -public class TopCryptoOfferBookViewModel extends OfferBookViewModel { - - public static TradeCurrency TOP_CRYPTO = GUIUtil.TOP_CRYPTO; - - @Inject - public TopCryptoOfferBookViewModel(User user, - OpenOfferManager openOfferManager, - OfferBook offerBook, - Preferences preferences, - WalletsSetup walletsSetup, - P2PService p2PService, - PriceFeedService priceFeedService, - ClosedTradableManager closedTradableManager, - AccountAgeWitnessService accountAgeWitnessService, - Navigation navigation, - PriceUtil priceUtil, - OfferFilterService offerFilterService, - @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, - CoreApi coreApi) { - super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, coreApi); - } - - @Override - protected void activate() { - super.activate(); - TOP_CRYPTO = GUIUtil.TOP_CRYPTO; - } - - @Override - void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) { - // No need to store anything as it is just one Crypto offers anyway - } - - @Override - protected ObservableList filterPaymentMethods(ObservableList list, - TradeCurrency selectedTradeCurrency) { - return FXCollections.observableArrayList(list.stream().filter(PaymentMethod::isBlockchain).collect(Collectors.toList())); - } - - @Override - void fillCurrencies(ObservableList tradeCurrencies, - ObservableList allCurrencies) { - tradeCurrencies.add(TOP_CRYPTO); - allCurrencies.add(TOP_CRYPTO); - } - - @Override - Predicate getCurrencyAndMethodPredicate(OfferDirection direction, - TradeCurrency selectedTradeCurrency) { - return offerBookListItem -> { - Offer offer = offerBookListItem.getOffer(); - // BUY Crypto is actually SELL Bitcoin - boolean directionResult = offer.getDirection() == direction; - boolean currencyResult = offer.getCurrencyCode().equals(TOP_CRYPTO.getCode()); - boolean paymentMethodResult = showAllPaymentMethods || - offer.getPaymentMethod().equals(selectedPaymentMethod); - boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook(); - return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated; - }; - } - - @Override - TradeCurrency getDefaultTradeCurrency() { - return TOP_CRYPTO; - } - - @Override - String getCurrencyCodeFromPreferences(OfferDirection direction) { - return TOP_CRYPTO.getCode(); - } -} diff --git a/desktop/src/main/java/haveno/desktop/util/GUIUtil.java b/desktop/src/main/java/haveno/desktop/util/GUIUtil.java index 2c314ea5..a5a0b86d 100644 --- a/desktop/src/main/java/haveno/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/haveno/desktop/util/GUIUtil.java @@ -134,8 +134,6 @@ public class GUIUtil { private static Preferences preferences; - public static TradeCurrency TOP_CRYPTO = CurrencyUtil.getTradeCurrency("BTC").get(); - public static void setPreferences(Preferences preferences) { GUIUtil.preferences = preferences; } @@ -1033,12 +1031,4 @@ public class GUIUtil { columnConstraints2.setHgrow(Priority.ALWAYS); gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2); } - - public static void updateTopCrypto(Preferences preferences) { - TradeCurrency tradeCurrency = preferences.getPreferredTradeCurrency(); - if (CurrencyUtil.isTraditionalCurrency(tradeCurrency.getCode())) { - return; - } - TOP_CRYPTO = tradeCurrency; - } } diff --git a/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java b/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java index bce59e65..3b648533 100644 --- a/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java +++ b/desktop/src/test/java/haveno/desktop/main/offer/offerbook/OfferBookViewModelTest.java @@ -241,7 +241,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); assertEquals(0, model.maxPlacesForAmount.intValue()); } @@ -255,7 +255,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); model.activate(); @@ -273,7 +273,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); model.activate(); @@ -292,7 +292,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); assertEquals(0, model.maxPlacesForVolume.intValue()); } @@ -306,7 +306,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); model.activate(); @@ -324,7 +324,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); model.activate(); @@ -342,7 +342,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); assertEquals(0, model.maxPlacesForPrice.intValue()); } @@ -356,7 +356,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); model.activate(); @@ -374,7 +374,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new XmrOfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue()); } @@ -409,7 +409,7 @@ public class OfferBookViewModelTest { item4.getOffer().setPriceFeedService(priceFeedService); offerBookListItems.addAll(item1, item2); - final OfferBookViewModel model = new XmrOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, priceFeedService, + final OfferBookViewModel model = new FiatOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, priceFeedService, null, null, null, getPriceUtil(), null, coinFormatter, null); model.activate(); @@ -430,7 +430,7 @@ public class OfferBookViewModelTest { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true)); - final OfferBookViewModel model = new XmrOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new FiatOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, null); final OfferBookListItem item = make(xmrBuyItem.but( diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 00b44736..db5aa49d 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1742,6 +1742,8 @@ message PreferencesPayload { bool split_offer_output = 62; bool use_sound_for_notifications = 63; bool use_sound_for_notifications_initialized = 64; + string buy_screen_other_currency_code = 65; + string sell_screen_other_currency_code = 66; } message AutoConfirmSettings {