From 98f355d3fa98f79ade3db39e522995de085e52f9 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 1 Apr 2022 10:04:38 +0200 Subject: [PATCH 01/35] Adapt navigational structure and offerbook handling to buy and sell different assets Still missing correct create and take offer handling --- .../bisq/core/payment/PaymentAccountUtil.java | 39 +++++ .../main/java/bisq/core/user/Preferences.java | 10 ++ .../bisq/core/user/PreferencesPayload.java | 8 + .../resources/i18n/displayStrings.properties | 20 +-- .../market/offerbook/OfferBookChartView.java | 1 + .../bisq/desktop/main/offer/BuyOfferView.java | 1 - .../bisq/desktop/main/offer/OfferView.java | 146 +++++++++++------- .../desktop/main/offer/SellOfferView.java | 3 - .../main/offer/bisq_v1/MutableOfferView.java | 5 +- .../main/offer/bisq_v1/OfferViewUtil.java | 22 +-- .../bisq_v1/takeoffer/TakeOfferView.java | 5 +- ...ferBookView.fxml => BsqOfferBookView.fxml} | 2 +- .../offer/offerbook/BsqOfferBookView.java | 74 +++++++++ .../offerbook/BsqOfferBookViewModel.java | 115 ++++++++++++++ .../offer/offerbook/BtcOfferBookView.fxml | 30 ++++ .../offer/offerbook/BtcOfferBookView.java | 64 ++++++++ .../offerbook/BtcOfferBookViewModel.java | 133 ++++++++++++++++ .../main/offer/offerbook/OfferBookView.java | 90 ++++------- .../offer/offerbook/OfferBookViewModel.java | 56 +++---- .../offer/offerbook/OtherOfferBookView.fxml | 30 ++++ .../offer/offerbook/OtherOfferBookView.java | 62 ++++++++ .../offerbook/OtherOfferBookViewModel.java | 141 +++++++++++++++++ .../offerbook/TopAltcoinOfferBookView.fxml | 30 ++++ .../offerbook/TopAltcoinOfferBookView.java | 72 +++++++++ .../TopAltcoinOfferBookViewModel.java | 115 ++++++++++++++ .../offerbook/OfferBookViewModelTest.java | 44 +++--- proto/src/main/proto/pb.proto | 2 + 27 files changed, 1115 insertions(+), 205 deletions(-) rename desktop/src/main/java/bisq/desktop/main/offer/offerbook/{OfferBookView.fxml => BsqOfferBookView.fxml} (97%) create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.fxml create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.fxml create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.fxml create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java index fc810b017d4..34936b48121 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java @@ -19,6 +19,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.Country; +import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -29,6 +30,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; @@ -38,6 +40,10 @@ import javax.annotation.Nullable; +import static bisq.core.locale.CurrencyUtil.*; +import static bisq.core.payment.payload.PaymentMethod.*; +import static java.util.Comparator.comparing; + @Slf4j public class PaymentAccountUtil { @@ -106,6 +112,39 @@ public static ArrayList getAcceptedCountryCodes(PaymentAccount paymentAc return acceptedCountryCodes; } + public static List getTradeCurrencies(PaymentMethod paymentMethod) { + switch (paymentMethod.getId()) { + case ADVANCED_CASH_ID: + return getAllAdvancedCashCurrencies(); + case AMAZON_GIFT_CARD_ID: + return getAllAmazonGiftCardCurrencies(); + case CAPITUAL_ID: + return getAllCapitualCurrencies(); + case MONEY_GRAM_ID: + return getAllMoneyGramCurrencies(); + case PAXUM_ID: + return getAllPaxumCurrencies(); + case PAYSERA_ID: + return getAllPayseraCurrencies(); + case REVOLUT_ID: + return getAllRevolutCurrencies(); + case SWIFT_ID: + return new ArrayList<>(getAllSortedFiatCurrencies( + comparing(TradeCurrency::getCode))); + case TRANSFERWISE_ID: + return getAllTransferwiseCurrencies(); + case UPHOLD_ID: + return getAllUpholdCurrencies(); + default: + return Collections.emptyList(); + } + } + + public static boolean supportsCurrency(PaymentMethod paymentMethod, TradeCurrency selectedTradeCurrency) { + return getTradeCurrencies(paymentMethod).stream() + .anyMatch(tradeCurrency -> tradeCurrency.equals(selectedTradeCurrency)); + } + @Nullable public static List getAcceptedBanks(PaymentAccount paymentAccount) { List acceptedBanks = null; diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index 78c9f6b0b3e..d5191738cc5 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -592,6 +592,16 @@ public void setSellScreenCurrencyCode(String sellScreenCurrencyCode) { requestPersistence(); } + public void setBuyScreenCryptoCurrencyCode(String buyScreenCurrencyCode) { + prefPayload.setBuyScreenCryptoCurrencyCode(buyScreenCurrencyCode); + requestPersistence(); + } + + public void setSellScreenCryptoCurrencyCode(String sellScreenCurrencyCode) { + prefPayload.setSellScreenCryptoCurrencyCode(sellScreenCurrencyCode); + requestPersistence(); + } + public void setIgnoreTradersList(List ignoreTradersList) { prefPayload.setIgnoreTradersList(ignoreTradersList); requestPersistence(); diff --git a/core/src/main/java/bisq/core/user/PreferencesPayload.java b/core/src/main/java/bisq/core/user/PreferencesPayload.java index c7b5e1650da..4544cbeba4d 100644 --- a/core/src/main/java/bisq/core/user/PreferencesPayload.java +++ b/core/src/main/java/bisq/core/user/PreferencesPayload.java @@ -78,6 +78,10 @@ public final class PreferencesPayload implements PersistableEnvelope { private String buyScreenCurrencyCode; @Nullable private String sellScreenCurrencyCode; + @Nullable + private String buyScreenCryptoCurrencyCode; + @Nullable + private String sellScreenCryptoCurrencyCode; private int tradeStatisticsTickUnitIndex = 3; private boolean resyncSpvRequested; private boolean sortMarketCurrenciesNumerically = true; @@ -213,6 +217,8 @@ public Message toProtoMessage() { Optional.ofNullable(tradeChartsScreenCurrencyCode).ifPresent(builder::setTradeChartsScreenCurrencyCode); Optional.ofNullable(buyScreenCurrencyCode).ifPresent(builder::setBuyScreenCurrencyCode); Optional.ofNullable(sellScreenCurrencyCode).ifPresent(builder::setSellScreenCurrencyCode); + Optional.ofNullable(buyScreenCryptoCurrencyCode).ifPresent(builder::setBuyScreenCryptoCurrencyCode); + Optional.ofNullable(sellScreenCryptoCurrencyCode).ifPresent(builder::setSellScreenCryptoCurrencyCode); Optional.ofNullable(selectedPaymentAccountForCreateOffer).ifPresent( account -> builder.setSelectedPaymentAccountForCreateOffer(selectedPaymentAccountForCreateOffer.toProtoMessage())); Optional.ofNullable(bridgeAddresses).ifPresent(builder::addAllBridgeAddresses); @@ -261,6 +267,8 @@ public static PreferencesPayload fromProto(protobuf.PreferencesPayload proto, Co ProtoUtil.stringOrNullFromProto(proto.getTradeChartsScreenCurrencyCode()), ProtoUtil.stringOrNullFromProto(proto.getBuyScreenCurrencyCode()), ProtoUtil.stringOrNullFromProto(proto.getSellScreenCurrencyCode()), + ProtoUtil.stringOrNullFromProto(proto.getBuyScreenCryptoCurrencyCode()), + ProtoUtil.stringOrNullFromProto(proto.getSellScreenCryptoCurrencyCode()), 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 14679978e77..9d7a696924b 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -233,8 +233,8 @@ shared.enabled=Enabled #################################################################### mainView.menu.market=Market -mainView.menu.buyBtc=Buy BTC -mainView.menu.sellBtc=Sell BTC +mainView.menu.buyBtc=Buy +mainView.menu.sellBtc=Sell mainView.menu.portfolio=Portfolio mainView.menu.funds=Funds mainView.menu.support=Support @@ -337,17 +337,16 @@ market.trades.showVolumeInUSD=Show volume in USD offerbook.createOffer=Create offer offerbook.takeOffer=Take offer offerbook.takeOffer.createAccount=Create account and take offer -offerbook.takeOfferToBuy=Take offer to buy {0} -offerbook.takeOfferToSell=Take offer to sell {0} offerbook.trader=Trader offerbook.offerersBankId=Maker''s bank ID (BIC/SWIFT): {0} offerbook.offerersBankName=Maker''s bank name: {0} offerbook.offerersBankSeat=Maker''s seat of bank country: {0} offerbook.offerersAcceptedBankSeatsEuro=Accepted seat of bank countries (taker): All Euro countries offerbook.offerersAcceptedBankSeats=Accepted seat of bank countries (taker):\n {0} -offerbook.availableOffers=Available offers -offerbook.filterByCurrency=Filter by currency -offerbook.filterByPaymentMethod=Filter by payment method +offerbook.availableOffersToBuy=Buy {0} with {1} +offerbook.availableOffersToSell=Sell {0} for {1} +offerbook.filterByCurrency=Choose currency +offerbook.filterByPaymentMethod=Choose payment method offerbook.matchingOffers=Offers matching my accounts offerbook.timeSinceSigning=Account info offerbook.timeSinceSigning.info.arbitrator=signed by an arbitrator and can sign peer accounts @@ -380,12 +379,7 @@ offerbook.volume={0} (min - max) offerbook.deposit=Deposit BTC (%) offerbook.deposit.help=Deposit paid by each trader to guarantee the trade. Will be returned when the trade is completed. -offerbook.createOfferToBuy=Create new offer to buy {0} -offerbook.createOfferToSell=Create new offer to sell {0} -offerbook.createOfferToBuy.withFiat=Create new offer to buy {0} with {1} -offerbook.createOfferToSell.forFiat=Create new offer to sell {0} for {1} -offerbook.createOfferToBuy.withCrypto=Create new offer to sell {0} (buy {1}) -offerbook.createOfferToSell.forCrypto=Create new offer to buy {0} (sell {1}) +offerbook.createNewOffer=Create new offer offerbook.createOfferDisabled.tooltip=You can only create one offer at a time offerbook.takeOfferButton.tooltip=Take offer for {0} diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index c15860f3852..bfe705ccc10 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -323,6 +323,7 @@ private void createListener() { }; buyTableRowSelectionListener = (observable, oldValue, newValue) -> { + model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode()); navigation.navigateTo(MainView.class, SellOfferView.class); }; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java index f473ec71461..e72e44b4a7e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java @@ -43,7 +43,6 @@ public BuyOfferView(ViewLoader viewLoader, super(viewLoader, navigation, preferences, - arbitratorManager, user, p2PService, OfferDirection.BUY); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index 1aad98f66a0..caf7de6439d 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -26,20 +26,21 @@ import bisq.desktop.main.offer.bisq_v1.takeoffer.TakeOfferView; import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView; import bisq.desktop.main.offer.bsq_swap.take_offer.BsqSwapTakeOfferView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookView; +import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookView; -import bisq.desktop.main.overlays.popups.Popup; +import bisq.desktop.main.offer.offerbook.OtherOfferBookView; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; import bisq.desktop.util.GUIUtil; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.GlobalSettings; -import bisq.core.locale.LanguageUtil; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferDirection; import bisq.core.offer.bsq_swap.BsqSwapOfferPayload; import bisq.core.payment.payload.PaymentMethod; -import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager; import bisq.core.user.Preferences; import bisq.core.user.User; @@ -55,19 +56,18 @@ import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import javax.annotation.Nullable; public abstract class OfferView extends ActivatableView { - private OfferBookView offerBookView; + private OfferBookView btcOfferBookView, bsqOfferBookView, topAltcoinOfferBookView, otherOfferBookView; private CreateOfferView createOfferView; private BsqSwapCreateOfferView bsqSwapCreateOfferView; private TakeOfferView takeOfferView; private BsqSwapTakeOfferView bsqSwapTakeOfferView; private AnchorPane createOfferPane, takeOfferPane; - private Tab takeOfferTab, createOfferTab, offerBookTab; + private Tab takeOfferTab, createOfferTab, btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab; private final ViewLoader viewLoader; private final Navigation navigation; @@ -75,7 +75,6 @@ public abstract class OfferView extends ActivatableView { private final User user; private final P2PService p2PService; private final OfferDirection direction; - private final ArbitratorManager arbitratorManager; private Offer offer; private TradeCurrency tradeCurrency; @@ -88,7 +87,6 @@ public abstract class OfferView extends ActivatableView { protected OfferView(ViewLoader viewLoader, Navigation navigation, Preferences preferences, - ArbitratorManager arbitratorManager, User user, P2PService p2PService, OfferDirection direction) { @@ -98,7 +96,6 @@ protected OfferView(ViewLoader viewLoader, this.user = user; this.p2PService = p2PService; this.direction = direction; - this.arbitratorManager = arbitratorManager; } @Override @@ -117,8 +114,30 @@ protected void initialize() { takeOfferView.onTabSelected(true); } else if (newValue.equals(takeOfferTab) && bsqSwapTakeOfferView != null) { bsqSwapTakeOfferView.onTabSelected(true); - } else if (newValue.equals(offerBookTab) && offerBookView != null) { - offerBookView.onTabSelected(true); + } else if (newValue.equals(btcOfferBookTab)) { + if (btcOfferBookView != null) { + btcOfferBookView.onTabSelected(true); + } else { + loadView(BtcOfferBookView.class, null); + } + } else if (newValue.equals(bsqOfferBookTab)) { + if (bsqOfferBookView != null) { + bsqOfferBookView.onTabSelected(true); + } else { + loadView(BsqOfferBookView.class, null); + } + } else if (newValue.equals(topAltcoinOfferBookTab)) { + if (topAltcoinOfferBookView != null) { + topAltcoinOfferBookView.onTabSelected(true); + } else { + loadView(TopAltcoinOfferBookView.class, null); + } + } else if (newValue.equals(otherOfferBookTab)) { + if (otherOfferBookView != null) { + otherOfferBookView.onTabSelected(true); + } else { + loadView(OtherOfferBookView.class, null); + } } } if (oldValue != null) { @@ -130,8 +149,14 @@ protected void initialize() { takeOfferView.onTabSelected(false); } else if (oldValue.equals(takeOfferTab) && bsqSwapTakeOfferView != null) { bsqSwapTakeOfferView.onTabSelected(false); - } else if (oldValue.equals(offerBookTab) && offerBookView != null) { - offerBookView.onTabSelected(false); + } else if (oldValue.equals(btcOfferBookTab) && btcOfferBookView != null) { + btcOfferBookView.onTabSelected(false); + } else if (oldValue.equals(bsqOfferBookTab) && bsqOfferBookView != null) { + bsqOfferBookView.onTabSelected(false); + } else if (oldValue.equals(topAltcoinOfferBookTab) && topAltcoinOfferBookView != null) { + topAltcoinOfferBookView.onTabSelected(false); + } else if (oldValue.equals(otherOfferBookTab) && otherOfferBookView != null) { + otherOfferBookView.onTabSelected(false); } } }; @@ -162,7 +187,8 @@ public void onTakeOffer(Offer offer) { if (takeOfferViewOpen) { root.getTabs().remove(takeOfferTab); } - if (canCreateOrTakeOffer(CurrencyUtil.getTradeCurrency(offer.getCurrencyCode()).get())) { + Optional optionalTradeCurrency = CurrencyUtil.getTradeCurrency(offer.getCurrencyCode()); + if (optionalTradeCurrency.isPresent() && canCreateOrTakeOffer(optionalTradeCurrency.get())) { openTakeOffer(offer); } } @@ -179,8 +205,8 @@ protected void activate() { root.getSelectionModel().selectedItemProperty().addListener(tabChangeListener); root.getTabs().addListener(tabListChangeListener); navigation.addListener(navigationListener); - if (offerBookView == null) { - navigation.navigateTo(MainView.class, this.getClass(), OfferBookView.class); + if (btcOfferBookView == null) { + navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); } } @@ -205,22 +231,55 @@ private void loadView(Class viewClass, @Nullable Object data) { TabPane tabPane = root; tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); View view; - boolean isBuy = direction == OfferDirection.BUY; - if (viewClass == OfferBookView.class) { - if (offerBookTab != null && offerBookView != null) { - tabPane.getSelectionModel().select(offerBookTab); + if (OfferBookView.class.isAssignableFrom(viewClass)) { + + if (viewClass == BtcOfferBookView.class && btcOfferBookTab != null && btcOfferBookView != null) { + tabPane.getSelectionModel().select(btcOfferBookTab); + } else if (viewClass == BsqOfferBookView.class && bsqOfferBookTab != null && bsqOfferBookView != null) { + tabPane.getSelectionModel().select(bsqOfferBookTab); + } else if (viewClass == TopAltcoinOfferBookView.class && topAltcoinOfferBookTab != null && topAltcoinOfferBookView != null) { + tabPane.getSelectionModel().select(topAltcoinOfferBookTab); + } else if (viewClass == OtherOfferBookView.class && otherOfferBookTab != null && otherOfferBookView != null) { + tabPane.getSelectionModel().select(topAltcoinOfferBookTab); } else { - view = viewLoader.load(viewClass); - // Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens. - offerBookTab = new Tab(isBuy ? Res.get("shared.buyBitcoin").toUpperCase() : Res.get("shared.sellBitcoin").toUpperCase()); - offerBookTab.setClosable(false); - offerBookTab.setContent(view.getRoot()); - tabPane.getTabs().add(offerBookTab); - offerBookView = (OfferBookView) view; - offerBookView.onTabSelected(true); - offerBookView.setOfferActionHandler(offerActionHandler); - offerBookView.setDirection(direction); + if (btcOfferBookTab == null) { + btcOfferBookTab = new Tab("BTC"); + btcOfferBookTab.setClosable(false); + bsqOfferBookTab = new Tab("BSQ"); + bsqOfferBookTab.setClosable(false); + topAltcoinOfferBookTab = new Tab("XMR"); + topAltcoinOfferBookTab.setClosable(false); + otherOfferBookTab = new Tab("OTHER"); + otherOfferBookTab.setClosable(false); + + tabPane.getTabs().addAll(btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab); + } + if (viewClass == BtcOfferBookView.class) { + btcOfferBookView = (OfferBookView) viewLoader.load(BtcOfferBookView.class); + btcOfferBookTab.setContent(btcOfferBookView.getRoot()); + btcOfferBookView.setOfferActionHandler(offerActionHandler); + btcOfferBookView.setDirection(direction); + btcOfferBookView.onTabSelected(true); + } else if (viewClass == BsqOfferBookView.class) { + bsqOfferBookView = (OfferBookView) viewLoader.load(BsqOfferBookView.class); + bsqOfferBookView.setOfferActionHandler(offerActionHandler); + bsqOfferBookView.setDirection(direction); + bsqOfferBookTab.setContent(bsqOfferBookView.getRoot()); + bsqOfferBookView.onTabSelected(true); + } else if (viewClass == TopAltcoinOfferBookView.class) { + topAltcoinOfferBookView = (OfferBookView) viewLoader.load(TopAltcoinOfferBookView.class); + topAltcoinOfferBookView.setOfferActionHandler(offerActionHandler); + topAltcoinOfferBookView.setDirection(direction); + topAltcoinOfferBookTab.setContent(topAltcoinOfferBookView.getRoot()); + topAltcoinOfferBookView.onTabSelected(true); + } else if (viewClass == OtherOfferBookView.class) { + otherOfferBookView = (OfferBookView) viewLoader.load(OtherOfferBookView.class); + otherOfferBookView.setOfferActionHandler(offerActionHandler); + otherOfferBookView.setDirection(direction); + otherOfferBookTab.setContent(otherOfferBookView.getRoot()); + otherOfferBookView.onTabSelected(true); + } } } else if (viewClass == CreateOfferView.class && createOfferView == null) { view = viewLoader.load(viewClass); @@ -286,23 +345,6 @@ protected boolean canCreateOrTakeOffer(TradeCurrency tradeCurrency) { GUIUtil.canCreateOrTakeOfferOrShowPopup(user, navigation, tradeCurrency); } - private void showNoArbitratorForUserLocaleWarning() { - String key = "NoArbitratorForUserLocaleWarning"; - new Popup().information(Res.get("offerbook.info.noArbitrationInUserLanguage", - getArbitrationLanguages(), LanguageUtil.getDisplayName(preferences.getUserLanguage()))) - .closeButtonText(Res.get("shared.ok")) - .dontShowAgainId(key) - .show(); - } - - private String getArbitrationLanguages() { - return arbitratorManager.getObservableMap().values().stream() - .flatMap(arbitrator -> arbitrator.getLanguageCodes().stream()) - .distinct() - .map(LanguageUtil::getDisplayName) - .collect(Collectors.joining(", ")); - } - private void openTakeOffer(Offer offer) { takeOfferViewOpen = true; this.offer = offer; @@ -332,9 +374,9 @@ private void onCreateOfferViewRemoved() { if (bsqSwapCreateOfferView != null) { bsqSwapCreateOfferView = null; } - offerBookView.enableCreateOfferButton(); - - navigation.navigateTo(MainView.class, this.getClass(), OfferBookView.class); + btcOfferBookView.enableCreateOfferButton(); + //TODO: go to last selected tab + navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); } private void onTakeOfferViewRemoved() { @@ -347,8 +389,8 @@ private void onTakeOfferViewRemoved() { if (bsqSwapTakeOfferView != null) { bsqSwapTakeOfferView = null; } - - navigation.navigateTo(MainView.class, this.getClass(), OfferBookView.class); + //TODO: go to last selected tab + navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); } public interface OfferActionHandler { diff --git a/desktop/src/main/java/bisq/desktop/main/offer/SellOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/SellOfferView.java index bbd16178149..7d48e0a9874 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/SellOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/SellOfferView.java @@ -22,7 +22,6 @@ import bisq.desktop.common.view.ViewLoader; import bisq.core.offer.OfferDirection; -import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager; import bisq.core.user.Preferences; import bisq.core.user.User; @@ -37,13 +36,11 @@ public class SellOfferView extends OfferView { public SellOfferView(ViewLoader viewLoader, Navigation navigation, Preferences preferences, - ArbitratorManager arbitratorManager, User user, P2PService p2PService) { super(viewLoader, navigation, preferences, - arbitratorManager, user, p2PService, OfferDirection.SELL); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index 6363347063e..e8f9c89842c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -1031,7 +1031,7 @@ private void addGridPane() { } private void addPaymentGroup() { - paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.selectTradingAccount")); + paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, "Buy BTC with Fiat"); GridPane.setColumnSpan(paymentTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); @@ -1106,8 +1106,7 @@ 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); buyBsqBox = buyBsqButtonBox.second; buyBsqBox.setManaged(false); buyBsqBox.setVisible(false); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java index 712a8fdd20b..dcff7647640 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java @@ -23,11 +23,13 @@ import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.main.MainView; import bisq.desktop.main.offer.SellOfferView; -import bisq.desktop.main.offer.offerbook.OfferBookView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookView; import bisq.desktop.main.overlays.popups.Popup; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; -import bisq.core.user.Preferences; +import bisq.core.offer.Offer; +import bisq.core.offer.OfferDirection; import bisq.common.UserThread; import bisq.common.util.Tuple2; @@ -84,14 +86,13 @@ public static void addPayInfoEntry(GridPane infoGridPane, int row, String labelT infoGridPane.getChildren().addAll(label, textField); } - public static Tuple2 createBuyBsqButtonBox(Navigation navigation, - Preferences preferences) { + 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, preferences) + buyBsqButton.setOnAction(e -> openBuyBsqOfferBook(navigation) ); var info = new AutoTooltipLabel("BSQ is colored BTC that helps fund Bisq developers."); @@ -100,7 +101,7 @@ public static Tuple2 createBuyBsqButtonBox(Navigation n .information(Res.get("createOffer.buyBsq.popupMessage")) .actionButtonText(buyBsqText) .buttonAlignment(HPos.CENTER) - .onAction(() -> openBuyBsqOfferBook(navigation, preferences)).show()); + .onAction(() -> openBuyBsqOfferBook(navigation)).show()); learnMore.setMinWidth(100); HBox buyBsqBox = new HBox(buyBsqButton, info, learnMore); @@ -111,9 +112,12 @@ public static Tuple2 createBuyBsqButtonBox(Navigation n return new Tuple2<>(buyBsqButton, buyBsqBox); } - private static void openBuyBsqOfferBook(Navigation navigation, Preferences preferences) { - preferences.setSellScreenCurrencyCode("BSQ"); + private static void openBuyBsqOfferBook(Navigation navigation) { navigation.navigateTo( - MainView.class, SellOfferView.class, OfferBookView.class); + MainView.class, SellOfferView.class, BsqOfferBookView.class); + } + + public static boolean isShownAsSellOffer(Offer offer) { + return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) == (offer.getDirection() == OfferDirection.SELL); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index 057547912f4..728b55109ff 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -307,7 +307,7 @@ protected void activate() { paymentAccountsComboBox.setItems(model.getPossiblePaymentAccounts()); paymentAccountsComboBox.getSelectionModel().select(lastPaymentAccount); model.onPaymentAccountSelected(lastPaymentAccount); - paymentAccountTitledGroupBg.setText(Res.get("shared.selectTradingAccount")); + paymentAccountTitledGroupBg.setText(Res.get("Buy BTC with EUR (using SEPA)")); } balanceTextField.setTargetAmount(model.dataModel.getTotalToPayAsCoin().get()); @@ -882,8 +882,7 @@ 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); buyBsqBox = buyBsqButtonBox.second; buyBsqBox.setManaged(false); buyBsqBox.setVisible(false); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.fxml b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.fxml similarity index 97% rename from desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.fxml rename to desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.fxml index 87c9745e249..ae1fd7b2449 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.fxml +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.fxml @@ -19,7 +19,7 @@ - diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java new file mode 100644 index 00000000000..ef4d5d30c33 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java @@ -0,0 +1,74 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; +import bisq.desktop.common.view.FxmlView; +import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; +import bisq.desktop.main.overlays.windows.OfferDetailsWindow; + +import bisq.core.account.sign.SignedWitnessService; +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.alert.PrivateNotificationManager; +import bisq.core.locale.Res; +import bisq.core.offer.OfferDirection; +import bisq.core.user.Preferences; +import bisq.core.util.FormattingUtils; +import bisq.core.util.coin.CoinFormatter; + +import bisq.common.config.Config; + +import javax.inject.Inject; +import javax.inject.Named; + +import javafx.scene.layout.GridPane; + +@FxmlView +public class BsqOfferBookView extends OfferBookView { + + @Inject + BsqOfferBookView(BsqOfferBookViewModel model, + Navigation navigation, + OfferDetailsWindow offerDetailsWindow, + BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow, + @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, + PrivateNotificationManager privateNotificationManager, + @Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys, + AccountAgeWitnessService accountAgeWitnessService, + SignedWitnessService signedWitnessService, + Preferences preferences) { + super(model, navigation, offerDetailsWindow, bsqSwapOfferDetailsWindow, formatter, privateNotificationManager, useDevPrivilegeKeys, accountAgeWitnessService, signedWitnessService); + } + + @Override + protected String getMarketTitle() { + return model.getDirection().equals(OfferDirection.BUY) ? + Res.get("offerbook.availableOffersToBuy", "BSQ", "BTC") : + Res.get("offerbook.availableOffersToSell", "BSQ", "BTC"); + } + + @Override + protected void activate() { + model.onSetTradeCurrency(BsqOfferBookViewModel.BSQ); + + super.activate(); + + currencyComboBoxContainer.setVisible(false); + currencyComboBoxContainer.setManaged(false); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java new file mode 100644 index 00000000000..ee9c02beebb --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java @@ -0,0 +1,115 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; + +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.api.CoreApi; +import bisq.core.btc.setup.WalletsSetup; +import bisq.core.btc.wallet.BsqWalletService; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; +import bisq.core.offer.Offer; +import bisq.core.offer.OfferDirection; +import bisq.core.offer.OfferFilterService; +import bisq.core.offer.OpenOfferManager; +import bisq.core.payment.payload.PaymentMethod; +import bisq.core.provider.price.PriceFeedService; +import bisq.core.trade.ClosedTradableManager; +import bisq.core.user.Preferences; +import bisq.core.user.User; +import bisq.core.util.FormattingUtils; +import bisq.core.util.PriceUtil; +import bisq.core.util.coin.BsqFormatter; +import bisq.core.util.coin.CoinFormatter; + +import bisq.network.p2p.P2PService; + +import com.google.inject.Inject; + +import javax.inject.Named; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class BsqOfferBookViewModel extends OfferBookViewModel { + + + public static final TradeCurrency BSQ = CurrencyUtil.getTradeCurrency("BSQ").get(); + + @Inject + public BsqOfferBookViewModel(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, + BsqFormatter bsqFormatter, + BsqWalletService bsqWalletService, CoreApi coreApi) { + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); + } + + @Override + void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) { + // No need to store anything as it is just BSQ offers anyway + } + + @Override + protected ObservableList filterPaymentMethods(ObservableList list, + TradeCurrency selectedTradeCurrency) { + return FXCollections.observableArrayList(list.stream().filter(PaymentMethod::isAltcoin).collect(Collectors.toList())); + } + + @Override + void fillCurrencies(ObservableList tradeCurrencies, + ObservableList allCurrencies) { + tradeCurrencies.add(BSQ); + allCurrencies.add(BSQ); + } + + @Override + Predicate getCurrencyAndMethodPredicate(OfferDirection direction, + TradeCurrency selectedTradeCurrency) { + return offerBookListItem -> { + Offer offer = offerBookListItem.getOffer(); + // BUY Altcoin is actually SELL Bitcoin + boolean directionResult = offer.getDirection() == direction; + boolean currencyResult = offer.getCurrencyCode().equals(BSQ.getCode()); + boolean paymentMethodResult = showAllPaymentMethods || + offer.getPaymentMethod().equals(selectedPaymentMethod); + boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook(); + return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated; + }; + } + + @Override + String getCurrencyCodeFromPreferences(OfferDirection direction) { + return BSQ.getCode(); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.fxml b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.fxml new file mode 100644 index 00000000000..a66cbf57d18 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java new file mode 100644 index 00000000000..480a7d0579e --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java @@ -0,0 +1,64 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; +import bisq.desktop.common.view.FxmlView; +import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; +import bisq.desktop.main.overlays.windows.OfferDetailsWindow; + +import bisq.core.account.sign.SignedWitnessService; +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.alert.PrivateNotificationManager; +import bisq.core.locale.Res; +import bisq.core.offer.OfferDirection; +import bisq.core.util.FormattingUtils; +import bisq.core.util.coin.CoinFormatter; + +import bisq.common.config.Config; + +import javax.inject.Inject; +import javax.inject.Named; + +import javafx.scene.layout.GridPane; + +@FxmlView +public class BtcOfferBookView extends OfferBookView { + + @Inject + BtcOfferBookView(BtcOfferBookViewModel model, + Navigation navigation, + OfferDetailsWindow offerDetailsWindow, + BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow, + @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, bsqSwapOfferDetailsWindow, formatter, privateNotificationManager, useDevPrivilegeKeys, accountAgeWitnessService, signedWitnessService); + } + + @Override + protected String getMarketTitle() { + return model.getDirection().equals(OfferDirection.BUY) ? + Res.get("offerbook.availableOffersToBuy", "BTC", "Fiat") : + Res.get("offerbook.availableOffersToSell", "BTC", "Fiat"); + + + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java new file mode 100644 index 00000000000..427bf59e864 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java @@ -0,0 +1,133 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; +import bisq.desktop.util.GUIUtil; + +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.api.CoreApi; +import bisq.core.btc.setup.WalletsSetup; +import bisq.core.btc.wallet.BsqWalletService; +import bisq.core.locale.CryptoCurrency; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; +import bisq.core.offer.Offer; +import bisq.core.offer.OfferDirection; +import bisq.core.offer.OfferFilterService; +import bisq.core.offer.OpenOfferManager; +import bisq.core.payment.PaymentAccountUtil; +import bisq.core.payment.payload.PaymentMethod; +import bisq.core.provider.price.PriceFeedService; +import bisq.core.trade.ClosedTradableManager; +import bisq.core.user.Preferences; +import bisq.core.user.User; +import bisq.core.util.FormattingUtils; +import bisq.core.util.PriceUtil; +import bisq.core.util.coin.BsqFormatter; +import bisq.core.util.coin.CoinFormatter; + +import bisq.network.p2p.P2PService; + +import com.google.inject.Inject; + +import javax.inject.Named; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class BtcOfferBookViewModel extends OfferBookViewModel { + + @Inject + public BtcOfferBookViewModel(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, + BsqFormatter bsqFormatter, + BsqWalletService bsqWalletService, CoreApi coreApi) { + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); + } + + @Override + void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) { + if (direction == OfferDirection.BUY) { + preferences.setBuyScreenCurrencyCode(code); + } else { + preferences.setSellScreenCurrencyCode(code); + } + } + + @Override + protected ObservableList filterPaymentMethods(ObservableList list, + TradeCurrency selectedTradeCurrency) { + return FXCollections.observableArrayList(list.stream() + .filter(paymentMethod -> { + if (showAllTradeCurrenciesProperty.get()) { + return paymentMethod.isFiat(); + } + return paymentMethod.isFiat() && + PaymentAccountUtil.supportsCurrency(paymentMethod, selectedTradeCurrency); + }) + .collect(Collectors.toList())); + } + + @Override + void fillCurrencies(ObservableList tradeCurrencies, + ObservableList allCurrencies) { + // Used for ignoring filter (show all) + tradeCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); + tradeCurrencies.addAll(preferences.getFiatCurrenciesAsObservable()); + tradeCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); + + allCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); + allCurrencies.addAll(CurrencyUtil.getAllSortedFiatCurrencies()); + 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; + boolean currencyResult = (showAllTradeCurrenciesProperty.get() && CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) || + 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 + String getCurrencyCodeFromPreferences(OfferDirection direction) { + return direction == OfferDirection.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode(); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index 2065068f8ef..833cb839204 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -19,7 +19,6 @@ import bisq.desktop.Navigation; import bisq.desktop.common.view.ActivatableViewAndModel; -import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.AccountStatusTooltipLabel; import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.AutoTooltipLabel; @@ -38,6 +37,7 @@ import bisq.desktop.main.funds.FundsView; import bisq.desktop.main.funds.withdrawal.WithdrawalView; import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; import bisq.desktop.main.overlays.windows.OfferDetailsWindow; @@ -52,7 +52,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.alert.PrivateNotificationManager; import bisq.core.locale.CurrencyUtil; -import bisq.core.locale.FiatCurrency; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.monetary.Price; @@ -64,20 +63,15 @@ import bisq.core.payment.PaymentAccount; import bisq.core.payment.payload.PaymentMethod; import bisq.core.user.DontShowAgainLookup; -import bisq.core.util.FormattingUtils; import bisq.core.util.coin.CoinFormatter; import bisq.network.p2p.NodeAddress; import bisq.common.app.DevEnv; -import bisq.common.config.Config; import bisq.common.util.Tuple3; import org.bitcoinj.core.Coin; -import javax.inject.Inject; -import javax.inject.Named; - import de.jensd.fx.fontawesome.AwesomeIcon; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; @@ -124,8 +118,7 @@ import static bisq.desktop.util.FormBuilder.addTitledGroupBg; -@FxmlView -public class OfferBookView extends ActivatableViewAndModel { +abstract public class OfferBookView extends ActivatableViewAndModel { private final Navigation navigation; private final OfferDetailsWindow offerDetailsWindow; @@ -137,7 +130,7 @@ public class OfferBookView extends ActivatableViewAndModel currencyComboBox; + protected AutocompleteComboBox currencyComboBox; private AutocompleteComboBox paymentMethodComboBox; private AutoTooltipButton createOfferButton; private AutoTooltipSlideToggleButton matchingOffersToggle; @@ -157,19 +150,19 @@ public class OfferBookView extends ActivatableViewAndModel> currencyBoxTuple = FormBuilder.addTopLabelAutocompleteComboBox( Res.get("offerbook.filterByCurrency")); + currencyComboBoxContainer = currencyBoxTuple.first; currencyComboBox = currencyBoxTuple.third; currencyComboBox.setPrefWidth(270); @@ -216,7 +210,7 @@ public void initialize() { matchingOffersToggle.setText(Res.get("offerbook.matchingOffers")); HBox.setMargin(matchingOffersToggle, new Insets(7, 0, -9, -15)); - createOfferButton = new AutoTooltipButton(); + createOfferButton = new AutoTooltipButton(Res.get("offerbook.createNewOffer")); createOfferButton.setMinHeight(40); createOfferButton.setGraphicTextGap(10); @@ -340,8 +334,11 @@ public void initialize() { priceFeedUpdateCounterListener = (observable, oldValue, newValue) -> tableView.sort(); } + abstract protected String getMarketTitle(); + @Override protected void activate() { + titledGroupBg.setText(getMarketTitle()); titledGroupBg.setHelpUrl(model.getDirection() == OfferDirection.SELL ? "https://bisq.wiki/Introduction#In_a_nutshell" : "https://bisq.wiki/Taking_an_offer"); @@ -360,6 +357,8 @@ protected void activate() { if (currencyComboBox.getEditor().getText().isEmpty()) currencyComboBox.getSelectionModel().select(SHOW_ALL); model.onSetTradeCurrency(currencyComboBox.getSelectionModel().getSelectedItem()); + paymentMethodComboBox.setAutocompleteItems(model.getPaymentMethods()); + updatePaymentMethodComboBoxEditor(); }); updateCurrencyComboBoxFromModel(); @@ -401,18 +400,13 @@ protected void activate() { updateSigningStateColumn(); }); - if (model.showAllPaymentMethods) - paymentMethodComboBox.getSelectionModel().select(SHOW_ALL); - else - paymentMethodComboBox.getSelectionModel().select(model.selectedPaymentMethod); - paymentMethodComboBox.getEditor().setText(new PaymentMethodStringConverter(paymentMethodComboBox).toString(paymentMethodComboBox.getSelectionModel().getSelectedItem())); + updatePaymentMethodComboBoxEditor(); createOfferButton.setOnAction(e -> onCreateOffer()); MonadicBinding currencySelectionBinding = EasyBind.combine( model.showAllTradeCurrenciesProperty, model.tradeCurrencyCode, (showAll, code) -> { - setDirectionTitles(); if (showAll) { volumeColumn.setTitleWithHelpText(Res.get("shared.amountMinMax"), Res.get("shared.amountHelp")); priceColumn.setTitle(Res.get("shared.price")); @@ -444,7 +438,15 @@ protected void activate() { model.priceFeedService.updateCounterProperty().addListener(priceFeedUpdateCounterListener); } - private void updateCurrencyComboBoxFromModel() { + private void updatePaymentMethodComboBoxEditor() { + if (model.showAllPaymentMethods) + paymentMethodComboBox.getSelectionModel().select(SHOW_ALL); + else + paymentMethodComboBox.getSelectionModel().select(model.selectedPaymentMethod); + paymentMethodComboBox.getEditor().setText(new PaymentMethodStringConverter(paymentMethodComboBox).toString(paymentMethodComboBox.getSelectionModel().getSelectedItem())); + } + + protected void updateCurrencyComboBoxFromModel() { if (model.showAllTradeCurrenciesProperty.get()) { currencyComboBox.getSelectionModel().select(SHOW_ALL); } else { @@ -588,36 +590,6 @@ public void setDirection(OfferDirection direction) { iconView.setId(direction == OfferDirection.SELL ? "image-sell-white" : "image-buy-white"); createOfferButton.setId(direction == OfferDirection.SELL ? "sell-button-big" : "buy-button-big"); avatarColumn.setTitle(direction == OfferDirection.SELL ? Res.get("shared.buyerUpperCase") : Res.get("shared.sellerUpperCase")); - setDirectionTitles(); - } - - private void setDirectionTitles() { - TradeCurrency selectedTradeCurrency = model.getSelectedTradeCurrency(); - if (selectedTradeCurrency != null) { - OfferDirection direction = model.getDirection(); - String offerButtonText; - String code = selectedTradeCurrency.getCode(); - - if (model.showAllTradeCurrenciesProperty.get()) { - offerButtonText = direction == OfferDirection.BUY ? - Res.get("offerbook.createOfferToBuy", - Res.getBaseCurrencyCode()) : - Res.get("offerbook.createOfferToSell", - Res.getBaseCurrencyCode()); - } else if (selectedTradeCurrency instanceof FiatCurrency) { - offerButtonText = direction == OfferDirection.BUY ? - Res.get("offerbook.createOfferToBuy.withFiat", - Res.getBaseCurrencyCode(), code) : - Res.get("offerbook.createOfferToSell.forFiat", Res.getBaseCurrencyCode(), code); - - } else { - offerButtonText = direction == OfferDirection.BUY ? - Res.get("offerbook.createOfferToBuy.withCrypto", - code, Res.getBaseCurrencyCode()) : - Res.get("offerbook.createOfferToSell.forCrypto", code, Res.getBaseCurrencyCode()); - } - createOfferButton.updateText(offerButtonText); - } } public void setOfferActionHandler(OfferView.OfferActionHandler offerActionHandler) { @@ -1181,19 +1153,11 @@ public void updateItem(final OfferBookListItem item, boolean empty) { button2.setManaged(true); button2.setVisible(true); } else { - boolean isSellOffer = offer.getDirection() == OfferDirection.SELL; + boolean isSellOffer = OfferViewUtil.isShownAsSellOffer(offer); iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white"); button.setId(isSellOffer ? "buy-button" : "sell-button"); button.setStyle("-fx-text-fill: white"); - if (isSellOffer) { - title = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? - Res.get("offerbook.takeOfferToBuy", offer.getBaseCurrencyCode()) : - Res.get("offerbook.takeOfferToSell", offer.getCurrencyCode()); - } else { - title = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? - Res.get("offerbook.takeOfferToSell", offer.getBaseCurrencyCode()) : - Res.get("offerbook.takeOfferToBuy", offer.getCurrencyCode()); - } + title = Res.get("offerbook.takeOffer"); button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer)))); button.setOnAction(e -> onTakeOffer(offer)); button2.setManaged(false); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index df3ff85659b..9becffd25dc 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -68,10 +68,6 @@ import org.bitcoinj.core.Coin; -import com.google.inject.Inject; - -import javax.inject.Named; - import com.google.common.base.Joiner; import javafx.beans.property.BooleanProperty; @@ -102,7 +98,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -class OfferBookViewModel extends ActivatableViewModel { +abstract class OfferBookViewModel extends ActivatableViewModel { private final OpenOfferManager openOfferManager; private final User user; private final OfferBook offerBook; @@ -156,7 +152,6 @@ class OfferBookViewModel extends ActivatableViewModel { // Constructor, lifecycle /////////////////////////////////////////////////////////////////////////////////////////// - @Inject public OfferBookViewModel(User user, OpenOfferManager openOfferManager, OfferBook offerBook, @@ -170,7 +165,7 @@ public OfferBookViewModel(User user, Navigation navigation, PriceUtil priceUtil, OfferFilterService offerFilterService, - @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, + CoinFormatter btcFormatter, BsqFormatter bsqFormatter, BsqWalletService bsqWalletService, CoreApi coreApi) { @@ -297,13 +292,12 @@ else if (!showAllEntry) { setMarketPriceFeedCurrency(); filterOffers(); - if (direction == OfferDirection.BUY) - preferences.setBuyScreenCurrencyCode(code); - else - preferences.setSellScreenCurrencyCode(code); + saveSelectedCurrencyCodeInPreferences(direction, code); } } + abstract void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code); + void onSetPaymentMethod(PaymentMethod paymentMethod) { if (paymentMethod == null) return; @@ -381,11 +375,16 @@ ObservableList getPaymentMethods() { } } + list = filterPaymentMethods(list, selectedTradeCurrency); + list.sort(Comparator.naturalOrder()); list.add(0, getShowAllEntryForPaymentMethod()); return list; } + protected abstract ObservableList filterPaymentMethods(ObservableList list, + TradeCurrency selectedTradeCurrency); + String getAmount(OfferBookListItem item) { return formatAmount(item.getOffer(), true); } @@ -557,18 +556,13 @@ private void setMarketPriceFeedCurrency() { private void fillCurrencies() { tradeCurrencies.clear(); - // Used for ignoring filter (show all) - tradeCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); - tradeCurrencies.addAll(preferences.getTradeCurrenciesAsObservable()); - tradeCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); - allCurrencies.clear(); - allCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); - allCurrencies.addAll(CurrencyUtil.getAllSortedFiatCurrencies()); - allCurrencies.addAll(CurrencyUtil.getAllSortedCryptoCurrencies()); - allCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); + + fillCurrencies(tradeCurrencies, allCurrencies); } + abstract void fillCurrencies(ObservableList tradeCurrencies, + ObservableList allCurrencies); /////////////////////////////////////////////////////////////////////////////////////////// // Checks @@ -594,23 +588,13 @@ boolean canCreateOrTakeOffer() { private void filterOffers() { Predicate predicate = useOffersMatchingMyAccountsFilter ? - getCurrencyAndMethodPredicate().and(getOffersMatchingMyAccountsPredicate()) : - getCurrencyAndMethodPredicate(); + getCurrencyAndMethodPredicate(direction, selectedTradeCurrency).and(getOffersMatchingMyAccountsPredicate()) : + getCurrencyAndMethodPredicate(direction, selectedTradeCurrency); filteredItems.setPredicate(predicate); } - private Predicate getCurrencyAndMethodPredicate() { - return offerBookListItem -> { - Offer offer = offerBookListItem.getOffer(); - boolean directionResult = offer.getDirection() != direction; - boolean currencyResult = (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; - }; - } + abstract Predicate getCurrencyAndMethodPredicate(OfferDirection direction, + TradeCurrency selectedTradeCurrency); private Predicate getOffersMatchingMyAccountsPredicate() { // This code duplicates code in the view at the button column. We need there the different results for @@ -706,7 +690,7 @@ public void onTakeOffer(Offer offer) { } private void updateSelectedTradeCurrency() { - String code = direction == OfferDirection.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode(); + String code = getCurrencyCodeFromPreferences(direction); if (code != null && !code.isEmpty() && !isShowAllEntry(code) && CurrencyUtil.getTradeCurrency(code).isPresent()) { showAllTradeCurrenciesProperty.set(false); @@ -718,6 +702,8 @@ private void updateSelectedTradeCurrency() { tradeCurrencyCode.set(selectedTradeCurrency.getCode()); } + abstract String getCurrencyCodeFromPreferences(OfferDirection direction); + public OpenOffer getOpenOffer(Offer offer) { return openOfferManager.getOpenOfferById(offer.getId()).orElse(null); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.fxml b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.fxml new file mode 100644 index 00000000000..697fcac5601 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java new file mode 100644 index 00000000000..7ccb4f74978 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java @@ -0,0 +1,62 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; +import bisq.desktop.common.view.FxmlView; +import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; +import bisq.desktop.main.overlays.windows.OfferDetailsWindow; + +import bisq.core.account.sign.SignedWitnessService; +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.alert.PrivateNotificationManager; +import bisq.core.locale.Res; +import bisq.core.offer.OfferDirection; +import bisq.core.util.FormattingUtils; +import bisq.core.util.coin.CoinFormatter; + +import bisq.common.config.Config; + +import javax.inject.Inject; +import javax.inject.Named; + +import javafx.scene.layout.GridPane; + +@FxmlView +public class OtherOfferBookView extends OfferBookView { + + @Inject + OtherOfferBookView(OtherOfferBookViewModel model, + Navigation navigation, + OfferDetailsWindow offerDetailsWindow, + BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow, + @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, bsqSwapOfferDetailsWindow, formatter, privateNotificationManager, useDevPrivilegeKeys, accountAgeWitnessService, signedWitnessService); + } + + @Override + protected String getMarketTitle() { + return model.getDirection().equals(OfferDirection.BUY) ? + Res.get("offerbook.availableOffersToBuy", "Other assets", "BTC") : + Res.get("offerbook.availableOffersToSell", "Other assets", "BTC"); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java new file mode 100644 index 00000000000..ca0560230fa --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java @@ -0,0 +1,141 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; +import bisq.desktop.util.GUIUtil; + +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.api.CoreApi; +import bisq.core.btc.setup.WalletsSetup; +import bisq.core.btc.wallet.BsqWalletService; +import bisq.core.locale.CryptoCurrency; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; +import bisq.core.offer.Offer; +import bisq.core.offer.OfferDirection; +import bisq.core.offer.OfferFilterService; +import bisq.core.offer.OpenOfferManager; +import bisq.core.payment.payload.PaymentMethod; +import bisq.core.provider.price.PriceFeedService; +import bisq.core.trade.ClosedTradableManager; +import bisq.core.user.Preferences; +import bisq.core.user.User; +import bisq.core.util.FormattingUtils; +import bisq.core.util.PriceUtil; +import bisq.core.util.coin.BsqFormatter; +import bisq.core.util.coin.CoinFormatter; + +import bisq.network.p2p.P2PService; + +import com.google.inject.Inject; + +import javax.inject.Named; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.jetbrains.annotations.NotNull; + +public class OtherOfferBookViewModel extends OfferBookViewModel { + + @Inject + public OtherOfferBookViewModel(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, + BsqFormatter bsqFormatter, + BsqWalletService bsqWalletService, CoreApi coreApi) { + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, 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::isBlockchain).collect(Collectors.toList())); + } + + @Override + void fillCurrencies(ObservableList tradeCurrencies, + ObservableList allCurrencies) { + + tradeCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); + tradeCurrencies.addAll(preferences.getCryptoCurrenciesAsObservable().stream() + .filter(withoutBSQAndTopAltcoin()) + .collect(Collectors.toList())); + tradeCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); + + allCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "")); + allCurrencies.addAll(CurrencyUtil.getAllSortedCryptoCurrencies().stream() + .filter(withoutBSQAndTopAltcoin()) + .collect(Collectors.toList())); + allCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, "")); + } + + @Override + Predicate getCurrencyAndMethodPredicate(OfferDirection direction, + TradeCurrency selectedTradeCurrency) { + return offerBookListItem -> { + Offer offer = offerBookListItem.getOffer(); + // BUY Altcoin is actually SELL Bitcoin + boolean directionResult = offer.getDirection() == direction; + boolean currencyResult = CurrencyUtil.isCryptoCurrency(offer.getCurrencyCode()) && + ((showAllTradeCurrenciesProperty.get() && + !offer.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()) && + !offer.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode())) || + 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 + String getCurrencyCodeFromPreferences(OfferDirection direction) { + return direction == OfferDirection.BUY ? preferences.getBuyScreenCryptoCurrencyCode() : preferences.getSellScreenCryptoCurrencyCode(); + } + + @NotNull + private Predicate withoutBSQAndTopAltcoin() { + return cryptoCurrency -> + !cryptoCurrency.equals(BsqOfferBookViewModel.BSQ) && + !cryptoCurrency.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.fxml b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.fxml new file mode 100644 index 00000000000..332e6ecfe8d --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java new file mode 100644 index 00000000000..076b83cad55 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java @@ -0,0 +1,72 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; +import bisq.desktop.common.view.FxmlView; +import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; +import bisq.desktop.main.overlays.windows.OfferDetailsWindow; + +import bisq.core.account.sign.SignedWitnessService; +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.alert.PrivateNotificationManager; +import bisq.core.locale.Res; +import bisq.core.offer.OfferDirection; +import bisq.core.util.FormattingUtils; +import bisq.core.util.coin.CoinFormatter; + +import bisq.common.config.Config; + +import javax.inject.Inject; +import javax.inject.Named; + +import javafx.scene.layout.GridPane; + +@FxmlView +public class TopAltcoinOfferBookView extends OfferBookView { + + @Inject + TopAltcoinOfferBookView(TopAltcoinOfferBookViewModel model, + Navigation navigation, + OfferDetailsWindow offerDetailsWindow, + BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow, + @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, bsqSwapOfferDetailsWindow, formatter, privateNotificationManager, useDevPrivilegeKeys, accountAgeWitnessService, signedWitnessService); + } + + @Override + protected String getMarketTitle() { + return model.getDirection().equals(OfferDirection.BUY) ? + Res.get("offerbook.availableOffersToBuy", TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode(), "BTC") : + Res.get("offerbook.availableOffersToSell", TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode(), "BTC"); + } + + @Override + protected void activate() { + model.onSetTradeCurrency(TopAltcoinOfferBookViewModel.TOP_ALTCOIN); + + super.activate(); + + currencyComboBoxContainer.setVisible(false); + currencyComboBoxContainer.setManaged(false); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java new file mode 100644 index 00000000000..6135e59e254 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java @@ -0,0 +1,115 @@ +/* + * 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 bisq.desktop.main.offer.offerbook; + +import bisq.desktop.Navigation; + +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.api.CoreApi; +import bisq.core.btc.setup.WalletsSetup; +import bisq.core.btc.wallet.BsqWalletService; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; +import bisq.core.offer.Offer; +import bisq.core.offer.OfferDirection; +import bisq.core.offer.OfferFilterService; +import bisq.core.offer.OpenOfferManager; +import bisq.core.payment.payload.PaymentMethod; +import bisq.core.provider.price.PriceFeedService; +import bisq.core.trade.ClosedTradableManager; +import bisq.core.user.Preferences; +import bisq.core.user.User; +import bisq.core.util.FormattingUtils; +import bisq.core.util.PriceUtil; +import bisq.core.util.coin.BsqFormatter; +import bisq.core.util.coin.CoinFormatter; + +import bisq.network.p2p.P2PService; + +import com.google.inject.Inject; + +import javax.inject.Named; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class TopAltcoinOfferBookViewModel extends OfferBookViewModel { + + public static final TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get(); + + @Inject + public TopAltcoinOfferBookViewModel(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, + BsqFormatter bsqFormatter, + BsqWalletService bsqWalletService, + CoreApi coreApi) { + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); + } + + @Override + void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) { + // No need to store anything as it is just one Altcoin 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_ALTCOIN); + allCurrencies.add(TOP_ALTCOIN); + } + + @Override + Predicate getCurrencyAndMethodPredicate(OfferDirection direction, + TradeCurrency selectedTradeCurrency) { + return offerBookListItem -> { + Offer offer = offerBookListItem.getOffer(); + // BUY Altcoin is actually SELL Bitcoin + boolean directionResult = offer.getDirection() == direction; + boolean currencyResult = offer.getCurrencyCode().equals(TOP_ALTCOIN.getCode()); + boolean paymentMethodResult = showAllPaymentMethods || + offer.getPaymentMethod().equals(selectedPaymentMethod); + boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook(); + return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated; + }; + } + + @Override + String getCurrencyCodeFromPreferences(OfferDirection direction) { + return TOP_ALTCOIN.getCode(); + } +} diff --git a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java index cffe57e297a..01288ca0f27 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java @@ -238,8 +238,8 @@ public void testMaxCharactersForAmountWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForAmount.intValue()); } @@ -252,8 +252,8 @@ public void testMaxCharactersForAmount() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(6, model.maxPlacesForAmount.intValue()); @@ -270,8 +270,8 @@ public void testMaxCharactersForAmountRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(15, model.maxPlacesForAmount.intValue()); @@ -289,8 +289,8 @@ public void testMaxCharactersForVolumeWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForVolume.intValue()); } @@ -303,8 +303,8 @@ public void testMaxCharactersForVolume() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(5, model.maxPlacesForVolume.intValue()); @@ -321,8 +321,8 @@ public void testMaxCharactersForVolumeRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(9, model.maxPlacesForVolume.intValue()); @@ -340,8 +340,8 @@ public void testMaxCharactersForPriceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForPrice.intValue()); } @@ -354,8 +354,8 @@ public void testMaxCharactersForPrice() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(7, model.maxPlacesForPrice.intValue()); @@ -372,8 +372,8 @@ public void testMaxCharactersForPriceDistanceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue()); } @@ -407,8 +407,8 @@ public void testMaxCharactersForPriceDistance() { item4.getOffer().setPriceFeedService(priceFeedService); offerBookListItems.addAll(item1, item2); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue()); //" (1.97%)" @@ -428,8 +428,8 @@ public void testGetPrice() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true)); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); final OfferBookListItem item = make(btcBuyItem.but( with(useMarketBasedPrice, true), diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 8a63d6a1c10..d5c4e0b3f07 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1952,6 +1952,8 @@ message PreferencesPayload { bool notify_on_pre_release = 61; bool use_full_mode_dao_monitor = 62; int32 clear_data_after_days = 63; + string buy_screen_crypto_currency_code = 64; + string sell_screen_crypto_currency_code = 65; } message AutoConfirmSettings { From 875e5f4e870ccb9585b02287dd60cd32d9935c97 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 1 Apr 2022 13:30:40 +0200 Subject: [PATCH 02/35] Adapt offer book chart view to new navigational structure --- .../resources/i18n/displayStrings.properties | 8 +- .../market/offerbook/OfferBookChartView.java | 141 +++++++++--------- .../offerbook/OfferBookChartViewModel.java | 25 ++-- .../bisq/desktop/main/offer/OfferView.java | 4 + 4 files changed, 88 insertions(+), 90 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 9d7a696924b..237f22716cc 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -301,10 +301,10 @@ market.tabs.spreadPayment=Offers by Payment Method market.tabs.trades=Trades # OfferBookChartView -market.offerBook.buyAltcoin=Buy {0} (sell {1}) -market.offerBook.sellAltcoin=Sell {0} (buy {1}) -market.offerBook.buyWithFiat=Buy {0} -market.offerBook.sellWithFiat=Sell {0} +market.offerBook.buyAltcoin=Buy {0} +market.offerBook.sellAltcoin=Sell {0} +market.offerBook.buyWith=Buy {0} +market.offerBook.sellWith=Sell {0} market.offerBook.sellOffersHeaderLabel=Sell {0} to market.offerBook.buyOffersHeaderLabel=Buy {0} from market.offerBook.buy=I want to buy bitcoin diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index bfe705ccc10..16b6a066dd4 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -29,7 +29,14 @@ import bisq.desktop.main.MainView; import bisq.desktop.main.offer.BuyOfferView; import bisq.desktop.main.offer.SellOfferView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; +import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookListItem; +import bisq.desktop.main.offer.offerbook.OfferBookView; +import bisq.desktop.main.offer.offerbook.OtherOfferBookView; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.CurrencyListItem; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -85,9 +92,7 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; -import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; import javafx.util.Callback; import javafx.util.StringConverter; @@ -118,19 +123,19 @@ public class OfferBookChartView extends ActivatableViewAndModel selectedTabIndexListener; private SingleSelectionModel tabPaneSelectionModel; - private Label leftHeaderLabel, rightHeaderLabel; + private Label sellHeaderLabel, buyHeaderLabel; private ChangeListener sellTableRowSelectionListener, buyTableRowSelectionListener; - private HBox bottomHBox; private ListChangeListener changeListener; private ListChangeListener currencyListItemsListener; private final double dataLimitFactor = 3; private final double initialOfferTableViewHeight = 121; - private final double pixelsPerOfferTableRow = (initialOfferTableViewHeight - 30) / 5.0; // initial visible row count=5, header height=30 private final Function offerTableViewHeight = (screenSize) -> { + // initial visible row count=5, header height=30 + double pixelsPerOfferTableRow = (initialOfferTableViewHeight - 30) / 5.0; int extraRows = screenSize <= INITIAL_WINDOW_HEIGHT ? 0 : (int) ((screenSize - INITIAL_WINDOW_HEIGHT) / pixelsPerOfferTableRow); return extraRows == 0 ? initialOfferTableViewHeight : Math.ceil(initialOfferTableViewHeight + ((extraRows + 1) * pixelsPerOfferTableRow)); }; @@ -169,13 +174,13 @@ public void initialize() { buyOfferTableView = tupleBuy.first; sellOfferTableView = tupleSell.first; - leftButton = (AutoTooltipButton) tupleBuy.third; - rightButton = (AutoTooltipButton) tupleSell.third; + sellButton = (AutoTooltipButton) tupleBuy.third; + buyButton = (AutoTooltipButton) tupleSell.third; - leftHeaderLabel = tupleBuy.fourth; - rightHeaderLabel = tupleSell.fourth; + sellHeaderLabel = tupleBuy.fourth; + buyHeaderLabel = tupleSell.fourth; - bottomHBox = new HBox(); + HBox bottomHBox = new HBox(); bottomHBox.setSpacing(20); //30 bottomHBox.setAlignment(Pos.CENTER); VBox.setMargin(bottomHBox, new Insets(-5, 0, 0, 0)); @@ -225,15 +230,15 @@ protected void activate() { String code = tradeCurrency.getCode(); volumeColumnLabel.set(Res.get("offerbook.volume", code)); xAxis.setTickLabelFormatter(new StringConverter<>() { - int cryptoPrecision = 3; - DecimalFormat df = new DecimalFormat(",###"); + final int cryptoPrecision = 3; + final DecimalFormat df = new DecimalFormat(",###"); @Override public String toString(Number object) { final double doubleValue = (double) object; if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) { final String withCryptoPrecision = FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, cryptoPrecision); - if (withCryptoPrecision.substring(0, 3).equals("0.0")) { + if (withCryptoPrecision.startsWith("0.0")) { return FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, 8).replaceFirst("0+$", ""); } else { return withCryptoPrecision.replaceFirst("0+$", ""); @@ -249,37 +254,21 @@ public Number fromString(String string) { } }); - if (CurrencyUtil.isCryptoCurrency(code)) { - if (bottomHBox.getChildren().size() == 2 && bottomHBox.getChildren().get(0).getUserData().equals(OfferDirection.BUY.name())) { - bottomHBox.getChildren().get(0).toFront(); - reverseTableColumns(); - } - - leftHeaderLabel.setText(Res.get("market.offerBook.buyOffersHeaderLabel", code)); - leftButton.updateText(Res.get("market.offerBook.buyAltcoin", code, Res.getBaseCurrencyCode())); + String viewBaseCurrencyCode = CurrencyUtil.isCryptoCurrency(code) ? code : Res.getBaseCurrencyCode(); + String viewPriceCurrencyCode = CurrencyUtil.isCryptoCurrency(code) ? Res.getBaseCurrencyCode() : code; - rightHeaderLabel.setText(Res.get("market.offerBook.sellOffersHeaderLabel", code)); - rightButton.updateText(Res.get("market.offerBook.sellAltcoin", code, Res.getBaseCurrencyCode())); - - priceColumnLabel.set(Res.get("shared.priceWithCur", Res.getBaseCurrencyCode())); - } else { - if (bottomHBox.getChildren().size() == 2 && bottomHBox.getChildren().get(0).getUserData().equals(OfferDirection.SELL.name())) { - bottomHBox.getChildren().get(0).toFront(); - reverseTableColumns(); - } + sellHeaderLabel.setText(Res.get("market.offerBook.sellOffersHeaderLabel", viewBaseCurrencyCode)); + sellButton.updateText(Res.get("market.offerBook.sellWith", viewBaseCurrencyCode, viewPriceCurrencyCode)); - leftHeaderLabel.setText(Res.get("market.offerBook.sellOffersHeaderLabel", Res.getBaseCurrencyCode())); - leftButton.updateText(Res.get("market.offerBook.sellWithFiat", Res.getBaseCurrencyCode(), code)); + buyHeaderLabel.setText(Res.get("market.offerBook.buyOffersHeaderLabel", viewBaseCurrencyCode)); + buyButton.updateText(Res.get("market.offerBook.buyWith", viewBaseCurrencyCode, viewPriceCurrencyCode)); - rightHeaderLabel.setText(Res.get("market.offerBook.buyOffersHeaderLabel", Res.getBaseCurrencyCode())); - rightButton.updateText(Res.get("market.offerBook.buyWithFiat", Res.getBaseCurrencyCode(), code)); + priceColumnLabel.set(Res.get("shared.priceWithCur", viewPriceCurrencyCode)); - priceColumnLabel.set(Res.get("shared.priceWithCur", code)); - } xAxis.setLabel(CurrencyUtil.getPriceWithCurrencyCode(code)); - seriesBuy.setName(leftHeaderLabel.getText() + " "); - seriesSell.setName(rightHeaderLabel.getText()); + seriesBuy.setName(sellHeaderLabel.getText() + " "); + seriesSell.setName(buyHeaderLabel.getText()); }); buyOfferTableView.setItems(model.getTopBuyOfferList()); @@ -295,7 +284,7 @@ public Number fromString(String string) { } static class CurrencyListItemStringConverter extends StringConverter { - private ComboBox comboBox; + private final ComboBox comboBox; CurrencyListItemStringConverter(ComboBox comboBox) { this.comboBox = comboBox; @@ -390,33 +379,30 @@ private void updateChartData() { seriesSell.getData().clear(); areaChart.getData().clear(); - boolean isCrypto = CurrencyUtil.isCryptoCurrency(model.getCurrencyCode()); - - // crypto: left-sell, right-buy. fiat: left-buy, right-sell - seriesBuy.getData().addAll(filterOutliersBuy(model.getBuyData(), isCrypto)); - seriesSell.getData().addAll(filterOutliersSell(model.getSellData(), isCrypto)); + seriesBuy.getData().addAll(filterOutliersBuy(model.getBuyData())); + seriesSell.getData().addAll(filterOutliersSell(model.getSellData())); areaChart.getData().addAll(List.of(seriesBuy, seriesSell)); } - List> filterOutliersBuy(List> buy, boolean isCrypto) { - List mnmx = isCrypto ? minMaxFilterRight(buy) : minMaxFilterLeft(buy); - if (mnmx.get(0).doubleValue() == Double.MAX_VALUE || - mnmx.get(1).doubleValue() == Double.MIN_VALUE) { // no filtering + List> filterOutliersBuy(List> buy) { + List mnmx = minMaxFilterLeft(buy); + if (mnmx.get(0) == Double.MAX_VALUE || + mnmx.get(1) == Double.MIN_VALUE) { // no filtering return buy; } // apply filtering - return isCrypto ? filterRight(buy, mnmx.get(0)) : filterLeft(buy, mnmx.get(1)); + return filterLeft(buy, mnmx.get(1)); } - List> filterOutliersSell(List> sell, boolean isCrypto) { - List mnmx = isCrypto ? minMaxFilterLeft(sell) : minMaxFilterRight(sell); - if (mnmx.get(0).doubleValue() == Double.MAX_VALUE || - mnmx.get(1).doubleValue() == Double.MIN_VALUE) { // no filtering + List> filterOutliersSell(List> sell) { + List mnmx = minMaxFilterRight(sell); + if (mnmx.get(0) == Double.MAX_VALUE || + mnmx.get(1) == Double.MIN_VALUE) { // no filtering return sell; } // apply filtering - return isCrypto ? filterLeft(sell, mnmx.get(1)) : filterRight(sell, mnmx.get(0)); + return filterRight(sell, mnmx.get(0)); } private List minMaxFilterLeft(List> data) { @@ -674,12 +660,35 @@ public void updateItem(final OfferListItem newItem, boolean empty) { button.setMinHeight(32); button.setId(isSellOffer ? "buy-button-big" : "sell-button-big"); button.setOnAction(e -> { + Class> offerBookViewClazz; + if (CurrencyUtil.isFiatCurrency(model.getCurrencyCode())) { + offerBookViewClazz = BtcOfferBookView.class; + } else if (model.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode())) { + offerBookViewClazz = BsqOfferBookView.class; + } else if (model.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + offerBookViewClazz = TopAltcoinOfferBookView.class; + } else { + offerBookViewClazz = OtherOfferBookView.class; + } + if (isSellOffer) { - model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode()); - navigation.navigateTo(MainView.class, BuyOfferView.class); + if (CurrencyUtil.isFiatCurrency(model.getCurrencyCode())) { + model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode()); + } else if (!model.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && + model.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + model.preferences.setBuyScreenCryptoCurrencyCode(model.getCurrencyCode()); + } + + navigation.navigateTo(MainView.class, BuyOfferView.class, offerBookViewClazz); } else { - model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode()); - navigation.navigateTo(MainView.class, SellOfferView.class); + if (CurrencyUtil.isFiatCurrency(model.getCurrencyCode())) { + model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode()); + } else if (!model.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && + model.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + model.preferences.setSellScreenCryptoCurrencyCode(model.getCurrencyCode()); + } + + navigation.navigateTo(MainView.class, SellOfferView.class, offerBookViewClazz); } }); @@ -700,18 +709,6 @@ public void updateItem(final OfferListItem newItem, boolean empty) { return new Tuple4<>(tableView, vBox, button, titleLabel); } - private void reverseTableColumns() { - ObservableList> columns = FXCollections.observableArrayList(buyOfferTableView.getColumns()); - buyOfferTableView.getColumns().clear(); - FXCollections.reverse(columns); - buyOfferTableView.getColumns().addAll(columns); - - columns = FXCollections.observableArrayList(sellOfferTableView.getColumns()); - sellOfferTableView.getColumns().clear(); - FXCollections.reverse(columns); - sellOfferTableView.getColumns().addAll(columns); - } - private void layout() { UserThread.runAfter(() -> { if (root.getScene() != null) { diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java index 1c9c275d789..db48b2e9b99 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java @@ -293,7 +293,7 @@ private void updateChartData() { // the buy column is actually the sell column and vice versa. To maintain the expected // ordering, we have to reverse the price comparator. boolean isCrypto = CurrencyUtil.isCryptoCurrency(getCurrencyCode()); - if (isCrypto) offerPriceComparator = offerPriceComparator.reversed(); +// if (isCrypto) offerPriceComparator = offerPriceComparator.reversed(); // Offer amounts are used for the secondary sort. They are sorted from high to low. Comparator offerAmountComparator = Comparator.comparing(Offer::getAmount).reversed(); @@ -305,10 +305,12 @@ private void updateChartData() { offerPriceComparator .thenComparing(offerAmountComparator); + OfferDirection buyOfferDirection = isCrypto ? OfferDirection.SELL : OfferDirection.BUY; + List allBuyOffers = offerBookListItems.stream() .map(OfferBookListItem::getOffer) .filter(e -> e.getCurrencyCode().equals(selectedTradeCurrencyProperty.get().getCode()) - && e.getDirection().equals(OfferDirection.BUY)) + && e.getDirection().equals(buyOfferDirection)) .sorted(buyOfferSortComparator) .collect(Collectors.toList()); @@ -334,10 +336,12 @@ private void updateChartData() { buildChartAndTableEntries(allBuyOffers, OfferDirection.BUY, buyData, topBuyOfferList); + OfferDirection sellOfferDirection = isCrypto ? OfferDirection.BUY : OfferDirection.SELL; + List allSellOffers = offerBookListItems.stream() .map(OfferBookListItem::getOffer) .filter(e -> e.getCurrencyCode().equals(selectedTradeCurrencyProperty.get().getCode()) - && e.getDirection().equals(OfferDirection.SELL)) + && e.getDirection().equals(sellOfferDirection)) .sorted(sellOfferSortComparator) .collect(Collectors.toList()); @@ -377,17 +381,10 @@ private void buildChartAndTableEntries(List sortedList, offerTableListTemp.add(new OfferListItem(offer, accumulatedAmount)); double priceAsDouble = (double) price.getValue() / LongMath.pow(10, price.smallestUnitExponent()); - if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) { - if (direction.equals(OfferDirection.SELL)) - data.add(0, new XYChart.Data<>(priceAsDouble, accumulatedAmount)); - else - data.add(new XYChart.Data<>(priceAsDouble, accumulatedAmount)); - } else { - if (direction.equals(OfferDirection.BUY)) - data.add(0, new XYChart.Data<>(priceAsDouble, accumulatedAmount)); - else - data.add(new XYChart.Data<>(priceAsDouble, accumulatedAmount)); - } + if (direction.equals(OfferDirection.BUY)) + data.add(0, new XYChart.Data<>(priceAsDouble, accumulatedAmount)); + else + data.add(new XYChart.Data<>(priceAsDouble, accumulatedAmount)); } } offerTableList.setAll(offerTableListTemp); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index caf7de6439d..d66075ed5ac 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -260,23 +260,27 @@ private void loadView(Class viewClass, @Nullable Object data) { btcOfferBookTab.setContent(btcOfferBookView.getRoot()); btcOfferBookView.setOfferActionHandler(offerActionHandler); btcOfferBookView.setDirection(direction); + tabPane.getSelectionModel().select(btcOfferBookTab); btcOfferBookView.onTabSelected(true); } else if (viewClass == BsqOfferBookView.class) { bsqOfferBookView = (OfferBookView) viewLoader.load(BsqOfferBookView.class); bsqOfferBookView.setOfferActionHandler(offerActionHandler); bsqOfferBookView.setDirection(direction); + tabPane.getSelectionModel().select(bsqOfferBookTab); bsqOfferBookTab.setContent(bsqOfferBookView.getRoot()); bsqOfferBookView.onTabSelected(true); } else if (viewClass == TopAltcoinOfferBookView.class) { topAltcoinOfferBookView = (OfferBookView) viewLoader.load(TopAltcoinOfferBookView.class); topAltcoinOfferBookView.setOfferActionHandler(offerActionHandler); topAltcoinOfferBookView.setDirection(direction); + tabPane.getSelectionModel().select(topAltcoinOfferBookTab); topAltcoinOfferBookTab.setContent(topAltcoinOfferBookView.getRoot()); topAltcoinOfferBookView.onTabSelected(true); } else if (viewClass == OtherOfferBookView.class) { otherOfferBookView = (OfferBookView) viewLoader.load(OtherOfferBookView.class); otherOfferBookView.setOfferActionHandler(offerActionHandler); otherOfferBookView.setDirection(direction); + tabPane.getSelectionModel().select(otherOfferBookTab); otherOfferBookTab.setContent(otherOfferBookView.getRoot()); otherOfferBookView.onTabSelected(true); } From 5781e3bd13d96b6b08651ee7f98e4cbde73bbcde Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 1 Apr 2022 13:31:24 +0200 Subject: [PATCH 03/35] Add payment account filtering for remaining payment methods --- .../java/bisq/core/locale/CurrencyUtil.java | 108 ++++++++++++++++++ .../java/bisq/core/payment/AliPayAccount.java | 4 +- .../bisq/core/payment/AustraliaPayid.java | 4 +- .../bisq/core/payment/CashAppAccount.java | 4 +- .../core/payment/ChaseQuickPayAccount.java | 4 +- .../core/payment/ClearXchangeAccount.java | 4 +- .../core/payment/FasterPaymentsAccount.java | 4 +- .../bisq/core/payment/HalCashAccount.java | 4 +- .../core/payment/InteracETransferAccount.java | 4 +- .../bisq/core/payment/JapanBankAccount.java | 4 +- .../bisq/core/payment/MoneyBeamAccount.java | 4 +- .../bisq/core/payment/PaymentAccountUtil.java | 65 +++++++++++ .../core/payment/PerfectMoneyAccount.java | 4 +- .../bisq/core/payment/PopmoneyAccount.java | 4 +- .../bisq/core/payment/PromptPayAccount.java | 4 +- .../java/bisq/core/payment/SwishAccount.java | 4 +- .../payment/USPostalMoneyOrderAccount.java | 4 +- .../java/bisq/core/payment/VenmoAccount.java | 4 +- .../bisq/core/payment/WeChatPayAccount.java | 4 +- .../components/paymentmethods/BizumForm.java | 8 +- .../paymentmethods/IfscBankForm.java | 4 +- .../components/paymentmethods/NequiForm.java | 8 +- .../components/paymentmethods/PaytmForm.java | 4 +- .../components/paymentmethods/PixForm.java | 4 +- .../paymentmethods/SatispayForm.java | 4 +- .../components/paymentmethods/StrikeForm.java | 4 +- .../components/paymentmethods/TikkieForm.java | 4 +- .../paymentmethods/TransferwiseUsdForm.java | 4 +- .../components/paymentmethods/UpiForm.java | 4 +- 29 files changed, 231 insertions(+), 58 deletions(-) diff --git a/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index 47b7afaa1fb..f4acde79fa3 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -85,6 +85,10 @@ public static Collection getAllSortedFiatCurrencies() { return fiatCurrencyMapSupplier.get().values(); // sorted by currency name } + public static List getAllFiatCurrencies() { + return new ArrayList<>(fiatCurrencyMapSupplier.get().values()); + } + public static Collection getAllSortedFiatCurrencies(Comparator comparator) { return (List) getAllSortedFiatCurrencies().stream() .sorted(comparator) // sorted by comparator param @@ -502,6 +506,110 @@ public static List getAllRevolutCurrencies() { return currencies; } + public static List getAllInteracETransferIdCurrencies() { + return List.of(new FiatCurrency("CAD")); + } + + public static List getAllStrikeCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllTikkieIdCurrencies() { + return List.of(new FiatCurrency("EUR")); + } + + public static List getAllAliPayAccountCurrencies() { + return List.of(new FiatCurrency("CNY")); + } + + public static List getAllNequiCurrencies() { + return List.of(new FiatCurrency("COP")); + } + + public static List getAllIfscBankCurrencies() { + return List.of(new FiatCurrency("INR")); + } + + public static List getAllBizumCurrencies() { + return List.of(new FiatCurrency("EUR")); + } + + public static List getAllMoneyBeamCurrencies() { + return List.of(new FiatCurrency("EUR")); + } + + public static List getAllPixCurrencies() { + return List.of(new FiatCurrency("BRL")); + } + + public static List getAllSatispayCurrencies() { + return List.of(new FiatCurrency("EUR")); + } + + public static List getAllChaseQuickPayCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllUSPostalMoneyOrderCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllVenmoCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllFasterPaymentCurrencies() { + return List.of(new FiatCurrency("GBP")); + } + + public static List getAllJapanBankCurrencies() { + return List.of(new FiatCurrency("JPY")); + } + + public static List getAllWeChatPayCurrencies() { + return List.of(new FiatCurrency("CNY")); + } + + public static List getAllClearXchangeCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllAustraliaPayidCurrencies() { + return List.of(new FiatCurrency("AUD")); + } + + public static List getAllPerfectMoneyCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllHalCashCurrencies() { + return List.of(new FiatCurrency("EUR")); + } + + public static List getAllSwishCurrencies() { + return List.of(new FiatCurrency("SEK")); + } + + public static List getAllCashAppCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllPopmoneyCurrencies() { + return List.of(new FiatCurrency("USD")); + } + + public static List getAllPromptPayCurrencies() { + return List.of(new FiatCurrency("THB")); + } + + public static List getAllSEPACurrencies() { + return List.of(new FiatCurrency("EUR")); + } + + public static List getAllDomesticWireTransferCurrencies() { + return List.of(new FiatCurrency("USD")); + } + public static List getMatureMarketCurrencies() { ArrayList currencies = new ArrayList<>(Arrays.asList( new FiatCurrency("EUR"), diff --git a/core/src/main/java/bisq/core/payment/AliPayAccount.java b/core/src/main/java/bisq/core/payment/AliPayAccount.java index b01b71bbfeb..f126fd30169 100644 --- a/core/src/main/java/bisq/core/payment/AliPayAccount.java +++ b/core/src/main/java/bisq/core/payment/AliPayAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.AliPayAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -28,7 +28,7 @@ public final class AliPayAccount extends PaymentAccount { public AliPayAccount() { super(PaymentMethod.ALI_PAY); - setSingleTradeCurrency(new FiatCurrency("CNY")); + setSingleTradeCurrency(CurrencyUtil.getAllAliPayAccountCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/AustraliaPayid.java b/core/src/main/java/bisq/core/payment/AustraliaPayid.java index a64c62b42ac..e24422fb1c4 100644 --- a/core/src/main/java/bisq/core/payment/AustraliaPayid.java +++ b/core/src/main/java/bisq/core/payment/AustraliaPayid.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.AustraliaPayidPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -25,7 +25,7 @@ public final class AustraliaPayid extends PaymentAccount { public AustraliaPayid() { super(PaymentMethod.AUSTRALIA_PAYID); - setSingleTradeCurrency(new FiatCurrency("AUD")); + setSingleTradeCurrency(CurrencyUtil.getAllAustraliaPayidCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/CashAppAccount.java b/core/src/main/java/bisq/core/payment/CashAppAccount.java index acd4f6b6a5d..aa184d15f05 100644 --- a/core/src/main/java/bisq/core/payment/CashAppAccount.java +++ b/core/src/main/java/bisq/core/payment/CashAppAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.CashAppAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -31,7 +31,7 @@ public final class CashAppAccount extends PaymentAccount { public CashAppAccount() { super(PaymentMethod.CASH_APP); - setSingleTradeCurrency(new FiatCurrency("USD")); + setSingleTradeCurrency(CurrencyUtil.getAllCashAppCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java b/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java index 29f8d5329e4..2200fedac2c 100644 --- a/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java +++ b/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.ChaseQuickPayAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -31,7 +31,7 @@ public final class ChaseQuickPayAccount extends PaymentAccount { public ChaseQuickPayAccount() { super(PaymentMethod.CHASE_QUICK_PAY); - setSingleTradeCurrency(new FiatCurrency("USD")); + setSingleTradeCurrency(CurrencyUtil.getAllChaseQuickPayCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java b/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java index 397aeb44f0d..42a9bdfeba9 100644 --- a/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java +++ b/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.ClearXchangeAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -28,7 +28,7 @@ public final class ClearXchangeAccount extends PaymentAccount { public ClearXchangeAccount() { super(PaymentMethod.CLEAR_X_CHANGE); - setSingleTradeCurrency(new FiatCurrency("USD")); + setSingleTradeCurrency(CurrencyUtil.getAllClearXchangeCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java b/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java index 3c4f124c662..0fbfd5b8eb7 100644 --- a/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java +++ b/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.FasterPaymentsAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -28,7 +28,7 @@ public final class FasterPaymentsAccount extends PaymentAccount { public FasterPaymentsAccount() { super(PaymentMethod.FASTER_PAYMENTS); - setSingleTradeCurrency(new FiatCurrency("GBP")); + setSingleTradeCurrency(CurrencyUtil.getAllFasterPaymentCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/HalCashAccount.java b/core/src/main/java/bisq/core/payment/HalCashAccount.java index dba8ee82f11..fcec21acc48 100644 --- a/core/src/main/java/bisq/core/payment/HalCashAccount.java +++ b/core/src/main/java/bisq/core/payment/HalCashAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.HalCashAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -28,7 +28,7 @@ public final class HalCashAccount extends PaymentAccount { public HalCashAccount() { super(PaymentMethod.HAL_CASH); - setSingleTradeCurrency(new FiatCurrency("EUR")); + setSingleTradeCurrency(CurrencyUtil.getAllHalCashCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/InteracETransferAccount.java b/core/src/main/java/bisq/core/payment/InteracETransferAccount.java index b4b5f8310ac..8341c9040e5 100644 --- a/core/src/main/java/bisq/core/payment/InteracETransferAccount.java +++ b/core/src/main/java/bisq/core/payment/InteracETransferAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.InteracETransferAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -28,7 +28,7 @@ public final class InteracETransferAccount extends PaymentAccount { public InteracETransferAccount() { super(PaymentMethod.INTERAC_E_TRANSFER); - setSingleTradeCurrency(new FiatCurrency("CAD")); + setSingleTradeCurrency(CurrencyUtil.getAllInteracETransferIdCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/JapanBankAccount.java b/core/src/main/java/bisq/core/payment/JapanBankAccount.java index 8aa952d074d..6657f33d5ac 100644 --- a/core/src/main/java/bisq/core/payment/JapanBankAccount.java +++ b/core/src/main/java/bisq/core/payment/JapanBankAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.JapanBankAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -27,7 +27,7 @@ public final class JapanBankAccount extends PaymentAccount public JapanBankAccount() { super(PaymentMethod.JAPAN_BANK); - setSingleTradeCurrency(new FiatCurrency("JPY")); + setSingleTradeCurrency(CurrencyUtil.getAllJapanBankCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java b/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java index 4e67c334731..c63ea68b5ff 100644 --- a/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java +++ b/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.MoneyBeamAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; @@ -29,7 +29,7 @@ public final class MoneyBeamAccount extends PaymentAccount { public MoneyBeamAccount() { super(PaymentMethod.MONEY_BEAM); - setSingleTradeCurrency(new FiatCurrency("EUR")); + setSingleTradeCurrency(CurrencyUtil.getAllMoneyBeamCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java index 34936b48121..3efd484ae9e 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java @@ -19,6 +19,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.Country; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.payment.payload.PaymentAccountPayload; @@ -135,6 +136,70 @@ public static List getTradeCurrencies(PaymentMethod paymentMethod return getAllTransferwiseCurrencies(); case UPHOLD_ID: return getAllUpholdCurrencies(); + case INTERAC_E_TRANSFER_ID: + return getAllInteracETransferIdCurrencies(); + case STRIKE_ID: + return getAllStrikeCurrencies(); + case TIKKIE_ID: + return CurrencyUtil.getAllTikkieIdCurrencies(); + case ALI_PAY_ID: + return CurrencyUtil.getAllAliPayAccountCurrencies(); + case NEQUI_ID: + return CurrencyUtil.getAllNequiCurrencies(); + case IMPS_ID: + case NEFT_ID: + case PAYTM_ID: + case RTGS_ID: + case UPI_ID: + return CurrencyUtil.getAllIfscBankCurrencies(); + case BIZUM_ID: + return CurrencyUtil.getAllBizumCurrencies(); + case MONEY_BEAM_ID: + return CurrencyUtil.getAllMoneyBeamCurrencies(); + case PIX_ID: + return CurrencyUtil.getAllPixCurrencies(); + case SATISPAY_ID: + return CurrencyUtil.getAllSatispayCurrencies(); + case CHASE_QUICK_PAY_ID: + return CurrencyUtil.getAllChaseQuickPayCurrencies(); + case US_POSTAL_MONEY_ORDER_ID: + return CurrencyUtil.getAllUSPostalMoneyOrderCurrencies(); + case VENMO_ID: + return CurrencyUtil.getAllVenmoCurrencies(); + case JAPAN_BANK_ID: + return CurrencyUtil.getAllJapanBankCurrencies(); + case WECHAT_PAY_ID: + return CurrencyUtil.getAllWeChatPayCurrencies(); + case CLEAR_X_CHANGE_ID: + return CurrencyUtil.getAllClearXchangeCurrencies(); + case AUSTRALIA_PAYID_ID: + return CurrencyUtil.getAllAustraliaPayidCurrencies(); + case PERFECT_MONEY_ID: + return CurrencyUtil.getAllPerfectMoneyCurrencies(); + case HAL_CASH_ID: + return CurrencyUtil.getAllHalCashCurrencies(); + case SWISH_ID: + return CurrencyUtil.getAllSwishCurrencies(); + case CASH_APP_ID: + return CurrencyUtil.getAllCashAppCurrencies(); + case POPMONEY_ID: + return CurrencyUtil.getAllPopmoneyCurrencies(); + case PROMPT_PAY_ID: + return CurrencyUtil.getAllPromptPayCurrencies(); + case SEPA_ID: + case SEPA_INSTANT_ID: + return CurrencyUtil.getAllSEPACurrencies(); + case CASH_BY_MAIL_ID: + case F2F_ID: + case NATIONAL_BANK_ID: + case SAME_BANK_ID: + case SPECIFIC_BANKS_ID: + case CASH_DEPOSIT_ID: + return CurrencyUtil.getAllFiatCurrencies(); + case FASTER_PAYMENTS_ID: + return CurrencyUtil.getAllFasterPaymentCurrencies(); + case DOMESTIC_WIRE_TRANSFER_ID: + return CurrencyUtil.getAllDomesticWireTransferCurrencies(); default: return Collections.emptyList(); } diff --git a/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java b/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java index 0abc12f367f..0aa77dcda14 100644 --- a/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java +++ b/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PerfectMoneyAccountPayload; @@ -28,7 +28,7 @@ public final class PerfectMoneyAccount extends PaymentAccount { public PerfectMoneyAccount() { super(PaymentMethod.PERFECT_MONEY); - setSingleTradeCurrency(new FiatCurrency("USD")); + setSingleTradeCurrency(CurrencyUtil.getAllPerfectMoneyCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/PopmoneyAccount.java b/core/src/main/java/bisq/core/payment/PopmoneyAccount.java index c6f534c24eb..89a3d2d8705 100644 --- a/core/src/main/java/bisq/core/payment/PopmoneyAccount.java +++ b/core/src/main/java/bisq/core/payment/PopmoneyAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PopmoneyAccountPayload; @@ -29,7 +29,7 @@ public final class PopmoneyAccount extends PaymentAccount { public PopmoneyAccount() { super(PaymentMethod.POPMONEY); - setSingleTradeCurrency(new FiatCurrency("USD")); + setSingleTradeCurrency(CurrencyUtil.getAllPopmoneyCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/PromptPayAccount.java b/core/src/main/java/bisq/core/payment/PromptPayAccount.java index 89ed2102d31..ab22ea6d782 100644 --- a/core/src/main/java/bisq/core/payment/PromptPayAccount.java +++ b/core/src/main/java/bisq/core/payment/PromptPayAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PromptPayAccountPayload; @@ -28,7 +28,7 @@ public final class PromptPayAccount extends PaymentAccount { public PromptPayAccount() { super(PaymentMethod.PROMPT_PAY); - setSingleTradeCurrency(new FiatCurrency("THB")); + setSingleTradeCurrency(CurrencyUtil.getAllPromptPayCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/SwishAccount.java b/core/src/main/java/bisq/core/payment/SwishAccount.java index e3236300403..64738af559c 100644 --- a/core/src/main/java/bisq/core/payment/SwishAccount.java +++ b/core/src/main/java/bisq/core/payment/SwishAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SwishAccountPayload; @@ -28,7 +28,7 @@ public final class SwishAccount extends PaymentAccount { public SwishAccount() { super(PaymentMethod.SWISH); - setSingleTradeCurrency(new FiatCurrency("SEK")); + setSingleTradeCurrency(CurrencyUtil.getAllSwishCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java b/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java index af8f577e65b..a93e7c1d7fc 100644 --- a/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java +++ b/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.USPostalMoneyOrderAccountPayload; @@ -28,7 +28,7 @@ public final class USPostalMoneyOrderAccount extends PaymentAccount { public USPostalMoneyOrderAccount() { super(PaymentMethod.US_POSTAL_MONEY_ORDER); - setSingleTradeCurrency(new FiatCurrency("USD")); + setSingleTradeCurrency(CurrencyUtil.getAllUSPostalMoneyOrderCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/VenmoAccount.java b/core/src/main/java/bisq/core/payment/VenmoAccount.java index cd546601442..8a48d9485cb 100644 --- a/core/src/main/java/bisq/core/payment/VenmoAccount.java +++ b/core/src/main/java/bisq/core/payment/VenmoAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.VenmoAccountPayload; @@ -31,7 +31,7 @@ public final class VenmoAccount extends PaymentAccount { public VenmoAccount() { super(PaymentMethod.VENMO); - setSingleTradeCurrency(new FiatCurrency("USD")); + setSingleTradeCurrency(CurrencyUtil.getAllVenmoCurrencies().get(0)); } @Override diff --git a/core/src/main/java/bisq/core/payment/WeChatPayAccount.java b/core/src/main/java/bisq/core/payment/WeChatPayAccount.java index f4ef6f64406..dc23b81c084 100644 --- a/core/src/main/java/bisq/core/payment/WeChatPayAccount.java +++ b/core/src/main/java/bisq/core/payment/WeChatPayAccount.java @@ -17,7 +17,7 @@ package bisq.core.payment; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.WeChatPayAccountPayload; @@ -29,7 +29,7 @@ public final class WeChatPayAccount extends PaymentAccount { public WeChatPayAccount() { super(PaymentMethod.WECHAT_PAY); - setSingleTradeCurrency(new FiatCurrency("CNY")); + setSingleTradeCurrency(CurrencyUtil.getAllWeChatPayCurrencies().get(0)); } @Override diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java index bb1d8dc16cf..423158e0fa7 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java @@ -23,12 +23,12 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; -import bisq.core.payment.PaymentAccount; import bisq.core.payment.BizumAccount; -import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.PaymentAccount; import bisq.core.payment.payload.BizumAccountPayload; +import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.util.coin.CoinFormatter; import bisq.core.util.validation.InputValidator; @@ -59,7 +59,7 @@ public BizumForm(PaymentAccount paymentAccount, AccountAgeWitnessService account @Override public void addFormForAddAccount() { // this payment method is only for Spain/EUR - account.setSingleTradeCurrency(new FiatCurrency("EUR")); + account.setSingleTradeCurrency(CurrencyUtil.getAllBizumCurrencies().get(0)); CountryUtil.findCountryByCode("ES").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java index f8782b79a8b..2dec4410bbc 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java @@ -23,7 +23,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.payload.IfscBasedAccountPayload; @@ -66,7 +66,7 @@ public IfscBankForm(PaymentAccount paymentAccount, AccountAgeWitnessService acco @Override public void addFormForAddAccount() { // this payment method is only for India/INR - paymentAccount.setSingleTradeCurrency(new FiatCurrency("INR")); + paymentAccount.setSingleTradeCurrency(CurrencyUtil.getAllIfscBankCurrencies().get(0)); CountryUtil.findCountryByCode("IN").ifPresent(c -> ifscBasedAccountPayload.setCountryCode(c.code)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java index 8e9dbb2d7a8..a2357f3ffad 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java @@ -23,12 +23,12 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; -import bisq.core.payment.PaymentAccount; import bisq.core.payment.NequiAccount; -import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.PaymentAccount; import bisq.core.payment.payload.NequiAccountPayload; +import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.util.coin.CoinFormatter; import bisq.core.util.validation.InputValidator; @@ -59,7 +59,7 @@ public NequiForm(PaymentAccount paymentAccount, AccountAgeWitnessService account @Override public void addFormForAddAccount() { // this payment method is only for Columbia/COP - account.setSingleTradeCurrency(new FiatCurrency("COP")); + account.setSingleTradeCurrency(CurrencyUtil.getAllNequiCurrencies().get(0)); CountryUtil.findCountryByCode("CO").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java index 772f709bff3..c59a78969f7 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java @@ -23,7 +23,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PaytmAccount; @@ -59,7 +59,7 @@ public PaytmForm(PaymentAccount paymentAccount, AccountAgeWitnessService account @Override public void addFormForAddAccount() { // this payment method is only for India/INR - account.setSingleTradeCurrency(new FiatCurrency("INR")); + account.setSingleTradeCurrency(CurrencyUtil.getAllIfscBankCurrencies().get(0)); CountryUtil.findCountryByCode("IN").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java index 1cd1cc9988b..beac5b25e27 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java @@ -23,7 +23,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PixAccount; @@ -59,7 +59,7 @@ public PixForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAg @Override public void addFormForAddAccount() { // this payment method is only for Brazil/BRL - account.setSingleTradeCurrency(new FiatCurrency("BRL")); + account.setSingleTradeCurrency(CurrencyUtil.getAllPixCurrencies().get(0)); CountryUtil.findCountryByCode("BR").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java index 37641b04faa..fd578970394 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java @@ -22,7 +22,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.SatispayAccount; @@ -59,7 +59,7 @@ public SatispayForm(PaymentAccount paymentAccount, AccountAgeWitnessService acco @Override public void addFormForAddAccount() { // this payment method is only for Italy/EUR - account.setSingleTradeCurrency(new FiatCurrency("EUR")); + account.setSingleTradeCurrency(CurrencyUtil.getAllSatispayCurrencies().get(0)); CountryUtil.findCountryByCode("IT").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java index f4067a23503..a13310e993c 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java @@ -23,7 +23,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.StrikeAccount; @@ -59,7 +59,7 @@ public StrikeForm(PaymentAccount paymentAccount, AccountAgeWitnessService accoun @Override public void addFormForAddAccount() { // this payment method is currently restricted to United States/USD - account.setSingleTradeCurrency(new FiatCurrency("USD")); + account.setSingleTradeCurrency(CurrencyUtil.getAllStrikeCurrencies().get(0)); CountryUtil.findCountryByCode("US").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java index 0c47afd4ce4..c47aecfa3fc 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java @@ -23,7 +23,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.TikkieAccount; @@ -59,7 +59,7 @@ public TikkieForm(PaymentAccount paymentAccount, AccountAgeWitnessService accoun @Override public void addFormForAddAccount() { // this payment method is only for Netherlands/EUR - account.setSingleTradeCurrency(new FiatCurrency("EUR")); + account.setSingleTradeCurrency(CurrencyUtil.getAllTikkieIdCurrencies().get(0)); CountryUtil.findCountryByCode("NL").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java index 6155a99cbc3..2971875a5fd 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java @@ -24,7 +24,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.TransferwiseUsdAccount; @@ -75,7 +75,7 @@ public TransferwiseUsdForm(PaymentAccount paymentAccount, AccountAgeWitnessServi @Override public void addFormForAddAccount() { // this payment method is currently restricted to United States/USD - account.setSingleTradeCurrency(new FiatCurrency("USD")); + account.setSingleTradeCurrency(CurrencyUtil.getAllStrikeCurrencies().get(0)); CountryUtil.findCountryByCode("US").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java index 13090e19e25..faee4a7c6ba 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java @@ -22,7 +22,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.UpiAccount; @@ -58,7 +58,7 @@ public UpiForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAg @Override public void addFormForAddAccount() { // this payment method is only for India/INR - account.setSingleTradeCurrency(new FiatCurrency("INR")); + account.setSingleTradeCurrency(CurrencyUtil.getAllIfscBankCurrencies().get(0)); CountryUtil.findCountryByCode("IN").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; From 810a29b54f1cbb6d3b3639f2d0a2193901bae349 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 1 Apr 2022 14:08:43 +0200 Subject: [PATCH 04/35] Add missing payment account filtering --- .../main/java/bisq/core/locale/CurrencyUtil.java | 8 ++++++++ .../bisq/core/payment/PaymentAccountUtil.java | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index f4acde79fa3..cbe66fe22c8 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -610,6 +610,10 @@ public static List getAllDomesticWireTransferCurrencies() { return List.of(new FiatCurrency("USD")); } + public static List getAllACHTransferCurrencies() { + return List.of(new FiatCurrency("USD")); + } + public static List getMatureMarketCurrencies() { ArrayList currencies = new ArrayList<>(Arrays.asList( new FiatCurrency("EUR"), @@ -914,4 +918,8 @@ public static boolean apiSupportsCryptoCurrency(String currencyCode) { format("Method requires a crypto currency code, but was given '%s'.", currencyCode)); } + + public static List getAllTransferwiseUSDCurrencies() { + return List.of(new FiatCurrency("USD")); + } } diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java index 3efd484ae9e..0d6456a08da 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java @@ -195,11 +195,22 @@ public static List getTradeCurrencies(PaymentMethod paymentMethod case SAME_BANK_ID: case SPECIFIC_BANKS_ID: case CASH_DEPOSIT_ID: + case WESTERN_UNION_ID: return CurrencyUtil.getAllFiatCurrencies(); case FASTER_PAYMENTS_ID: return CurrencyUtil.getAllFasterPaymentCurrencies(); - case DOMESTIC_WIRE_TRANSFER_ID: - return CurrencyUtil.getAllDomesticWireTransferCurrencies(); + case DOMESTIC_WIRE_TRANSFER_ID: + return CurrencyUtil.getAllDomesticWireTransferCurrencies(); + case ACH_TRANSFER_ID: + return CurrencyUtil.getAllACHTransferCurrencies(); + case CELPAY_ID: + return CurrencyUtil.getAllCelPayCurrencies(); + case MONESE_ID: + return CurrencyUtil.getAllMoneseCurrencies(); + case TRANSFERWISE_USD_ID: + return CurrencyUtil.getAllTransferwiseUSDCurrencies(); + case VERSE_ID: + return CurrencyUtil.getAllVerseCurrencies(); default: return Collections.emptyList(); } From e3ceb80a11d674603e000f9287d0e4b00f6bf9ff Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 1 Apr 2022 14:09:34 +0200 Subject: [PATCH 05/35] Show all payment methods if currency does not support previous selected payment method in a different currency. --- .../bisq/desktop/main/offer/offerbook/OfferBookView.java | 2 ++ .../desktop/main/offer/offerbook/OfferBookViewModel.java | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index 833cb839204..ce711627b16 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -358,7 +358,9 @@ protected void activate() { currencyComboBox.getSelectionModel().select(SHOW_ALL); model.onSetTradeCurrency(currencyComboBox.getSelectionModel().getSelectedItem()); paymentMethodComboBox.setAutocompleteItems(model.getPaymentMethods()); + model.updateSelectedPaymentMethod(); updatePaymentMethodComboBoxEditor(); + model.onSetPaymentMethod(paymentMethodComboBox.getSelectionModel().getSelectedItem()); }); updateCurrencyComboBoxFromModel(); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index 9becffd25dc..2b5592c4144 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -702,6 +702,11 @@ private void updateSelectedTradeCurrency() { tradeCurrencyCode.set(selectedTradeCurrency.getCode()); } + public void updateSelectedPaymentMethod() { + showAllPaymentMethods = getPaymentMethods().stream().noneMatch(paymentMethod -> + paymentMethod.equals(selectedPaymentMethod)); + } + abstract String getCurrencyCodeFromPreferences(OfferDirection direction); public OpenOffer getOpenOffer(Offer offer) { From 924e92aa47c0dcb5c19a85edace3772a712785da Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 4 Apr 2022 13:59:49 +0200 Subject: [PATCH 06/35] Adapt take offer process to new navigation structure --- .../resources/i18n/displayStrings.properties | 3 + .../bisq/desktop/main/offer/Closable.java | 22 +++ .../main/offer/InitializableWithData.java | 26 +++ .../bisq/desktop/main/offer/OfferView.java | 159 +++++++++--------- .../main/offer/bisq_v1/OfferViewUtil.java | 4 + .../bisq_v1/takeoffer/TakeOfferView.java | 28 ++- .../main/offer/bsq_swap/BsqSwapOfferView.java | 3 +- .../take_offer/BsqSwapTakeOfferView.java | 10 +- .../windows/BsqSwapOfferDetailsWindow.java | 13 +- .../overlays/windows/OfferDetailsWindow.java | 24 ++- 10 files changed, 191 insertions(+), 101 deletions(-) create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/Closable.java create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/InitializableWithData.java diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 237f22716cc..bca58c669b5 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -571,6 +571,7 @@ takeOffer.bsqSwap.success.info=Until your trade is included in a block you can s # new entries takeOffer.takeOfferButton=Review: Take offer to {0} bitcoin +takeOffer.takeOfferButtonAltcoin=Review: Take offer to {0} {1} takeOffer.noPriceFeedAvailable=You cannot take that offer as it uses a percentage price based on the market price but there is no price feed available. takeOffer.takeOfferFundWalletInfo.headline=Fund your trade # suppress inspection "TrailingSpacesInProperty" @@ -2815,7 +2816,9 @@ offerDetailsWindow.commitment=Commitment offerDetailsWindow.agree=I agree offerDetailsWindow.tac=Terms and conditions offerDetailsWindow.confirm.maker=Confirm: Place offer to {0} bitcoin +offerDetailsWindow.confirm.makerAltcoin=Confirm: Place offer to {0} {1} offerDetailsWindow.confirm.taker=Confirm: Take offer to {0} bitcoin +offerDetailsWindow.confirm.takerAltcoin=Confirm: Take offer to {0} {1} offerDetailsWindow.creationDate=Creation date offerDetailsWindow.makersOnion=Maker's onion address diff --git a/desktop/src/main/java/bisq/desktop/main/offer/Closable.java b/desktop/src/main/java/bisq/desktop/main/offer/Closable.java new file mode 100644 index 00000000000..57c9a89a089 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/Closable.java @@ -0,0 +1,22 @@ +/* + * 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 bisq.desktop.main.offer; + +public interface Closable { + public void setCloseHandler(OfferView.CloseHandler closeHandler); +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/InitializableWithData.java b/desktop/src/main/java/bisq/desktop/main/offer/InitializableWithData.java new file mode 100644 index 00000000000..2a6cdeec773 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/InitializableWithData.java @@ -0,0 +1,26 @@ +/* + * 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 bisq.desktop.main.offer; + +import bisq.core.offer.Offer; + +public interface InitializableWithData { + + public void initWithData(Offer offer); + +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index d66075ed5ac..a85cfbca06c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -27,10 +27,12 @@ import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView; import bisq.desktop.main.offer.bsq_swap.take_offer.BsqSwapTakeOfferView; import bisq.desktop.main.offer.offerbook.BsqOfferBookView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookView; import bisq.desktop.main.offer.offerbook.OtherOfferBookView; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.GUIUtil; import bisq.core.locale.CurrencyUtil; @@ -61,13 +63,12 @@ public abstract class OfferView extends ActivatableView { - private OfferBookView btcOfferBookView, bsqOfferBookView, topAltcoinOfferBookView, otherOfferBookView; + private OfferBookView btcOfferBookView, bsqOfferBookView, topAltcoinOfferBookView, otherOfferBookView; private CreateOfferView createOfferView; private BsqSwapCreateOfferView bsqSwapCreateOfferView; - private TakeOfferView takeOfferView; - private BsqSwapTakeOfferView bsqSwapTakeOfferView; - private AnchorPane createOfferPane, takeOfferPane; - private Tab takeOfferTab, createOfferTab, btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab; + + private AnchorPane createOfferPane; + private Tab createOfferTab, btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab; private final ViewLoader viewLoader; private final Navigation navigation; @@ -78,12 +79,15 @@ public abstract class OfferView extends ActivatableView { private Offer offer; private TradeCurrency tradeCurrency; - private boolean createOfferViewOpen, takeOfferViewOpen; + private boolean createOfferViewOpen; private Navigation.Listener navigationListener; private ChangeListener tabChangeListener; private ListChangeListener tabListChangeListener; private OfferView.OfferActionHandler offerActionHandler; + private Class currentViewClass; + + protected OfferView(ViewLoader viewLoader, Navigation navigation, Preferences preferences, @@ -101,8 +105,11 @@ protected OfferView(ViewLoader viewLoader, @Override protected void initialize() { navigationListener = (viewPath, data) -> { - if (viewPath.size() == 3 && viewPath.indexOf(this.getClass()) == 1) - loadView(viewPath.tip(), data); + if (viewPath.size() == 3 && viewPath.indexOf(this.getClass()) == 1) { + loadView(viewPath.tip(), null, data); + } else if (viewPath.size() == 4 && viewPath.indexOf(this.getClass()) == 1) { + loadView(viewPath.get(2), viewPath.tip(), data); + } }; tabChangeListener = (observableValue, oldValue, newValue) -> { if (newValue != null) { @@ -110,33 +117,29 @@ protected void initialize() { createOfferView.onTabSelected(true); } else if (newValue.equals(createOfferTab) && bsqSwapCreateOfferView != null) { bsqSwapCreateOfferView.onTabSelected(true); - } else if (newValue.equals(takeOfferTab) && takeOfferView != null) { - takeOfferView.onTabSelected(true); - } else if (newValue.equals(takeOfferTab) && bsqSwapTakeOfferView != null) { - bsqSwapTakeOfferView.onTabSelected(true); } else if (newValue.equals(btcOfferBookTab)) { if (btcOfferBookView != null) { btcOfferBookView.onTabSelected(true); } else { - loadView(BtcOfferBookView.class, null); + loadView(BtcOfferBookView.class, null, null); } } else if (newValue.equals(bsqOfferBookTab)) { if (bsqOfferBookView != null) { bsqOfferBookView.onTabSelected(true); } else { - loadView(BsqOfferBookView.class, null); + loadView(BsqOfferBookView.class, null, null); } } else if (newValue.equals(topAltcoinOfferBookTab)) { if (topAltcoinOfferBookView != null) { topAltcoinOfferBookView.onTabSelected(true); } else { - loadView(TopAltcoinOfferBookView.class, null); + loadView(TopAltcoinOfferBookView.class, null, null); } } else if (newValue.equals(otherOfferBookTab)) { if (otherOfferBookView != null) { otherOfferBookView.onTabSelected(true); } else { - loadView(OtherOfferBookView.class, null); + loadView(OtherOfferBookView.class, null, null); } } } @@ -145,10 +148,6 @@ protected void initialize() { createOfferView.onTabSelected(false); } else if (oldValue.equals(createOfferTab) && bsqSwapCreateOfferView != null) { bsqSwapCreateOfferView.onTabSelected(false); - } else if (oldValue.equals(takeOfferTab) && takeOfferView != null) { - takeOfferView.onTabSelected(false); - } else if (oldValue.equals(takeOfferTab) && bsqSwapTakeOfferView != null) { - bsqSwapTakeOfferView.onTabSelected(false); } else if (oldValue.equals(btcOfferBookTab) && btcOfferBookView != null) { btcOfferBookView.onTabSelected(false); } else if (oldValue.equals(bsqOfferBookTab) && bsqOfferBookView != null) { @@ -166,8 +165,6 @@ protected void initialize() { if (removedTabs.size() == 1) { if (removedTabs.get(0).getContent().equals(createOfferPane)) onCreateOfferViewRemoved(); - else if (removedTabs.get(0).getContent().equals(takeOfferPane)) - onTakeOfferViewRemoved(); } }; @@ -184,9 +181,7 @@ public void onCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMeth @Override public void onTakeOffer(Offer offer) { - if (takeOfferViewOpen) { - root.getTabs().remove(takeOfferTab); - } + // can we have multiple take offer views open? Optional optionalTradeCurrency = CurrencyUtil.getTradeCurrency(offer.getCurrencyCode()); if (optionalTradeCurrency.isPresent() && canCreateOrTakeOffer(optionalTradeCurrency.get())) { openTakeOffer(offer); @@ -227,28 +222,51 @@ private String getTakeOfferTabName() { return Res.get("offerbook.takeOffer").toUpperCase(); } - private void loadView(Class viewClass, @Nullable Object data) { + private void loadView(Class viewClass, + Class childViewClass, + @Nullable Object data) { TabPane tabPane = root; tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); + currentViewClass = viewClass; View view; if (OfferBookView.class.isAssignableFrom(viewClass)) { if (viewClass == BtcOfferBookView.class && btcOfferBookTab != null && btcOfferBookView != null) { + if (childViewClass == null) { + btcOfferBookTab.setContent(btcOfferBookView.getRoot()); + } else { + loadTakeViewClass(viewClass, childViewClass, btcOfferBookTab); + } tabPane.getSelectionModel().select(btcOfferBookTab); } else if (viewClass == BsqOfferBookView.class && bsqOfferBookTab != null && bsqOfferBookView != null) { + if (childViewClass == null) { + bsqOfferBookTab.setContent(bsqOfferBookView.getRoot()); + } else { + loadTakeViewClass(viewClass, childViewClass, bsqOfferBookTab); + } tabPane.getSelectionModel().select(bsqOfferBookTab); } else if (viewClass == TopAltcoinOfferBookView.class && topAltcoinOfferBookTab != null && topAltcoinOfferBookView != null) { + if (childViewClass == null) { + topAltcoinOfferBookTab.setContent(topAltcoinOfferBookView.getRoot()); + } else { + loadTakeViewClass(viewClass, childViewClass, topAltcoinOfferBookTab); + } tabPane.getSelectionModel().select(topAltcoinOfferBookTab); } else if (viewClass == OtherOfferBookView.class && otherOfferBookTab != null && otherOfferBookView != null) { + if (childViewClass == null) { + otherOfferBookTab.setContent(otherOfferBookView.getRoot()); + } else { + loadTakeViewClass(viewClass, childViewClass, otherOfferBookTab); + } tabPane.getSelectionModel().select(topAltcoinOfferBookTab); } else { if (btcOfferBookTab == null) { - btcOfferBookTab = new Tab("BTC"); + btcOfferBookTab = new Tab("BITCOIN"); btcOfferBookTab.setClosable(false); bsqOfferBookTab = new Tab("BSQ"); bsqOfferBookTab.setClosable(false); - topAltcoinOfferBookTab = new Tab("XMR"); + topAltcoinOfferBookTab = new Tab("MONERO"); topAltcoinOfferBookTab.setClosable(false); otherOfferBookTab = new Tab("OTHER"); otherOfferBookTab.setClosable(false); @@ -256,28 +274,28 @@ private void loadView(Class viewClass, @Nullable Object data) { tabPane.getTabs().addAll(btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab); } if (viewClass == BtcOfferBookView.class) { - btcOfferBookView = (OfferBookView) viewLoader.load(BtcOfferBookView.class); + btcOfferBookView = (BtcOfferBookView) viewLoader.load(BtcOfferBookView.class); btcOfferBookTab.setContent(btcOfferBookView.getRoot()); btcOfferBookView.setOfferActionHandler(offerActionHandler); btcOfferBookView.setDirection(direction); tabPane.getSelectionModel().select(btcOfferBookTab); btcOfferBookView.onTabSelected(true); } else if (viewClass == BsqOfferBookView.class) { - bsqOfferBookView = (OfferBookView) viewLoader.load(BsqOfferBookView.class); + bsqOfferBookView = (BsqOfferBookView) viewLoader.load(BsqOfferBookView.class); bsqOfferBookView.setOfferActionHandler(offerActionHandler); bsqOfferBookView.setDirection(direction); tabPane.getSelectionModel().select(bsqOfferBookTab); bsqOfferBookTab.setContent(bsqOfferBookView.getRoot()); bsqOfferBookView.onTabSelected(true); } else if (viewClass == TopAltcoinOfferBookView.class) { - topAltcoinOfferBookView = (OfferBookView) viewLoader.load(TopAltcoinOfferBookView.class); + topAltcoinOfferBookView = (TopAltcoinOfferBookView) viewLoader.load(TopAltcoinOfferBookView.class); topAltcoinOfferBookView.setOfferActionHandler(offerActionHandler); topAltcoinOfferBookView.setDirection(direction); tabPane.getSelectionModel().select(topAltcoinOfferBookTab); topAltcoinOfferBookTab.setContent(topAltcoinOfferBookView.getRoot()); topAltcoinOfferBookView.onTabSelected(true); } else if (viewClass == OtherOfferBookView.class) { - otherOfferBookView = (OfferBookView) viewLoader.load(OtherOfferBookView.class); + otherOfferBookView = (OtherOfferBookView) viewLoader.load(OtherOfferBookView.class); otherOfferBookView.setOfferActionHandler(offerActionHandler); otherOfferBookView.setDirection(direction); tabPane.getSelectionModel().select(otherOfferBookTab); @@ -313,50 +331,49 @@ private void loadView(Class viewClass, @Nullable Object data) { tabPane.getTabs().add(createOfferTab); tabPane.getSelectionModel().select(createOfferTab); createOfferViewOpen = true; - } else if (viewClass == TakeOfferView.class && takeOfferView == null && offer != null) { - view = viewLoader.load(viewClass); - // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times - // in different graphs - takeOfferView = (TakeOfferView) view; - takeOfferView.initWithData(offer); - takeOfferPane = takeOfferView.getRoot(); - takeOfferTab = new Tab(getTakeOfferTabName()); - takeOfferTab.setClosable(true); - // close handler from close on take offer action - takeOfferView.setCloseHandler(() -> tabPane.getTabs().remove(takeOfferTab)); - takeOfferTab.setContent(takeOfferPane); - tabPane.getTabs().add(takeOfferTab); - tabPane.getSelectionModel().select(takeOfferTab); - } else if (viewClass == BsqSwapTakeOfferView.class && takeOfferView == null && offer != null) { - view = viewLoader.load(viewClass); - // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times - // in different graphs - bsqSwapTakeOfferView = (BsqSwapTakeOfferView) view; - bsqSwapTakeOfferView.initWithData(offer); - takeOfferPane = bsqSwapTakeOfferView.getRoot(); - takeOfferTab = new Tab(getTakeOfferTabName()); - takeOfferTab.setClosable(true); - // close handler from close on take offer action - bsqSwapTakeOfferView.setCloseHandler(() -> tabPane.getTabs().remove(takeOfferTab)); - takeOfferTab.setContent(takeOfferPane); - tabPane.getTabs().add(takeOfferTab); - tabPane.getSelectionModel().select(takeOfferTab); } } + private void loadTakeViewClass(Class viewClass, + Class childViewClass, + Tab marketOfferBookTab) { + + if (offer == null) { + return; + } + + View view; + view = viewLoader.load(offer.isBsqSwapOffer() ? BsqSwapTakeOfferView.class : childViewClass); + // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times + // in different graphs + + ((InitializableWithData) view).initWithData(offer); + // close handler from close on take offer action + ((Closable) view).setCloseHandler(() -> { + navigation.navigateTo(MainView.class, this.getClass(), viewClass); + }); + marketOfferBookTab.setContent(view.getRoot()); + } + protected boolean canCreateOrTakeOffer(TradeCurrency tradeCurrency) { return GUIUtil.isBootstrappedOrShowPopup(p2PService) && GUIUtil.canCreateOrTakeOfferOrShowPopup(user, navigation, tradeCurrency); } private void openTakeOffer(Offer offer) { - takeOfferViewOpen = true; this.offer = offer; - if (offer.isBsqSwapOffer()) { - navigation.navigateTo(MainView.class, this.getClass(), BsqSwapTakeOfferView.class); + Class> offerBookViewClass; + + if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) { + offerBookViewClass = BtcOfferBookView.class; + } else if (offer.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode())) { + offerBookViewClass = BsqOfferBookView.class; + } else if (offer.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + offerBookViewClass = TopAltcoinOfferBookView.class; } else { - navigation.navigateTo(MainView.class, this.getClass(), TakeOfferView.class); + offerBookViewClass = OtherOfferBookView.class; } + navigation.navigateTo(MainView.class, this.getClass(), offerBookViewClass, TakeOfferView.class); } private void openCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMethod) { @@ -383,20 +400,6 @@ private void onCreateOfferViewRemoved() { navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); } - private void onTakeOfferViewRemoved() { - offer = null; - takeOfferViewOpen = false; - if (takeOfferView != null) { - takeOfferView.onClose(); - takeOfferView = null; - } - if (bsqSwapTakeOfferView != null) { - bsqSwapTakeOfferView = null; - } - //TODO: go to last selected tab - navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); - } - public interface OfferActionHandler { void onCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMethod); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java index dcff7647640..e059242cd78 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java @@ -120,4 +120,8 @@ private static void openBuyBsqOfferBook(Navigation navigation) { public static boolean isShownAsSellOffer(Offer offer) { return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) == (offer.getDirection() == OfferDirection.SELL); } + + public static boolean isShownAsBuyOffer(Offer offer) { + return !isShownAsSellOffer(offer); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index 728b55109ff..e57354cf2c4 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -36,6 +36,8 @@ import bisq.desktop.main.dao.wallet.receive.BsqReceiveView; import bisq.desktop.main.funds.FundsView; import bisq.desktop.main.funds.withdrawal.WithdrawalView; +import bisq.desktop.main.offer.Closable; +import bisq.desktop.main.offer.InitializableWithData; import bisq.desktop.main.offer.OfferView; import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.overlays.notifications.Notification; @@ -52,7 +54,6 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.offer.Offer; -import bisq.core.offer.OfferDirection; import bisq.core.payment.FasterPaymentsAccount; import bisq.core.payment.PaymentAccount; import bisq.core.payment.payload.PaymentMethod; @@ -122,7 +123,7 @@ import static javafx.beans.binding.Bindings.createStringBinding; @FxmlView -public class TakeOfferView extends ActivatableViewAndModel { +public class TakeOfferView extends ActivatableViewAndModel implements Closable, InitializableWithData { private final Navigation navigation; private final CoinFormatter formatter; private final BsqFormatter bsqFormatter; @@ -152,7 +153,7 @@ public class TakeOfferView extends ActivatableViewAndModel model.fundFromSavingsWallet()); @@ -1341,5 +1343,15 @@ private GridPane createInfoPopover() { return infoGridPane; } + + @NotNull + private String getTakeOfferLabel(Offer offer, String direction) { + return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + Res.get("takeOffer.takeOfferButton", direction) : + Res.get("takeOffer.takeOfferButtonAltcoin", + direction, + CurrencyUtil.getNameByCode(offer.getCurrencyCode())); + } + } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java index 623044694b3..76a5154ca6c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java @@ -24,6 +24,7 @@ import bisq.desktop.components.FundsTextField; import bisq.desktop.components.InputTextField; import bisq.desktop.components.TitledGroupBg; +import bisq.desktop.main.offer.Closable; import bisq.desktop.main.offer.OfferView; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; import bisq.desktop.util.GUIUtil; @@ -68,7 +69,7 @@ import static bisq.desktop.util.FormBuilder.addTitledGroupBg; import static javafx.scene.layout.Region.USE_COMPUTED_SIZE; -public abstract class BsqSwapOfferView> extends ActivatableViewAndModel { +public abstract class BsqSwapOfferView> extends ActivatableViewAndModel implements Closable { protected final Navigation navigation; protected final BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java index a60856f7cd4..fd11db20a0e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java @@ -25,6 +25,8 @@ import bisq.desktop.components.InputTextField; import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.MainView; +import bisq.desktop.main.offer.InitializableWithData; +import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; @@ -72,7 +74,7 @@ import static bisq.desktop.util.FormBuilder.*; @FxmlView -public class BsqSwapTakeOfferView extends BsqSwapOfferView { +public class BsqSwapTakeOfferView extends BsqSwapOfferView implements InitializableWithData { private HBox minAmountHBox; private Label offerAvailabilityLabel; private TextField paymentMethodTextField, currencyTextField, priceTextField, @@ -152,16 +154,16 @@ protected void deactivate() { public void initWithData(Offer offer) { model.initWithData(offer); - if (model.dataModel.isSellOffer()) { + if (OfferViewUtil.isShownAsSellOffer(model.dataModel.getOffer())) { actionButton.setId("buy-button-big"); - actionButton.updateText(Res.get("takeOffer.takeOfferButton", Res.get("shared.buy"))); + actionButton.updateText(Res.get("takeOffer.takeOfferButtonAltcoin", Res.get("shared.buy"), BSQ)); nextButton.setId("buy-button"); volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescription")); } else { actionButton.setId("sell-button-big"); nextButton.setId("sell-button"); - actionButton.updateText(Res.get("takeOffer.takeOfferButton", Res.get("shared.sell"))); + actionButton.updateText(Res.get("takeOffer.takeOfferButtonAltcoin", Res.get("shared.sell"), BSQ)); volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); } diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java index ade88cb5fa7..8e42f6bf7f0 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java @@ -19,10 +19,12 @@ import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.BusyAnimation; +import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.Layout; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.monetary.Price; import bisq.core.monetary.Volume; @@ -264,14 +266,15 @@ private void addContent() { } private void addConfirmAndCancelButtons(boolean isPlaceOffer) { - boolean isBuyOffer = offer.isBuyOffer(); + boolean isBuyOffer = OfferViewUtil.isShownAsBuyOffer(offer); boolean isBuyerRole = isPlaceOffer == isBuyOffer; + String tradeCurrencyByName = CurrencyUtil.getNameByCode(offer.getCurrencyCode()); String placeOfferButtonText = isBuyerRole ? - Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) : - Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell")); + Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.buy"), tradeCurrencyByName) : + Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.sell"), tradeCurrencyByName); String takeOfferButtonText = isBuyerRole ? - Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) : - Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell")); + Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.buy"), tradeCurrencyByName) : + Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.sell"), tradeCurrencyByName); ImageView iconView = new ImageView(); iconView.setId(isBuyerRole ? "image-buy-white" : "image-sell-white"); diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java index a67be3fb433..d09ddb91632 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java @@ -22,6 +22,7 @@ import bisq.desktop.components.BusyAnimation; import bisq.desktop.components.TitledGroupBg; import bisq.desktop.components.TxIdTextField; +import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -387,14 +388,27 @@ private void addContent() { } private void addConfirmAndCancelButtons(boolean isPlaceOffer) { - boolean isBuyOffer = offer.isBuyOffer(); + boolean isBuyOffer = OfferViewUtil.isShownAsBuyOffer(offer); boolean isBuyerRole = isPlaceOffer == isBuyOffer; + String tradeCurrencyByName = CurrencyUtil.getNameByCode(offer.getCurrencyCode()); String placeOfferButtonText = isBuyerRole ? - Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) : - Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell")); + CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) : + Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.buy"), + tradeCurrencyByName) : + CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell")) : + Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.sell"), + tradeCurrencyByName); String takeOfferButtonText = isBuyerRole ? - Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) : - Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell")); + CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) : + Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.buy"), + tradeCurrencyByName) : + CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell")) : + Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.sell"), + tradeCurrencyByName); ImageView iconView = new ImageView(); iconView.setId(isBuyerRole ? "image-buy-white" : "image-sell-white"); From a8189d7bb3689bba06bee90f0b866568f0d18d2d Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 6 Apr 2022 18:00:59 +0200 Subject: [PATCH 07/35] Adapt create offer process to new navigation structure --- .../resources/i18n/displayStrings.properties | 9 +- .../{Closable.java => ClosableView.java} | 2 +- ...> InitializableViewWithTakeOfferData.java} | 2 +- .../bisq/desktop/main/offer/OfferView.java | 204 ++++++++---------- .../desktop/main/offer/SelectableView.java | 22 ++ .../offer/bisq_v1/MutableOfferDataModel.java | 21 +- .../main/offer/bisq_v1/MutableOfferView.java | 64 +++++- .../offer/bisq_v1/MutableOfferViewModel.java | 4 + .../main/offer/bisq_v1/OfferViewUtil.java | 11 +- .../bisq_v1/createoffer/CreateOfferView.java | 41 ++++ .../bisq_v1/takeoffer/TakeOfferView.java | 9 +- .../main/offer/bsq_swap/BsqSwapOfferView.java | 4 +- .../create_offer/BsqSwapCreateOfferView.java | 9 +- .../take_offer/BsqSwapTakeOfferView.java | 5 +- .../offer/offerbook/BsqOfferBookView.java | 9 +- .../offerbook/BsqOfferBookViewModel.java | 5 + .../offer/offerbook/BtcOfferBookView.java | 9 +- .../offerbook/BtcOfferBookViewModel.java | 6 + .../main/offer/offerbook/OfferBookView.java | 28 ++- .../offer/offerbook/OfferBookViewModel.java | 10 +- .../offer/offerbook/OtherOfferBookView.java | 9 +- .../offerbook/OtherOfferBookViewModel.java | 9 + .../offerbook/TopAltcoinOfferBookView.java | 9 +- .../TopAltcoinOfferBookViewModel.java | 5 + .../duplicateoffer/DuplicateOfferView.java | 18 +- .../portfolio/editoffer/EditOfferView.java | 8 + .../portfolio/presentation/PortfolioUtil.java | 8 +- 27 files changed, 362 insertions(+), 178 deletions(-) rename desktop/src/main/java/bisq/desktop/main/offer/{Closable.java => ClosableView.java} (96%) rename desktop/src/main/java/bisq/desktop/main/offer/{InitializableWithData.java => InitializableViewWithTakeOfferData.java} (93%) create mode 100644 desktop/src/main/java/bisq/desktop/main/offer/SelectableView.java diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index bca58c669b5..1e556868a09 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -100,11 +100,10 @@ shared.dontRemoveOffer=Don't remove offer shared.editOffer=Edit offer shared.duplicateOffer=Duplicate offer shared.openLargeQRWindow=Open large QR code window -shared.tradingAccount=Trading account +shared.chooseTradingAccount=Choose trading account shared.faq=Visit FAQ page shared.yesCancel=Yes, cancel shared.nextStep=Next step -shared.selectTradingAccount=Select trading account shared.fundFromSavingsWalletButton=Transfer funds from Bisq wallet shared.fundFromExternalWalletButton=Open your external wallet for funding shared.openDefaultWalletFailed=Failed to open a Bitcoin wallet application. Are you sure you have one installed? @@ -198,6 +197,7 @@ shared.iConfirm=I confirm shared.openURL=Open {0} shared.fiat=Fiat shared.crypto=Crypto +shared.otherAssets=other assets shared.all=All shared.edit=Edit shared.advancedOptions=Advanced options @@ -379,7 +379,7 @@ offerbook.volume={0} (min - max) offerbook.deposit=Deposit BTC (%) offerbook.deposit.help=Deposit paid by each trader to guarantee the trade. Will be returned when the trade is completed. -offerbook.createNewOffer=Create new offer +offerbook.createNewOffer=Create new offer to {0} {1} offerbook.createOfferDisabled.tooltip=You can only create one offer at a time offerbook.takeOfferButton.tooltip=Take offer for {0} @@ -393,7 +393,7 @@ offerbook.withdrawFundsHint=Offer has been removed. Funds are not reserved for t You can send Available funds to an external wallet at the {0} screen. offerbook.warning.noTradingAccountForCurrency.headline=No payment account for selected currency -offerbook.warning.noTradingAccountForCurrency.msg=You don't have a payment account set up for the selected currency.\n\nWould you like to create an offer for another currency instead? +offerbook.warning.noTradingAccountForCurrency.msg=You don't have a payment account set up for the selected currency. offerbook.warning.noMatchingAccount.headline=No matching payment account. offerbook.warning.noMatchingAccount.msg=This offer uses a payment method you haven't set up yet. \n\nWould you like to set up a new payment account now? offerbook.warning.noMatchingBsqAccount.msg=This offer uses BSQ as a payment method you haven't set up yet. \n\nWould you like to automatically create an account now? @@ -490,6 +490,7 @@ createOffer.buyBsq.popupMessage=Trading fees are paid to fund the Bisq DAO. Fees # new entries createOffer.placeOfferButton=Review: Place offer to {0} bitcoin +createOffer.placeOfferButtonAltcoin=Review: Place offer to {0} {1} createOffer.createOfferFundWalletInfo.headline=Fund your offer # suppress inspection "TrailingSpacesInProperty" createOffer.createOfferFundWalletInfo.tradeAmount=- Trade amount: {0} \n diff --git a/desktop/src/main/java/bisq/desktop/main/offer/Closable.java b/desktop/src/main/java/bisq/desktop/main/offer/ClosableView.java similarity index 96% rename from desktop/src/main/java/bisq/desktop/main/offer/Closable.java rename to desktop/src/main/java/bisq/desktop/main/offer/ClosableView.java index 57c9a89a089..e1499e5fd4f 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/Closable.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/ClosableView.java @@ -17,6 +17,6 @@ package bisq.desktop.main.offer; -public interface Closable { +public interface ClosableView { public void setCloseHandler(OfferView.CloseHandler closeHandler); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/InitializableWithData.java b/desktop/src/main/java/bisq/desktop/main/offer/InitializableViewWithTakeOfferData.java similarity index 93% rename from desktop/src/main/java/bisq/desktop/main/offer/InitializableWithData.java rename to desktop/src/main/java/bisq/desktop/main/offer/InitializableViewWithTakeOfferData.java index 2a6cdeec773..4c4e2a2cf9a 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/InitializableWithData.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/InitializableViewWithTakeOfferData.java @@ -19,7 +19,7 @@ import bisq.core.offer.Offer; -public interface InitializableWithData { +public interface InitializableViewWithTakeOfferData { public void initWithData(Offer offer); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index a85cfbca06c..46e2f912900 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -31,13 +31,13 @@ import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookView; import bisq.desktop.main.offer.offerbook.OtherOfferBookView; +import bisq.desktop.main.offer.offerbook.OtherOfferBookViewModel; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.GUIUtil; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.GlobalSettings; -import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferDirection; @@ -50,25 +50,20 @@ import javafx.scene.control.Tab; import javafx.scene.control.TabPane; -import javafx.scene.layout.AnchorPane; import javafx.beans.value.ChangeListener; -import javafx.collections.ListChangeListener; - -import java.util.List; import java.util.Optional; +import org.jetbrains.annotations.NotNull; + import javax.annotation.Nullable; public abstract class OfferView extends ActivatableView { private OfferBookView btcOfferBookView, bsqOfferBookView, topAltcoinOfferBookView, otherOfferBookView; - private CreateOfferView createOfferView; - private BsqSwapCreateOfferView bsqSwapCreateOfferView; - private AnchorPane createOfferPane; - private Tab createOfferTab, btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab; + private Tab btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab; private final ViewLoader viewLoader; private final Navigation navigation; @@ -79,15 +74,10 @@ public abstract class OfferView extends ActivatableView { private Offer offer; private TradeCurrency tradeCurrency; - private boolean createOfferViewOpen; private Navigation.Listener navigationListener; private ChangeListener tabChangeListener; - private ListChangeListener tabListChangeListener; private OfferView.OfferActionHandler offerActionHandler; - private Class currentViewClass; - - protected OfferView(ViewLoader viewLoader, Navigation navigation, Preferences preferences, @@ -113,11 +103,7 @@ protected void initialize() { }; tabChangeListener = (observableValue, oldValue, newValue) -> { if (newValue != null) { - if (newValue.equals(createOfferTab) && createOfferView != null) { - createOfferView.onTabSelected(true); - } else if (newValue.equals(createOfferTab) && bsqSwapCreateOfferView != null) { - bsqSwapCreateOfferView.onTabSelected(true); - } else if (newValue.equals(btcOfferBookTab)) { + if (newValue.equals(btcOfferBookTab)) { if (btcOfferBookView != null) { btcOfferBookView.onTabSelected(true); } else { @@ -144,11 +130,7 @@ protected void initialize() { } } if (oldValue != null) { - if (oldValue.equals(createOfferTab) && createOfferView != null) { - createOfferView.onTabSelected(false); - } else if (oldValue.equals(createOfferTab) && bsqSwapCreateOfferView != null) { - bsqSwapCreateOfferView.onTabSelected(false); - } else if (oldValue.equals(btcOfferBookTab) && btcOfferBookView != null) { + if (oldValue.equals(btcOfferBookTab) && btcOfferBookView != null) { btcOfferBookView.onTabSelected(false); } else if (oldValue.equals(bsqOfferBookTab) && bsqOfferBookView != null) { bsqOfferBookView.onTabSelected(false); @@ -159,32 +141,20 @@ protected void initialize() { } } }; - tabListChangeListener = change -> { - change.next(); - List removedTabs = change.getRemoved(); - if (removedTabs.size() == 1) { - if (removedTabs.get(0).getContent().equals(createOfferPane)) - onCreateOfferViewRemoved(); - } - }; offerActionHandler = new OfferActionHandler() { @Override public void onCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMethod) { - if (createOfferViewOpen) { - root.getTabs().remove(createOfferTab); - } if (canCreateOrTakeOffer(tradeCurrency)) { - openCreateOffer(tradeCurrency, paymentMethod); + showCreateOffer(tradeCurrency, paymentMethod); } } @Override public void onTakeOffer(Offer offer) { - // can we have multiple take offer views open? Optional optionalTradeCurrency = CurrencyUtil.getTradeCurrency(offer.getCurrencyCode()); if (optionalTradeCurrency.isPresent() && canCreateOrTakeOffer(optionalTradeCurrency.get())) { - openTakeOffer(offer); + showTakeOffer(offer); } } }; @@ -198,7 +168,6 @@ protected void activate() { tradeCurrency = tradeCurrencyOptional.orElseGet(GlobalSettings::getDefaultTradeCurrency); root.getSelectionModel().selectedItemProperty().addListener(tabChangeListener); - root.getTabs().addListener(tabListChangeListener); navigation.addListener(navigationListener); if (btcOfferBookView == null) { navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); @@ -209,17 +178,6 @@ protected void activate() { protected void deactivate() { navigation.removeListener(navigationListener); root.getSelectionModel().selectedItemProperty().removeListener(tabChangeListener); - root.getTabs().removeListener(tabListChangeListener); - } - - private String getCreateOfferTabName(Class viewClass) { - return viewClass == BsqSwapCreateOfferView.class ? - Res.get("offerbook.bsqSwap.createOffer").toUpperCase() : - Res.get("offerbook.createOffer").toUpperCase(); - } - - private String getTakeOfferTabName() { - return Res.get("offerbook.takeOffer").toUpperCase(); } private void loadView(Class viewClass, @@ -227,41 +185,57 @@ private void loadView(Class viewClass, @Nullable Object data) { TabPane tabPane = root; tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); - currentViewClass = viewClass; - View view; if (OfferBookView.class.isAssignableFrom(viewClass)) { if (viewClass == BtcOfferBookView.class && btcOfferBookTab != null && btcOfferBookView != null) { if (childViewClass == null) { btcOfferBookTab.setContent(btcOfferBookView.getRoot()); - } else { + } else if (childViewClass == TakeOfferView.class) { loadTakeViewClass(viewClass, childViewClass, btcOfferBookTab); + } else { + loadCreateViewClass(btcOfferBookView, viewClass, childViewClass, btcOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(btcOfferBookTab); } else if (viewClass == BsqOfferBookView.class && bsqOfferBookTab != null && bsqOfferBookView != null) { if (childViewClass == null) { bsqOfferBookTab.setContent(bsqOfferBookView.getRoot()); - } else { + } else if (childViewClass == TakeOfferView.class) { loadTakeViewClass(viewClass, childViewClass, bsqOfferBookTab); + } else if (data instanceof BsqSwapOfferPayload) { + loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, PaymentMethod.BSQ_SWAP, (BsqSwapOfferPayload) data); + } else { + loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(bsqOfferBookTab); } else if (viewClass == TopAltcoinOfferBookView.class && topAltcoinOfferBookTab != null && topAltcoinOfferBookView != null) { if (childViewClass == null) { topAltcoinOfferBookTab.setContent(topAltcoinOfferBookView.getRoot()); - } else { + } else if (childViewClass == TakeOfferView.class) { loadTakeViewClass(viewClass, childViewClass, topAltcoinOfferBookTab); + } else { + loadCreateViewClass(topAltcoinOfferBookView, viewClass, childViewClass, topAltcoinOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(topAltcoinOfferBookTab); } else if (viewClass == OtherOfferBookView.class && otherOfferBookTab != null && otherOfferBookView != null) { if (childViewClass == null) { otherOfferBookTab.setContent(otherOfferBookView.getRoot()); - } else { + } else if (childViewClass == TakeOfferView.class) { loadTakeViewClass(viewClass, childViewClass, otherOfferBookTab); + } else { + //add sanity check in case of app restart + if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) { + Optional tradeCurrencyOptional = (this.direction == OfferDirection.SELL) ? + CurrencyUtil.getTradeCurrency(preferences.getSellScreenCryptoCurrencyCode()) : + CurrencyUtil.getTradeCurrency(preferences.getBuyScreenCryptoCurrencyCode()); + tradeCurrency = tradeCurrencyOptional.isEmpty() ? OtherOfferBookViewModel.DEFAULT_ALTCOIN : tradeCurrencyOptional.get(); + } + loadCreateViewClass(otherOfferBookView, viewClass, childViewClass, otherOfferBookTab, (PaymentMethod) data, null); } - tabPane.getSelectionModel().select(topAltcoinOfferBookTab); + tabPane.getSelectionModel().select(otherOfferBookTab); } else { if (btcOfferBookTab == null) { + //TODO: use naming from currencies or from translations btcOfferBookTab = new Tab("BITCOIN"); btcOfferBookTab.setClosable(false); bsqOfferBookTab = new Tab("BSQ"); @@ -303,37 +277,41 @@ private void loadView(Class viewClass, otherOfferBookView.onTabSelected(true); } } - } else if (viewClass == CreateOfferView.class && createOfferView == null) { - view = viewLoader.load(viewClass); - // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times - // in different graphs - createOfferView = (CreateOfferView) view; - createOfferView.initWithData(direction, tradeCurrency, offerActionHandler); - createOfferPane = createOfferView.getRoot(); - createOfferTab = new Tab(getCreateOfferTabName(viewClass)); - createOfferTab.setClosable(true); - // close handler from close on create offer action - createOfferView.setCloseHandler(() -> tabPane.getTabs().remove(createOfferTab)); - createOfferTab.setContent(createOfferPane); - tabPane.getTabs().add(createOfferTab); - tabPane.getSelectionModel().select(createOfferTab); - createOfferViewOpen = true; - } else if (viewClass == BsqSwapCreateOfferView.class && bsqSwapCreateOfferView == null) { - view = viewLoader.load(viewClass); - bsqSwapCreateOfferView = (BsqSwapCreateOfferView) view; - bsqSwapCreateOfferView.initWithData(direction, offerActionHandler, (BsqSwapOfferPayload) data); - createOfferPane = bsqSwapCreateOfferView.getRoot(); - createOfferTab = new Tab(getCreateOfferTabName(viewClass)); - createOfferTab.setClosable(true); - // close handler from close on create offer action - bsqSwapCreateOfferView.setCloseHandler(() -> tabPane.getTabs().remove(createOfferTab)); - createOfferTab.setContent(createOfferPane); - tabPane.getTabs().add(createOfferTab); - tabPane.getSelectionModel().select(createOfferTab); - createOfferViewOpen = true; } } + private void loadCreateViewClass(OfferBookView offerBookView, + Class viewClass, + Class childViewClass, + Tab marketOfferBookTab, + @Nullable PaymentMethod paymentMethod, + @Nullable BsqSwapOfferPayload payload) { + if (tradeCurrency == null) { + return; + } + + View view = viewLoader.load(paymentMethod != null && paymentMethod.isBsqSwap() ? BsqSwapCreateOfferView.class : childViewClass); + // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times + // in different graphs + if (paymentMethod != null && paymentMethod.isBsqSwap()) { + ((BsqSwapCreateOfferView) view).initWithData(direction, offerActionHandler, payload); + } else { + ((CreateOfferView) view).initWithData(direction, tradeCurrency, offerActionHandler); + } + + ((SelectableView) view).onTabSelected(true); + + ((ClosableView) view).setCloseHandler(() -> { + offerBookView.enableCreateOfferButton(); + ((SelectableView) view).onTabSelected(false); + navigation.navigateTo(MainView.class, this.getClass(), viewClass); + }); + + + // close handler from close on create offer action + marketOfferBookTab.setContent(view.getRoot()); + } + private void loadTakeViewClass(Class viewClass, Class childViewClass, Tab marketOfferBookTab) { @@ -342,14 +320,15 @@ private void loadTakeViewClass(Class viewClass, return; } - View view; - view = viewLoader.load(offer.isBsqSwapOffer() ? BsqSwapTakeOfferView.class : childViewClass); + View view = viewLoader.load(offer.isBsqSwapOffer() ? BsqSwapTakeOfferView.class : childViewClass); // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times // in different graphs + ((InitializableViewWithTakeOfferData) view).initWithData(offer); + ((SelectableView) view).onTabSelected(true); - ((InitializableWithData) view).initWithData(offer); // close handler from close on take offer action - ((Closable) view).setCloseHandler(() -> { + ((ClosableView) view).setCloseHandler(() -> { + ((SelectableView) view).onTabSelected(false); navigation.navigateTo(MainView.class, this.getClass(), viewClass); }); marketOfferBookTab.setContent(view.getRoot()); @@ -360,44 +339,33 @@ protected boolean canCreateOrTakeOffer(TradeCurrency tradeCurrency) { GUIUtil.canCreateOrTakeOfferOrShowPopup(user, navigation, tradeCurrency); } - private void openTakeOffer(Offer offer) { + private void showTakeOffer(Offer offer) { this.offer = offer; - Class> offerBookViewClass; - if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) { - offerBookViewClass = BtcOfferBookView.class; - } else if (offer.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode())) { - offerBookViewClass = BsqOfferBookView.class; - } else if (offer.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { - offerBookViewClass = TopAltcoinOfferBookView.class; - } else { - offerBookViewClass = OtherOfferBookView.class; - } + Class> offerBookViewClass = getOfferBookViewClassFor(offer.getCurrencyCode()); navigation.navigateTo(MainView.class, this.getClass(), offerBookViewClass, TakeOfferView.class); } - private void openCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMethod) { - createOfferViewOpen = true; + private void showCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMethod) { this.tradeCurrency = tradeCurrency; - if (tradeCurrency.getCode().equals("BSQ") && paymentMethod.isBsqSwap()) { - navigation.navigateTo(MainView.class, this.getClass(), BsqSwapCreateOfferView.class); - } else { - navigation.navigateTo(MainView.class, this.getClass(), CreateOfferView.class); - } + + Class> offerBookViewClass = getOfferBookViewClassFor(tradeCurrency.getCode()); + navigation.navigateToWithData(paymentMethod, MainView.class, this.getClass(), offerBookViewClass, CreateOfferView.class); } - private void onCreateOfferViewRemoved() { - createOfferViewOpen = false; - if (createOfferView != null) { - createOfferView.onClose(); - createOfferView = null; - } - if (bsqSwapCreateOfferView != null) { - bsqSwapCreateOfferView = null; + @NotNull + private Class> getOfferBookViewClassFor(String currencyCode) { + Class> offerBookViewClass; + if (CurrencyUtil.isFiatCurrency(currencyCode)) { + offerBookViewClass = BtcOfferBookView.class; + } else if (currencyCode.equals(BsqOfferBookViewModel.BSQ.getCode())) { + offerBookViewClass = BsqOfferBookView.class; + } else if (currencyCode.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + offerBookViewClass = TopAltcoinOfferBookView.class; + } else { + offerBookViewClass = OtherOfferBookView.class; } - btcOfferBookView.enableCreateOfferButton(); - //TODO: go to last selected tab - navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); + return offerBookViewClass; } public interface OfferActionHandler { diff --git a/desktop/src/main/java/bisq/desktop/main/offer/SelectableView.java b/desktop/src/main/java/bisq/desktop/main/offer/SelectableView.java new file mode 100644 index 00000000000..7d7dfb2a6ff --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/SelectableView.java @@ -0,0 +1,22 @@ +/* + * 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 bisq.desktop.main.offer; + +public interface SelectableView { + public void onTabSelected(boolean isSelected); +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java index 2389ebfb9eb..83477489fa4 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java @@ -18,6 +18,8 @@ package bisq.desktop.main.offer.bisq_v1; import bisq.desktop.Navigation; +import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -81,6 +83,7 @@ import java.util.Comparator; import java.util.Date; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Predicate; @@ -88,6 +91,8 @@ import lombok.Getter; +import org.jetbrains.annotations.NotNull; + import javax.annotation.Nullable; import static bisq.core.payment.payload.PaymentMethod.HAL_CASH_ID; @@ -247,7 +252,7 @@ public boolean initWithData(OfferDirection direction, TradeCurrency tradeCurrenc if (account != null) { this.paymentAccount = account; } else { - Optional paymentAccountOptional = paymentAccounts.stream().findAny(); + Optional paymentAccountOptional = getAnyPaymentAccount(); if (paymentAccountOptional.isPresent()) { this.paymentAccount = paymentAccountOptional.get(); @@ -277,6 +282,18 @@ public boolean initWithData(OfferDirection direction, TradeCurrency tradeCurrenc return true; } + @NotNull + private Optional getAnyPaymentAccount() { + if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) { + return paymentAccounts.stream().filter(paymentAccount1 -> !paymentAccount1.getPaymentMethod().isAltcoin()).findAny(); + } else { + return paymentAccounts.stream().filter(paymentAccount1 -> paymentAccount1.getPaymentMethod().isAltcoin() && + paymentAccount1.getTradeCurrency().isPresent() && + !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), BsqOfferBookViewModel.BSQ.getCode()) && + !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())).findAny(); + } + } + protected PaymentAccount getPreselectedPaymentAccount() { return preferences.getSelectedPaymentAccountForCreateOffer(); } @@ -405,7 +422,7 @@ void onCurrencySelected(TradeCurrency tradeCurrency) { Optional tradeCurrencyOptional = preferences.getTradeCurrenciesAsObservable() .stream().filter(e -> e.getCode().equals(code)).findAny(); - if (!tradeCurrencyOptional.isPresent()) { + if (tradeCurrencyOptional.isEmpty()) { if (CurrencyUtil.isCryptoCurrency(code)) { CurrencyUtil.getCryptoCurrency(code).ifPresent(preferences::addCryptoCurrency); } else { diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index e8f9c89842c..1a500404248 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -35,7 +35,9 @@ import bisq.desktop.main.dao.DaoView; import bisq.desktop.main.dao.wallet.BsqWalletView; import bisq.desktop.main.dao.wallet.receive.BsqReceiveView; +import bisq.desktop.main.offer.ClosableView; import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.SelectableView; import bisq.desktop.main.overlays.notifications.Notification; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.OfferDetailsWindow; @@ -104,6 +106,7 @@ import javafx.event.EventHandler; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.util.StringConverter; @@ -125,7 +128,7 @@ import static bisq.desktop.util.FormBuilder.*; import static javafx.beans.binding.Bindings.createStringBinding; -public abstract class MutableOfferView> extends ActivatableViewAndModel { +public abstract class MutableOfferView> extends ActivatableViewAndModel implements ClosableView, SelectableView { protected final Navigation navigation; private final Preferences preferences; private final OfferDetailsWindow offerDetailsWindow; @@ -137,7 +140,7 @@ public abstract class MutableOfferView> exten private TitledGroupBg payFundsTitledGroupBg, setDepositTitledGroupBg, paymentTitledGroupBg; protected TitledGroupBg amountTitledGroupBg; private BusyAnimation waitingForFundsSpinner; - private AutoTooltipButton nextButton, cancelButton1, cancelButton2, placeOfferButton; + private AutoTooltipButton nextButton, cancelButton1, cancelButton2, placeOfferButton, fundFromSavingsWalletButton; private Button priceTypeToggleButton; private InputTextField fixedPriceTextField, marketBasedPriceTextField, triggerPriceInputTextField; protected InputTextField amountTextField, minAmountTextField, volumeTextField, buyerSecurityDepositInputTextField; @@ -217,7 +220,7 @@ protected void initialize() { balanceTextField.setFormatter(model.getBtcFormatter()); paymentAccountsComboBox.setConverter(GUIUtil.getPaymentAccountsComboBoxStringConverter()); - paymentAccountsComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.selectTradingAccount"), + paymentAccountsComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.chooseTradingAccount"), paymentAccountsComboBox, false)); paymentAccountsComboBox.setCellFactory(model.getPaymentAccountListCellFactory(paymentAccountsComboBox)); @@ -252,9 +255,9 @@ protected void doActivate() { addressTextField.setAddress(model.getAddressAsString()); addressTextField.setPaymentLabel(model.getPaymentLabel()); - paymentAccountsComboBox.setItems(model.getDataModel().getPaymentAccounts()); - paymentAccountsComboBox.getSelectionModel().select(model.getPaymentAccount()); currencyComboBox.getSelectionModel().select(model.getTradeCurrency()); + paymentAccountsComboBox.setItems(getPaymentAccounts()); + paymentAccountsComboBox.getSelectionModel().select(model.getPaymentAccount()); onPaymentAccountsComboBoxSelected(); @@ -327,14 +330,30 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency, }).show(); } - if (direction == OfferDirection.BUY) { + String placeOfferButtonLabel; + + if (OfferViewUtil.isShownAsBuyOffer(direction, tradeCurrency)) { placeOfferButton.setId("buy-button-big"); - placeOfferButton.updateText(Res.get("createOffer.placeOfferButton", Res.get("shared.buy"))); + if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) { + placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.buy")); + } else { + placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), tradeCurrency.getName()); + } + placeOfferButton.updateText(placeOfferButtonLabel); + nextButton.setId("buy-button"); + fundFromSavingsWalletButton.setId("buy-button"); } else { placeOfferButton.setId("sell-button-big"); - placeOfferButton.updateText(Res.get("createOffer.placeOfferButton", Res.get("shared.sell"))); + if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) { + placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.sell")); + } else { + placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), tradeCurrency.getName()); + } + nextButton.setId("sell-button"); + fundFromSavingsWalletButton.setId("sell-button"); } + updatePriceToggle(); if (!model.getDataModel().isMakerFeeValid() && model.getDataModel().getMakerFee() != null) @@ -771,6 +790,15 @@ private void createListeners() { marketBasedPriceTextField.clear(); volumeTextField.clear(); triggerPriceInputTextField.clear(); + if (!CurrencyUtil.isFiatCurrency(newValue)) { + if (model.isShownAsBuyOffer()) { + placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), + model.getTradeCurrency().getName())); + } else { + placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), + model.getTradeCurrency().getName())); + } + } }; placeOfferCompletedListener = (o, oldValue, newValue) -> { @@ -1031,7 +1059,7 @@ private void addGridPane() { } private void addPaymentGroup() { - paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, "Buy BTC with Fiat"); + paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.chooseTradingAccount")); GridPane.setColumnSpan(paymentTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); @@ -1040,7 +1068,7 @@ private void addPaymentGroup() { paymentGroupBox.setPadding(new Insets(10, 0, 18, 0)); final Tuple3> tradingAccountBoxTuple = addTopLabelComboBox( - Res.get("shared.tradingAccount"), Res.get("shared.selectTradingAccount")); + Res.get("shared.chooseTradingAccount"), Res.get("shared.chooseTradingAccount")); final Tuple3> currencyBoxTuple = addTopLabelComboBox( Res.get("shared.currency"), Res.get("list.currency.select")); @@ -1234,7 +1262,7 @@ private void addFundingGroup() { fundingHBox.setVisible(false); fundingHBox.setManaged(false); fundingHBox.setSpacing(10); - Button fundFromSavingsWalletButton = new AutoTooltipButton(Res.get("shared.fundFromSavingsWalletButton")); + fundFromSavingsWalletButton = new AutoTooltipButton(Res.get("shared.fundFromSavingsWalletButton")); fundFromSavingsWalletButton.setDefaultButton(true); fundFromSavingsWalletButton.getStyleClass().add("action-button"); fundFromSavingsWalletButton.setOnAction(e -> model.fundFromSavingsWallet()); @@ -1553,4 +1581,18 @@ private GridPane createInfoPopover() { model.getTotalToPayInfo()); return infoGridPane; } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Helpers + /////////////////////////////////////////////////////////////////////////////////////////// + + private ObservableList getPaymentAccounts() { + return filterPaymentAccounts(model.getDataModel().getPaymentAccounts()); + } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Abstract Methods + /////////////////////////////////////////////////////////////////////////////////////////// + + protected abstract ObservableList filterPaymentAccounts(ObservableList paymentAccounts); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java index a7f4c138ca4..b0e10fd42cd 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java @@ -981,6 +981,10 @@ CoinFormatter getBtcFormatter() { return btcFormatter; } + public boolean isShownAsBuyOffer() { + return OfferViewUtil.isShownAsBuyOffer(dataModel.getDirection(), dataModel.getTradeCurrency()); + } + public boolean isSellOffer() { return dataModel.getDirection() == OfferDirection.SELL; } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java index e059242cd78..2d7b37fae9e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java @@ -28,6 +28,7 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; +import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferDirection; @@ -118,10 +119,18 @@ private static void openBuyBsqOfferBook(Navigation navigation) { } public static boolean isShownAsSellOffer(Offer offer) { - return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) == (offer.getDirection() == OfferDirection.SELL); + return isShownAsSellOffer(offer.getCurrencyCode(), offer.getDirection()); + } + + public static boolean isShownAsSellOffer(String currencyCode, OfferDirection direction) { + return CurrencyUtil.isFiatCurrency(currencyCode) == (direction == OfferDirection.SELL); } public static boolean isShownAsBuyOffer(Offer offer) { return !isShownAsSellOffer(offer); } + + public static boolean isShownAsBuyOffer(OfferDirection direction, TradeCurrency tradeCurrency) { + return !isShownAsSellOffer(tradeCurrency.getCode(), direction); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java index 0ad84c2c006..2f4d7995e2b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java @@ -19,9 +19,16 @@ import bisq.desktop.Navigation; import bisq.desktop.common.view.FxmlView; +import bisq.desktop.main.offer.OfferView; import bisq.desktop.main.offer.bisq_v1.MutableOfferView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.overlays.windows.OfferDetailsWindow; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; +import bisq.core.offer.OfferDirection; +import bisq.core.payment.PaymentAccount; import bisq.core.user.Preferences; import bisq.core.util.FormattingUtils; import bisq.core.util.coin.BsqFormatter; @@ -31,6 +38,12 @@ import javax.inject.Named; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import java.util.Objects; +import java.util.stream.Collectors; + @FxmlView public class CreateOfferView extends MutableOfferView { @Inject @@ -42,4 +55,32 @@ private CreateOfferView(CreateOfferViewModel model, BsqFormatter bsqFormatter) { super(model, navigation, preferences, offerDetailsWindow, btcFormatter, bsqFormatter); } + + @Override + 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); + } + + @Override + protected ObservableList filterPaymentAccounts(ObservableList paymentAccounts) { + return FXCollections.observableArrayList( + paymentAccounts.stream().filter(paymentAccount -> { + if (model.getTradeCurrency().equals(BsqOfferBookViewModel.BSQ)) { + return Objects.equals(paymentAccount.getSingleTradeCurrency(), BsqOfferBookViewModel.BSQ); + } else if (model.getTradeCurrency().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN)) { + return Objects.equals(paymentAccount.getSingleTradeCurrency(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN); + } else if (CurrencyUtil.isFiatCurrency(model.getTradeCurrency().getCode())) { + return !paymentAccount.getPaymentMethod().isAltcoin(); + } else { + return paymentAccount.getPaymentMethod().isAltcoin() && + !(Objects.equals(paymentAccount.getSingleTradeCurrency(), BsqOfferBookViewModel.BSQ) || + Objects.equals(paymentAccount.getSingleTradeCurrency(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN)); + } + }).collect(Collectors.toList())); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index e57354cf2c4..a507c073d8c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -36,9 +36,10 @@ import bisq.desktop.main.dao.wallet.receive.BsqReceiveView; import bisq.desktop.main.funds.FundsView; import bisq.desktop.main.funds.withdrawal.WithdrawalView; -import bisq.desktop.main.offer.Closable; -import bisq.desktop.main.offer.InitializableWithData; +import bisq.desktop.main.offer.ClosableView; +import bisq.desktop.main.offer.InitializableViewWithTakeOfferData; import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.SelectableView; import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.overlays.notifications.Notification; import bisq.desktop.main.overlays.popups.Popup; @@ -123,7 +124,7 @@ import static javafx.beans.binding.Bindings.createStringBinding; @FxmlView -public class TakeOfferView extends ActivatableViewAndModel implements Closable, InitializableWithData { +public class TakeOfferView extends ActivatableViewAndModel implements ClosableView, InitializableViewWithTakeOfferData, SelectableView { private final Navigation navigation; private final CoinFormatter formatter; private final BsqFormatter bsqFormatter; @@ -819,7 +820,7 @@ private void addPaymentGroup() { GridPane.setColumnSpan(paymentAccountTitledGroupBg, 2); final Tuple4, Label, TextField, HBox> paymentAccountTuple = addComboBoxTopLabelTextField(gridPane, - gridRow, Res.get("shared.selectTradingAccount"), + gridRow, Res.get("shared.chooseTradingAccount"), Res.get("shared.paymentMethod"), Layout.FIRST_ROW_DISTANCE); paymentAccountsComboBox = paymentAccountTuple.first; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java index 76a5154ca6c..79bc4645243 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java @@ -24,7 +24,7 @@ import bisq.desktop.components.FundsTextField; import bisq.desktop.components.InputTextField; import bisq.desktop.components.TitledGroupBg; -import bisq.desktop.main.offer.Closable; +import bisq.desktop.main.offer.ClosableView; import bisq.desktop.main.offer.OfferView; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; import bisq.desktop.util.GUIUtil; @@ -69,7 +69,7 @@ import static bisq.desktop.util.FormBuilder.addTitledGroupBg; import static javafx.scene.layout.Region.USE_COMPUTED_SIZE; -public abstract class BsqSwapOfferView> extends ActivatableViewAndModel implements Closable { +public abstract class BsqSwapOfferView> extends ActivatableViewAndModel implements ClosableView { protected final Navigation navigation; protected final BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index ec4037eeb91..2e9c97a6af7 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -26,6 +26,7 @@ import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.MainView; import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.SelectableView; import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; @@ -82,7 +83,7 @@ @FxmlView @Slf4j -public class BsqSwapCreateOfferView extends BsqSwapOfferView { +public class BsqSwapCreateOfferView extends BsqSwapOfferView implements SelectableView { private InputTextField minAmountTextField, priceTextField, volumeTextField; private Label miningPowLabel; private BusyAnimation miningPowBusyAnimation; @@ -431,7 +432,7 @@ protected void removeBindings() { @Override protected void addPaymentAccountGroup() { - paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.selectTradingAccount")); + paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.chooseTradingAccount")); GridPane.setColumnSpan(paymentAccountTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); @@ -440,7 +441,7 @@ protected void addPaymentAccountGroup() { paymentGroupBox.setPadding(new Insets(10, 0, 18, 0)); Tuple3> paymentAccountBoxTuple = addTopLabelComboBox( - Res.get("shared.tradingAccount"), Res.get("shared.selectTradingAccount")); + Res.get("shared.chooseTradingAccount"), Res.get("shared.chooseTradingAccount")); Tuple3 currencyTextFieldTuple = addTopLabelTextField(gridPane, gridRow, Res.get("shared.currency"), BSQ, 5d); @@ -459,7 +460,7 @@ protected void addPaymentAccountGroup() { paymentAccountsComboBox.setMinWidth(paymentAccountVBox.getMinWidth()); paymentAccountsComboBox.setPrefWidth(paymentAccountVBox.getMinWidth()); paymentAccountsComboBox.setConverter(GUIUtil.getPaymentAccountsComboBoxStringConverter()); - paymentAccountsComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.selectTradingAccount"), + paymentAccountsComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.chooseTradingAccount"), paymentAccountsComboBox, false)); paymentAccountsComboBox.setCellFactory(getPaymentAccountListCellFactory(paymentAccountsComboBox)); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java index fd11db20a0e..d7d0c16f245 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java @@ -25,7 +25,8 @@ import bisq.desktop.components.InputTextField; import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.MainView; -import bisq.desktop.main.offer.InitializableWithData; +import bisq.desktop.main.offer.InitializableViewWithTakeOfferData; +import bisq.desktop.main.offer.SelectableView; import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView; import bisq.desktop.main.overlays.popups.Popup; @@ -74,7 +75,7 @@ import static bisq.desktop.util.FormBuilder.*; @FxmlView -public class BsqSwapTakeOfferView extends BsqSwapOfferView implements InitializableWithData { +public class BsqSwapTakeOfferView extends BsqSwapOfferView implements InitializableViewWithTakeOfferData, SelectableView { private HBox minAmountHBox; private Label offerAvailabilityLabel; private TextField paymentMethodTextField, currencyTextField, priceTextField, diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java index ef4d5d30c33..46c86fdadf4 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java @@ -58,8 +58,8 @@ public class BsqOfferBookView extends OfferBookView getCurrencyAndMethodPredicate(OfferDirection direct }; } + @Override + TradeCurrency getDefaultTradeCurrency() { + return BSQ; + } + @Override String getCurrencyCodeFromPreferences(OfferDirection direction) { return BSQ.getCode(); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java index 480a7d0579e..ad04f538b0f 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java @@ -56,9 +56,14 @@ public class BtcOfferBookView extends OfferBookView getCurrencyAndMethodPredicate(OfferDirection direct }; } + @Override + TradeCurrency getDefaultTradeCurrency() { + return GlobalSettings.getDefaultTradeCurrency(); + } + @Override String getCurrencyCodeFromPreferences(OfferDirection direction) { return direction == OfferDirection.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode(); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index ce711627b16..c7ed1a5dc0d 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -210,7 +210,7 @@ public void initialize() { matchingOffersToggle.setText(Res.get("offerbook.matchingOffers")); HBox.setMargin(matchingOffersToggle, new Insets(7, 0, -9, -15)); - createOfferButton = new AutoTooltipButton(Res.get("offerbook.createNewOffer")); + createOfferButton = new AutoTooltipButton(""); createOfferButton.setMinHeight(40); createOfferButton.setGraphicTextGap(10); @@ -361,6 +361,7 @@ protected void activate() { model.updateSelectedPaymentMethod(); updatePaymentMethodComboBoxEditor(); model.onSetPaymentMethod(paymentMethodComboBox.getSelectionModel().getSelectedItem()); + updateCreateOfferButton(); }); updateCurrencyComboBoxFromModel(); @@ -587,7 +588,6 @@ private void disableCreateOfferButton() { public void setDirection(OfferDirection direction) { model.initWithDirection(direction); ImageView iconView = new ImageView(); - createOfferButton.setGraphic(iconView); iconView.setId(direction == OfferDirection.SELL ? "image-sell-white" : "image-buy-white"); createOfferButton.setId(direction == OfferDirection.SELL ? "sell-button-big" : "buy-button-big"); @@ -605,6 +605,7 @@ public void onTabSelected(boolean isSelected) { updateCurrencyComboBoxFromModel(); root.requestFocus(); } + updateCreateOfferButton(); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -616,12 +617,14 @@ private void onCreateOffer() { if (!model.hasPaymentAccountForCurrency()) { new Popup().headLine(Res.get("offerbook.warning.noTradingAccountForCurrency.headline")) .instruction(Res.get("offerbook.warning.noTradingAccountForCurrency.msg")) - .actionButtonText(Res.get("offerbook.yesCreateOffer")) - .onAction(this::disableCreateOfferButton) - .secondaryActionButtonText(Res.get("offerbook.setupNewAccount")) - .onSecondaryAction(() -> { + .actionButtonText(Res.get("offerbook.setupNewAccount")) + .onAction(() -> { navigation.setReturnPath(navigation.getCurrentPath()); - navigation.navigateTo(MainView.class, AccountView.class, FiatAccountsView.class); + if (CurrencyUtil.isFiatCurrency(model.getSelectedTradeCurrency().getCode())) { + navigation.navigateTo(MainView.class, AccountView.class, FiatAccountsView.class); + } else { + navigation.navigateTo(MainView.class, AccountView.class, AltCoinAccountsView.class); + } }) .width(725) .show(); @@ -1084,6 +1087,7 @@ public TableCell call(TableColumn call(TableColumn call(TableColumn getMostMaturePaymentAccountForOffer(Offer offer) { private void setMarketPriceFeedCurrency() { if (isTabSelected) { if (showAllTradeCurrenciesProperty.get()) - priceFeedService.setCurrencyCode(GlobalSettings.getDefaultTradeCurrency().getCode()); + priceFeedService.setCurrencyCode(getDefaultTradeCurrency().getCode()); else priceFeedService.setCurrencyCode(tradeCurrencyCode.get()); } @@ -697,11 +695,13 @@ private void updateSelectedTradeCurrency() { selectedTradeCurrency = CurrencyUtil.getTradeCurrency(code).get(); } else { showAllTradeCurrenciesProperty.set(true); - selectedTradeCurrency = GlobalSettings.getDefaultTradeCurrency(); + selectedTradeCurrency = getDefaultTradeCurrency(); } tradeCurrencyCode.set(selectedTradeCurrency.getCode()); } + abstract TradeCurrency getDefaultTradeCurrency(); + public void updateSelectedPaymentMethod() { showAllPaymentMethods = getPaymentMethods().stream().noneMatch(paymentMethod -> paymentMethod.equals(selectedPaymentMethod)); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java index 7ccb4f74978..b04719bb996 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java @@ -56,7 +56,12 @@ public class OtherOfferBookView extends OfferBookView getCurrencyAndMethodPredicate(OfferDirection direct }; } + @Override + TradeCurrency getDefaultTradeCurrency() { + // select first currency in list, otherwise if view is not initialized add Ether as default one + return !getTradeCurrencies().isEmpty() ? getTradeCurrencies().get(1) : + DEFAULT_ALTCOIN; + } + @Override String getCurrencyCodeFromPreferences(OfferDirection direction) { return direction == OfferDirection.BUY ? preferences.getBuyScreenCryptoCurrencyCode() : preferences.getSellScreenCryptoCurrencyCode(); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java index 076b83cad55..081f0caf6e1 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java @@ -56,8 +56,8 @@ public class TopAltcoinOfferBookView extends OfferBookView getCurrencyAndMethodPredicate(OfferDirection direct }; } + @Override + TradeCurrency getDefaultTradeCurrency() { + return TOP_ALTCOIN; + } + @Override String getCurrencyCodeFromPreferences(OfferDirection direction) { return TOP_ALTCOIN.getCode(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java index db6eb38ba19..b6850c27acb 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java @@ -24,6 +24,7 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.offer.bisq_v1.OfferPayload; +import bisq.core.payment.PaymentAccount; import bisq.core.user.Preferences; import bisq.core.util.FormattingUtils; import bisq.core.util.coin.BsqFormatter; @@ -33,16 +34,18 @@ import javax.inject.Named; +import javafx.collections.ObservableList; + @FxmlView public class DuplicateOfferView extends MutableOfferView { @Inject private DuplicateOfferView(DuplicateOfferViewModel model, - Navigation navigation, - Preferences preferences, - OfferDetailsWindow offerDetailsWindow, - @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, - BsqFormatter bsqFormatter) { + Navigation navigation, + Preferences preferences, + OfferDetailsWindow offerDetailsWindow, + @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, + BsqFormatter bsqFormatter) { super(model, navigation, preferences, offerDetailsWindow, btcFormatter, bsqFormatter); } @@ -61,6 +64,11 @@ protected void doActivate() { onPaymentAccountsComboBoxSelected(); } + @Override + protected ObservableList filterPaymentAccounts(ObservableList paymentAccounts) { + return paymentAccounts; + } + public void initWithData(OfferPayload offerPayload) { initWithData(offerPayload.getDirection(), CurrencyUtil.getTradeCurrency(offerPayload.getCurrencyCode()).get(), diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java index 3fe8ae92383..59a9cd0bec9 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java @@ -28,6 +28,7 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.offer.OpenOffer; +import bisq.core.payment.PaymentAccount; import bisq.core.user.DontShowAgainLookup; import bisq.core.user.Preferences; import bisq.core.util.FormattingUtils; @@ -50,6 +51,8 @@ import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.collections.ObservableList; + import static bisq.desktop.util.FormBuilder.addButtonBusyAnimationLabelAfterGroup; @FxmlView @@ -174,6 +177,11 @@ private void removeBindings() { confirmButton.disableProperty().unbind(); } + @Override + protected ObservableList filterPaymentAccounts(ObservableList paymentAccounts) { + return paymentAccounts; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Build UI elements /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/presentation/PortfolioUtil.java b/desktop/src/main/java/bisq/desktop/main/portfolio/presentation/PortfolioUtil.java index 22ef5712950..13e5966607e 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/presentation/PortfolioUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/presentation/PortfolioUtil.java @@ -21,7 +21,8 @@ import bisq.desktop.main.MainView; import bisq.desktop.main.offer.BuyOfferView; import bisq.desktop.main.offer.SellOfferView; -import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView; +import bisq.desktop.main.offer.bisq_v1.createoffer.CreateOfferView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookView; import bisq.desktop.main.portfolio.PortfolioView; import bisq.desktop.main.portfolio.duplicateoffer.DuplicateOfferView; @@ -33,8 +34,9 @@ public class PortfolioUtil { public static void duplicateOffer(Navigation navigation, OfferPayloadBase offerPayload) { if (offerPayload instanceof BsqSwapOfferPayload) { - var offerViewClass = offerPayload.getDirection() == OfferDirection.BUY ? BuyOfferView.class : SellOfferView.class; - navigation.navigateToWithData(offerPayload, MainView.class, offerViewClass, BsqSwapCreateOfferView.class); + // BUY Bitcoin means SELL BSQ + var offerViewClass = offerPayload.getDirection() == OfferDirection.BUY ? SellOfferView.class : BuyOfferView.class; + navigation.navigateToWithData(offerPayload, MainView.class, offerViewClass, BsqOfferBookView.class, CreateOfferView.class); } else { navigation.navigateToWithData(offerPayload, MainView.class, PortfolioView.class, DuplicateOfferView.class); } From 497158ad13082467a3a3a8145775a45360818af4 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Thu, 7 Apr 2022 21:13:24 +0200 Subject: [PATCH 08/35] Fix rebase errors with master --- .../bisq/core/payment/PaymentAccountUtil.java | 61 +++++++++---------- .../offerbook/BsqOfferBookViewModel.java | 7 ++- .../offerbook/BtcOfferBookViewModel.java | 4 +- .../offerbook/OtherOfferBookViewModel.java | 4 +- .../TopAltcoinOfferBookViewModel.java | 4 +- .../offerbook/OfferBookViewModelTest.java | 22 +++---- 6 files changed, 55 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java index 0d6456a08da..363aea0a0b8 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java @@ -19,7 +19,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.Country; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.payment.payload.PaymentAccountPayload; @@ -141,54 +140,54 @@ public static List getTradeCurrencies(PaymentMethod paymentMethod case STRIKE_ID: return getAllStrikeCurrencies(); case TIKKIE_ID: - return CurrencyUtil.getAllTikkieIdCurrencies(); + return getAllTikkieIdCurrencies(); case ALI_PAY_ID: - return CurrencyUtil.getAllAliPayAccountCurrencies(); + return getAllAliPayAccountCurrencies(); case NEQUI_ID: - return CurrencyUtil.getAllNequiCurrencies(); + return getAllNequiCurrencies(); case IMPS_ID: case NEFT_ID: case PAYTM_ID: case RTGS_ID: case UPI_ID: - return CurrencyUtil.getAllIfscBankCurrencies(); + return getAllIfscBankCurrencies(); case BIZUM_ID: - return CurrencyUtil.getAllBizumCurrencies(); + return getAllBizumCurrencies(); case MONEY_BEAM_ID: - return CurrencyUtil.getAllMoneyBeamCurrencies(); + return getAllMoneyBeamCurrencies(); case PIX_ID: - return CurrencyUtil.getAllPixCurrencies(); + return getAllPixCurrencies(); case SATISPAY_ID: - return CurrencyUtil.getAllSatispayCurrencies(); + return getAllSatispayCurrencies(); case CHASE_QUICK_PAY_ID: - return CurrencyUtil.getAllChaseQuickPayCurrencies(); + return getAllChaseQuickPayCurrencies(); case US_POSTAL_MONEY_ORDER_ID: - return CurrencyUtil.getAllUSPostalMoneyOrderCurrencies(); + return getAllUSPostalMoneyOrderCurrencies(); case VENMO_ID: - return CurrencyUtil.getAllVenmoCurrencies(); + return getAllVenmoCurrencies(); case JAPAN_BANK_ID: - return CurrencyUtil.getAllJapanBankCurrencies(); + return getAllJapanBankCurrencies(); case WECHAT_PAY_ID: - return CurrencyUtil.getAllWeChatPayCurrencies(); + return getAllWeChatPayCurrencies(); case CLEAR_X_CHANGE_ID: - return CurrencyUtil.getAllClearXchangeCurrencies(); + return getAllClearXchangeCurrencies(); case AUSTRALIA_PAYID_ID: - return CurrencyUtil.getAllAustraliaPayidCurrencies(); + return getAllAustraliaPayidCurrencies(); case PERFECT_MONEY_ID: - return CurrencyUtil.getAllPerfectMoneyCurrencies(); + return getAllPerfectMoneyCurrencies(); case HAL_CASH_ID: - return CurrencyUtil.getAllHalCashCurrencies(); + return getAllHalCashCurrencies(); case SWISH_ID: - return CurrencyUtil.getAllSwishCurrencies(); + return getAllSwishCurrencies(); case CASH_APP_ID: - return CurrencyUtil.getAllCashAppCurrencies(); + return getAllCashAppCurrencies(); case POPMONEY_ID: - return CurrencyUtil.getAllPopmoneyCurrencies(); + return getAllPopmoneyCurrencies(); case PROMPT_PAY_ID: - return CurrencyUtil.getAllPromptPayCurrencies(); + return getAllPromptPayCurrencies(); case SEPA_ID: case SEPA_INSTANT_ID: - return CurrencyUtil.getAllSEPACurrencies(); + return getAllSEPACurrencies(); case CASH_BY_MAIL_ID: case F2F_ID: case NATIONAL_BANK_ID: @@ -196,21 +195,21 @@ public static List getTradeCurrencies(PaymentMethod paymentMethod case SPECIFIC_BANKS_ID: case CASH_DEPOSIT_ID: case WESTERN_UNION_ID: - return CurrencyUtil.getAllFiatCurrencies(); + return getAllFiatCurrencies(); case FASTER_PAYMENTS_ID: - return CurrencyUtil.getAllFasterPaymentCurrencies(); + return getAllFasterPaymentCurrencies(); case DOMESTIC_WIRE_TRANSFER_ID: - return CurrencyUtil.getAllDomesticWireTransferCurrencies(); + return getAllDomesticWireTransferCurrencies(); case ACH_TRANSFER_ID: - return CurrencyUtil.getAllACHTransferCurrencies(); + return getAllACHTransferCurrencies(); case CELPAY_ID: - return CurrencyUtil.getAllCelPayCurrencies(); + return getAllCelPayCurrencies(); case MONESE_ID: - return CurrencyUtil.getAllMoneseCurrencies(); + return getAllMoneseCurrencies(); case TRANSFERWISE_USD_ID: - return CurrencyUtil.getAllTransferwiseUSDCurrencies(); + return getAllTransferwiseUSDCurrencies(); case VERSE_ID: - return CurrencyUtil.getAllVerseCurrencies(); + return getAllVerseCurrencies(); default: return Collections.emptyList(); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java index d430b1fafb9..44706bdb8eb 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java @@ -32,6 +32,7 @@ import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.ClosedTradableManager; +import bisq.core.trade.bsq_swap.BsqSwapTradeManager; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.FormattingUtils; @@ -65,14 +66,16 @@ public BsqOfferBookViewModel(User user, P2PService p2PService, PriceFeedService priceFeedService, ClosedTradableManager closedTradableManager, + BsqSwapTradeManager bsqSwapTradeManager, AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, PriceUtil priceUtil, OfferFilterService offerFilterService, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, BsqFormatter bsqFormatter, - BsqWalletService bsqWalletService, CoreApi coreApi) { - super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); + BsqWalletService bsqWalletService, + CoreApi coreApi) { + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, bsqSwapTradeManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); } @Override diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java index 969137feb23..1e18554272f 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java @@ -36,6 +36,7 @@ import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.ClosedTradableManager; +import bisq.core.trade.bsq_swap.BsqSwapTradeManager; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.FormattingUtils; @@ -66,6 +67,7 @@ public BtcOfferBookViewModel(User user, P2PService p2PService, PriceFeedService priceFeedService, ClosedTradableManager closedTradableManager, + BsqSwapTradeManager bsqSwapTradeManager, AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, PriceUtil priceUtil, @@ -73,7 +75,7 @@ public BtcOfferBookViewModel(User user, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, BsqFormatter bsqFormatter, BsqWalletService bsqWalletService, CoreApi coreApi) { - super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, bsqSwapTradeManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); } @Override diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java index 72fb9b4108f..26c6347632b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java @@ -34,6 +34,7 @@ import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.ClosedTradableManager; +import bisq.core.trade.bsq_swap.BsqSwapTradeManager; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.FormattingUtils; @@ -68,6 +69,7 @@ public OtherOfferBookViewModel(User user, P2PService p2PService, PriceFeedService priceFeedService, ClosedTradableManager closedTradableManager, + BsqSwapTradeManager bsqSwapTradeManager, AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, PriceUtil priceUtil, @@ -75,7 +77,7 @@ public OtherOfferBookViewModel(User user, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, BsqFormatter bsqFormatter, BsqWalletService bsqWalletService, CoreApi coreApi) { - super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, bsqSwapTradeManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); } @Override diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java index 956e5d90b35..e3392c057bc 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java @@ -32,6 +32,7 @@ import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.ClosedTradableManager; +import bisq.core.trade.bsq_swap.BsqSwapTradeManager; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.FormattingUtils; @@ -64,6 +65,7 @@ public TopAltcoinOfferBookViewModel(User user, P2PService p2PService, PriceFeedService priceFeedService, ClosedTradableManager closedTradableManager, + BsqSwapTradeManager bsqSwapTradeManager, AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, PriceUtil priceUtil, @@ -72,7 +74,7 @@ public TopAltcoinOfferBookViewModel(User user, BsqFormatter bsqFormatter, BsqWalletService bsqWalletService, CoreApi coreApi) { - super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); + super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, bsqSwapTradeManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); } @Override diff --git a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java index 01288ca0f27..0a70c5acd11 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java @@ -239,7 +239,7 @@ public void testMaxCharactersForAmountWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForAmount.intValue()); } @@ -253,7 +253,7 @@ public void testMaxCharactersForAmount() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(6, model.maxPlacesForAmount.intValue()); @@ -271,7 +271,7 @@ public void testMaxCharactersForAmountRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(15, model.maxPlacesForAmount.intValue()); @@ -290,7 +290,7 @@ public void testMaxCharactersForVolumeWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForVolume.intValue()); } @@ -304,7 +304,7 @@ public void testMaxCharactersForVolume() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(5, model.maxPlacesForVolume.intValue()); @@ -322,7 +322,7 @@ public void testMaxCharactersForVolumeRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(9, model.maxPlacesForVolume.intValue()); @@ -341,7 +341,7 @@ public void testMaxCharactersForPriceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForPrice.intValue()); } @@ -355,7 +355,7 @@ public void testMaxCharactersForPrice() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(7, model.maxPlacesForPrice.intValue()); @@ -373,7 +373,7 @@ public void testMaxCharactersForPriceDistanceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue()); } @@ -408,7 +408,7 @@ public void testMaxCharactersForPriceDistance() { offerBookListItems.addAll(item1, item2); final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue()); //" (1.97%)" @@ -429,7 +429,7 @@ public void testGetPrice() { when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true)); final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, - null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); final OfferBookListItem item = make(btcBuyItem.but( with(useMarketBasedPrice, true), From 33725c2b4ecac501a16b1e53d7858f5302dbc2a3 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 8 Apr 2022 17:49:33 +0200 Subject: [PATCH 09/35] Adapt navigation labels back to currency code and fix lots of minor issues --- .../resources/i18n/displayStrings.properties | 2 +- .../bisq/desktop/main/offer/BuyOfferView.java | 2 -- .../bisq/desktop/main/offer/OfferView.java | 16 +++++++++------- .../main/offer/bisq_v1/MutableOfferView.java | 8 ++++---- .../main/offer/bisq_v1/OfferViewUtil.java | 9 +++++++++ .../bisq_v1/takeoffer/TakeOfferView.java | 2 +- .../create_offer/BsqSwapCreateOfferView.java | 19 +++++++++++++------ .../take_offer/BsqSwapTakeOfferView.java | 2 +- .../offer/offerbook/BsqOfferBookView.java | 6 +++--- .../offer/offerbook/BtcOfferBookView.java | 8 ++++---- .../main/offer/offerbook/OfferBookView.java | 6 +++--- .../offer/offerbook/OtherOfferBookView.java | 8 ++++---- .../offerbook/OtherOfferBookViewModel.java | 7 +++---- .../offerbook/TopAltcoinOfferBookView.java | 8 ++++---- .../windows/BsqSwapOfferDetailsWindow.java | 11 +++++------ .../overlays/windows/OfferDetailsWindow.java | 10 +++++----- 16 files changed, 69 insertions(+), 55 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 1e556868a09..15824a99a98 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -198,6 +198,7 @@ shared.openURL=Open {0} shared.fiat=Fiat shared.crypto=Crypto shared.otherAssets=other assets +shared.other=Other shared.all=All shared.edit=Edit shared.advancedOptions=Advanced options @@ -383,7 +384,6 @@ offerbook.createNewOffer=Create new offer to {0} {1} offerbook.createOfferDisabled.tooltip=You can only create one offer at a time offerbook.takeOfferButton.tooltip=Take offer for {0} -offerbook.yesCreateOffer=Yes, create offer offerbook.setupNewAccount=Set up a new trading account offerbook.removeOffer.success=Remove offer was successful. offerbook.removeOffer.failed=Remove offer failed:\n{0} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java index e72e44b4a7e..247420183d1 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java @@ -22,7 +22,6 @@ import bisq.desktop.common.view.ViewLoader; import bisq.core.offer.OfferDirection; -import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager; import bisq.core.user.Preferences; import bisq.core.user.User; @@ -37,7 +36,6 @@ public class BuyOfferView extends OfferView { public BuyOfferView(ViewLoader viewLoader, Navigation navigation, Preferences preferences, - ArbitratorManager arbitratorManager, User user, P2PService p2PService) { super(viewLoader, diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index 46e2f912900..95ef6b9d67f 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -22,6 +22,7 @@ import bisq.desktop.common.view.View; import bisq.desktop.common.view.ViewLoader; import bisq.desktop.main.MainView; +import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.offer.bisq_v1.createoffer.CreateOfferView; import bisq.desktop.main.offer.bisq_v1.takeoffer.TakeOfferView; import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView; @@ -31,13 +32,13 @@ import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookView; import bisq.desktop.main.offer.offerbook.OtherOfferBookView; -import bisq.desktop.main.offer.offerbook.OtherOfferBookViewModel; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.GUIUtil; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.GlobalSettings; +import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferDirection; @@ -205,6 +206,7 @@ private void loadView(Class viewClass, } else if (data instanceof BsqSwapOfferPayload) { loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, PaymentMethod.BSQ_SWAP, (BsqSwapOfferPayload) data); } else { + tradeCurrency = BsqOfferBookViewModel.BSQ; loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(bsqOfferBookTab); @@ -214,6 +216,7 @@ private void loadView(Class viewClass, } else if (childViewClass == TakeOfferView.class) { loadTakeViewClass(viewClass, childViewClass, topAltcoinOfferBookTab); } else { + tradeCurrency = TopAltcoinOfferBookViewModel.TOP_ALTCOIN; loadCreateViewClass(topAltcoinOfferBookView, viewClass, childViewClass, topAltcoinOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(topAltcoinOfferBookTab); @@ -228,21 +231,20 @@ private void loadView(Class viewClass, Optional tradeCurrencyOptional = (this.direction == OfferDirection.SELL) ? CurrencyUtil.getTradeCurrency(preferences.getSellScreenCryptoCurrencyCode()) : CurrencyUtil.getTradeCurrency(preferences.getBuyScreenCryptoCurrencyCode()); - tradeCurrency = tradeCurrencyOptional.isEmpty() ? OtherOfferBookViewModel.DEFAULT_ALTCOIN : tradeCurrencyOptional.get(); + tradeCurrency = tradeCurrencyOptional.isEmpty() ? OfferViewUtil.getAnyOfMainCryptoCurrencies() : tradeCurrencyOptional.get(); } loadCreateViewClass(otherOfferBookView, viewClass, childViewClass, otherOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(otherOfferBookTab); } else { if (btcOfferBookTab == null) { - //TODO: use naming from currencies or from translations - btcOfferBookTab = new Tab("BITCOIN"); + btcOfferBookTab = new Tab(Res.getBaseCurrencyName().toUpperCase()); btcOfferBookTab.setClosable(false); - bsqOfferBookTab = new Tab("BSQ"); + bsqOfferBookTab = new Tab(BsqOfferBookViewModel.BSQ.getCode()); bsqOfferBookTab.setClosable(false); - topAltcoinOfferBookTab = new Tab("MONERO"); + topAltcoinOfferBookTab = new Tab(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()); topAltcoinOfferBookTab.setClosable(false); - otherOfferBookTab = new Tab("OTHER"); + otherOfferBookTab = new Tab(Res.get("shared.other").toUpperCase()); otherOfferBookTab.setClosable(false); tabPane.getTabs().addAll(btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index 1a500404248..6d4b5911686 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -337,7 +337,7 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency, if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) { placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.buy")); } else { - placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), tradeCurrency.getName()); + placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), tradeCurrency.getCode()); } placeOfferButton.updateText(placeOfferButtonLabel); nextButton.setId("buy-button"); @@ -347,7 +347,7 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency, if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) { placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.sell")); } else { - placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), tradeCurrency.getName()); + placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), tradeCurrency.getCode()); } nextButton.setId("sell-button"); fundFromSavingsWalletButton.setId("sell-button"); @@ -793,10 +793,10 @@ private void createListeners() { if (!CurrencyUtil.isFiatCurrency(newValue)) { if (model.isShownAsBuyOffer()) { placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), - model.getTradeCurrency().getName())); + model.getTradeCurrency().getCode())); } else { placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), - model.getTradeCurrency().getName())); + model.getTradeCurrency().getCode())); } } }; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java index 2d7b37fae9e..773d799fe37 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java @@ -24,6 +24,8 @@ import bisq.desktop.main.MainView; import bisq.desktop.main.offer.SellOfferView; import bisq.desktop.main.offer.offerbook.BsqOfferBookView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.CurrencyUtil; @@ -46,6 +48,7 @@ import javafx.geometry.VPos; import java.util.HashMap; +import java.util.Objects; import java.util.concurrent.TimeUnit; // Shared utils for Views @@ -133,4 +136,10 @@ public static boolean isShownAsBuyOffer(Offer offer) { public static boolean isShownAsBuyOffer(OfferDirection direction, TradeCurrency tradeCurrency) { return !isShownAsSellOffer(tradeCurrency.getCode(), direction); } + + public static TradeCurrency getAnyOfMainCryptoCurrencies() { + return CurrencyUtil.getMainCryptoCurrencies().stream().filter(cryptoCurrency -> + !Objects.equals(cryptoCurrency.getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()) && + !Objects.equals(cryptoCurrency.getCode(), BsqOfferBookViewModel.BSQ.getCode())).findAny().get(); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index a507c073d8c..12dfeb7a442 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -1351,7 +1351,7 @@ private String getTakeOfferLabel(Offer offer, String direction) { Res.get("takeOffer.takeOfferButton", direction) : Res.get("takeOffer.takeOfferButtonAltcoin", direction, - CurrencyUtil.getNameByCode(offer.getCurrencyCode())); + offer.getCurrencyCode()); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index 2e9c97a6af7..27f8d5a892a 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -27,7 +27,9 @@ import bisq.desktop.main.MainView; import bisq.desktop.main.offer.OfferView; import bisq.desktop.main.offer.SelectableView; +import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; import bisq.desktop.main.portfolio.PortfolioView; @@ -168,16 +170,21 @@ public void initWithData(OfferDirection direction, @Nullable BsqSwapOfferPayload offerPayload) { this.offerActionHandler = offerActionHandler; - model.initWithData(offerPayload != null ? offerPayload.getDirection() : direction, offerPayload); + // Invert direction for non-Fiat trade currencies -> BUY BSQ is to SELL Bitcoin + OfferDirection offerDirection = direction == OfferDirection.BUY ? OfferDirection.SELL : OfferDirection.BUY; - if (model.dataModel.isBuyOffer()) { + model.initWithData(offerPayload != null ? offerPayload.getDirection() : offerDirection, offerPayload); + + if (OfferViewUtil.isShownAsBuyOffer(offerDirection, BsqOfferBookViewModel.BSQ)) { actionButton.setId("buy-button-big"); - actionButton.updateText(Res.get("createOffer.placeOfferButton", Res.get("shared.buy"))); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); + actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), BSQ)); + nextButton.setId("buy-button"); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); } else { actionButton.setId("sell-button-big"); - actionButton.updateText(Res.get("createOffer.placeOfferButton", Res.get("shared.sell"))); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); + actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), BSQ)); + nextButton.setId("sell-button"); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); } String amountDescription = Res.get("createOffer.amountPriceBox.amountDescription", diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java index d7d0c16f245..a440317cde8 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java @@ -163,8 +163,8 @@ public void initWithData(Offer offer) { amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescription")); } else { actionButton.setId("sell-button-big"); - nextButton.setId("sell-button"); actionButton.updateText(Res.get("takeOffer.takeOfferButtonAltcoin", Res.get("shared.sell"), BSQ)); + nextButton.setId("sell-button"); volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java index 46c86fdadf4..c66dc7b35a8 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java @@ -58,8 +58,8 @@ public class BsqOfferBookView extends OfferBookView getCurrencyAndMethodPredicate(OfferDirection direct @Override TradeCurrency getDefaultTradeCurrency() { - // select first currency in list, otherwise if view is not initialized add Ether as default one + // select first currency in list, otherwise if view is not initialized any of the main crypto currencies return !getTradeCurrencies().isEmpty() ? getTradeCurrencies().get(1) : - DEFAULT_ALTCOIN; + OfferViewUtil.getAnyOfMainCryptoCurrencies(); } @Override diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java index 081f0caf6e1..1a1644a738c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java @@ -56,8 +56,8 @@ public class TopAltcoinOfferBookView extends OfferBookView Date: Fri, 8 Apr 2022 18:02:27 +0200 Subject: [PATCH 10/35] Fix BSQ swap labels --- .../bsq_swap/create_offer/BsqSwapCreateOfferView.java | 2 ++ .../offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index 27f8d5a892a..07d511b21c0 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -180,11 +180,13 @@ public void initWithData(OfferDirection direction, actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), BSQ)); nextButton.setId("buy-button"); volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); } else { actionButton.setId("sell-button-big"); actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), BSQ)); nextButton.setId("sell-button"); volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescription")); } String amountDescription = Res.get("createOffer.amountPriceBox.amountDescription", diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java index a440317cde8..df290047684 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java @@ -159,14 +159,14 @@ public void initWithData(Offer offer) { actionButton.setId("buy-button-big"); actionButton.updateText(Res.get("takeOffer.takeOfferButtonAltcoin", Res.get("shared.buy"), BSQ)); nextButton.setId("buy-button"); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); - amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescription")); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); } else { actionButton.setId("sell-button-big"); actionButton.updateText(Res.get("takeOffer.takeOfferButtonAltcoin", Res.get("shared.sell"), BSQ)); nextButton.setId("sell-button"); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); - amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescription")); } paymentMethodTextField.setText(PaymentMethod.BSQ_SWAP.getDisplayString()); From 98285da146fc47594087eec7f048a31005b00a83 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 10:29:27 +0200 Subject: [PATCH 11/35] Move OfferViewUtil --- .../bisq/desktop/main/offer/OfferView.java | 1 - .../offer/{bisq_v1 => }/OfferViewUtil.java | 21 +++++++++++++++++-- .../main/offer/bisq_v1/MutableOfferView.java | 3 ++- .../offer/bisq_v1/MutableOfferViewModel.java | 1 + .../bisq_v1/takeoffer/TakeOfferView.java | 4 ++-- .../create_offer/BsqSwapCreateOfferView.java | 2 +- .../take_offer/BsqSwapTakeOfferView.java | 2 +- .../main/offer/offerbook/OfferBookView.java | 2 +- .../offerbook/OtherOfferBookViewModel.java | 2 +- .../windows/BsqSwapOfferDetailsWindow.java | 2 +- .../overlays/windows/OfferDetailsWindow.java | 2 +- 11 files changed, 30 insertions(+), 12 deletions(-) rename desktop/src/main/java/bisq/desktop/main/offer/{bisq_v1 => }/OfferViewUtil.java (85%) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index 95ef6b9d67f..d5b797efc80 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -22,7 +22,6 @@ import bisq.desktop.common.view.View; import bisq.desktop.common.view.ViewLoader; import bisq.desktop.main.MainView; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.offer.bisq_v1.createoffer.CreateOfferView; import bisq.desktop.main.offer.bisq_v1.takeoffer.TakeOfferView; import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java similarity index 85% rename from desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java rename to desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java index 773d799fe37..9dafa669aee 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java @@ -15,16 +15,19 @@ * along with Bisq. If not, see . */ -package bisq.desktop.main.offer.bisq_v1; +package bisq.desktop.main.offer; import bisq.desktop.Navigation; import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.AutoTooltipLabel; import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.main.MainView; -import bisq.desktop.main.offer.SellOfferView; import bisq.desktop.main.offer.offerbook.BsqOfferBookView; import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; +import bisq.desktop.main.offer.offerbook.BtcOfferBookView; +import bisq.desktop.main.offer.offerbook.OfferBookView; +import bisq.desktop.main.offer.offerbook.OtherOfferBookView; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.overlays.popups.Popup; @@ -121,6 +124,20 @@ private static void openBuyBsqOfferBook(Navigation navigation) { MainView.class, SellOfferView.class, BsqOfferBookView.class); } + public static Class> getOfferBookViewClass(String currencyCode) { + Class> offerBookViewClazz; + if (CurrencyUtil.isFiatCurrency(currencyCode)) { + offerBookViewClazz = BtcOfferBookView.class; + } else if (currencyCode.equals(BsqOfferBookViewModel.BSQ.getCode())) { + offerBookViewClazz = BsqOfferBookView.class; + } else if (currencyCode.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + offerBookViewClazz = TopAltcoinOfferBookView.class; + } else { + offerBookViewClazz = OtherOfferBookView.class; + } + return offerBookViewClazz; + } + public static boolean isShownAsSellOffer(Offer offer) { return isShownAsSellOffer(offer.getCurrencyCode(), offer.getDirection()); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index 6d4b5911686..cfc045b62fe 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -37,6 +37,7 @@ import bisq.desktop.main.dao.wallet.receive.BsqReceiveView; import bisq.desktop.main.offer.ClosableView; import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.offer.SelectableView; import bisq.desktop.main.overlays.notifications.Notification; import bisq.desktop.main.overlays.popups.Popup; @@ -124,7 +125,7 @@ import org.jetbrains.annotations.NotNull; import static bisq.core.payment.payload.PaymentMethod.HAL_CASH_ID; -import static bisq.desktop.main.offer.bisq_v1.OfferViewUtil.addPayInfoEntry; +import static bisq.desktop.main.offer.OfferViewUtil.addPayInfoEntry; import static bisq.desktop.util.FormBuilder.*; import static javafx.beans.binding.Bindings.createStringBinding; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java index b0e10fd42cd..bd6cd386237 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java @@ -22,6 +22,7 @@ import bisq.desktop.main.MainView; import bisq.desktop.main.funds.FundsView; import bisq.desktop.main.funds.deposit.DepositView; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.settings.SettingsView; import bisq.desktop.main.settings.preferences.PreferencesView; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index 12dfeb7a442..0294b100cd5 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -39,8 +39,8 @@ import bisq.desktop.main.offer.ClosableView; import bisq.desktop.main.offer.InitializableViewWithTakeOfferData; import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.offer.SelectableView; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.overlays.notifications.Notification; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.GenericMessageWindow; @@ -119,7 +119,7 @@ import org.jetbrains.annotations.NotNull; -import static bisq.desktop.main.offer.bisq_v1.OfferViewUtil.addPayInfoEntry; +import static bisq.desktop.main.offer.OfferViewUtil.addPayInfoEntry; import static bisq.desktop.util.FormBuilder.*; import static javafx.beans.binding.Bindings.createStringBinding; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index 07d511b21c0..be66dd890d1 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -26,8 +26,8 @@ import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.MainView; import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.offer.SelectableView; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView; import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.overlays.popups.Popup; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java index df290047684..4f92ccb9c0b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java @@ -26,8 +26,8 @@ import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.MainView; import bisq.desktop.main.offer.InitializableViewWithTakeOfferData; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.offer.SelectableView; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index 57dbdcad872..baa1df48bcb 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -37,7 +37,7 @@ import bisq.desktop.main.funds.FundsView; import bisq.desktop.main.funds.withdrawal.WithdrawalView; import bisq.desktop.main.offer.OfferView; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; import bisq.desktop.main.overlays.windows.OfferDetailsWindow; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java index 6d4cc4d43d7..6751f8cfa12 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java @@ -18,7 +18,7 @@ package bisq.desktop.main.offer.offerbook; import bisq.desktop.Navigation; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.util.GUIUtil; import bisq.core.account.witness.AccountAgeWitnessService; diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java index 2407021238d..38d9abf843f 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java @@ -19,7 +19,7 @@ import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.BusyAnimation; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.Layout; diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java index 4fd12f53c40..0adefbfd82e 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java @@ -22,7 +22,7 @@ import bisq.desktop.components.BusyAnimation; import bisq.desktop.components.TitledGroupBg; import bisq.desktop.components.TxIdTextField; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; From b7344206686372ef974687dc769fb970836c679a Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 10:30:18 +0200 Subject: [PATCH 12/35] Fix navigation to specific offer book view --- .../market/offerbook/OfferBookChartView.java | 60 ++----------------- .../offerbook/OfferBookChartViewModel.java | 35 ++++++++++- 2 files changed, 38 insertions(+), 57 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java index 16b6a066dd4..b7c8c567b47 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartView.java @@ -17,7 +17,6 @@ package bisq.desktop.main.market.offerbook; -import bisq.desktop.Navigation; import bisq.desktop.common.view.ActivatableViewAndModel; import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.AutoTooltipButton; @@ -26,17 +25,7 @@ import bisq.desktop.components.AutocompleteComboBox; import bisq.desktop.components.ColoredDecimalPlacesWithZerosText; import bisq.desktop.components.PeerInfoIconSmall; -import bisq.desktop.main.MainView; -import bisq.desktop.main.offer.BuyOfferView; -import bisq.desktop.main.offer.SellOfferView; -import bisq.desktop.main.offer.offerbook.BsqOfferBookView; -import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; -import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookListItem; -import bisq.desktop.main.offer.offerbook.OfferBookView; -import bisq.desktop.main.offer.offerbook.OtherOfferBookView; -import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; -import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.CurrencyListItem; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -113,7 +102,6 @@ public class OfferBookChartView extends ActivatableViewAndModel seriesBuy, seriesSell; - private final Navigation navigation; private final CoinFormatter formatter; private TableView buyOfferTableView; private TableView sellOfferTableView; @@ -147,11 +135,9 @@ public class OfferBookChartView extends ActivatableViewAndModel { - - model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode()); - navigation.navigateTo(MainView.class, SellOfferView.class); - }; - sellTableRowSelectionListener = (observable, oldValue, newValue) -> { - model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode()); - navigation.navigateTo(MainView.class, BuyOfferView.class); - }; + buyTableRowSelectionListener = (observable, oldValue, newValue) -> model.goToOfferView(OfferDirection.BUY); + sellTableRowSelectionListener = (observable, oldValue, newValue) -> model.goToOfferView(OfferDirection.SELL); bisqWindowVerticalSizeListener = (observable, oldValue, newValue) -> layout(); } @@ -592,7 +571,7 @@ public void updateItem(final OfferListItem offerListItem, boolean empty) { } }); - boolean isSellOffer = direction == OfferDirection.SELL; + boolean isSellOffer = model.isSellOffer(direction); // trader avatar TableColumn avatarColumn = new AutoTooltipTableColumn<>(isSellOffer ? @@ -659,38 +638,7 @@ public void updateItem(final OfferListItem newItem, boolean empty) { button.updateText(isSellOffer ? Res.get("market.offerBook.buy") : Res.get("market.offerBook.sell")); button.setMinHeight(32); button.setId(isSellOffer ? "buy-button-big" : "sell-button-big"); - button.setOnAction(e -> { - Class> offerBookViewClazz; - if (CurrencyUtil.isFiatCurrency(model.getCurrencyCode())) { - offerBookViewClazz = BtcOfferBookView.class; - } else if (model.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode())) { - offerBookViewClazz = BsqOfferBookView.class; - } else if (model.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { - offerBookViewClazz = TopAltcoinOfferBookView.class; - } else { - offerBookViewClazz = OtherOfferBookView.class; - } - - if (isSellOffer) { - if (CurrencyUtil.isFiatCurrency(model.getCurrencyCode())) { - model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode()); - } else if (!model.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && - model.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { - model.preferences.setBuyScreenCryptoCurrencyCode(model.getCurrencyCode()); - } - - navigation.navigateTo(MainView.class, BuyOfferView.class, offerBookViewClazz); - } else { - if (CurrencyUtil.isFiatCurrency(model.getCurrencyCode())) { - model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode()); - } else if (!model.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && - model.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { - model.preferences.setSellScreenCryptoCurrencyCode(model.getCurrencyCode()); - } - - navigation.navigateTo(MainView.class, SellOfferView.class, offerBookViewClazz); - } - }); + button.setOnAction(e -> model.goToOfferView(direction)); Region spacer = new Region(); diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java index db48b2e9b99..e3a17e23d6c 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java @@ -20,8 +20,14 @@ import bisq.desktop.Navigation; import bisq.desktop.common.model.ActivatableViewModel; import bisq.desktop.main.MainView; +import bisq.desktop.main.offer.BuyOfferView; +import bisq.desktop.main.offer.OfferView; +import bisq.desktop.main.offer.OfferViewUtil; +import bisq.desktop.main.offer.SellOfferView; +import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.offer.offerbook.OfferBook; import bisq.desktop.main.offer.offerbook.OfferBookListItem; +import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.settings.SettingsView; import bisq.desktop.main.settings.preferences.PreferencesView; import bisq.desktop.util.CurrencyList; @@ -194,11 +200,20 @@ public void onSetTradeCurrency(TradeCurrency tradeCurrency) { } } - void setSelectedTabIndex(int selectedTabIndex) { + public void setSelectedTabIndex(int selectedTabIndex) { this.selectedTabIndex = selectedTabIndex; syncPriceFeedCurrency(); } + public boolean isSellOffer(OfferDirection direction) { + return direction == OfferDirection.SELL; + } + + public void goToOfferView(OfferDirection direction) { + updateScreenCurrencyInPreferences(direction); + Class offerView = isSellOffer(direction) ? BuyOfferView.class : SellOfferView.class; + navigation.navigateTo(MainView.class, offerView, OfferViewUtil.getOfferBookViewClass(getCurrencyCode())); + } /////////////////////////////////////////////////////////////////////////////////////////// // Getters @@ -393,4 +408,22 @@ private void buildChartAndTableEntries(List sortedList, private boolean isEditEntry(String id) { return id.equals(GUIUtil.EDIT_FLAG); } + + private void updateScreenCurrencyInPreferences(OfferDirection direction) { + if (isSellOffer(direction)) { + if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) { + preferences.setBuyScreenCurrencyCode(getCurrencyCode()); + } else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && + getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + preferences.setBuyScreenCryptoCurrencyCode(getCurrencyCode()); + } + } else { + if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) { + preferences.setSellScreenCurrencyCode(getCurrencyCode()); + } else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && + getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + preferences.setSellScreenCryptoCurrencyCode(getCurrencyCode()); + } + } + } } From 5b67766109cfe96e8ab2db9580b02aee9b548a74 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 10:46:05 +0200 Subject: [PATCH 13/35] Properly rename main navigation Otherwise it would display the old 'Buy BTC' and 'Sell BTC' navigation --- core/src/main/resources/i18n/displayStrings.properties | 4 ++-- desktop/src/main/java/bisq/desktop/main/MainView.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 15824a99a98..d880a581b80 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -234,8 +234,8 @@ shared.enabled=Enabled #################################################################### mainView.menu.market=Market -mainView.menu.buyBtc=Buy -mainView.menu.sellBtc=Sell +mainView.menu.buy=Buy +mainView.menu.sell=Sell mainView.menu.portfolio=Portfolio mainView.menu.funds=Funds mainView.menu.support=Support diff --git a/desktop/src/main/java/bisq/desktop/main/MainView.java b/desktop/src/main/java/bisq/desktop/main/MainView.java index 72d6a362633..77a0c2154f9 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainView.java +++ b/desktop/src/main/java/bisq/desktop/main/MainView.java @@ -177,8 +177,8 @@ protected void initialize() { 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.buyBtc").toUpperCase()); - ToggleButton sellButton = new NavButton(SellOfferView.class, Res.get("mainView.menu.sellBtc").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 portfolioButton = new NavButton(PortfolioView.class, Res.get("mainView.menu.portfolio").toUpperCase()); ToggleButton fundsButton = new NavButton(FundsView.class, Res.get("mainView.menu.funds").toUpperCase()); From 1712f7498e58f907929f147c6cdede2610a6b406 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 11:05:36 +0200 Subject: [PATCH 14/35] Use BSQ Swap as default when BSQ offer is created --- .../src/main/java/bisq/desktop/main/offer/OfferView.java | 7 +++++-- .../desktop/main/offer/offerbook/OfferBookViewModel.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index d5b797efc80..dc757f9fe8c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -291,12 +291,15 @@ private void loadCreateViewClass(OfferBookView offerBookView, return; } - View view = viewLoader.load(paymentMethod != null && paymentMethod.isBsqSwap() ? BsqSwapCreateOfferView.class : childViewClass); + View view; // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times // in different graphs - if (paymentMethod != null && paymentMethod.isBsqSwap()) { + if ((paymentMethod != null && paymentMethod.isBsqSwap()) || + (paymentMethod == null && viewClass.isAssignableFrom(BsqOfferBookView.class))) { + view = viewLoader.load(BsqSwapCreateOfferView.class); ((BsqSwapCreateOfferView) view).initWithData(direction, offerActionHandler, payload); } else { + view = viewLoader.load(childViewClass); ((CreateOfferView) view).initWithData(direction, tradeCurrency, offerActionHandler); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index e1f34fe8898..b91adb4d56c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -296,7 +296,7 @@ else if (!showAllEntry) { abstract void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code); - void onSetPaymentMethod(PaymentMethod paymentMethod) { + protected void onSetPaymentMethod(PaymentMethod paymentMethod) { if (paymentMethod == null) return; @@ -613,7 +613,7 @@ private boolean isEditEntry(String id) { return id.equals(GUIUtil.EDIT_FLAG); } - int getNumTrades(Offer offer) { + public int getNumTrades(Offer offer) { return Stream.concat(closedTradableManager.getTradableList().stream(), bsqSwapTradeManager.getTradableList().stream()) .filter(e -> e instanceof Trade || e instanceof BsqSwapTrade) // weed out canceled offers .filter(e -> { From 492ff35b093a0f6cf7a211c0003ed59dcf790433 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 11:32:55 +0200 Subject: [PATCH 15/35] Adapt amount and volume description for take offer --- core/src/main/java/bisq/core/offer/Offer.java | 6 ++++- .../resources/i18n/displayStrings.properties | 4 +++ .../bisq_v1/takeoffer/TakeOfferView.java | 27 +++++++++---------- .../bisq_v1/takeoffer/TakeOfferViewModel.java | 18 ++++++++++--- .../take_offer/BsqSwapTakeOfferView.java | 8 +++--- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java index 121d5108e47..37cece17724 100644 --- a/core/src/main/java/bisq/core/offer/Offer.java +++ b/core/src/main/java/bisq/core/offer/Offer.java @@ -179,7 +179,7 @@ public void cancelAvailabilityRequest() { public Price getPrice() { String currencyCode = getCurrencyCode(); Optional optionalOfferPayload = getOfferPayload(); - if (!optionalOfferPayload.isPresent()) { + if (optionalOfferPayload.isEmpty()) { return Price.valueOf(currencyCode, offerPayloadBase.getPrice()); } @@ -562,6 +562,10 @@ public Optional getOfferPayload() { return Optional.empty(); } + public boolean isFiatOffer() { + return CurrencyUtil.isFiatCurrency(currencyCode); + } + public Optional getBsqSwapOfferPayload() { if (offerPayloadBase instanceof BsqSwapOfferPayload) { return Optional.of((BsqSwapOfferPayload) offerPayloadBase); diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index d880a581b80..b17a92985ae 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -456,6 +456,8 @@ createOffer.volume.prompt=Enter amount in {0} createOffer.amountPriceBox.amountDescription=Amount of BTC to {0} createOffer.amountPriceBox.buy.volumeDescription=Amount in {0} to spend createOffer.amountPriceBox.sell.volumeDescription=Amount in {0} to receive +createOffer.amountPriceBox.buy.volumeDescriptionAltcoin=Amount in {0} to sell +createOffer.amountPriceBox.sell.volumeDescriptionAltcoin=Amount in {0} to buy createOffer.amountPriceBox.minAmountDescription=Minimum amount of BTC createOffer.securityDeposit.prompt=Security deposit createOffer.fundsBox.title=Fund your offer @@ -549,6 +551,8 @@ createOffer.bsqSwap.mintingPow=Creating proof of work... takeOffer.amount.prompt=Enter amount in BTC takeOffer.amountPriceBox.buy.amountDescription=Amount of BTC to sell takeOffer.amountPriceBox.sell.amountDescription=Amount of BTC to buy +takeOffer.amountPriceBox.buy.amountDescriptionAltcoin=Amount of BTC to spend +takeOffer.amountPriceBox.sell.amountDescriptionAltcoin=Amount of BTC to receive takeOffer.amountPriceBox.priceDescription=Price per bitcoin in {0} takeOffer.amountPriceBox.amountRangeDescription=Possible amount range takeOffer.amountPriceBox.warning.invalidBtcDecimalPlaces=The amount you have entered exceeds the number of allowed decimal places.\nThe amount has been adjusted to 4 decimal places. diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index 0294b100cd5..ec7fe475a92 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -133,7 +133,8 @@ public class TakeOfferView extends ActivatableViewAndModel, Label, TextField, HBox> paymentAccountTuple = addComboBoxTopLabelTextField(gridPane, @@ -922,9 +923,7 @@ private void nextStepCheckMakerTx() { int result = model.dataModel.mempoolStatus.get(); if (result == 0) { new Popup().warning(Res.get("popup.warning.makerTxInvalid") + model.dataModel.getMempoolStatusText()) - .onClose(() -> { - cancelButton1.fire(); - }) + .onClose(() -> cancelButton1.fire()) .show(); } else { if (result == -1) { @@ -1294,16 +1293,14 @@ private void maybeShowCashByMailWarning(PaymentAccount paymentAccount, Offer off if (paymentAccount.getPaymentMethod().getId().equals(PaymentMethod.CASH_BY_MAIL_ID) && !cashByMailWarningDisplayed && !offer.getExtraInfo().isEmpty()) { cashByMailWarningDisplayed = true; - UserThread.runAfter(() -> { - new GenericMessageWindow() - .preamble(Res.get("payment.cashByMail.tradingRestrictions")) - .instruction(offer.getExtraInfo()) - .actionButtonText(Res.get("shared.iConfirm")) - .closeButtonText(Res.get("shared.close")) - .width(Layout.INITIAL_WINDOW_WIDTH) - .onClose(() -> close(false)) - .show(); - }, 500, TimeUnit.MILLISECONDS); + UserThread.runAfter(() -> new GenericMessageWindow() + .preamble(Res.get("payment.cashByMail.tradingRestrictions")) + .instruction(offer.getExtraInfo()) + .actionButtonText(Res.get("shared.iConfirm")) + .closeButtonText(Res.get("shared.close")) + .width(Layout.INITIAL_WINDOW_WIDTH) + .onClose(() -> close(false)) + .show(), 500, TimeUnit.MILLISECONDS); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java index 5d8c180d351..228cb91ca45 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java @@ -201,9 +201,14 @@ void initWithData(Offer offer) { dataModel.initWithData(offer); this.offer = offer; + String buyAmountDescriptionKey = offer.isFiatOffer() ? "takeOffer.amountPriceBox.buy.amountDescription" : + "takeOffer.amountPriceBox.buy.amountDescriptionAltcoin"; + String sellAmountDescriptionKey = offer.isFiatOffer() ? "takeOffer.amountPriceBox.sell.amountDescription" : + "takeOffer.amountPriceBox.sell.amountDescriptionAltcoin"; + amountDescription = offer.isBuyOffer() - ? Res.get("takeOffer.amountPriceBox.buy.amountDescription") - : Res.get("takeOffer.amountPriceBox.sell.amountDescription"); + ? Res.get(buyAmountDescriptionKey) + : Res.get(sellAmountDescriptionKey); amountRange = btcFormatter.formatCoin(offer.getMinAmount()) + " - " + btcFormatter.formatCoin(offer.getAmount()); price = FormattingUtils.formatPrice(dataModel.tradePrice); @@ -478,10 +483,15 @@ private void updateButtonDisableState() { private void addBindings() { volume.bind(createStringBinding(() -> VolumeUtil.formatVolume(dataModel.volume.get()), dataModel.volume)); + String buyVolumeDescriptionKey = offer.isFiatOffer() ? "createOffer.amountPriceBox.buy.volumeDescription" : + "createOffer.amountPriceBox.buy.volumeDescriptionAltcoin"; + String sellVolumeDescriptionKey = offer.isFiatOffer() ? "createOffer.amountPriceBox.sell.volumeDescription" : + "createOffer.amountPriceBox.sell.volumeDescriptionAltcoin"; + if (dataModel.getDirection() == OfferDirection.SELL) { - volumeDescriptionLabel.set(Res.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getCurrencyCode())); + volumeDescriptionLabel.set(Res.get(buyVolumeDescriptionKey, dataModel.getCurrencyCode())); } else { - volumeDescriptionLabel.set(Res.get("createOffer.amountPriceBox.sell.volumeDescription", dataModel.getCurrencyCode())); + volumeDescriptionLabel.set(Res.get(sellVolumeDescriptionKey, dataModel.getCurrencyCode())); } totalToPay.bind(createStringBinding(() -> btcFormatter.formatCoinWithCode(dataModel.getTotalToPayAsCoin().get()), dataModel.getTotalToPayAsCoin())); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java index 4f92ccb9c0b..b4cf34adc30 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java @@ -159,14 +159,14 @@ public void initWithData(Offer offer) { actionButton.setId("buy-button-big"); actionButton.updateText(Res.get("takeOffer.takeOfferButtonAltcoin", Res.get("shared.buy"), BSQ)); nextButton.setId("buy-button"); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); - amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescriptionAltcoin", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescriptionAltcoin")); } else { actionButton.setId("sell-button-big"); actionButton.updateText(Res.get("takeOffer.takeOfferButtonAltcoin", Res.get("shared.sell"), BSQ)); nextButton.setId("sell-button"); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); - amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescription")); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescriptionAltcoin", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescriptionAltcoin")); } paymentMethodTextField.setText(PaymentMethod.BSQ_SWAP.getDisplayString()); From 63ea0540266479e9dc92ad05e788ba7c350c23fa Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 12:12:47 +0200 Subject: [PATCH 16/35] Adapt amount and volume description for create offer --- .../resources/i18n/displayStrings.properties | 2 ++ .../main/offer/bisq_v1/MutableOfferView.java | 3 +-- .../offer/bisq_v1/MutableOfferViewModel.java | 22 ++++++++++++++----- .../bisq_v1/takeoffer/TakeOfferViewModel.java | 22 +++++++++---------- .../create_offer/BsqSwapCreateOfferView.java | 13 ++++------- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index b17a92985ae..0ab195405d5 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -454,6 +454,8 @@ createOffer.amount.prompt=Enter amount in BTC createOffer.price.prompt=Enter price createOffer.volume.prompt=Enter amount in {0} createOffer.amountPriceBox.amountDescription=Amount of BTC to {0} +createOffer.amountPriceBox.buy.amountDescriptionAltcoin=Amount in BTC to spend +createOffer.amountPriceBox.sell.amountDescriptionAltcoin=Amount in BTC to receive createOffer.amountPriceBox.buy.volumeDescription=Amount in {0} to spend createOffer.amountPriceBox.sell.volumeDescription=Amount in {0} to receive createOffer.amountPriceBox.buy.volumeDescriptionAltcoin=Amount in {0} to sell diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index cfc045b62fe..c0e2fdec1ed 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -340,7 +340,6 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency, } else { placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), tradeCurrency.getCode()); } - placeOfferButton.updateText(placeOfferButtonLabel); nextButton.setId("buy-button"); fundFromSavingsWalletButton.setId("buy-button"); } else { @@ -354,7 +353,7 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency, fundFromSavingsWalletButton.setId("sell-button"); } - + placeOfferButton.updateText(placeOfferButtonLabel); updatePriceToggle(); if (!model.getDataModel().isMakerFeeValid() && model.getDataModel().getMakerFee() != null) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java index bd6cd386237..705a8001cd6 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java @@ -269,11 +269,15 @@ protected void deactivate() { private void addBindings() { if (dataModel.getDirection() == OfferDirection.BUY) { volumeDescriptionLabel.bind(createStringBinding( - () -> Res.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getTradeCurrencyCode().get()), - dataModel.getTradeCurrencyCode())); + () -> Res.get(CurrencyUtil.isFiatCurrency(dataModel.getTradeCurrencyCode().get()) ? + "createOffer.amountPriceBox.buy.volumeDescription" : + "createOffer.amountPriceBox.buy.volumeDescriptionAltcoin", dataModel.getTradeCurrencyCode().get(), + dataModel.getTradeCurrencyCode()))); } else { volumeDescriptionLabel.bind(createStringBinding( - () -> Res.get("createOffer.amountPriceBox.sell.volumeDescription", dataModel.getTradeCurrencyCode().get()), + () -> Res.get(CurrencyUtil.isFiatCurrency(dataModel.getTradeCurrencyCode().get()) ? + "createOffer.amountPriceBox.sell.volumeDescription" : + "createOffer.amountPriceBox.sell.volumeDescriptionAltcoin", dataModel.getTradeCurrencyCode().get()), dataModel.getTradeCurrencyCode())); } volumePromptLabel.bind(createStringBinding( @@ -590,8 +594,16 @@ boolean initWithData(OfferDirection direction, TradeCurrency tradeCurrency) { btcValidator.setMinValue(Restrictions.getMinTradeAmount()); final boolean isBuy = dataModel.getDirection() == OfferDirection.BUY; - amountDescription = Res.get("createOffer.amountPriceBox.amountDescription", - isBuy ? Res.get("shared.buy") : Res.get("shared.sell")); + + boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(tradeCurrency.getCode()); + + if (isFiatCurrency) { + amountDescription = Res.get("createOffer.amountPriceBox.amountDescription", + isBuy ? Res.get("shared.buy") : Res.get("shared.sell")); + } else { + amountDescription = Res.get(isBuy ? "createOffer.amountPriceBox.sell.amountDescriptionAltcoin" : + "createOffer.amountPriceBox.buy.amountDescriptionAltcoin"); + } securityDepositValidator.setPaymentAccount(dataModel.paymentAccount); validateAndSetBuyerSecurityDepositToModel(); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java index 228cb91ca45..a4f2841bcdb 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java @@ -167,6 +167,17 @@ protected void activate() { addBindings(); addListeners(); + String buyVolumeDescriptionKey = offer.isFiatOffer() ? "createOffer.amountPriceBox.buy.volumeDescription" : + "createOffer.amountPriceBox.buy.volumeDescriptionAltcoin"; + String sellVolumeDescriptionKey = offer.isFiatOffer() ? "createOffer.amountPriceBox.sell.volumeDescription" : + "createOffer.amountPriceBox.sell.volumeDescriptionAltcoin"; + + if (dataModel.getDirection() == OfferDirection.SELL) { + volumeDescriptionLabel.set(Res.get(buyVolumeDescriptionKey, dataModel.getCurrencyCode())); + } else { + volumeDescriptionLabel.set(Res.get(sellVolumeDescriptionKey, dataModel.getCurrencyCode())); + } + amount.set(btcFormatter.formatCoin(dataModel.getAmount().get())); showTransactionPublishedScreen.set(false); @@ -482,17 +493,6 @@ private void updateButtonDisableState() { private void addBindings() { volume.bind(createStringBinding(() -> VolumeUtil.formatVolume(dataModel.volume.get()), dataModel.volume)); - - String buyVolumeDescriptionKey = offer.isFiatOffer() ? "createOffer.amountPriceBox.buy.volumeDescription" : - "createOffer.amountPriceBox.buy.volumeDescriptionAltcoin"; - String sellVolumeDescriptionKey = offer.isFiatOffer() ? "createOffer.amountPriceBox.sell.volumeDescription" : - "createOffer.amountPriceBox.sell.volumeDescriptionAltcoin"; - - if (dataModel.getDirection() == OfferDirection.SELL) { - volumeDescriptionLabel.set(Res.get(buyVolumeDescriptionKey, dataModel.getCurrencyCode())); - } else { - volumeDescriptionLabel.set(Res.get(sellVolumeDescriptionKey, dataModel.getCurrencyCode())); - } totalToPay.bind(createStringBinding(() -> btcFormatter.formatCoinWithCode(dataModel.getTotalToPayAsCoin().get()), dataModel.getTotalToPayAsCoin())); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index be66dd890d1..a499aa7749d 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -179,20 +179,15 @@ public void initWithData(OfferDirection direction, actionButton.setId("buy-button-big"); actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), BSQ)); nextButton.setId("buy-button"); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); - amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescriptionAltcoin", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescriptionAltcoin")); } else { actionButton.setId("sell-button-big"); actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), BSQ)); nextButton.setId("sell-button"); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescription", BSQ)); - amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescription")); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescriptionAltcoin", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescriptionAltcoin")); } - - String amountDescription = Res.get("createOffer.amountPriceBox.amountDescription", - model.dataModel.isBuyOffer() ? Res.get("shared.buy") : Res.get("shared.sell")); - amountDescriptionLabel.setText(amountDescription); - } From 9a3ed33238a689a3c05d98597c2bf635a26c5d86 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 12:31:54 +0200 Subject: [PATCH 17/35] Use Offer.isFiat helper method --- core/src/main/java/bisq/core/offer/Offer.java | 2 +- .../src/main/java/bisq/core/offer/OfferFilterService.java | 5 ++--- .../main/java/bisq/core/offer/bisq_v1/TakeOfferModel.java | 3 +-- .../main/java/bisq/core/trade/model/bisq_v1/Trade.java | 3 +-- .../java/bisq/desktop/components/PeerInfoIconTrading.java | 3 +-- .../main/market/offerbook/OfferBookChartViewModel.java | 4 ++-- .../main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java | 2 +- .../main/offer/bisq_v1/takeoffer/TakeOfferView.java | 4 ++-- .../main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java | 5 ++--- .../main/offer/offerbook/BtcOfferBookViewModel.java | 2 +- .../bisq/desktop/main/offer/offerbook/OfferBookView.java | 2 +- .../desktop/main/offer/offerbook/OfferBookViewModel.java | 2 +- .../desktop/main/overlays/windows/OfferDetailsWindow.java | 8 ++++---- .../desktop/main/overlays/windows/TradeDetailsWindow.java | 3 +-- 14 files changed, 21 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java index 37cece17724..57136ad6929 100644 --- a/core/src/main/java/bisq/core/offer/Offer.java +++ b/core/src/main/java/bisq/core/offer/Offer.java @@ -269,7 +269,7 @@ public Volume getVolumeByAmount(Coin amount) { Volume volumeByAmount = price.getVolumeByAmount(amount); if (offerPayloadBase.getPaymentMethodId().equals(PaymentMethod.HAL_CASH_ID)) volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount); - else if (CurrencyUtil.isFiatCurrency(offerPayloadBase.getCurrencyCode())) + else if (isFiatOffer()) volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount); return volumeByAmount; diff --git a/core/src/main/java/bisq/core/offer/OfferFilterService.java b/core/src/main/java/bisq/core/offer/OfferFilterService.java index 7a18db1f965..62268c7dce9 100644 --- a/core/src/main/java/bisq/core/offer/OfferFilterService.java +++ b/core/src/main/java/bisq/core/offer/OfferFilterService.java @@ -19,7 +19,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.filter.FilterManager; -import bisq.core.locale.CurrencyUtil; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PaymentAccountUtil; import bisq.core.user.Preferences; @@ -178,7 +177,7 @@ public boolean isInsufficientCounterpartyTradeLimit(Offer offer) { return insufficientCounterpartyTradeLimitCache.get(offerId); } - boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) && + boolean result = offer.isFiatOffer() && !accountAgeWitnessService.verifyPeersTradeAmount(offer, offer.getAmount(), errorMessage -> { }); @@ -205,7 +204,7 @@ public boolean isMyInsufficientTradeLimit(Offer offer) { accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null", Coin.valueOf(myTradeLimit).toFriendlyString(), Coin.valueOf(offerMinAmount).toFriendlyString()); - boolean result = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) && + boolean result = offer.isFiatOffer() && accountOptional.isPresent() && myTradeLimit < offerMinAmount; myInsufficientTradeLimitCache.put(offerId, result); diff --git a/core/src/main/java/bisq/core/offer/bisq_v1/TakeOfferModel.java b/core/src/main/java/bisq/core/offer/bisq_v1/TakeOfferModel.java index 447d1d7076f..c6d69a47a10 100644 --- a/core/src/main/java/bisq/core/offer/bisq_v1/TakeOfferModel.java +++ b/core/src/main/java/bisq/core/offer/bisq_v1/TakeOfferModel.java @@ -20,7 +20,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.locale.CurrencyUtil; import bisq.core.monetary.Price; import bisq.core.monetary.Volume; import bisq.core.offer.Offer; @@ -196,7 +195,7 @@ private void calculateVolume() { if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID)) volumeByAmount = getAdjustedVolumeForHalCash(volumeByAmount); - else if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) + else if (offer.isFiatOffer()) volumeByAmount = getRoundedFiatVolume(volumeByAmount); volume = volumeByAmount; diff --git a/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java b/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java index 5a37ce1c015..b5ad48d1fcb 100644 --- a/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java +++ b/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java @@ -18,7 +18,6 @@ package bisq.core.trade.model.bisq_v1; import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.locale.CurrencyUtil; import bisq.core.monetary.Price; import bisq.core.monetary.Volume; import bisq.core.offer.Offer; @@ -776,7 +775,7 @@ public Volume getVolume() { if (offer != null) { if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID)) volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount); - else if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) + else if (offer.isFiatOffer()) volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount); } return volumeByAmount; diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconTrading.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconTrading.java index 43a2c559e2a..a8d079c4f33 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconTrading.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconTrading.java @@ -19,7 +19,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.alert.PrivateNotificationManager; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.offer.Offer; import bisq.core.payment.payload.PaymentMethod; @@ -107,7 +106,7 @@ private PeerInfoIconTrading(NodeAddress nodeAddress, offer = tradeModel.getOffer(); } checkNotNull(offer, "Offer must not be null"); - isFiatCurrency = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()); + isFiatCurrency = offer.isFiatOffer(); initialize(role, offer, tradeModel, privateNotificationManager, useDevPrivilegeKeys); } diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java index e3a17e23d6c..bd9b66fd1d9 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java @@ -253,13 +253,13 @@ public Optional getSelectedCurrencyListItem() { } public int getMaxNumberOfPriceZeroDecimalsToColorize(Offer offer) { - return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) + return offer.isFiatOffer() ? GUIUtil.FIAT_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS; } public int getZeroDecimalsForPrice(Offer offer) { - return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) + return offer.isFiatOffer() ? GUIUtil.FIAT_PRICE_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS; } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java index 26171216a1b..67c81244168 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java @@ -492,7 +492,7 @@ void calculateVolume() { Volume volumeByAmount = tradePrice.getVolumeByAmount(amount.get()); if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID)) volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount); - else if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) + else if (offer.isFiatOffer()) volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount); volume.set(volumeByAmount); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index ec7fe475a92..fab3f1a9bf5 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -406,7 +406,7 @@ public void initWithData(Offer offer) { addressTextField.setPaymentLabel(model.getPaymentLabel()); addressTextField.setAddress(model.dataModel.getAddressEntry().getAddressString()); - if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) { + if (offer.isFiatOffer()) { Label popOverLabel = OfferViewUtil.createPopOverLabel(Res.get("offerbook.info.roundedFiatVolume")); volumeInfoTextField.setContentForPrivacyPopOver(popOverLabel); } @@ -1344,7 +1344,7 @@ private GridPane createInfoPopover() { @NotNull private String getTakeOfferLabel(Offer offer, String direction) { - return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + return offer.isFiatOffer() ? Res.get("takeOffer.takeOfferButton", direction) : Res.get("takeOffer.takeOfferButtonAltcoin", direction, diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java index a4f2841bcdb..fa25380dd4c 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java @@ -31,7 +31,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.wallet.Restrictions; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.monetary.Price; import bisq.core.offer.Offer; @@ -341,7 +340,7 @@ void onFocusOutAmountTextField(boolean oldValue, boolean newValue, String userIn maxTradeLimit); dataModel.applyAmount(adjustedAmountForHalCash); amount.set(btcFormatter.formatCoin(dataModel.getAmount().get())); - } else if (CurrencyUtil.isFiatCurrency(dataModel.getCurrencyCode())) { + } else if (dataModel.getOffer().isFiatOffer()) { if (!isAmountEqualMinAmount(dataModel.getAmount().get()) && (!isAmountEqualMaxAmount(dataModel.getAmount().get()))) { // We only apply the rounding if the amount is variable (minAmount is lower as amount). // Otherwise we could get an amount lower then the minAmount set by rounding @@ -624,7 +623,7 @@ private void setAmountToModel() { if (price != null) { if (dataModel.isUsingHalCashAccount()) { amount = CoinUtil.getAdjustedAmountForHalCash(amount, price, maxTradeLimit); - } else if (CurrencyUtil.isFiatCurrency(dataModel.getCurrencyCode()) + } else if (dataModel.getOffer().isFiatOffer() && !isAmountEqualMinAmount(amount) && !isAmountEqualMaxAmount(amount)) { // We only apply the rounding if the amount is variable (minAmount is lower as amount). // Otherwise we could get an amount lower then the minAmount set by rounding diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java index 1e18554272f..bbfeecaceb2 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java @@ -120,7 +120,7 @@ Predicate getCurrencyAndMethodPredicate(OfferDirection direct return offerBookListItem -> { Offer offer = offerBookListItem.getOffer(); boolean directionResult = offer.getDirection() != direction; - boolean currencyResult = (showAllTradeCurrenciesProperty.get() && CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) || + boolean currencyResult = (showAllTradeCurrenciesProperty.get() && offer.isFiatOffer()) || offer.getCurrencyCode().equals(selectedTradeCurrency.getCode()); boolean paymentMethodResult = showAllPaymentMethods || offer.getPaymentMethod().equals(selectedPaymentMethod); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index baa1df48bcb..7c51cd125fb 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -774,7 +774,7 @@ private void openPopupForMissingAccountSetup(Offer offer) { }).show(); } else { - var accountViewClass = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? FiatAccountsView.class : AltCoinAccountsView.class; + var accountViewClass = offer.isFiatOffer() ? FiatAccountsView.class : AltCoinAccountsView.class; new Popup().headLine(headline) .instruction(Res.get("offerbook.warning.noMatchingAccount.msg")) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index b91adb4d56c..616431d2a18 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -450,7 +450,7 @@ private String formatVolume(Offer offer, boolean decimalAligned) { } int getNumberOfDecimalsForVolume(OfferBookListItem item) { - return CurrencyUtil.isFiatCurrency(item.getOffer().getCurrencyCode()) ? GUIUtil.FIAT_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS; + return item.getOffer().isFiatOffer() ? GUIUtil.FIAT_DECIMALS_WITH_ZEROS : GUIUtil.ALTCOINS_DECIMALS_WITH_ZEROS; } String getPaymentMethod(OfferBookListItem item) { diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java index 0adefbfd82e..80e5828271f 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java @@ -392,20 +392,20 @@ private void addConfirmAndCancelButtons(boolean isPlaceOffer) { boolean isBuyerRole = isPlaceOffer == isBuyOffer; String tradeCurrencyByCode = offer.getCurrencyCode(); String placeOfferButtonText = isBuyerRole ? - CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + offer.isFiatOffer() ? Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) : Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.buy"), tradeCurrencyByCode) : - CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + offer.isFiatOffer() ? Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell")) : Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.sell"), tradeCurrencyByCode); String takeOfferButtonText = isBuyerRole ? - CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + offer.isFiatOffer() ? Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) : Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.buy"), tradeCurrencyByCode) : - CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ? + offer.isFiatOffer() ? Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell")) : Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.sell"), tradeCurrencyByCode); diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/TradeDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/TradeDetailsWindow.java index 5a80df53303..d8b305b6ecf 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/TradeDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/TradeDetailsWindow.java @@ -27,7 +27,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.offer.Offer; import bisq.core.payment.payload.PaymentAccountPayload; @@ -340,7 +339,7 @@ private void addContent() { data += "\n\nOther detail data:"; data += "\n\nBuyerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getBuyerMultiSigPubKey()); data += "\nSellerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getSellerMultiSigPubKey()); - if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode())) { + if (offer.isFiatOffer()) { data += "\n\nBuyersAccountAge: " + buyersAccountAge; data += "\nSellersAccountAge: " + sellersAccountAge; } From 542cc4d5cfccd727d4a366335f9360e6ce564cbf Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 13:27:13 +0200 Subject: [PATCH 18/35] Remove close button duplication in DetailsWindows --- .../main/overlays/windows/BsqSwapOfferDetailsWindow.java | 8 +------- .../main/overlays/windows/BsqTradeDetailsWindow.java | 8 +------- .../main/overlays/windows/OfferDetailsWindow.java | 7 +------ desktop/src/main/java/bisq/desktop/util/FormBuilder.java | 9 +++++++++ 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java index 38d9abf843f..3cc03ed6f5f 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqSwapOfferDetailsWindow.java @@ -47,10 +47,8 @@ import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.ImageView; -import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; -import javafx.geometry.HPos; import javafx.geometry.Insets; import java.util.Optional; @@ -253,11 +251,7 @@ private void addContent() { } else if (isTakeOfferScreen) { addConfirmAndCancelButtons(false); } else { - Button closeButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("shared.close")); - GridPane.setColumnIndex(closeButton, 1); - GridPane.setHalignment(closeButton, HPos.RIGHT); - - closeButton.setOnAction(e -> { + addCloseButton(gridPane, ++rowIndex, () -> { closeHandlerOptional.ifPresent(Runnable::run); hide(); }); diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqTradeDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqTradeDetailsWindow.java index cccd6040a93..f0def033421 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqTradeDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/BsqTradeDetailsWindow.java @@ -36,11 +36,8 @@ import javax.inject.Inject; import javax.inject.Named; -import javafx.scene.control.Button; import javafx.scene.control.TextArea; -import javafx.scene.layout.GridPane; -import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.beans.property.IntegerProperty; @@ -205,10 +202,7 @@ private void addContent() { bsqSwapTrade.getState().name()); } - Button closeButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("shared.close")); - GridPane.setColumnIndex(closeButton, 1); - GridPane.setHalignment(closeButton, HPos.RIGHT); - closeButton.setOnAction(e -> { + addCloseButton(gridPane, ++rowIndex, () -> { closeHandlerOptional.ifPresent(Runnable::run); hide(); }); diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java index 80e5828271f..cbf9bd9858b 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/OfferDetailsWindow.java @@ -62,7 +62,6 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; -import javafx.geometry.HPos; import javafx.geometry.Insets; import java.util.List; @@ -376,11 +375,7 @@ private void addContent() { addConfirmAndCancelButtons(false); } else { - Button closeButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("shared.close")); - GridPane.setColumnIndex(closeButton, 1); - GridPane.setHalignment(closeButton, HPos.RIGHT); - - closeButton.setOnAction(e -> { + addCloseButton(gridPane, ++rowIndex, () -> { closeHandlerOptional.ifPresent(Runnable::run); hide(); }); diff --git a/desktop/src/main/java/bisq/desktop/util/FormBuilder.java b/desktop/src/main/java/bisq/desktop/util/FormBuilder.java index 96633f380b9..3d006b78544 100644 --- a/desktop/src/main/java/bisq/desktop/util/FormBuilder.java +++ b/desktop/src/main/java/bisq/desktop/util/FormBuilder.java @@ -1961,6 +1961,15 @@ public static Button addButton(GridPane gridPane, int rowIndex, String title, do return button; } + public static Button addCloseButton(GridPane gridPane, int rowIndex, Runnable closeHandler) { + Button closeButton = addButtonAfterGroup(gridPane, rowIndex, Res.get("shared.close")); + GridPane.setColumnIndex(closeButton, 1); + GridPane.setHalignment(closeButton, HPos.RIGHT); + + closeButton.setOnAction(e -> closeHandler.run()); + + return closeButton; + } /////////////////////////////////////////////////////////////////////////////////////////// // Button + Button From 098ece2a87b7f5895ac2daeee64547d6ae801737 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 14:15:10 +0200 Subject: [PATCH 19/35] Only show BSQ accounts --- .../create_offer/BsqSwapCreateOfferDataModel.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferDataModel.java index 13d9c52b6d9..b54bb438cb5 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferDataModel.java @@ -49,6 +49,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.Consumer; +import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -144,8 +145,12 @@ protected void removeListeners() { } private void fillPaymentAccounts() { - if (getUserPaymentAccounts() != null) { - paymentAccounts.setAll(new HashSet<>(getUserPaymentAccounts())); + Set userPaymentAccounts = getUserPaymentAccounts(); + if (userPaymentAccounts != null) { + paymentAccounts.setAll(new HashSet<>(userPaymentAccounts.stream().filter(paymentAccount1 -> { + Optional tradeCurrency = paymentAccount1.getTradeCurrency(); + return tradeCurrency.map(currency -> currency.getCode().equals("BSQ")).orElse(false); + }).collect(Collectors.toList()))); } paymentAccounts.sort(comparing(PaymentAccount::getAccountName)); } From 2055cc5c104c6371880534d9e5980a9af74b193d Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 11 Apr 2022 14:16:39 +0200 Subject: [PATCH 20/35] Fix wrong check to show BSQ swap as default for create offer --- desktop/src/main/java/bisq/desktop/main/offer/OfferView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index dc757f9fe8c..a42f09f0929 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -295,7 +295,7 @@ private void loadCreateViewClass(OfferBookView offerBookView, // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times // in different graphs if ((paymentMethod != null && paymentMethod.isBsqSwap()) || - (paymentMethod == null && viewClass.isAssignableFrom(BsqOfferBookView.class))) { + (paymentMethod == null && viewClass.equals(BsqOfferBookView.class))) { view = viewLoader.load(BsqSwapCreateOfferView.class); ((BsqSwapCreateOfferView) view).initWithData(direction, offerActionHandler, payload); } else { From fce247cbc0a1f1bf84db9ebbe814b474675a5e79 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 13 Apr 2022 12:35:58 +0200 Subject: [PATCH 21/35] Fix a couple of issues regarding default currencies --- .../resources/i18n/displayStrings.properties | 1 + .../bisq/desktop/main/offer/OfferView.java | 2 +- .../desktop/main/offer/OfferViewUtil.java | 11 +++++++++- .../offerbook/BsqOfferBookViewModel.java | 4 ++-- .../offer/offerbook/OfferBookViewModel.java | 9 +++++---- .../offerbook/OtherOfferBookViewModel.java | 20 +++++++++++++++---- .../TopAltcoinOfferBookViewModel.java | 4 ++-- .../settings/preferences/PreferencesView.java | 3 +++ .../main/java/bisq/desktop/util/GUIUtil.java | 4 +++- 9 files changed, 43 insertions(+), 15 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 0ab195405d5..cc5e2932148 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -1335,6 +1335,7 @@ setting.preferences.prefCurrency=Preferred currency setting.preferences.displayFiat=Display national currencies setting.preferences.noFiat=There are no national currencies selected setting.preferences.cannotRemovePrefCurrency=You cannot remove your selected preferred display currency +setting.preferences.cannotRemoveMainAltcoinCurrency=You cannot remove this main altcoin currency setting.preferences.displayAltcoins=Display altcoins setting.preferences.noAltcoins=There are no altcoins selected setting.preferences.addFiat=Add national currency diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index a42f09f0929..da497d6a4e8 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -295,7 +295,7 @@ private void loadCreateViewClass(OfferBookView offerBookView, // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times // in different graphs if ((paymentMethod != null && paymentMethod.isBsqSwap()) || - (paymentMethod == null && viewClass.equals(BsqOfferBookView.class))) { + viewClass.equals(BsqOfferBookView.class)) { view = viewLoader.load(BsqSwapCreateOfferView.class); ((BsqSwapCreateOfferView) view).initWithData(direction, offerActionHandler, payload); } else { 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 9dafa669aee..6a33ea27497 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java @@ -31,6 +31,7 @@ import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.overlays.popups.Popup; +import bisq.core.locale.CryptoCurrency; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; @@ -53,6 +54,9 @@ import java.util.HashMap; import java.util.Objects; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +import org.jetbrains.annotations.NotNull; // Shared utils for Views public class OfferViewUtil { @@ -155,8 +159,13 @@ public static boolean isShownAsBuyOffer(OfferDirection direction, TradeCurrency } public static TradeCurrency getAnyOfMainCryptoCurrencies() { + return getMainCryptoCurrencies().findAny().get(); + } + + @NotNull + public static Stream getMainCryptoCurrencies() { return CurrencyUtil.getMainCryptoCurrencies().stream().filter(cryptoCurrency -> !Objects.equals(cryptoCurrency.getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()) && - !Objects.equals(cryptoCurrency.getCode(), BsqOfferBookViewModel.BSQ.getCode())).findAny().get(); + !Objects.equals(cryptoCurrency.getCode(), BsqOfferBookViewModel.BSQ.getCode())); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java index 44706bdb8eb..ec8107ce702 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java @@ -18,12 +18,12 @@ package bisq.desktop.main.offer.offerbook; import bisq.desktop.Navigation; +import bisq.desktop.util.GUIUtil; import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.api.CoreApi; import bisq.core.btc.setup.WalletsSetup; import bisq.core.btc.wallet.BsqWalletService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferDirection; @@ -55,7 +55,7 @@ public class BsqOfferBookViewModel extends OfferBookViewModel { - public static final TradeCurrency BSQ = CurrencyUtil.getTradeCurrency("BSQ").get(); + public static final TradeCurrency BSQ = GUIUtil.BSQ; @Inject public BsqOfferBookViewModel(User user, diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index 616431d2a18..21594a0c5a9 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -567,10 +567,11 @@ abstract void fillCurrencies(ObservableList tradeCurrencies, /////////////////////////////////////////////////////////////////////////////////////////// boolean hasPaymentAccountForCurrency() { - return (showAllTradeCurrenciesProperty.get() && - user.getPaymentAccounts() != null && - !user.getPaymentAccounts().isEmpty()) || - user.hasPaymentAccountForCurrency(selectedTradeCurrency); + return hasPaymentAccountForCurrency(selectedTradeCurrency); + } + + boolean hasPaymentAccountForCurrency(TradeCurrency currency) { + return user.hasPaymentAccountForCurrency(currency); } boolean canCreateOrTakeOffer() { diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java index 6751f8cfa12..b1192e58076 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java @@ -52,6 +52,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -132,14 +133,25 @@ Predicate getCurrencyAndMethodPredicate(OfferDirection direct @Override TradeCurrency getDefaultTradeCurrency() { - // select first currency in list, otherwise if view is not initialized any of the main crypto currencies - return !getTradeCurrencies().isEmpty() ? getTradeCurrencies().get(1) : - OfferViewUtil.getAnyOfMainCryptoCurrencies(); + 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(); + return direction == OfferDirection.BUY ? preferences.getBuyScreenCryptoCurrencyCode() : + preferences.getSellScreenCryptoCurrencyCode(); } @NotNull diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java index e3392c057bc..7f4eda49a17 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java @@ -18,12 +18,12 @@ package bisq.desktop.main.offer.offerbook; import bisq.desktop.Navigation; +import bisq.desktop.util.GUIUtil; import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.api.CoreApi; import bisq.core.btc.setup.WalletsSetup; import bisq.core.btc.wallet.BsqWalletService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferDirection; @@ -54,7 +54,7 @@ public class TopAltcoinOfferBookViewModel extends OfferBookViewModel { - public static final TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get(); + public static final TradeCurrency TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN; @Inject public TopAltcoinOfferBookViewModel(User user, diff --git a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java index 551afe75d0c..819c26ed84c 100644 --- a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java +++ b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java @@ -553,6 +553,9 @@ public void updateItem(final CryptoCurrency item, boolean empty) { removeButton.setOnAction(e -> { if (item.equals(preferences.getPreferredTradeCurrency())) { new Popup().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show(); + } + if (item.equals(GUIUtil.BSQ) || item.equals(GUIUtil.TOP_ALTCOIN)) { + new Popup().warning(Res.get("setting.preferences.cannotRemoveMainAltcoinCurrency")).show(); } else { preferences.removeCryptoCurrency(item); if (!allCryptoCurrencies.contains(item)) { diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index d663f7873e7..7d91064d987 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -168,6 +168,9 @@ public class GUIUtil { public final static int AMOUNT_DECIMALS_WITH_ZEROS = 3; public final static int AMOUNT_DECIMALS = 4; + public final static TradeCurrency BSQ = CurrencyUtil.getTradeCurrency("BSQ").get(); + public final static TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get(); + private static FeeService feeService; private static Preferences preferences; @@ -1246,5 +1249,4 @@ public static void setDefaultTwoColumnConstraintsForGridPane(GridPane gridPane) columnConstraints2.setHgrow(Priority.ALWAYS); gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2); } - } From 348d1477e100b204430600561f272a317d75a955 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 19 Apr 2022 10:18:33 +0200 Subject: [PATCH 22/35] Fix broken option for BSQ Altcoin and BSQ Altcoin Instant --- desktop/src/main/java/bisq/desktop/main/offer/OfferView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index da497d6a4e8..f9ae9a33edc 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -294,8 +294,8 @@ private void loadCreateViewClass(OfferBookView offerBookView, View view; // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times // in different graphs - if ((paymentMethod != null && paymentMethod.isBsqSwap()) || - viewClass.equals(BsqOfferBookView.class)) { + if ((paymentMethod != null && (paymentMethod.isBsqSwap() || paymentMethod.getId().equals(GUIUtil.SHOW_ALL_FLAG))) || + (paymentMethod == null && viewClass.equals(BsqOfferBookView.class))) { view = viewLoader.load(BsqSwapCreateOfferView.class); ((BsqSwapCreateOfferView) view).initWithData(direction, offerActionHandler, payload); } else { From e43bad14874db89b5e7592b5fea0e43d5dae9df1 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 19 Apr 2022 10:23:13 +0200 Subject: [PATCH 23/35] Fix offer count for Altcoins --- .../java/bisq/desktop/main/offer/offerbook/OfferBookView.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index 7c51cd125fb..abfebe7c1b9 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -112,6 +112,7 @@ import javafx.util.StringConverter; import java.util.Comparator; +import java.util.Map; import java.util.Optional; import org.jetbrains.annotations.NotNull; @@ -343,9 +344,10 @@ protected void activate() { ? "https://bisq.wiki/Introduction#In_a_nutshell" : "https://bisq.wiki/Taking_an_offer"); + Map offerCounts = OfferViewUtil.isShownAsBuyOffer(model.getDirection(), model.getSelectedTradeCurrency()) ? model.getSellOfferCounts() : model.getBuyOfferCounts(); currencyComboBox.setCellFactory(GUIUtil.getTradeCurrencyCellFactory(Res.get("shared.oneOffer"), Res.get("shared.multipleOffers"), - (model.getDirection() == OfferDirection.BUY ? model.getSellOfferCounts() : model.getBuyOfferCounts()))); + offerCounts)); currencyComboBox.setConverter(new CurrencyStringConverter(currencyComboBox)); currencyComboBox.getEditor().getStyleClass().add("combo-box-editor-bold"); From d41235cebd9fa9ad35d873baefbd91c53761c2f1 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 19 Apr 2022 10:43:05 +0200 Subject: [PATCH 24/35] Fix storage of crypto screen currency --- .../main/market/offerbook/OfferBookChartViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java index bd9b66fd1d9..cd85cd23569 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java @@ -414,14 +414,14 @@ private void updateScreenCurrencyInPreferences(OfferDirection direction) { if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) { preferences.setBuyScreenCurrencyCode(getCurrencyCode()); } else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && - getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + !getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { preferences.setBuyScreenCryptoCurrencyCode(getCurrencyCode()); } } else { if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) { preferences.setSellScreenCurrencyCode(getCurrencyCode()); } else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && - getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + !getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { preferences.setSellScreenCryptoCurrencyCode(getCurrencyCode()); } } From be161669f1ed023321968b3767ac0ff95c25a239 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 20 Apr 2022 11:16:04 +0200 Subject: [PATCH 25/35] Fix sorting issue for Altcoins --- .../bisq/desktop/main/offer/offerbook/OfferBookView.java | 9 +++++---- .../desktop/main/offer/offerbook/OfferBookViewModel.java | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index abfebe7c1b9..d5a2c9525e2 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -881,13 +881,14 @@ public void updateItem(final OfferBookListItem item, boolean empty) { private HBox getPriceAndPercentage(OfferBookListItem item) { Offer offer = item.getOffer(); boolean useMarketBasedPrice = offer.isUseMarketBasedPrice(); + boolean isShownAsBuyOffer = OfferViewUtil.isShownAsBuyOffer(offer); MaterialDesignIcon icon = useMarketBasedPrice ? MaterialDesignIcon.CHART_LINE : MaterialDesignIcon.LOCK; String info; if (useMarketBasedPrice) { double marketPriceMargin = offer.getMarketPriceMargin(); if (marketPriceMargin == 0) { - if (offer.isBuyOffer()) { + if (isShownAsBuyOffer) { info = Res.get("offerbook.info.sellAtMarketPrice"); } else { info = Res.get("offerbook.info.buyAtMarketPrice"); @@ -895,13 +896,13 @@ private HBox getPriceAndPercentage(OfferBookListItem item) { } else { String absolutePriceMargin = model.getAbsolutePriceMargin(offer); if (marketPriceMargin > 0) { - if (offer.isBuyOffer()) { + if (isShownAsBuyOffer) { info = Res.get("offerbook.info.sellBelowMarketPrice", absolutePriceMargin); } else { info = Res.get("offerbook.info.buyAboveMarketPrice", absolutePriceMargin); } } else { - if (offer.isBuyOffer()) { + if (isShownAsBuyOffer) { info = Res.get("offerbook.info.sellAboveMarketPrice", absolutePriceMargin); } else { info = Res.get("offerbook.info.buyBelowMarketPrice", absolutePriceMargin); @@ -909,7 +910,7 @@ private HBox getPriceAndPercentage(OfferBookListItem item) { } } } else { - if (offer.isBuyOffer()) { + if (isShownAsBuyOffer) { info = Res.get("offerbook.info.sellAtFixedPrice"); } else { info = Res.get("offerbook.info.buyAtFixedPrice"); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index 21594a0c5a9..8e9753dea87 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -421,7 +421,9 @@ String getPriceAsPercentage(OfferBookListItem item) { } public Optional getMarketBasedPrice(Offer offer) { - return priceUtil.getMarketBasedPrice(offer, direction); + OfferDirection displayDirection = offer.isFiatOffer() ? direction : + direction.equals(OfferDirection.BUY) ? OfferDirection.SELL : OfferDirection.BUY; + return priceUtil.getMarketBasedPrice(offer, displayDirection); } String formatMarketPriceMargin(Offer offer) { From 7ecd159697183f44bea1a712460a1426705865e1 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 20 Apr 2022 11:19:48 +0200 Subject: [PATCH 26/35] Fix BSQ swap create offer handling (again) --- desktop/src/main/java/bisq/desktop/main/offer/OfferView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index f9ae9a33edc..2499faf9b87 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -294,7 +294,8 @@ private void loadCreateViewClass(OfferBookView offerBookView, View view; // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times // in different graphs - if ((paymentMethod != null && (paymentMethod.isBsqSwap() || paymentMethod.getId().equals(GUIUtil.SHOW_ALL_FLAG))) || + if ((paymentMethod != null && paymentMethod.isBsqSwap()) || + (paymentMethod != null && paymentMethod.getId().equals(GUIUtil.SHOW_ALL_FLAG) && viewClass.equals(BsqOfferBookView.class)) || (paymentMethod == null && viewClass.equals(BsqOfferBookView.class))) { view = viewLoader.load(BsqSwapCreateOfferView.class); ((BsqSwapCreateOfferView) view).initWithData(direction, offerActionHandler, payload); From 108255bf8e3bf167542ef7966926066e2f8846ce Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 20 Apr 2022 17:57:07 +0200 Subject: [PATCH 27/35] Move supported currencies into payment accounts --- .../payment/CreatePaymentAccountTest.java | 39 +- .../api/model/PaymentAccountTypeAdapter.java | 31 +- .../java/bisq/core/locale/CountryUtil.java | 3 +- .../java/bisq/core/locale/CurrencyUtil.java | 446 +----------------- .../bisq/core/payment/AchTransferAccount.java | 15 +- .../core/payment/AdvancedCashAccount.java | 25 +- .../java/bisq/core/payment/AliPayAccount.java | 16 +- .../core/payment/AmazonGiftCardAccount.java | 24 + ...aPayid.java => AustraliaPayidAccount.java} | 21 +- .../java/bisq/core/payment/BizumAccount.java | 15 +- .../bisq/core/payment/BsqSwapAccount.java | 12 + .../bisq/core/payment/CapitualAccount.java | 23 +- .../bisq/core/payment/CashAppAccount.java | 16 +- .../bisq/core/payment/CashByMailAccount.java | 13 + .../bisq/core/payment/CashDepositAccount.java | 14 + .../java/bisq/core/payment/CelPayAccount.java | 24 +- .../core/payment/ChaseQuickPayAccount.java | 16 +- .../core/payment/ClearXchangeAccount.java | 16 +- .../core/payment/CryptoCurrencyAccount.java | 13 + .../payment/DomesticWireTransferAccount.java | 13 + .../java/bisq/core/payment/F2FAccount.java | 13 + .../core/payment/FasterPaymentsAccount.java | 16 +- .../bisq/core/payment/HalCashAccount.java | 16 +- .../bisq/core/payment/IfscBasedAccount.java | 40 ++ .../java/bisq/core/payment/ImpsAccount.java | 15 +- .../payment/InstantCryptoCurrencyAccount.java | 13 + .../core/payment/InteracETransferAccount.java | 18 +- .../bisq/core/payment/JapanBankAccount.java | 75 +-- .../java/bisq/core/payment/MoneseAccount.java | 18 + .../bisq/core/payment/MoneyBeamAccount.java | 16 +- .../bisq/core/payment/MoneyGramAccount.java | 63 ++- .../core/payment/NationalBankAccount.java | 13 + .../java/bisq/core/payment/NeftAccount.java | 6 +- .../java/bisq/core/payment/NequiAccount.java | 15 +- .../java/bisq/core/payment/OKPayAccount.java | 43 +- .../java/bisq/core/payment/PaxumAccount.java | 37 +- .../bisq/core/payment/PaymentAccount.java | 5 + .../core/payment/PaymentAccountFactory.java | 2 +- .../bisq/core/payment/PaymentAccountUtil.java | 94 ++-- .../bisq/core/payment/PayseraAccount.java | 49 ++ .../java/bisq/core/payment/PaytmAccount.java | 2 +- .../core/payment/PerfectMoneyAccount.java | 16 +- .../java/bisq/core/payment/PixAccount.java | 13 + .../bisq/core/payment/PopmoneyAccount.java | 16 +- .../bisq/core/payment/PromptPayAccount.java | 16 +- .../bisq/core/payment/RevolutAccount.java | 49 +- .../java/bisq/core/payment/RtgsAccount.java | 3 +- .../bisq/core/payment/SameBankAccount.java | 13 + .../bisq/core/payment/SatispayAccount.java | 13 + .../java/bisq/core/payment/SepaAccount.java | 14 + .../bisq/core/payment/SepaInstantAccount.java | 14 + .../core/payment/SpecificBanksAccount.java | 12 + .../java/bisq/core/payment/StrikeAccount.java | 17 + .../java/bisq/core/payment/SwiftAccount.java | 22 +- .../java/bisq/core/payment/SwishAccount.java | 16 +- .../java/bisq/core/payment/TikkieAccount.java | 17 + .../core/payment/TransferwiseAccount.java | 59 +++ .../core/payment/TransferwiseUsdAccount.java | 17 + .../payment/USPostalMoneyOrderAccount.java | 16 +- .../java/bisq/core/payment/UpholdAccount.java | 43 +- .../java/bisq/core/payment/UpiAccount.java | 2 +- .../java/bisq/core/payment/VenmoAccount.java | 16 +- .../java/bisq/core/payment/VerseAccount.java | 22 +- .../bisq/core/payment/WeChatPayAccount.java | 15 +- .../core/payment/WesternUnionAccount.java | 14 + .../paymentmethods/AdvancedCashForm.java | 3 +- .../paymentmethods/AustraliaPayidForm.java | 28 +- .../components/paymentmethods/BizumForm.java | 3 +- .../paymentmethods/CapitualForm.java | 3 +- .../components/paymentmethods/CelPayForm.java | 3 +- .../paymentmethods/GeneralSepaForm.java | 16 +- .../paymentmethods/IfscBankForm.java | 3 +- .../components/paymentmethods/MoneseForm.java | 3 +- .../paymentmethods/MoneyGramForm.java | 8 +- .../components/paymentmethods/NequiForm.java | 3 +- .../components/paymentmethods/PaxumForm.java | 3 +- .../paymentmethods/PayseraForm.java | 3 +- .../components/paymentmethods/PaytmForm.java | 3 +- .../components/paymentmethods/PixForm.java | 3 +- .../paymentmethods/RevolutForm.java | 3 +- .../paymentmethods/SatispayForm.java | 3 +- .../components/paymentmethods/SepaForm.java | 4 +- .../components/paymentmethods/StrikeForm.java | 4 +- .../components/paymentmethods/TikkieForm.java | 4 +- .../paymentmethods/TransferwiseForm.java | 3 +- .../paymentmethods/TransferwiseUsdForm.java | 6 +- .../components/paymentmethods/UpholdForm.java | 3 +- .../components/paymentmethods/UpiForm.java | 3 +- .../components/paymentmethods/VerseForm.java | 3 +- .../fiataccounts/FiatAccountsView.java | 4 +- 90 files changed, 1229 insertions(+), 715 deletions(-) rename core/src/main/java/bisq/core/payment/{AustraliaPayid.java => AustraliaPayidAccount.java} (76%) create mode 100644 core/src/main/java/bisq/core/payment/IfscBasedAccount.java diff --git a/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java b/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java index c1d446895d7..857dfc46a4f 100644 --- a/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java +++ b/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java @@ -21,7 +21,7 @@ import bisq.core.locale.TradeCurrency; import bisq.core.payment.AdvancedCashAccount; import bisq.core.payment.AliPayAccount; -import bisq.core.payment.AustraliaPayid; +import bisq.core.payment.AustraliaPayidAccount; import bisq.core.payment.CapitualAccount; import bisq.core.payment.CashDepositAccount; import bisq.core.payment.ClearXchangeAccount; @@ -81,7 +81,8 @@ import static bisq.apitest.config.ApiTestConfig.USD; import static bisq.apitest.config.BisqAppConfig.alicedaemon; import static bisq.cli.table.builder.TableType.PAYMENT_ACCOUNT_TBL; -import static bisq.core.locale.CurrencyUtil.*; +import static bisq.core.locale.CurrencyUtil.getAllSortedFiatCurrencies; +import static bisq.core.locale.CurrencyUtil.getTradeCurrency; import static bisq.core.payment.payload.PaymentMethod.*; import static java.util.Comparator.comparing; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -117,7 +118,7 @@ public void testCreateAdvancedCashAccount(TestInfo testInfo) { COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, ADVANCED_CASH_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Advanced Cash Acct"); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NR, "0000 1111 2222"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllAdvancedCashCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, AdvancedCashAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -126,7 +127,7 @@ public void testCreateAdvancedCashAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(); AdvancedCashAccount paymentAccount = (AdvancedCashAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllAdvancedCashCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(AdvancedCashAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -166,7 +167,7 @@ public void testCreateAustraliaPayidAccount(TestInfo testInfo) { COMPLETED_FORM_MAP.put(PROPERTY_NAME_BANK_ACCOUNT_NAME, "Credit Union Australia"); COMPLETED_FORM_MAP.put(PROPERTY_NAME_SALT, encodeToHex("Restored Australia Pay ID Acct Salt")); String jsonString = getCompletedFormAsJsonString(); - AustraliaPayid paymentAccount = (AustraliaPayid) createPaymentAccount(aliceClient, jsonString); + AustraliaPayidAccount paymentAccount = (AustraliaPayidAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); verifyAccountSingleTradeCurrency("AUD", paymentAccount); verifyCommonFormEntries(paymentAccount); @@ -185,7 +186,7 @@ public void testCreateCapitualAccount(TestInfo testInfo) { COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, CAPITUAL_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Capitual Acct"); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NR, "1111 2222 3333-4"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllCapitualCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, CapitualAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -194,7 +195,7 @@ public void testCreateCapitualAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(); CapitualAccount paymentAccount = (CapitualAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllCapitualCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(CapitualAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -491,7 +492,7 @@ public void testCreateMoneyGramAccount(TestInfo testInfo) { PROPERTY_NAME_STATE); COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, MONEY_GRAM_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Money Gram Acct"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllMoneyGramCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, MoneyGramAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -504,7 +505,7 @@ public void testCreateMoneyGramAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(); MoneyGramAccount paymentAccount = (MoneyGramAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllMoneyGramCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(MoneyGramAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -544,7 +545,7 @@ public void testCreatePaxumAccount(TestInfo testInfo) { PROPERTY_NAME_EMAIL); COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, PAXUM_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Paxum Acct"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllPaxumCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, PaxumAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -554,7 +555,7 @@ public void testCreatePaxumAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(); PaxumAccount paymentAccount = (PaxumAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllPaxumCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(PaxumAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -570,7 +571,7 @@ public void testCreatePayseraAccount(TestInfo testInfo) { PROPERTY_NAME_EMAIL); COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, PAYSERA_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Paysera Acct"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllPayseraCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, PayseraAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -580,7 +581,7 @@ public void testCreatePayseraAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(); PayseraAccount paymentAccount = (PayseraAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllPayseraCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(PayseraAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -638,7 +639,7 @@ public void testCreateRevolutAccount(TestInfo testInfo) { PROPERTY_NAME_USERNAME); COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, REVOLUT_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Revolut Acct"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllRevolutCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, RevolutAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -648,7 +649,7 @@ public void testCreateRevolutAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(); RevolutAccount paymentAccount = (RevolutAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllRevolutCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(RevolutAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -959,7 +960,7 @@ public void testCreateTransferwiseAccountWithSupportedTradeCurrencies(TestInfo t PROPERTY_NAME_EMAIL); COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, TRANSFERWISE_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Transferwise Acct"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllTransferwiseCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, TransferwiseAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -969,7 +970,7 @@ public void testCreateTransferwiseAccountWithSupportedTradeCurrencies(TestInfo t String jsonString = getCompletedFormAsJsonString(); TransferwiseAccount paymentAccount = (TransferwiseAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllTransferwiseCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(TransferwiseAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -1024,7 +1025,7 @@ public void testCreateUpholdAccount(TestInfo testInfo) { COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, UPHOLD_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "Uphold Acct"); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_ID, "UA 9876"); - COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, getAllUpholdCurrencies() + COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, UpholdAccount.SUPPORTED_CURRENCIES .stream() .map(TradeCurrency::getCode) .collect(Collectors.joining(","))); @@ -1033,7 +1034,7 @@ public void testCreateUpholdAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(); UpholdAccount paymentAccount = (UpholdAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllUpholdCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(UpholdAccount.SUPPORTED_CURRENCIES, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); diff --git a/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java b/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java index 0613bd0060b..b912e4fbf66 100644 --- a/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java +++ b/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java @@ -52,8 +52,10 @@ import static bisq.common.util.ReflectionUtils.*; import static bisq.common.util.Utilities.decodeFromHex; import static bisq.core.locale.CountryUtil.findCountryByCode; -import static bisq.core.locale.CurrencyUtil.*; -import static bisq.core.payment.payload.PaymentMethod.*; +import static bisq.core.locale.CurrencyUtil.getCurrencyByCountryCode; +import static bisq.core.locale.CurrencyUtil.getTradeCurrenciesInList; +import static bisq.core.locale.CurrencyUtil.getTradeCurrency; +import static bisq.core.payment.payload.PaymentMethod.MONEY_GRAM_ID; import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.String.format; import static java.util.Arrays.stream; @@ -377,30 +379,7 @@ private boolean didReadTradeCurrenciesField(JsonReader in, private Optional> getReconciledTradeCurrencies(List currencyCodes, PaymentAccount account) { - if (account.hasPaymentMethodWithId(ADVANCED_CASH_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllAdvancedCashCurrencies()); - else if (account.hasPaymentMethodWithId(AMAZON_GIFT_CARD_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllAmazonGiftCardCurrencies()); - else if (account.hasPaymentMethodWithId(CAPITUAL_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllCapitualCurrencies()); - else if (account.hasPaymentMethodWithId(MONEY_GRAM_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllMoneyGramCurrencies()); - else if (account.hasPaymentMethodWithId(PAXUM_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllPaxumCurrencies()); - else if (account.hasPaymentMethodWithId(PAYSERA_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllPayseraCurrencies()); - else if (account.hasPaymentMethodWithId(REVOLUT_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllRevolutCurrencies()); - else if (account.hasPaymentMethodWithId(SWIFT_ID)) - return getTradeCurrenciesInList(currencyCodes, - new ArrayList<>(getAllSortedFiatCurrencies( - comparing(TradeCurrency::getCode)))); - else if (account.hasPaymentMethodWithId(TRANSFERWISE_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllTransferwiseCurrencies()); - else if (account.hasPaymentMethodWithId(UPHOLD_ID)) - return getTradeCurrenciesInList(currencyCodes, getAllUpholdCurrencies()); - else - return Optional.empty(); + return getTradeCurrenciesInList(currencyCodes, account.getSupportedCurrencies()); } private boolean didReadSelectedTradeCurrencyField(JsonReader in, diff --git a/core/src/main/java/bisq/core/locale/CountryUtil.java b/core/src/main/java/bisq/core/locale/CountryUtil.java index 5038ffc6a3b..51a419a37a6 100644 --- a/core/src/main/java/bisq/core/locale/CountryUtil.java +++ b/core/src/main/java/bisq/core/locale/CountryUtil.java @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -61,7 +62,7 @@ public static List getAllAmazonGiftCardCountries() { String[] codes = {"AU", "CA", "FR", "DE", "IT", "NL", "ES", "GB", "IN", "JP", "SA", "SE", "SG", "TR", "US"}; populateCountryListByCodes(list, codes); - list.sort((a, b) -> a.name.compareTo(b.name)); + list.sort(Comparator.comparing(a -> a.name)); return list; } diff --git a/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index cbe66fe22c8..61b83623f93 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -51,7 +51,6 @@ import lombok.extern.slf4j.Slf4j; -import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; @Slf4j @@ -72,10 +71,10 @@ public static void setup() { private static final Map isFiatCurrencyMap = new ConcurrentHashMap<>(); private static final Map isCryptoCurrencyMap = new ConcurrentHashMap<>(); - private static Supplier> fiatCurrencyMapSupplier = Suppliers.memoize( - CurrencyUtil::createFiatCurrencyMap)::get; - private static Supplier> cryptoCurrencyMapSupplier = Suppliers.memoize( - CurrencyUtil::createCryptoCurrencyMap)::get; + private static final Supplier> fiatCurrencyMapSupplier = Suppliers.memoize( + CurrencyUtil::createFiatCurrencyMap); + private static final Supplier> cryptoCurrencyMapSupplier = Suppliers.memoize( + CurrencyUtil::createCryptoCurrencyMap); public static void setBaseCurrencyCode(String baseCurrencyCode) { CurrencyUtil.baseCurrencyCode = baseCurrencyCode; @@ -187,433 +186,6 @@ public static List getRemovedCryptoCurrencies() { return currencies; } - public static List getAllAdvancedCashCurrencies() { - ArrayList currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("USD"), - new FiatCurrency("EUR"), - new FiatCurrency("GBP"), - new FiatCurrency("RUB"), - new FiatCurrency("UAH"), - new FiatCurrency("KZT"), - new FiatCurrency("BRL") - )); - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - public static List getAllMoneyGramCurrencies() { - ArrayList currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("AED"), - new FiatCurrency("ARS"), - new FiatCurrency("AUD"), - new FiatCurrency("BND"), - new FiatCurrency("CAD"), - new FiatCurrency("CHF"), - new FiatCurrency("CZK"), - new FiatCurrency("DKK"), - new FiatCurrency("EUR"), - new FiatCurrency("FJD"), - new FiatCurrency("GBP"), - new FiatCurrency("HKD"), - new FiatCurrency("HUF"), - new FiatCurrency("IDR"), - new FiatCurrency("ILS"), - new FiatCurrency("INR"), - new FiatCurrency("JPY"), - new FiatCurrency("KRW"), - new FiatCurrency("KWD"), - new FiatCurrency("LKR"), - new FiatCurrency("MAD"), - new FiatCurrency("MGA"), - new FiatCurrency("MXN"), - new FiatCurrency("MYR"), - new FiatCurrency("NOK"), - new FiatCurrency("NZD"), - new FiatCurrency("OMR"), - new FiatCurrency("PEN"), - new FiatCurrency("PGK"), - new FiatCurrency("PHP"), - new FiatCurrency("PKR"), - new FiatCurrency("PLN"), - new FiatCurrency("SAR"), - new FiatCurrency("SBD"), - new FiatCurrency("SCR"), - new FiatCurrency("SEK"), - new FiatCurrency("SGD"), - new FiatCurrency("THB"), - new FiatCurrency("TOP"), - new FiatCurrency("TRY"), - new FiatCurrency("TWD"), - new FiatCurrency("USD"), - new FiatCurrency("VND"), - new FiatCurrency("VUV"), - new FiatCurrency("WST"), - new FiatCurrency("XOF"), - new FiatCurrency("XPF"), - new FiatCurrency("ZAR") - )); - - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - // https://support.uphold.com/hc/en-us/articles/202473803-Supported-currencies - public static List getAllUpholdCurrencies() { - ArrayList currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("USD"), - new FiatCurrency("EUR"), - new FiatCurrency("GBP"), - new FiatCurrency("CNY"), - new FiatCurrency("JPY"), - new FiatCurrency("CHF"), - new FiatCurrency("INR"), - new FiatCurrency("MXN"), - new FiatCurrency("AUD"), - new FiatCurrency("CAD"), - new FiatCurrency("HKD"), - new FiatCurrency("NZD"), - new FiatCurrency("SGD"), - new FiatCurrency("KES"), - new FiatCurrency("ILS"), - new FiatCurrency("DKK"), - new FiatCurrency("NOK"), - new FiatCurrency("SEK"), - new FiatCurrency("PLN"), - new FiatCurrency("ARS"), - new FiatCurrency("BRL"), - new FiatCurrency("AED"), - new FiatCurrency("PHP") - )); - - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - // https://github.com/bisq-network/proposals/issues/243 - public static List getAllTransferwiseCurrencies() { - ArrayList currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("ARS"), - new FiatCurrency("AUD"), - new FiatCurrency("XOF"), - new FiatCurrency("BGN"), - new FiatCurrency("CAD"), - new FiatCurrency("CLP"), - new FiatCurrency("HRK"), - new FiatCurrency("CZK"), - new FiatCurrency("DKK"), - new FiatCurrency("EGP"), - new FiatCurrency("EUR"), - new FiatCurrency("GEL"), - new FiatCurrency("HKD"), - new FiatCurrency("HUF"), - new FiatCurrency("IDR"), - new FiatCurrency("ILS"), - new FiatCurrency("JPY"), - new FiatCurrency("KES"), - new FiatCurrency("MYR"), - new FiatCurrency("MXN"), - new FiatCurrency("MAD"), - new FiatCurrency("NPR"), - new FiatCurrency("NZD"), - new FiatCurrency("NOK"), - new FiatCurrency("PKR"), - new FiatCurrency("PEN"), - new FiatCurrency("PHP"), - new FiatCurrency("PLN"), - new FiatCurrency("RON"), - new FiatCurrency("RUB"), - new FiatCurrency("SGD"), - new FiatCurrency("ZAR"), - new FiatCurrency("KRW"), - new FiatCurrency("SEK"), - new FiatCurrency("CHF"), - new FiatCurrency("THB"), - new FiatCurrency("TRY"), - new FiatCurrency("UGX"), - new FiatCurrency("AED"), - new FiatCurrency("GBP"), - new FiatCurrency("VND"), - new FiatCurrency("ZMW") - )); - - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - // https://github.com/bisq-network/growth/issues/233 - public static List getAllPayseraCurrencies() { - ArrayList currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("AUD"), - new FiatCurrency("BGN"), - new FiatCurrency("BYN"), - new FiatCurrency("CAD"), - new FiatCurrency("CHF"), - new FiatCurrency("CNY"), - new FiatCurrency("CZK"), - new FiatCurrency("DKK"), - new FiatCurrency("EUR"), - new FiatCurrency("GBP"), - new FiatCurrency("GEL"), - new FiatCurrency("HKD"), - new FiatCurrency("HRK"), - new FiatCurrency("HUF"), - new FiatCurrency("ILS"), - new FiatCurrency("INR"), - new FiatCurrency("JPY"), - new FiatCurrency("KZT"), - new FiatCurrency("MXN"), - new FiatCurrency("NOK"), - new FiatCurrency("NZD"), - new FiatCurrency("PHP"), - new FiatCurrency("PLN"), - new FiatCurrency("RON"), - new FiatCurrency("RSD"), - new FiatCurrency("RUB"), - new FiatCurrency("SEK"), - new FiatCurrency("SGD"), - new FiatCurrency("THB"), - new FiatCurrency("TRY"), - new FiatCurrency("USD"), - new FiatCurrency("ZAR") - )); - - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - // https://github.com/bisq-network/growth/issues/235 - public static List getAllPaxumCurrencies() { - ArrayList currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("USD"), - new FiatCurrency("CAD"), - new FiatCurrency("EUR"), - new FiatCurrency("DKK"), - new FiatCurrency("CZK"), - new FiatCurrency("AUD"), - new FiatCurrency("ZAR"), - new FiatCurrency("THB"), - new FiatCurrency("CHF"), - new FiatCurrency("SEK"), - new FiatCurrency("RON"), - new FiatCurrency("PLN"), - new FiatCurrency("NZD"), - new FiatCurrency("NOK"), - new FiatCurrency("INR"), - new FiatCurrency("IDR"), - new FiatCurrency("HUF"), - new FiatCurrency("GBP") - )); - - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - public static List getAllAmazonGiftCardCurrencies() { - List currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("AUD"), - new FiatCurrency("CAD"), - new FiatCurrency("EUR"), - new FiatCurrency("GBP"), - new FiatCurrency("INR"), - new FiatCurrency("JPY"), - new FiatCurrency("SAR"), - new FiatCurrency("SEK"), - new FiatCurrency("SGD"), - new FiatCurrency("TRY"), - new FiatCurrency("USD") - )); - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - public static List getAllCapitualCurrencies() { - return new ArrayList<>(Arrays.asList( - new FiatCurrency("BRL"), - new FiatCurrency("EUR"), - new FiatCurrency("GBP"), - new FiatCurrency("USD") - )); - } - - // https://github.com/bisq-network/growth/issues/231 - public static List getAllCelPayCurrencies() { - return new ArrayList<>(Arrays.asList( - new FiatCurrency("AUD"), - new FiatCurrency("CAD"), - new FiatCurrency("GBP"), - new FiatCurrency("HKD"), - new FiatCurrency("USD") - )); - } - - // https://github.com/bisq-network/growth/issues/227 - public static List getAllMoneseCurrencies() { - return new ArrayList<>(Arrays.asList( - new FiatCurrency("EUR"), - new FiatCurrency("GBP"), - new FiatCurrency("RON") - )); - } - - // https://github.com/bisq-network/growth/issues/223 - public static List getAllVerseCurrencies() { - return new ArrayList<>(Arrays.asList( - new FiatCurrency("DKK"), - new FiatCurrency("EUR"), - new FiatCurrency("HUF"), - new FiatCurrency("PLN"), - new FiatCurrency("SEK") - )); - } - - // https://www.revolut.com/help/getting-started/exchanging-currencies/what-fiat-currencies-are-supported-for-holding-and-exchange - public static List getAllRevolutCurrencies() { - ArrayList currencies = new ArrayList<>(Arrays.asList( - new FiatCurrency("AED"), - new FiatCurrency("AUD"), - new FiatCurrency("BGN"), - new FiatCurrency("CAD"), - new FiatCurrency("CHF"), - new FiatCurrency("CZK"), - new FiatCurrency("DKK"), - new FiatCurrency("EUR"), - new FiatCurrency("GBP"), - new FiatCurrency("HKD"), - new FiatCurrency("HRK"), - new FiatCurrency("HUF"), - new FiatCurrency("ILS"), - new FiatCurrency("ISK"), - new FiatCurrency("JPY"), - new FiatCurrency("MAD"), - new FiatCurrency("MXN"), - new FiatCurrency("NOK"), - new FiatCurrency("NZD"), - new FiatCurrency("PLN"), - new FiatCurrency("QAR"), - new FiatCurrency("RON"), - new FiatCurrency("RSD"), - new FiatCurrency("RUB"), - new FiatCurrency("SAR"), - new FiatCurrency("SEK"), - new FiatCurrency("SGD"), - new FiatCurrency("THB"), - new FiatCurrency("TRY"), - new FiatCurrency("USD"), - new FiatCurrency("ZAR") - )); - - currencies.sort(Comparator.comparing(TradeCurrency::getCode)); - return currencies; - } - - public static List getAllInteracETransferIdCurrencies() { - return List.of(new FiatCurrency("CAD")); - } - - public static List getAllStrikeCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllTikkieIdCurrencies() { - return List.of(new FiatCurrency("EUR")); - } - - public static List getAllAliPayAccountCurrencies() { - return List.of(new FiatCurrency("CNY")); - } - - public static List getAllNequiCurrencies() { - return List.of(new FiatCurrency("COP")); - } - - public static List getAllIfscBankCurrencies() { - return List.of(new FiatCurrency("INR")); - } - - public static List getAllBizumCurrencies() { - return List.of(new FiatCurrency("EUR")); - } - - public static List getAllMoneyBeamCurrencies() { - return List.of(new FiatCurrency("EUR")); - } - - public static List getAllPixCurrencies() { - return List.of(new FiatCurrency("BRL")); - } - - public static List getAllSatispayCurrencies() { - return List.of(new FiatCurrency("EUR")); - } - - public static List getAllChaseQuickPayCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllUSPostalMoneyOrderCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllVenmoCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllFasterPaymentCurrencies() { - return List.of(new FiatCurrency("GBP")); - } - - public static List getAllJapanBankCurrencies() { - return List.of(new FiatCurrency("JPY")); - } - - public static List getAllWeChatPayCurrencies() { - return List.of(new FiatCurrency("CNY")); - } - - public static List getAllClearXchangeCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllAustraliaPayidCurrencies() { - return List.of(new FiatCurrency("AUD")); - } - - public static List getAllPerfectMoneyCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllHalCashCurrencies() { - return List.of(new FiatCurrency("EUR")); - } - - public static List getAllSwishCurrencies() { - return List.of(new FiatCurrency("SEK")); - } - - public static List getAllCashAppCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllPopmoneyCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllPromptPayCurrencies() { - return List.of(new FiatCurrency("THB")); - } - - public static List getAllSEPACurrencies() { - return List.of(new FiatCurrency("EUR")); - } - - public static List getAllDomesticWireTransferCurrencies() { - return List.of(new FiatCurrency("USD")); - } - - public static List getAllACHTransferCurrencies() { - return List.of(new FiatCurrency("USD")); - } - public static List getMatureMarketCurrencies() { ArrayList currencies = new ArrayList<>(Arrays.asList( new FiatCurrency("EUR"), @@ -644,9 +216,7 @@ public static boolean isFiatCurrency(String currencyCode) { return isFiatCurrency; } catch (Throwable t) { - if (currencyCode != null) { - isFiatCurrencyMap.put(currencyCode, false); - } + isFiatCurrencyMap.put(currencyCode, false); return false; } } @@ -684,7 +254,7 @@ public static boolean isCryptoCurrency(String currencyCode) { // It might be that an asset was removed from the assetsRegistry, we deal with such cases below by checking if // it is a fiat currency isCryptoCurrency = true; - } else if (!getFiatCurrency(currencyCode).isPresent()) { + } else if (getFiatCurrency(currencyCode).isEmpty()) { // In case the code is from a removed asset we cross check if there exist a fiat currency with that code, // if we don't find a fiat currency we treat it as a crypto currency. isCryptoCurrency = true; @@ -829,7 +399,7 @@ public static Optional findAsset(AssetRegistry assetRegistry, String curr .filter(asset -> assetMatchesCurrencyCode(asset, currencyCode)).collect(Collectors.toList()); // If we don't have the ticker symbol we throw an exception - if (!assets.stream().findFirst().isPresent()) + if (assets.stream().findFirst().isEmpty()) return Optional.empty(); if (currencyCode.equals("BSQ") && baseCurrencyNetwork.isMainnet() && !daoTradingActivated) @@ -846,8 +416,6 @@ public static Optional findAsset(AssetRegistry assetRegistry, String curr // that if no exact match was found in previous step if (!baseCurrencyNetwork.isMainnet()) { Optional optionalAsset = assets.stream().findFirst(); - checkArgument(optionalAsset.isPresent(), "optionalAsset must be present as we checked for " + - "not matching ticker symbols already above"); return optionalAsset; } diff --git a/core/src/main/java/bisq/core/payment/AchTransferAccount.java b/core/src/main/java/bisq/core/payment/AchTransferAccount.java index 386e9f2a798..7f8bfe678e0 100644 --- a/core/src/main/java/bisq/core/payment/AchTransferAccount.java +++ b/core/src/main/java/bisq/core/payment/AchTransferAccount.java @@ -17,15 +17,23 @@ package bisq.core.payment; -import bisq.core.payment.payload.BankAccountPayload; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.AchTransferAccountPayload; +import bisq.core.payment.payload.BankAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class AchTransferAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public AchTransferAccount() { super(PaymentMethod.ACH_TRANSFER); } @@ -60,4 +68,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.achTransfer.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/AdvancedCashAccount.java b/core/src/main/java/bisq/core/payment/AdvancedCashAccount.java index 688d1c53074..27156e0c899 100644 --- a/core/src/main/java/bisq/core/payment/AdvancedCashAccount.java +++ b/core/src/main/java/bisq/core/payment/AdvancedCashAccount.java @@ -17,18 +17,33 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.AdvancedCashAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class AdvancedCashAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("BRL"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("KZT"), + new FiatCurrency("RUB"), + new FiatCurrency("UAH"), + new FiatCurrency("USD")); + public AdvancedCashAccount() { super(PaymentMethod.ADVANCED_CASH); - tradeCurrencies.addAll(CurrencyUtil.getAllAdvancedCashCurrencies()); + tradeCurrencies.addAll(SUPPORTED_CURRENCIES); } @Override @@ -36,6 +51,12 @@ protected PaymentAccountPayload createPayload() { return new AdvancedCashAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountNr(String accountNr) { ((AdvancedCashAccountPayload) paymentAccountPayload).setAccountNr(accountNr); } diff --git a/core/src/main/java/bisq/core/payment/AliPayAccount.java b/core/src/main/java/bisq/core/payment/AliPayAccount.java index f126fd30169..7c20e29097f 100644 --- a/core/src/main/java/bisq/core/payment/AliPayAccount.java +++ b/core/src/main/java/bisq/core/payment/AliPayAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.AliPayAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class AliPayAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("CNY")); + public AliPayAccount() { super(PaymentMethod.ALI_PAY); - setSingleTradeCurrency(CurrencyUtil.getAllAliPayAccountCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new AliPayAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountNr(String accountNr) { ((AliPayAccountPayload) paymentAccountPayload).setAccountNr(accountNr); } diff --git a/core/src/main/java/bisq/core/payment/AmazonGiftCardAccount.java b/core/src/main/java/bisq/core/payment/AmazonGiftCardAccount.java index b65cbe6cbd3..b3fed9befc9 100644 --- a/core/src/main/java/bisq/core/payment/AmazonGiftCardAccount.java +++ b/core/src/main/java/bisq/core/payment/AmazonGiftCardAccount.java @@ -19,16 +19,34 @@ import bisq.core.locale.Country; import bisq.core.locale.CountryUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.AmazonGiftCardAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; public final class AmazonGiftCardAccount extends PaymentAccount { + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AUD"), + new FiatCurrency("CAD"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("INR"), + new FiatCurrency("JPY"), + new FiatCurrency("SAR"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("TRY"), + new FiatCurrency("USD") + ); + @Nullable private Country country; @@ -41,6 +59,12 @@ protected PaymentAccountPayload createPayload() { return new AmazonGiftCardAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public String getEmailOrMobileNr() { return getAmazonGiftCardAccountPayload().getEmailOrMobileNr(); } diff --git a/core/src/main/java/bisq/core/payment/AustraliaPayid.java b/core/src/main/java/bisq/core/payment/AustraliaPayidAccount.java similarity index 76% rename from core/src/main/java/bisq/core/payment/AustraliaPayid.java rename to core/src/main/java/bisq/core/payment/AustraliaPayidAccount.java index e24422fb1c4..a09a62209c8 100644 --- a/core/src/main/java/bisq/core/payment/AustraliaPayid.java +++ b/core/src/main/java/bisq/core/payment/AustraliaPayidAccount.java @@ -17,15 +17,23 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.AustraliaPayidPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -public final class AustraliaPayid extends PaymentAccount { - public AustraliaPayid() { +import java.util.List; + +import lombok.NonNull; + +public final class AustraliaPayidAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("AUD")); + + public AustraliaPayidAccount() { super(PaymentMethod.AUSTRALIA_PAYID); - setSingleTradeCurrency(CurrencyUtil.getAllAustraliaPayidCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -33,6 +41,11 @@ protected PaymentAccountPayload createPayload() { return new AustraliaPayidPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public String getPayid() { return ((AustraliaPayidPayload) paymentAccountPayload).getPayid(); } diff --git a/core/src/main/java/bisq/core/payment/BizumAccount.java b/core/src/main/java/bisq/core/payment/BizumAccount.java index 09d43b32acb..3fd995922af 100644 --- a/core/src/main/java/bisq/core/payment/BizumAccount.java +++ b/core/src/main/java/bisq/core/payment/BizumAccount.java @@ -17,14 +17,22 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; +import bisq.core.payment.payload.BizumAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -import bisq.core.payment.payload.BizumAccountPayload; + +import java.util.List; import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class BizumAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR")); + public BizumAccount() { super(PaymentMethod.BIZUM); } @@ -53,4 +61,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.bizum.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/BsqSwapAccount.java b/core/src/main/java/bisq/core/payment/BsqSwapAccount.java index bc5899d5343..b47026499da 100644 --- a/core/src/main/java/bisq/core/payment/BsqSwapAccount.java +++ b/core/src/main/java/bisq/core/payment/BsqSwapAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; +import bisq.core.locale.CryptoCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.BsqSwapAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import java.util.Date; +import java.util.List; import lombok.EqualsAndHashCode; +import lombok.NonNull; // Placeholder account for Bsq swaps. We do not hold any data here, its just used to fit into the // standard domain. We mimic the different trade protocol as a payment method with a dedicated account. @EqualsAndHashCode(callSuper = true) public final class BsqSwapAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new CryptoCurrency("BSQ", "BSQ")); + public static final String ID = "BsqSwapAccount"; public BsqSwapAccount() { @@ -47,4 +54,9 @@ protected PaymentAccountPayload createPayload() { return new BsqSwapAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + } diff --git a/core/src/main/java/bisq/core/payment/CapitualAccount.java b/core/src/main/java/bisq/core/payment/CapitualAccount.java index 46ba14a43f1..66752189705 100644 --- a/core/src/main/java/bisq/core/payment/CapitualAccount.java +++ b/core/src/main/java/bisq/core/payment/CapitualAccount.java @@ -17,18 +17,31 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.CapitualAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class CapitualAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("BRL"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("USD") + ); + public CapitualAccount() { super(PaymentMethod.CAPITUAL); - tradeCurrencies.addAll(CurrencyUtil.getAllCapitualCurrencies()); + tradeCurrencies.addAll(SUPPORTED_CURRENCIES); } @Override @@ -36,6 +49,12 @@ protected PaymentAccountPayload createPayload() { return new CapitualAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountNr(String accountNr) { ((CapitualAccountPayload) paymentAccountPayload).setAccountNr(accountNr); } diff --git a/core/src/main/java/bisq/core/payment/CashAppAccount.java b/core/src/main/java/bisq/core/payment/CashAppAccount.java index aa184d15f05..c88ad24b8a3 100644 --- a/core/src/main/java/bisq/core/payment/CashAppAccount.java +++ b/core/src/main/java/bisq/core/payment/CashAppAccount.java @@ -17,21 +17,28 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.CashAppAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; // Removed due too high chargeback risk // Cannot be deleted as it would break old trade history entries @Deprecated @EqualsAndHashCode(callSuper = true) public final class CashAppAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public CashAppAccount() { super(PaymentMethod.CASH_APP); - setSingleTradeCurrency(CurrencyUtil.getAllCashAppCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -39,6 +46,11 @@ protected PaymentAccountPayload createPayload() { return new CashAppAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setCashTag(String cashTag) { ((CashAppAccountPayload) paymentAccountPayload).setCashTag(cashTag); } diff --git a/core/src/main/java/bisq/core/payment/CashByMailAccount.java b/core/src/main/java/bisq/core/payment/CashByMailAccount.java index d7d1b85ecce..a2d9c653e5e 100644 --- a/core/src/main/java/bisq/core/payment/CashByMailAccount.java +++ b/core/src/main/java/bisq/core/payment/CashByMailAccount.java @@ -17,12 +17,20 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.CashByMailAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + +import lombok.NonNull; + public final class CashByMailAccount extends PaymentAccount { + public static final List SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies(); + public CashByMailAccount() { super(PaymentMethod.CASH_BY_MAIL); } @@ -32,6 +40,11 @@ protected PaymentAccountPayload createPayload() { return new CashByMailAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setPostalAddress(String postalAddress) { ((CashByMailAccountPayload) paymentAccountPayload).setPostalAddress(postalAddress); } diff --git a/core/src/main/java/bisq/core/payment/CashDepositAccount.java b/core/src/main/java/bisq/core/payment/CashDepositAccount.java index f39de46b57b..15ac2b3c725 100644 --- a/core/src/main/java/bisq/core/payment/CashDepositAccount.java +++ b/core/src/main/java/bisq/core/payment/CashDepositAccount.java @@ -17,13 +17,22 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.CashDepositAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + +import lombok.NonNull; + import javax.annotation.Nullable; public final class CashDepositAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount { + + public static final List SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies(); + public CashDepositAccount() { super(PaymentMethod.CASH_DEPOSIT); } @@ -33,6 +42,11 @@ protected PaymentAccountPayload createPayload() { return new CashDepositAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + @Override public String getBankId() { return ((CashDepositAccountPayload) paymentAccountPayload).getBankId(); diff --git a/core/src/main/java/bisq/core/payment/CelPayAccount.java b/core/src/main/java/bisq/core/payment/CelPayAccount.java index 4fbd12032cc..5f19d0cc756 100644 --- a/core/src/main/java/bisq/core/payment/CelPayAccount.java +++ b/core/src/main/java/bisq/core/payment/CelPayAccount.java @@ -17,14 +17,30 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; +import bisq.core.payment.payload.CelPayAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -import bisq.core.payment.payload.CelPayAccountPayload; + +import java.util.List; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class CelPayAccount extends PaymentAccount { + + // https://github.com/bisq-network/growth/issues/231 + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AUD"), + new FiatCurrency("CAD"), + new FiatCurrency("GBP"), + new FiatCurrency("HKD"), + new FiatCurrency("USD") + ); + public CelPayAccount() { super(PaymentMethod.CELPAY); } @@ -53,4 +69,10 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.celpay.info.account"; } + + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java b/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java index 2200fedac2c..1481f7cb067 100644 --- a/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java +++ b/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java @@ -17,21 +17,28 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.ChaseQuickPayAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; // Removed due to QuickPay becoming Zelle // Cannot be deleted as it would break old trade history entries @Deprecated @EqualsAndHashCode(callSuper = true) public final class ChaseQuickPayAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public ChaseQuickPayAccount() { super(PaymentMethod.CHASE_QUICK_PAY); - setSingleTradeCurrency(CurrencyUtil.getAllChaseQuickPayCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -39,6 +46,11 @@ protected PaymentAccountPayload createPayload() { return new ChaseQuickPayAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setEmail(String email) { ((ChaseQuickPayAccountPayload) paymentAccountPayload).setEmail(email); } diff --git a/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java b/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java index 42a9bdfeba9..72b572b3744 100644 --- a/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java +++ b/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.ClearXchangeAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class ClearXchangeAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public ClearXchangeAccount() { super(PaymentMethod.CLEAR_X_CHANGE); - setSingleTradeCurrency(CurrencyUtil.getAllClearXchangeCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new ClearXchangeAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setEmailOrMobileNr(String mobileNr) { ((ClearXchangeAccountPayload) paymentAccountPayload).setEmailOrMobileNr(mobileNr); } diff --git a/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java b/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java index 534157bd1f8..54935925388 100644 --- a/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java +++ b/core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java @@ -17,15 +17,23 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.CryptoCurrencyAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.ArrayList; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class CryptoCurrencyAccount extends AssetAccount { + public static final List SUPPORTED_CURRENCIES = new ArrayList<>(CurrencyUtil.getAllSortedCryptoCurrencies()); + public CryptoCurrencyAccount() { super(PaymentMethod.BLOCK_CHAINS); } @@ -34,4 +42,9 @@ public CryptoCurrencyAccount() { protected PaymentAccountPayload createPayload() { return new CryptoCurrencyAccountPayload(paymentMethod.getId(), id); } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/DomesticWireTransferAccount.java b/core/src/main/java/bisq/core/payment/DomesticWireTransferAccount.java index 4844211c335..b18ca82cd81 100644 --- a/core/src/main/java/bisq/core/payment/DomesticWireTransferAccount.java +++ b/core/src/main/java/bisq/core/payment/DomesticWireTransferAccount.java @@ -17,15 +17,23 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.BankAccountPayload; import bisq.core.payment.payload.DomesticWireTransferAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class DomesticWireTransferAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public DomesticWireTransferAccount() { super(PaymentMethod.DOMESTIC_WIRE_TRANSFER); } @@ -60,4 +68,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.domesticWire.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/F2FAccount.java b/core/src/main/java/bisq/core/payment/F2FAccount.java index 03554c3eb05..6f92ae1a863 100644 --- a/core/src/main/java/bisq/core/payment/F2FAccount.java +++ b/core/src/main/java/bisq/core/payment/F2FAccount.java @@ -17,14 +17,22 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.F2FAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class F2FAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies(); + public F2FAccount() { super(PaymentMethod.F2F); } @@ -34,6 +42,11 @@ protected PaymentAccountPayload createPayload() { return new F2FAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setContact(String contact) { ((F2FAccountPayload) paymentAccountPayload).setContact(contact); } diff --git a/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java b/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java index 0fbfd5b8eb7..e31e321c126 100644 --- a/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java +++ b/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.FasterPaymentsAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class FasterPaymentsAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("GBP")); + public FasterPaymentsAccount() { super(PaymentMethod.FASTER_PAYMENTS); - setSingleTradeCurrency(CurrencyUtil.getAllFasterPaymentCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new FasterPaymentsAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setHolderName(String value) { ((FasterPaymentsAccountPayload) paymentAccountPayload).setHolderName(value); } diff --git a/core/src/main/java/bisq/core/payment/HalCashAccount.java b/core/src/main/java/bisq/core/payment/HalCashAccount.java index fcec21acc48..ca79105c0e1 100644 --- a/core/src/main/java/bisq/core/payment/HalCashAccount.java +++ b/core/src/main/java/bisq/core/payment/HalCashAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.HalCashAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class HalCashAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR")); + public HalCashAccount() { super(PaymentMethod.HAL_CASH); - setSingleTradeCurrency(CurrencyUtil.getAllHalCashCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new HalCashAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setMobileNr(String mobileNr) { ((HalCashAccountPayload) paymentAccountPayload).setMobileNr(mobileNr); } diff --git a/core/src/main/java/bisq/core/payment/IfscBasedAccount.java b/core/src/main/java/bisq/core/payment/IfscBasedAccount.java new file mode 100644 index 00000000000..0a57f6d1d37 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/IfscBasedAccount.java @@ -0,0 +1,40 @@ +/* + * 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 bisq.core.payment; + +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; +import bisq.core.payment.payload.PaymentMethod; + +import java.util.List; + +import lombok.NonNull; + +abstract public class IfscBasedAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("INR")); + + protected IfscBasedAccount(PaymentMethod paymentMethod) { + super(paymentMethod); + } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } +} diff --git a/core/src/main/java/bisq/core/payment/ImpsAccount.java b/core/src/main/java/bisq/core/payment/ImpsAccount.java index f16349e8ad5..eee6f49d970 100644 --- a/core/src/main/java/bisq/core/payment/ImpsAccount.java +++ b/core/src/main/java/bisq/core/payment/ImpsAccount.java @@ -17,14 +17,22 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; +import bisq.core.payment.payload.ImpsAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -import bisq.core.payment.payload.ImpsAccountPayload; + +import java.util.List; import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class ImpsAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("INR")); + public ImpsAccount() { super(PaymentMethod.IMPS); } @@ -45,4 +53,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.imps.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/InstantCryptoCurrencyAccount.java b/core/src/main/java/bisq/core/payment/InstantCryptoCurrencyAccount.java index 17ddf5eca77..7810463d558 100644 --- a/core/src/main/java/bisq/core/payment/InstantCryptoCurrencyAccount.java +++ b/core/src/main/java/bisq/core/payment/InstantCryptoCurrencyAccount.java @@ -17,15 +17,23 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.InstantCryptoCurrencyPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.ArrayList; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class InstantCryptoCurrencyAccount extends AssetAccount { + public static final List SUPPORTED_CURRENCIES = new ArrayList<>(CurrencyUtil.getAllSortedCryptoCurrencies()); + public InstantCryptoCurrencyAccount() { super(PaymentMethod.BLOCK_CHAINS_INSTANT); } @@ -34,4 +42,9 @@ public InstantCryptoCurrencyAccount() { protected PaymentAccountPayload createPayload() { return new InstantCryptoCurrencyPayload(paymentMethod.getId(), id); } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/InteracETransferAccount.java b/core/src/main/java/bisq/core/payment/InteracETransferAccount.java index 8341c9040e5..0fece8b1113 100644 --- a/core/src/main/java/bisq/core/payment/InteracETransferAccount.java +++ b/core/src/main/java/bisq/core/payment/InteracETransferAccount.java @@ -17,18 +17,26 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.InteracETransferAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class InteracETransferAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("CAD")); + public InteracETransferAccount() { super(PaymentMethod.INTERAC_E_TRANSFER); - setSingleTradeCurrency(CurrencyUtil.getAllInteracETransferIdCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +44,12 @@ protected PaymentAccountPayload createPayload() { return new InteracETransferAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setEmail(String email) { ((InteracETransferAccountPayload) paymentAccountPayload).setEmail(email); } diff --git a/core/src/main/java/bisq/core/payment/JapanBankAccount.java b/core/src/main/java/bisq/core/payment/JapanBankAccount.java index 6657f33d5ac..99ff306d99f 100644 --- a/core/src/main/java/bisq/core/payment/JapanBankAccount.java +++ b/core/src/main/java/bisq/core/payment/JapanBankAccount.java @@ -17,98 +17,101 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.JapanBankAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -public final class JapanBankAccount extends PaymentAccount -{ - public JapanBankAccount() - { +import java.util.List; + +import lombok.NonNull; + +public final class JapanBankAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("JPY")); + + public JapanBankAccount() { super(PaymentMethod.JAPAN_BANK); - setSingleTradeCurrency(CurrencyUtil.getAllJapanBankCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override - protected PaymentAccountPayload createPayload() - { + protected PaymentAccountPayload createPayload() { return new JapanBankAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + // bank code - public String getBankCode() - { + public String getBankCode() { return ((JapanBankAccountPayload) paymentAccountPayload).getBankCode(); } - public void setBankCode(String bankCode) - { + + public void setBankCode(String bankCode) { if (bankCode == null) bankCode = ""; ((JapanBankAccountPayload) paymentAccountPayload).setBankCode(bankCode); } // bank name - public String getBankName() - { + public String getBankName() { return ((JapanBankAccountPayload) paymentAccountPayload).getBankName(); } - public void setBankName(String bankName) - { + + public void setBankName(String bankName) { if (bankName == null) bankName = ""; ((JapanBankAccountPayload) paymentAccountPayload).setBankName(bankName); } // branch code - public String getBankBranchCode() - { + public String getBankBranchCode() { return ((JapanBankAccountPayload) paymentAccountPayload).getBankBranchCode(); } - public void setBankBranchCode(String bankBranchCode) - { + + public void setBankBranchCode(String bankBranchCode) { if (bankBranchCode == null) bankBranchCode = ""; ((JapanBankAccountPayload) paymentAccountPayload).setBankBranchCode(bankBranchCode); } // branch name - public String getBankBranchName() - { + public String getBankBranchName() { return ((JapanBankAccountPayload) paymentAccountPayload).getBankBranchName(); } - public void setBankBranchName(String bankBranchName) - { + + public void setBankBranchName(String bankBranchName) { if (bankBranchName == null) bankBranchName = ""; ((JapanBankAccountPayload) paymentAccountPayload).setBankBranchName(bankBranchName); } // account type - public String getBankAccountType() - { + public String getBankAccountType() { return ((JapanBankAccountPayload) paymentAccountPayload).getBankAccountType(); } - public void setBankAccountType(String bankAccountType) - { + + public void setBankAccountType(String bankAccountType) { if (bankAccountType == null) bankAccountType = ""; ((JapanBankAccountPayload) paymentAccountPayload).setBankAccountType(bankAccountType); } // account number - public String getBankAccountNumber() - { + public String getBankAccountNumber() { return ((JapanBankAccountPayload) paymentAccountPayload).getBankAccountNumber(); } - public void setBankAccountNumber(String bankAccountNumber) - { + + public void setBankAccountNumber(String bankAccountNumber) { if (bankAccountNumber == null) bankAccountNumber = ""; ((JapanBankAccountPayload) paymentAccountPayload).setBankAccountNumber(bankAccountNumber); } // account name - public String getBankAccountName() - { + public String getBankAccountName() { return ((JapanBankAccountPayload) paymentAccountPayload).getBankAccountName(); } - public void setBankAccountName(String bankAccountName) - { + + public void setBankAccountName(String bankAccountName) { if (bankAccountName == null) bankAccountName = ""; ((JapanBankAccountPayload) paymentAccountPayload).setBankAccountName(bankAccountName); } diff --git a/core/src/main/java/bisq/core/payment/MoneseAccount.java b/core/src/main/java/bisq/core/payment/MoneseAccount.java index efc583c325b..14ca436b285 100644 --- a/core/src/main/java/bisq/core/payment/MoneseAccount.java +++ b/core/src/main/java/bisq/core/payment/MoneseAccount.java @@ -17,14 +17,27 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.MoneseAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class MoneseAccount extends PaymentAccount { + + // https://github.com/bisq-network/growth/issues/227 + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("RON") + ); + public MoneseAccount() { super(PaymentMethod.MONESE); } @@ -61,4 +74,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.monese.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java b/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java index c63ea68b5ff..e85bf70071e 100644 --- a/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java +++ b/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java @@ -17,19 +17,26 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.MoneyBeamAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; //TODO missing support for selected trade currency @EqualsAndHashCode(callSuper = true) public final class MoneyBeamAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR")); + public MoneyBeamAccount() { super(PaymentMethod.MONEY_BEAM); - setSingleTradeCurrency(CurrencyUtil.getAllMoneyBeamCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -37,6 +44,11 @@ protected PaymentAccountPayload createPayload() { return new MoneyBeamAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountId(String accountId) { ((MoneyBeamAccountPayload) paymentAccountPayload).setAccountId(accountId); } diff --git a/core/src/main/java/bisq/core/payment/MoneyGramAccount.java b/core/src/main/java/bisq/core/payment/MoneyGramAccount.java index 996fa013782..ea17f5a0e5f 100644 --- a/core/src/main/java/bisq/core/payment/MoneyGramAccount.java +++ b/core/src/main/java/bisq/core/payment/MoneyGramAccount.java @@ -19,11 +19,14 @@ import bisq.core.locale.Country; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.MoneyGramAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; import org.jetbrains.annotations.NotNull; @@ -36,10 +39,60 @@ public final class MoneyGramAccount extends PaymentAccount { @Nullable private Country country; + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AED"), + new FiatCurrency("ARS"), + new FiatCurrency("AUD"), + new FiatCurrency("BND"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CZK"), + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("FJD"), + new FiatCurrency("GBP"), + new FiatCurrency("HKD"), + new FiatCurrency("HUF"), + new FiatCurrency("IDR"), + new FiatCurrency("ILS"), + new FiatCurrency("INR"), + new FiatCurrency("JPY"), + new FiatCurrency("KRW"), + new FiatCurrency("KWD"), + new FiatCurrency("LKR"), + new FiatCurrency("MAD"), + new FiatCurrency("MGA"), + new FiatCurrency("MXN"), + new FiatCurrency("MYR"), + new FiatCurrency("NOK"), + new FiatCurrency("NZD"), + new FiatCurrency("OMR"), + new FiatCurrency("PEN"), + new FiatCurrency("PGK"), + new FiatCurrency("PHP"), + new FiatCurrency("PKR"), + new FiatCurrency("PLN"), + new FiatCurrency("SAR"), + new FiatCurrency("SBD"), + new FiatCurrency("SCR"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("THB"), + new FiatCurrency("TOP"), + new FiatCurrency("TRY"), + new FiatCurrency("TWD"), + new FiatCurrency("USD"), + new FiatCurrency("VND"), + new FiatCurrency("VUV"), + new FiatCurrency("WST"), + new FiatCurrency("XOF"), + new FiatCurrency("XPF"), + new FiatCurrency("ZAR") + ); public MoneyGramAccount() { super(PaymentMethod.MONEY_GRAM); - tradeCurrencies.addAll(CurrencyUtil.getAllMoneyGramCurrencies()); + tradeCurrencies.addAll(SUPPORTED_CURRENCIES); } @Override @@ -47,6 +100,12 @@ protected PaymentAccountPayload createPayload() { return new MoneyGramAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + @Nullable public Country getCountry() { if (country == null) { diff --git a/core/src/main/java/bisq/core/payment/NationalBankAccount.java b/core/src/main/java/bisq/core/payment/NationalBankAccount.java index bccad09e17f..01a7b10222e 100644 --- a/core/src/main/java/bisq/core/payment/NationalBankAccount.java +++ b/core/src/main/java/bisq/core/payment/NationalBankAccount.java @@ -17,15 +17,23 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.BankAccountPayload; import bisq.core.payment.payload.NationalBankAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class NationalBankAccount extends CountryBasedPaymentAccount implements SameCountryRestrictedBankAccount { + + public static final List SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies(); + public NationalBankAccount() { super(PaymentMethod.NATIONAL_BANK); } @@ -35,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new NationalBankAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + @Override public String getBankId() { return ((BankAccountPayload) paymentAccountPayload).getBankId(); diff --git a/core/src/main/java/bisq/core/payment/NeftAccount.java b/core/src/main/java/bisq/core/payment/NeftAccount.java index cb954d8d872..1277cdc850e 100644 --- a/core/src/main/java/bisq/core/payment/NeftAccount.java +++ b/core/src/main/java/bisq/core/payment/NeftAccount.java @@ -17,14 +17,15 @@ package bisq.core.payment; +import bisq.core.payment.payload.NeftAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -import bisq.core.payment.payload.NeftAccountPayload; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) -public final class NeftAccount extends CountryBasedPaymentAccount { +public final class NeftAccount extends IfscBasedAccount { + public NeftAccount() { super(PaymentMethod.NEFT); } @@ -45,4 +46,5 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.neft.info.account"; } + } diff --git a/core/src/main/java/bisq/core/payment/NequiAccount.java b/core/src/main/java/bisq/core/payment/NequiAccount.java index d623ccf78ff..60126703b8e 100644 --- a/core/src/main/java/bisq/core/payment/NequiAccount.java +++ b/core/src/main/java/bisq/core/payment/NequiAccount.java @@ -17,14 +17,22 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; +import bisq.core.payment.payload.NequiAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -import bisq.core.payment.payload.NequiAccountPayload; + +import java.util.List; import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class NequiAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("COP")); + public NequiAccount() { super(PaymentMethod.NEQUI); } @@ -53,4 +61,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.nequi.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/OKPayAccount.java b/core/src/main/java/bisq/core/payment/OKPayAccount.java index 24730181708..ed4f5093631 100644 --- a/core/src/main/java/bisq/core/payment/OKPayAccount.java +++ b/core/src/main/java/bisq/core/payment/OKPayAccount.java @@ -17,22 +17,53 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.OKPayAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + // Cannot be deleted as it would break old trade history entries @Deprecated @EqualsAndHashCode(callSuper = true) public final class OKPayAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AED"), + new FiatCurrency("ARS"), + new FiatCurrency("AUD"), + new FiatCurrency("BRL"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CNY"), + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("HKD"), + new FiatCurrency("ILS"), + new FiatCurrency("INR"), + new FiatCurrency("JPY"), + new FiatCurrency("KES"), + new FiatCurrency("MXN"), + new FiatCurrency("NOK"), + new FiatCurrency("NZD"), + new FiatCurrency("PHP"), + new FiatCurrency("PLN"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("USD") + ); + public OKPayAccount() { super(PaymentMethod.OK_PAY); - // Incorrect call but we don't want to keep Deprecated code in CurrencyUtil if not needed... - tradeCurrencies.addAll(CurrencyUtil.getAllUpholdCurrencies()); + tradeCurrencies.addAll(SUPPORTED_CURRENCIES); } @Override @@ -40,6 +71,12 @@ protected PaymentAccountPayload createPayload() { return new OKPayAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountNr(String accountNr) { ((OKPayAccountPayload) paymentAccountPayload).setAccountNr(accountNr); } diff --git a/core/src/main/java/bisq/core/payment/PaxumAccount.java b/core/src/main/java/bisq/core/payment/PaxumAccount.java index e95111f47ad..11618ec08b8 100644 --- a/core/src/main/java/bisq/core/payment/PaxumAccount.java +++ b/core/src/main/java/bisq/core/payment/PaxumAccount.java @@ -17,14 +17,43 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; +import bisq.core.payment.payload.PaxumAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; -import bisq.core.payment.payload.PaxumAccountPayload; + +import java.util.List; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class PaxumAccount extends PaymentAccount { + + // https://github.com/bisq-network/growth/issues/235 + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AUD"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CZK"), + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("HUF"), + new FiatCurrency("IDR"), + new FiatCurrency("INR"), + new FiatCurrency("NOK"), + new FiatCurrency("NZD"), + new FiatCurrency("PLN"), + new FiatCurrency("RON"), + new FiatCurrency("SEK"), + new FiatCurrency("THB"), + new FiatCurrency("USD"), + new FiatCurrency("ZAR") + ); + public PaxumAccount() { super(PaymentMethod.PAXUM); } @@ -34,6 +63,12 @@ protected PaymentAccountPayload createPayload() { return new PaxumAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setEmail(String accountId) { ((PaxumAccountPayload) paymentAccountPayload).setEmail(accountId); } diff --git a/core/src/main/java/bisq/core/payment/PaymentAccount.java b/core/src/main/java/bisq/core/payment/PaymentAccount.java index 2faf2b538df..b95802fb1cb 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccount.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccount.java @@ -35,6 +35,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.ToString; import lombok.extern.slf4j.Slf4j; @@ -49,6 +50,7 @@ @Getter @Slf4j public abstract class PaymentAccount implements PersistablePayload { + protected final PaymentMethod paymentMethod; @Setter protected String id; @@ -259,4 +261,7 @@ public void onPersistChanges() { public void revertChanges() { setAccountName(getPersistedAccountName()); } + + @NonNull + public abstract List getSupportedCurrencies(); } diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java index 8e3c1e74a36..0cd171949d1 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountFactory.java @@ -47,7 +47,7 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) { case PaymentMethod.JAPAN_BANK_ID: return new JapanBankAccount(); case PaymentMethod.AUSTRALIA_PAYID_ID: - return new AustraliaPayid(); + return new AustraliaPayidAccount(); case PaymentMethod.ALI_PAY_ID: return new AliPayAccount(); case PaymentMethod.WECHAT_PAY_ID: diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java index 363aea0a0b8..1cec80bdc5c 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java @@ -40,9 +40,7 @@ import javax.annotation.Nullable; -import static bisq.core.locale.CurrencyUtil.*; import static bisq.core.payment.payload.PaymentMethod.*; -import static java.util.Comparator.comparing; @Slf4j public class PaymentAccountUtil { @@ -115,101 +113,107 @@ public static ArrayList getAcceptedCountryCodes(PaymentAccount paymentAc public static List getTradeCurrencies(PaymentMethod paymentMethod) { switch (paymentMethod.getId()) { case ADVANCED_CASH_ID: - return getAllAdvancedCashCurrencies(); + return AdvancedCashAccount.SUPPORTED_CURRENCIES; case AMAZON_GIFT_CARD_ID: - return getAllAmazonGiftCardCurrencies(); + return AmazonGiftCardAccount.SUPPORTED_CURRENCIES; case CAPITUAL_ID: - return getAllCapitualCurrencies(); + return CapitualAccount.SUPPORTED_CURRENCIES; case MONEY_GRAM_ID: - return getAllMoneyGramCurrencies(); + return MoneyGramAccount.SUPPORTED_CURRENCIES; case PAXUM_ID: - return getAllPaxumCurrencies(); + return PaxumAccount.SUPPORTED_CURRENCIES; case PAYSERA_ID: - return getAllPayseraCurrencies(); + return PayseraAccount.SUPPORTED_CURRENCIES; case REVOLUT_ID: - return getAllRevolutCurrencies(); + return RevolutAccount.SUPPORTED_CURRENCIES; case SWIFT_ID: - return new ArrayList<>(getAllSortedFiatCurrencies( - comparing(TradeCurrency::getCode))); + return SwiftAccount.SUPPORTED_CURRENCIES; case TRANSFERWISE_ID: - return getAllTransferwiseCurrencies(); + return TransferwiseAccount.SUPPORTED_CURRENCIES; case UPHOLD_ID: - return getAllUpholdCurrencies(); + return UpholdAccount.SUPPORTED_CURRENCIES; case INTERAC_E_TRANSFER_ID: - return getAllInteracETransferIdCurrencies(); + return InteracETransferAccount.SUPPORTED_CURRENCIES; case STRIKE_ID: - return getAllStrikeCurrencies(); + return StrikeAccount.SUPPORTED_CURRENCIES; case TIKKIE_ID: - return getAllTikkieIdCurrencies(); + return TikkieAccount.SUPPORTED_CURRENCIES; case ALI_PAY_ID: - return getAllAliPayAccountCurrencies(); + return AliPayAccount.SUPPORTED_CURRENCIES; case NEQUI_ID: - return getAllNequiCurrencies(); + return NequiAccount.SUPPORTED_CURRENCIES; case IMPS_ID: case NEFT_ID: case PAYTM_ID: case RTGS_ID: case UPI_ID: - return getAllIfscBankCurrencies(); + return IfscBasedAccount.SUPPORTED_CURRENCIES; case BIZUM_ID: - return getAllBizumCurrencies(); + return BizumAccount.SUPPORTED_CURRENCIES; case MONEY_BEAM_ID: - return getAllMoneyBeamCurrencies(); + return MoneyBeamAccount.SUPPORTED_CURRENCIES; case PIX_ID: - return getAllPixCurrencies(); + return PixAccount.SUPPORTED_CURRENCIES; case SATISPAY_ID: - return getAllSatispayCurrencies(); + return SatispayAccount.SUPPORTED_CURRENCIES; case CHASE_QUICK_PAY_ID: - return getAllChaseQuickPayCurrencies(); + return ChaseQuickPayAccount.SUPPORTED_CURRENCIES; case US_POSTAL_MONEY_ORDER_ID: - return getAllUSPostalMoneyOrderCurrencies(); + return USPostalMoneyOrderAccount.SUPPORTED_CURRENCIES; case VENMO_ID: - return getAllVenmoCurrencies(); + return VenmoAccount.SUPPORTED_CURRENCIES; case JAPAN_BANK_ID: - return getAllJapanBankCurrencies(); + return JapanBankAccount.SUPPORTED_CURRENCIES; case WECHAT_PAY_ID: - return getAllWeChatPayCurrencies(); + return WeChatPayAccount.SUPPORTED_CURRENCIES; case CLEAR_X_CHANGE_ID: - return getAllClearXchangeCurrencies(); + return ClearXchangeAccount.SUPPORTED_CURRENCIES; case AUSTRALIA_PAYID_ID: - return getAllAustraliaPayidCurrencies(); + return AustraliaPayidAccount.SUPPORTED_CURRENCIES; case PERFECT_MONEY_ID: - return getAllPerfectMoneyCurrencies(); + return PerfectMoneyAccount.SUPPORTED_CURRENCIES; case HAL_CASH_ID: - return getAllHalCashCurrencies(); + return HalCashAccount.SUPPORTED_CURRENCIES; case SWISH_ID: - return getAllSwishCurrencies(); + return SwishAccount.SUPPORTED_CURRENCIES; case CASH_APP_ID: - return getAllCashAppCurrencies(); + return CashAppAccount.SUPPORTED_CURRENCIES; case POPMONEY_ID: - return getAllPopmoneyCurrencies(); + return PopmoneyAccount.SUPPORTED_CURRENCIES; case PROMPT_PAY_ID: - return getAllPromptPayCurrencies(); + return PromptPayAccount.SUPPORTED_CURRENCIES; case SEPA_ID: + return SepaAccount.SUPPORTED_CURRENCIES; case SEPA_INSTANT_ID: - return getAllSEPACurrencies(); + return SepaInstantAccount.SUPPORTED_CURRENCIES; case CASH_BY_MAIL_ID: + return CashByMailAccount.SUPPORTED_CURRENCIES; case F2F_ID: + return F2FAccount.SUPPORTED_CURRENCIES; case NATIONAL_BANK_ID: + return NationalBankAccount.SUPPORTED_CURRENCIES; case SAME_BANK_ID: + return SameBankAccount.SUPPORTED_CURRENCIES; case SPECIFIC_BANKS_ID: + return SpecificBanksAccount.SUPPORTED_CURRENCIES; case CASH_DEPOSIT_ID: + return CashDepositAccount.SUPPORTED_CURRENCIES; case WESTERN_UNION_ID: - return getAllFiatCurrencies(); + return WesternUnionAccount.SUPPORTED_CURRENCIES; case FASTER_PAYMENTS_ID: - return getAllFasterPaymentCurrencies(); + return FasterPaymentsAccount.SUPPORTED_CURRENCIES; case DOMESTIC_WIRE_TRANSFER_ID: - return getAllDomesticWireTransferCurrencies(); + return DomesticWireTransferAccount.SUPPORTED_CURRENCIES; case ACH_TRANSFER_ID: - return getAllACHTransferCurrencies(); + return AchTransferAccount.SUPPORTED_CURRENCIES; case CELPAY_ID: - return getAllCelPayCurrencies(); + return CelPayAccount.SUPPORTED_CURRENCIES; case MONESE_ID: - return getAllMoneseCurrencies(); + return MoneseAccount.SUPPORTED_CURRENCIES; case TRANSFERWISE_USD_ID: - return getAllTransferwiseUSDCurrencies(); + return TransferwiseUsdAccount.SUPPORTED_CURRENCIES; case VERSE_ID: - return getAllVerseCurrencies(); + return VerseAccount.SUPPORTED_CURRENCIES; default: return Collections.emptyList(); } diff --git a/core/src/main/java/bisq/core/payment/PayseraAccount.java b/core/src/main/java/bisq/core/payment/PayseraAccount.java index 0f943a1c1d8..a039e47a26e 100644 --- a/core/src/main/java/bisq/core/payment/PayseraAccount.java +++ b/core/src/main/java/bisq/core/payment/PayseraAccount.java @@ -17,14 +17,57 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PayseraAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class PayseraAccount extends PaymentAccount { + + // https://github.com/bisq-network/growth/issues/233 + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AUD"), + new FiatCurrency("BGN"), + new FiatCurrency("BYN"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CNY"), + new FiatCurrency("CZK"), + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("GEL"), + new FiatCurrency("HKD"), + new FiatCurrency("HRK"), + new FiatCurrency("HUF"), + new FiatCurrency("ILS"), + new FiatCurrency("INR"), + new FiatCurrency("JPY"), + new FiatCurrency("KZT"), + new FiatCurrency("MXN"), + new FiatCurrency("NOK"), + new FiatCurrency("NZD"), + new FiatCurrency("PHP"), + new FiatCurrency("PLN"), + new FiatCurrency("RON"), + new FiatCurrency("RSD"), + new FiatCurrency("RUB"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("THB"), + new FiatCurrency("TRY"), + new FiatCurrency("USD"), + new FiatCurrency("ZAR") + ); + public PayseraAccount() { super(PaymentMethod.PAYSERA); } @@ -34,6 +77,12 @@ protected PaymentAccountPayload createPayload() { return new PayseraAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setEmail(String accountId) { ((PayseraAccountPayload) paymentAccountPayload).setEmail(accountId); } diff --git a/core/src/main/java/bisq/core/payment/PaytmAccount.java b/core/src/main/java/bisq/core/payment/PaytmAccount.java index d2b27c7b478..93394adf56d 100644 --- a/core/src/main/java/bisq/core/payment/PaytmAccount.java +++ b/core/src/main/java/bisq/core/payment/PaytmAccount.java @@ -24,7 +24,7 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) -public final class PaytmAccount extends CountryBasedPaymentAccount { +public final class PaytmAccount extends IfscBasedAccount { public PaytmAccount() { super(PaymentMethod.PAYTM); } diff --git a/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java b/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java index 0aa77dcda14..dbd8355f504 100644 --- a/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java +++ b/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PerfectMoneyAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class PerfectMoneyAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public PerfectMoneyAccount() { super(PaymentMethod.PERFECT_MONEY); - setSingleTradeCurrency(CurrencyUtil.getAllPerfectMoneyCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new PerfectMoneyAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountNr(String accountNr) { ((PerfectMoneyAccountPayload) paymentAccountPayload).setAccountNr(accountNr); } diff --git a/core/src/main/java/bisq/core/payment/PixAccount.java b/core/src/main/java/bisq/core/payment/PixAccount.java index 9d40cf8a3e9..8096d6ff306 100644 --- a/core/src/main/java/bisq/core/payment/PixAccount.java +++ b/core/src/main/java/bisq/core/payment/PixAccount.java @@ -17,14 +17,22 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PixAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class PixAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("BRL")); + public PixAccount() { super(PaymentMethod.PIX); } @@ -53,4 +61,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.pix.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/PopmoneyAccount.java b/core/src/main/java/bisq/core/payment/PopmoneyAccount.java index 89a3d2d8705..3ebc60449c2 100644 --- a/core/src/main/java/bisq/core/payment/PopmoneyAccount.java +++ b/core/src/main/java/bisq/core/payment/PopmoneyAccount.java @@ -17,19 +17,26 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PopmoneyAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; //TODO missing support for selected trade currency @EqualsAndHashCode(callSuper = true) public final class PopmoneyAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public PopmoneyAccount() { super(PaymentMethod.POPMONEY); - setSingleTradeCurrency(CurrencyUtil.getAllPopmoneyCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -37,6 +44,11 @@ protected PaymentAccountPayload createPayload() { return new PopmoneyAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountId(String accountId) { ((PopmoneyAccountPayload) paymentAccountPayload).setAccountId(accountId); } diff --git a/core/src/main/java/bisq/core/payment/PromptPayAccount.java b/core/src/main/java/bisq/core/payment/PromptPayAccount.java index ab22ea6d782..00a3d771cd0 100644 --- a/core/src/main/java/bisq/core/payment/PromptPayAccount.java +++ b/core/src/main/java/bisq/core/payment/PromptPayAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.PromptPayAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class PromptPayAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("THB")); + public PromptPayAccount() { super(PaymentMethod.PROMPT_PAY); - setSingleTradeCurrency(CurrencyUtil.getAllPromptPayCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new PromptPayAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setPromptPayId(String promptPayId) { ((PromptPayAccountPayload) paymentAccountPayload).setPromptPayId(promptPayId); } diff --git a/core/src/main/java/bisq/core/payment/RevolutAccount.java b/core/src/main/java/bisq/core/payment/RevolutAccount.java index 93191bbac01..0e0d225bedc 100644 --- a/core/src/main/java/bisq/core/payment/RevolutAccount.java +++ b/core/src/main/java/bisq/core/payment/RevolutAccount.java @@ -17,18 +17,58 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.RevolutAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class RevolutAccount extends PaymentAccount { + + // https://www.revolut.com/help/getting-started/exchanging-currencies/what-fiat-currencies-are-supported-for-holding-and-exchange + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AED"), + new FiatCurrency("AUD"), + new FiatCurrency("BGN"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CZK"), + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("HKD"), + new FiatCurrency("HRK"), + new FiatCurrency("HUF"), + new FiatCurrency("ILS"), + new FiatCurrency("ISK"), + new FiatCurrency("JPY"), + new FiatCurrency("MAD"), + new FiatCurrency("MXN"), + new FiatCurrency("NOK"), + new FiatCurrency("NZD"), + new FiatCurrency("PLN"), + new FiatCurrency("QAR"), + new FiatCurrency("RON"), + new FiatCurrency("RSD"), + new FiatCurrency("RUB"), + new FiatCurrency("SAR"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("THB"), + new FiatCurrency("TRY"), + new FiatCurrency("USD"), + new FiatCurrency("ZAR") + ); + public RevolutAccount() { super(PaymentMethod.REVOLUT); - tradeCurrencies.addAll(CurrencyUtil.getAllRevolutCurrencies()); + tradeCurrencies.addAll(getSupportedCurrencies()); } @Override @@ -67,4 +107,9 @@ public void onAddToUser() { // At save we apply the userName to accountId in case it is empty for backward compatibility revolutAccountPayload().maybeApplyUserNameToAccountId(); } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/RtgsAccount.java b/core/src/main/java/bisq/core/payment/RtgsAccount.java index 0b9b2156faf..507b6c034fd 100644 --- a/core/src/main/java/bisq/core/payment/RtgsAccount.java +++ b/core/src/main/java/bisq/core/payment/RtgsAccount.java @@ -24,7 +24,8 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) -public final class RtgsAccount extends CountryBasedPaymentAccount { +public final class RtgsAccount extends IfscBasedAccount { + public RtgsAccount() { super(PaymentMethod.RTGS); } diff --git a/core/src/main/java/bisq/core/payment/SameBankAccount.java b/core/src/main/java/bisq/core/payment/SameBankAccount.java index d561cf582b5..750c47ca898 100644 --- a/core/src/main/java/bisq/core/payment/SameBankAccount.java +++ b/core/src/main/java/bisq/core/payment/SameBankAccount.java @@ -17,15 +17,23 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.BankAccountPayload; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SameBankAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class SameBankAccount extends CountryBasedPaymentAccount implements BankNameRestrictedBankAccount, SameCountryRestrictedBankAccount { + + public static final List SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies(); + public SameBankAccount() { super(PaymentMethod.SAME_BANK); } @@ -35,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new SameBankAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + @Override public String getBankId() { return ((BankAccountPayload) paymentAccountPayload).getBankId(); diff --git a/core/src/main/java/bisq/core/payment/SatispayAccount.java b/core/src/main/java/bisq/core/payment/SatispayAccount.java index f1d9b6f69f7..dc75b7240fc 100644 --- a/core/src/main/java/bisq/core/payment/SatispayAccount.java +++ b/core/src/main/java/bisq/core/payment/SatispayAccount.java @@ -17,14 +17,22 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SatispayAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class SatispayAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR")); + public SatispayAccount() { super(PaymentMethod.SATISPAY); } @@ -61,4 +69,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.satispay.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/SepaAccount.java b/core/src/main/java/bisq/core/payment/SepaAccount.java index 435f6649b5c..2ad436faa57 100644 --- a/core/src/main/java/bisq/core/payment/SepaAccount.java +++ b/core/src/main/java/bisq/core/payment/SepaAccount.java @@ -18,6 +18,8 @@ package bisq.core.payment; import bisq.core.locale.CountryUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SepaAccountPayload; @@ -26,10 +28,16 @@ import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class SepaAccount extends CountryBasedPaymentAccount implements BankAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR")); + public SepaAccount() { super(PaymentMethod.SEPA); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -90,4 +98,10 @@ public void revertChanges() { super.revertChanges(); ((SepaAccountPayload) paymentAccountPayload).revertChanges(); } + + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/SepaInstantAccount.java b/core/src/main/java/bisq/core/payment/SepaInstantAccount.java index 3c778cfaeec..00f0bc969a2 100644 --- a/core/src/main/java/bisq/core/payment/SepaInstantAccount.java +++ b/core/src/main/java/bisq/core/payment/SepaInstantAccount.java @@ -18,6 +18,8 @@ package bisq.core.payment; import bisq.core.locale.CountryUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SepaInstantAccountPayload; @@ -26,10 +28,16 @@ import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class SepaInstantAccount extends CountryBasedPaymentAccount implements BankAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR")); + public SepaInstantAccount() { super(PaymentMethod.SEPA_INSTANT); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -90,4 +98,10 @@ public void revertChanges() { super.revertChanges(); ((SepaInstantAccountPayload) paymentAccountPayload).revertChanges(); } + + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/SpecificBanksAccount.java b/core/src/main/java/bisq/core/payment/SpecificBanksAccount.java index 106d1f81643..f53074896f8 100644 --- a/core/src/main/java/bisq/core/payment/SpecificBanksAccount.java +++ b/core/src/main/java/bisq/core/payment/SpecificBanksAccount.java @@ -17,16 +17,23 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SpecificBanksAccountPayload; import java.util.ArrayList; +import java.util.List; import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class SpecificBanksAccount extends CountryBasedPaymentAccount implements BankNameRestrictedBankAccount, SameCountryRestrictedBankAccount { + + public static final List SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies(); + public SpecificBanksAccount() { super(PaymentMethod.SPECIFIC_BANKS); } @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new SpecificBanksAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + // TODO change to List public ArrayList getAcceptedBanks() { return ((SpecificBanksAccountPayload) paymentAccountPayload).getAcceptedBanks(); diff --git a/core/src/main/java/bisq/core/payment/StrikeAccount.java b/core/src/main/java/bisq/core/payment/StrikeAccount.java index deb37b0ca60..a983ec5bf3d 100644 --- a/core/src/main/java/bisq/core/payment/StrikeAccount.java +++ b/core/src/main/java/bisq/core/payment/StrikeAccount.java @@ -17,16 +17,27 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.StrikeAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class StrikeAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public StrikeAccount() { super(PaymentMethod.STRIKE); + // this payment method is currently restricted to United States/USD + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -53,4 +64,10 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.strike.info.account"; } + + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/SwiftAccount.java b/core/src/main/java/bisq/core/payment/SwiftAccount.java index 5b3c2af2160..602c66d36dd 100644 --- a/core/src/main/java/bisq/core/payment/SwiftAccount.java +++ b/core/src/main/java/bisq/core/payment/SwiftAccount.java @@ -17,24 +17,28 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; -import bisq.core.locale.FiatCurrency; import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SwiftAccountPayload; -import java.util.Comparator; +import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import lombok.EqualsAndHashCode; +import lombok.NonNull; + +import static bisq.core.locale.CurrencyUtil.getAllSortedFiatCurrencies; +import static java.util.Comparator.comparing; @EqualsAndHashCode(callSuper = true) public final class SwiftAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = new ArrayList<>(getAllSortedFiatCurrencies(comparing(TradeCurrency::getCode))); + public SwiftAccount() { super(PaymentMethod.SWIFT); - selectAllTradeCurrencies(); + tradeCurrencies.addAll(SUPPORTED_CURRENCIES); } @Override @@ -58,10 +62,8 @@ public String getMessageForAccountCreation() { return "payment.swift.info.account"; } - private void selectAllTradeCurrencies() { - List currencyCodesSorted = CurrencyUtil.getAllSortedFiatCurrencies().stream() - .sorted(Comparator.comparing(TradeCurrency::getCode)) - .collect(Collectors.toList()); - tradeCurrencies.addAll(currencyCodesSorted); + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; } } diff --git a/core/src/main/java/bisq/core/payment/SwishAccount.java b/core/src/main/java/bisq/core/payment/SwishAccount.java index 64738af559c..4a4427454a4 100644 --- a/core/src/main/java/bisq/core/payment/SwishAccount.java +++ b/core/src/main/java/bisq/core/payment/SwishAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.SwishAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class SwishAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("SEK")); + public SwishAccount() { super(PaymentMethod.SWISH); - setSingleTradeCurrency(CurrencyUtil.getAllSwishCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new SwishAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setMobileNr(String mobileNr) { ((SwishAccountPayload) paymentAccountPayload).setMobileNr(mobileNr); } diff --git a/core/src/main/java/bisq/core/payment/TikkieAccount.java b/core/src/main/java/bisq/core/payment/TikkieAccount.java index 813b2a70899..3446d2c1672 100644 --- a/core/src/main/java/bisq/core/payment/TikkieAccount.java +++ b/core/src/main/java/bisq/core/payment/TikkieAccount.java @@ -17,16 +17,27 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.TikkieAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class TikkieAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("EUR")); + public TikkieAccount() { super(PaymentMethod.TIKKIE); + // this payment method is only for Netherlands/EUR + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -53,4 +64,10 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.tikkie.info.account"; } + + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/TransferwiseAccount.java b/core/src/main/java/bisq/core/payment/TransferwiseAccount.java index 50a3379c4ab..996ef25bd87 100644 --- a/core/src/main/java/bisq/core/payment/TransferwiseAccount.java +++ b/core/src/main/java/bisq/core/payment/TransferwiseAccount.java @@ -17,14 +17,67 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.TransferwiseAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class TransferwiseAccount extends PaymentAccount { + + // https://github.com/bisq-network/proposals/issues/243 + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AED"), + new FiatCurrency("ARS"), + new FiatCurrency("AUD"), + new FiatCurrency("BGN"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CLP"), + new FiatCurrency("CZK"), + new FiatCurrency("DKK"), + new FiatCurrency("EGP"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("GEL"), + new FiatCurrency("HKD"), + new FiatCurrency("HRK"), + new FiatCurrency("HUF"), + new FiatCurrency("IDR"), + new FiatCurrency("ILS"), + new FiatCurrency("JPY"), + new FiatCurrency("KES"), + new FiatCurrency("KRW"), + new FiatCurrency("MAD"), + new FiatCurrency("MXN"), + new FiatCurrency("MYR"), + new FiatCurrency("NOK"), + new FiatCurrency("NPR"), + new FiatCurrency("NZD"), + new FiatCurrency("PEN"), + new FiatCurrency("PHP"), + new FiatCurrency("PKR"), + new FiatCurrency("PLN"), + new FiatCurrency("RON"), + new FiatCurrency("RUB"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("THB"), + new FiatCurrency("TRY"), + new FiatCurrency("UGX"), + new FiatCurrency("VND"), + new FiatCurrency("XOF"), + new FiatCurrency("ZAR"), + new FiatCurrency("ZMW") + ); + public TransferwiseAccount() { super(PaymentMethod.TRANSFERWISE); } @@ -34,6 +87,12 @@ protected PaymentAccountPayload createPayload() { return new TransferwiseAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setEmail(String accountId) { ((TransferwiseAccountPayload) paymentAccountPayload).setEmail(accountId); } diff --git a/core/src/main/java/bisq/core/payment/TransferwiseUsdAccount.java b/core/src/main/java/bisq/core/payment/TransferwiseUsdAccount.java index ab5e03ab41d..757a65c6318 100644 --- a/core/src/main/java/bisq/core/payment/TransferwiseUsdAccount.java +++ b/core/src/main/java/bisq/core/payment/TransferwiseUsdAccount.java @@ -17,16 +17,27 @@ package bisq.core.payment; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.TransferwiseUsdAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + @EqualsAndHashCode(callSuper = true) public final class TransferwiseUsdAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public TransferwiseUsdAccount() { super(PaymentMethod.TRANSFERWISE_USD); + // this payment method is currently restricted to United States/USD + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -69,4 +80,10 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.transferwiseUsd.info.account"; } + + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java b/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java index a93e7c1d7fc..c8cad3e163d 100644 --- a/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java +++ b/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java @@ -17,18 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.USPostalMoneyOrderAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class USPostalMoneyOrderAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public USPostalMoneyOrderAccount() { super(PaymentMethod.US_POSTAL_MONEY_ORDER); - setSingleTradeCurrency(CurrencyUtil.getAllUSPostalMoneyOrderCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -36,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new USPostalMoneyOrderAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setPostalAddress(String postalAddress) { ((USPostalMoneyOrderAccountPayload) paymentAccountPayload).setPostalAddress(postalAddress); } diff --git a/core/src/main/java/bisq/core/payment/UpholdAccount.java b/core/src/main/java/bisq/core/payment/UpholdAccount.java index bc30be0e775..0ae684e9fb9 100644 --- a/core/src/main/java/bisq/core/payment/UpholdAccount.java +++ b/core/src/main/java/bisq/core/payment/UpholdAccount.java @@ -17,19 +17,52 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.UpholdAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + //TODO missing support for selected trade currency @EqualsAndHashCode(callSuper = true) public final class UpholdAccount extends PaymentAccount { + + // https://support.uphold.com/hc/en-us/articles/202473803-Supported-currencies + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("AED"), + new FiatCurrency("ARS"), + new FiatCurrency("AUD"), + new FiatCurrency("BRL"), + new FiatCurrency("CAD"), + new FiatCurrency("CHF"), + new FiatCurrency("CNY"), + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("GBP"), + new FiatCurrency("HKD"), + new FiatCurrency("ILS"), + new FiatCurrency("INR"), + new FiatCurrency("JPY"), + new FiatCurrency("KES"), + new FiatCurrency("MXN"), + new FiatCurrency("NOK"), + new FiatCurrency("NZD"), + new FiatCurrency("PHP"), + new FiatCurrency("PLN"), + new FiatCurrency("SEK"), + new FiatCurrency("SGD"), + new FiatCurrency("USD") + ); + public UpholdAccount() { super(PaymentMethod.UPHOLD); - tradeCurrencies.addAll(CurrencyUtil.getAllUpholdCurrencies()); + tradeCurrencies.addAll(SUPPORTED_CURRENCIES); } @Override @@ -37,6 +70,12 @@ protected PaymentAccountPayload createPayload() { return new UpholdAccountPayload(paymentMethod.getId(), id); } + @NotNull + @Override + public List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountId(String accountId) { ((UpholdAccountPayload) paymentAccountPayload).setAccountId(accountId); } diff --git a/core/src/main/java/bisq/core/payment/UpiAccount.java b/core/src/main/java/bisq/core/payment/UpiAccount.java index 8dbce84fc28..ca7da65a76f 100644 --- a/core/src/main/java/bisq/core/payment/UpiAccount.java +++ b/core/src/main/java/bisq/core/payment/UpiAccount.java @@ -24,7 +24,7 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) -public final class UpiAccount extends CountryBasedPaymentAccount { +public final class UpiAccount extends IfscBasedAccount { public UpiAccount() { super(PaymentMethod.UPI); } diff --git a/core/src/main/java/bisq/core/payment/VenmoAccount.java b/core/src/main/java/bisq/core/payment/VenmoAccount.java index 8a48d9485cb..2de0e193935 100644 --- a/core/src/main/java/bisq/core/payment/VenmoAccount.java +++ b/core/src/main/java/bisq/core/payment/VenmoAccount.java @@ -17,21 +17,28 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.VenmoAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; // Removed due too high chargeback risk // Cannot be deleted as it would break old trade history entries @Deprecated @EqualsAndHashCode(callSuper = true) public final class VenmoAccount extends PaymentAccount { + + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("USD")); + public VenmoAccount() { super(PaymentMethod.VENMO); - setSingleTradeCurrency(CurrencyUtil.getAllVenmoCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -39,6 +46,11 @@ protected PaymentAccountPayload createPayload() { return new VenmoAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setVenmoUserName(String venmoUserName) { ((VenmoAccountPayload) paymentAccountPayload).setVenmoUserName(venmoUserName); } diff --git a/core/src/main/java/bisq/core/payment/VerseAccount.java b/core/src/main/java/bisq/core/payment/VerseAccount.java index a0a211704ce..4fcfb70734d 100644 --- a/core/src/main/java/bisq/core/payment/VerseAccount.java +++ b/core/src/main/java/bisq/core/payment/VerseAccount.java @@ -17,14 +17,29 @@ package bisq.core.payment; -import bisq.core.payment.payload.VerseAccountPayload; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; +import bisq.core.payment.payload.VerseAccountPayload; + +import java.util.List; import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class VerseAccount extends PaymentAccount { + + // https://github.com/bisq-network/growth/issues/223 + public static final List SUPPORTED_CURRENCIES = List.of( + new FiatCurrency("DKK"), + new FiatCurrency("EUR"), + new FiatCurrency("HUF"), + new FiatCurrency("PLN"), + new FiatCurrency("SEK") + ); + public VerseAccount() { super(PaymentMethod.VERSE); } @@ -53,4 +68,9 @@ public String getMessageForSeller() { public String getMessageForAccountCreation() { return "payment.verse.info.account"; } + + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } } diff --git a/core/src/main/java/bisq/core/payment/WeChatPayAccount.java b/core/src/main/java/bisq/core/payment/WeChatPayAccount.java index dc23b81c084..a8faf79a2c1 100644 --- a/core/src/main/java/bisq/core/payment/WeChatPayAccount.java +++ b/core/src/main/java/bisq/core/payment/WeChatPayAccount.java @@ -17,19 +17,25 @@ package bisq.core.payment; -import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.FiatCurrency; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.WeChatPayAccountPayload; +import java.util.List; + import lombok.EqualsAndHashCode; +import lombok.NonNull; @EqualsAndHashCode(callSuper = true) public final class WeChatPayAccount extends PaymentAccount { + public static final List SUPPORTED_CURRENCIES = List.of(new FiatCurrency("CNY")); + public WeChatPayAccount() { super(PaymentMethod.WECHAT_PAY); - setSingleTradeCurrency(CurrencyUtil.getAllWeChatPayCurrencies().get(0)); + setSingleTradeCurrency(SUPPORTED_CURRENCIES.get(0)); } @Override @@ -37,6 +43,11 @@ protected PaymentAccountPayload createPayload() { return new WeChatPayAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public void setAccountNr(String accountNr) { ((WeChatPayAccountPayload) paymentAccountPayload).setAccountNr(accountNr); } diff --git a/core/src/main/java/bisq/core/payment/WesternUnionAccount.java b/core/src/main/java/bisq/core/payment/WesternUnionAccount.java index 18c1e8cb110..ba09b92b397 100644 --- a/core/src/main/java/bisq/core/payment/WesternUnionAccount.java +++ b/core/src/main/java/bisq/core/payment/WesternUnionAccount.java @@ -17,11 +17,20 @@ package bisq.core.payment; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.payment.payload.WesternUnionAccountPayload; +import java.util.List; + +import lombok.NonNull; + public final class WesternUnionAccount extends CountryBasedPaymentAccount { + + public static final List SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies(); + public WesternUnionAccount() { super(PaymentMethod.WESTERN_UNION); } @@ -31,6 +40,11 @@ protected PaymentAccountPayload createPayload() { return new WesternUnionAccountPayload(paymentMethod.getId(), id); } + @Override + public @NonNull List getSupportedCurrencies() { + return SUPPORTED_CURRENCIES; + } + public String getEmail() { return ((WesternUnionAccountPayload) paymentAccountPayload).getEmail(); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/AdvancedCashForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/AdvancedCashForm.java index d21b13dc7b3..1220a126835 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/AdvancedCashForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/AdvancedCashForm.java @@ -22,7 +22,6 @@ import bisq.desktop.util.validation.AdvancedCashValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.AdvancedCashAccount; import bisq.core.payment.PaymentAccount; @@ -91,7 +90,7 @@ private void addCurrenciesGrid(boolean isEditable) { else flowPane.setId("flow-pane-checkboxes-non-editable-bg"); - CurrencyUtil.getAllAdvancedCashCurrencies().stream().forEach(e -> + paymentAccount.getSupportedCurrencies().forEach(e -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, e, advancedCashAccount)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/AustraliaPayidForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/AustraliaPayidForm.java index 8dda9f1da66..62d6e8c3983 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/AustraliaPayidForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/AustraliaPayidForm.java @@ -24,7 +24,7 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; -import bisq.core.payment.AustraliaPayid; +import bisq.core.payment.AustraliaPayidAccount; import bisq.core.payment.PaymentAccount; import bisq.core.payment.payload.AustraliaPayidPayload; import bisq.core.payment.payload.PaymentAccountPayload; @@ -38,7 +38,7 @@ import static bisq.desktop.util.FormBuilder.addTopLabelTextField; public class AustraliaPayidForm extends PaymentMethodForm { - private final AustraliaPayid australiaPayid; + private final AustraliaPayidAccount australiaPayidAccount; private final AustraliaPayidValidator australiaPayidValidator; public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) { @@ -57,7 +57,7 @@ public AustraliaPayidForm(PaymentAccount paymentAccount, int gridRow, CoinFormatter formatter) { super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); - this.australiaPayid = (AustraliaPayid) paymentAccount; + this.australiaPayidAccount = (AustraliaPayidAccount) paymentAccount; this.australiaPayidValidator = australiaPayidValidator; } @@ -69,18 +69,18 @@ public void addFormForAddAccount() { Res.get("payment.account.owner")); holderNameInputTextField.setValidator(inputValidator); holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - australiaPayid.setBankAccountName(newValue); + australiaPayidAccount.setBankAccountName(newValue); updateFromInputs(); }); InputTextField mobileNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.payid")); mobileNrInputTextField.setValidator(australiaPayidValidator); mobileNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - australiaPayid.setPayid(newValue); + australiaPayidAccount.setPayid(newValue); updateFromInputs(); }); - TradeCurrency singleTradeCurrency = australiaPayid.getSingleTradeCurrency(); + TradeCurrency singleTradeCurrency = australiaPayidAccount.getSingleTradeCurrency(); String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode); addLimitations(false); @@ -89,7 +89,7 @@ public void addFormForAddAccount() { @Override protected void autoFillNameTextField() { - setAccountNameWithString(australiaPayid.getPayid()); + setAccountNameWithString(australiaPayidAccount.getPayid()); } @Override @@ -97,13 +97,13 @@ public void addFormForEditAccount() { gridRowFrom = gridRow; addAccountNameTextFieldWithAutoFillToggleButton(); addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"), - Res.get(australiaPayid.getPaymentMethod().getId())); + Res.get(australiaPayidAccount.getPaymentMethod().getId())); addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.payid"), - australiaPayid.getPayid()); + australiaPayidAccount.getPayid()); TextField field = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.owner"), - australiaPayid.getBankAccountName()).second; + australiaPayidAccount.getBankAccountName()).second; field.setMouseTransparent(false); - TradeCurrency singleTradeCurrency = australiaPayid.getSingleTradeCurrency(); + TradeCurrency singleTradeCurrency = australiaPayidAccount.getSingleTradeCurrency(); String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode); addLimitations(true); @@ -112,8 +112,8 @@ public void addFormForEditAccount() { @Override public void updateAllInputsValid() { allInputsValid.set(isAccountNameValid() - && australiaPayidValidator.validate(australiaPayid.getPayid()).isValid - && inputValidator.validate(australiaPayid.getBankAccountName()).isValid - && australiaPayid.getTradeCurrencies().size() > 0); + && australiaPayidValidator.validate(australiaPayidAccount.getPayid()).isValid + && inputValidator.validate(australiaPayidAccount.getBankAccountName()).isValid + && australiaPayidAccount.getTradeCurrencies().size() > 0); } } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java index 423158e0fa7..f34df1a16f3 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/BizumForm.java @@ -23,7 +23,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.BizumAccount; import bisq.core.payment.PaymentAccount; @@ -59,7 +58,7 @@ public BizumForm(PaymentAccount paymentAccount, AccountAgeWitnessService account @Override public void addFormForAddAccount() { // this payment method is only for Spain/EUR - account.setSingleTradeCurrency(CurrencyUtil.getAllBizumCurrencies().get(0)); + account.setSingleTradeCurrency(account.getSupportedCurrencies().get(0)); CountryUtil.findCountryByCode("ES").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/CapitualForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/CapitualForm.java index 8b4991284cc..4fbb2c5dbd9 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/CapitualForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/CapitualForm.java @@ -22,7 +22,6 @@ import bisq.desktop.util.validation.CapitualValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.CapitualAccount; import bisq.core.payment.PaymentAccount; @@ -90,7 +89,7 @@ private void addCurrenciesGrid(boolean isEditable) { else flowPane.setId("flow-pane-checkboxes-non-editable-bg"); - CurrencyUtil.getAllCapitualCurrencies().forEach(e -> + paymentAccount.getSupportedCurrencies().forEach(e -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, e, capitualAccount)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/CelPayForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/CelPayForm.java index afa625f2b89..42a4283e828 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/CelPayForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/CelPayForm.java @@ -22,7 +22,6 @@ import bisq.desktop.util.validation.EmailValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.CelPayAccount; import bisq.core.payment.PaymentAccount; @@ -82,7 +81,7 @@ private void addCurrenciesGrid(boolean isEditable) { flowPane.setId("flow-pane-checkboxes-non-editable-bg"); } - CurrencyUtil.getAllCelPayCurrencies().forEach(currency -> + account.getSupportedCurrencies().forEach(currency -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java index e1f8cf0510f..f09c936fb10 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java @@ -5,8 +5,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.Country; -import bisq.core.locale.CurrencyUtil; -import bisq.core.locale.FiatCurrency; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.payment.CountryBasedPaymentAccount; @@ -30,7 +28,7 @@ import javafx.util.StringConverter; import java.util.List; -import java.util.Optional; +import java.util.Objects; import static bisq.desktop.util.FormBuilder.addTopLabelWithVBox; @@ -39,17 +37,8 @@ public abstract class GeneralSepaForm extends PaymentMethodForm { static final String BIC = "BIC"; static final String IBAN = "IBAN"; - private FiatCurrency euroCurrency = null; - GeneralSepaForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, InputValidator inputValidator, GridPane gridPane, int gridRow, CoinFormatter formatter) { super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); - - Optional euroCurrencyOptional = CurrencyUtil.getFiatCurrency("EUR"); - - if (euroCurrencyOptional.isPresent()) { - this.euroCurrency = euroCurrencyOptional.get(); - paymentAccount.setSingleTradeCurrency(euroCurrency); - } } @Override @@ -120,7 +109,8 @@ ComboBox addCountrySelection() { currencyTextField.setVisible(true); currencyTextField.setManaged(true); - currencyTextField.setText(Res.get("payment.currencyWithSymbol", euroCurrency.getNameAndCode())); + currencyTextField.setText(Res.get("payment.currencyWithSymbol", + Objects.requireNonNull(paymentAccount.getSingleTradeCurrency()).getNameAndCode())); hBox.getChildren().addAll(countryComboBox, currencyTextField); diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java index 2dec4410bbc..b06f35582bc 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/IfscBankForm.java @@ -23,7 +23,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.payload.IfscBasedAccountPayload; @@ -66,7 +65,7 @@ public IfscBankForm(PaymentAccount paymentAccount, AccountAgeWitnessService acco @Override public void addFormForAddAccount() { // this payment method is only for India/INR - paymentAccount.setSingleTradeCurrency(CurrencyUtil.getAllIfscBankCurrencies().get(0)); + paymentAccount.setSingleTradeCurrency(paymentAccount.getSupportedCurrencies().get(0)); CountryUtil.findCountryByCode("IN").ifPresent(c -> ifscBasedAccountPayload.setCountryCode(c.code)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneseForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneseForm.java index ce32fd8beb7..5288e845a32 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneseForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneseForm.java @@ -21,7 +21,6 @@ import bisq.desktop.util.FormBuilder; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.MoneseAccount; import bisq.core.payment.PaymentAccount; @@ -88,7 +87,7 @@ private void addCurrenciesGrid(boolean isEditable) { flowPane.setId("flow-pane-checkboxes-non-editable-bg"); } - CurrencyUtil.getAllMoneseCurrencies().forEach(currency -> + account.getSupportedCurrencies().forEach(currency -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyGramForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyGramForm.java index a805c6c66d9..539c36912c7 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyGramForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyGramForm.java @@ -26,7 +26,6 @@ import bisq.core.locale.BankUtil; import bisq.core.locale.Country; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.MoneyGramAccount; import bisq.core.payment.PaymentAccount; @@ -43,7 +42,10 @@ import lombok.extern.slf4j.Slf4j; -import static bisq.desktop.util.FormBuilder.*; +import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField; +import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon; +import static bisq.desktop.util.FormBuilder.addInputTextField; +import static bisq.desktop.util.FormBuilder.addTopLabelFlowPane; @Slf4j public class MoneyGramForm extends PaymentMethodForm { @@ -153,7 +155,7 @@ private void addCurrenciesGrid(boolean isEditable) { else flowPane.setId("flow-pane-checkboxes-non-editable-bg"); - CurrencyUtil.getAllMoneyGramCurrencies().forEach(e -> + paymentAccount.getSupportedCurrencies().forEach(e -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, e, paymentAccount)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java index a2357f3ffad..34c41d2cafe 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/NequiForm.java @@ -23,7 +23,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.NequiAccount; import bisq.core.payment.PaymentAccount; @@ -59,7 +58,7 @@ public NequiForm(PaymentAccount paymentAccount, AccountAgeWitnessService account @Override public void addFormForAddAccount() { // this payment method is only for Columbia/COP - account.setSingleTradeCurrency(CurrencyUtil.getAllNequiCurrencies().get(0)); + account.setSingleTradeCurrency(account.getSupportedCurrencies().get(0)); CountryUtil.findCountryByCode("CO").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java index a548c6db865..f89fb11b2da 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaxumForm.java @@ -22,7 +22,6 @@ import bisq.desktop.util.validation.EmailValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaxumAccount; import bisq.core.payment.PaymentAccount; @@ -82,7 +81,7 @@ private void addCurrenciesGrid(boolean isEditable) { flowPane.setId("flow-pane-checkboxes-non-editable-bg"); } - CurrencyUtil.getAllPaxumCurrencies().forEach(currency -> + paymentAccount.getSupportedCurrencies().forEach(currency -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java index 3b806097f37..349bf1e1dd9 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PayseraForm.java @@ -22,7 +22,6 @@ import bisq.desktop.util.validation.EmailValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PayseraAccount; @@ -82,7 +81,7 @@ private void addCurrenciesGrid(boolean isEditable) { flowPane.setId("flow-pane-checkboxes-non-editable-bg"); } - CurrencyUtil.getAllPayseraCurrencies().forEach(currency -> + paymentAccount.getSupportedCurrencies().forEach(currency -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java index c59a78969f7..8762afbee42 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaytmForm.java @@ -23,7 +23,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PaytmAccount; @@ -59,7 +58,7 @@ public PaytmForm(PaymentAccount paymentAccount, AccountAgeWitnessService account @Override public void addFormForAddAccount() { // this payment method is only for India/INR - account.setSingleTradeCurrency(CurrencyUtil.getAllIfscBankCurrencies().get(0)); + account.setSingleTradeCurrency(account.getSupportedCurrencies().get(0)); CountryUtil.findCountryByCode("IN").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java index beac5b25e27..342087e6d0d 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PixForm.java @@ -23,7 +23,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.PixAccount; @@ -59,7 +58,7 @@ public PixForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAg @Override public void addFormForAddAccount() { // this payment method is only for Brazil/BRL - account.setSingleTradeCurrency(CurrencyUtil.getAllPixCurrencies().get(0)); + account.setSingleTradeCurrency(account.getSupportedCurrencies().get(0)); CountryUtil.findCountryByCode("BR").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java index 2441db6507f..394cceacc61 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java @@ -23,7 +23,6 @@ import bisq.desktop.util.validation.RevolutValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.RevolutAccount; @@ -90,7 +89,7 @@ private void addCurrenciesGrid(boolean isEditable) { else flowPane.setId("flow-pane-checkboxes-non-editable-bg"); - CurrencyUtil.getAllRevolutCurrencies().forEach(e -> + account.getSupportedCurrencies().forEach(e -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, e, account)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java index fd578970394..2e105b6da98 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SatispayForm.java @@ -22,7 +22,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.SatispayAccount; @@ -59,7 +58,7 @@ public SatispayForm(PaymentAccount paymentAccount, AccountAgeWitnessService acco @Override public void addFormForAddAccount() { // this payment method is only for Italy/EUR - account.setSingleTradeCurrency(CurrencyUtil.getAllSatispayCurrencies().get(0)); + account.setSingleTradeCurrency(account.getSupportedCurrencies().get(0)); CountryUtil.findCountryByCode("IT").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java index 397d97733f2..5e13059e213 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java @@ -135,9 +135,7 @@ public void addFormForAddAccount() { .filter(c -> c.code.equals(ibanCountryCode)) .findFirst(); - if (ibanCountry.isPresent()) { - countryComboBox.setValue(ibanCountry.get()); - } + ibanCountry.ifPresent(countryComboBox::setValue); } }); diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java index a13310e993c..7b3d9a9d81c 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/StrikeForm.java @@ -23,7 +23,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.StrikeAccount; @@ -59,8 +58,7 @@ public StrikeForm(PaymentAccount paymentAccount, AccountAgeWitnessService accoun @Override public void addFormForAddAccount() { // this payment method is currently restricted to United States/USD - account.setSingleTradeCurrency(CurrencyUtil.getAllStrikeCurrencies().get(0)); - CountryUtil.findCountryByCode("US").ifPresent(c -> account.setCountry(c)); + CountryUtil.findCountryByCode("US").ifPresent(account::setCountry); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java index c47aecfa3fc..590bc9bfbca 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TikkieForm.java @@ -23,7 +23,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.TikkieAccount; @@ -59,8 +58,7 @@ public TikkieForm(PaymentAccount paymentAccount, AccountAgeWitnessService accoun @Override public void addFormForAddAccount() { // this payment method is only for Netherlands/EUR - account.setSingleTradeCurrency(CurrencyUtil.getAllTikkieIdCurrencies().get(0)); - CountryUtil.findCountryByCode("NL").ifPresent(c -> account.setCountry(c)); + CountryUtil.findCountryByCode("NL").ifPresent(account::setCountry); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseForm.java index 870384ba88a..29b2aa5373e 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseForm.java @@ -22,7 +22,6 @@ import bisq.desktop.util.validation.TransferwiseValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.TransferwiseAccount; @@ -83,7 +82,7 @@ private void addCurrenciesGrid(boolean isEditable) { flowPane.setId("flow-pane-checkboxes-non-editable-bg"); } - CurrencyUtil.getAllTransferwiseCurrencies().forEach(currency -> + account.getSupportedCurrencies().forEach(currency -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java index 2971875a5fd..f0194b2b6e6 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/TransferwiseUsdForm.java @@ -24,7 +24,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.TransferwiseUsdAccount; @@ -74,9 +73,8 @@ public TransferwiseUsdForm(PaymentAccount paymentAccount, AccountAgeWitnessServi @Override public void addFormForAddAccount() { - // this payment method is currently restricted to United States/USD - account.setSingleTradeCurrency(CurrencyUtil.getAllStrikeCurrencies().get(0)); - CountryUtil.findCountryByCode("US").ifPresent(c -> account.setCountry(c)); + + CountryUtil.findCountryByCode("US").ifPresent(account::setCountry); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpholdForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpholdForm.java index 63e52835d19..8c31988d449 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpholdForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpholdForm.java @@ -22,7 +22,6 @@ import bisq.desktop.util.validation.UpholdValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.UpholdAccount; @@ -99,7 +98,7 @@ private void addCurrenciesGrid(boolean isEditable) { else flowPane.setId("flow-pane-checkboxes-non-editable-bg"); - CurrencyUtil.getAllUpholdCurrencies().forEach(e -> + paymentAccount.getSupportedCurrencies().forEach(e -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, e, upholdAccount)); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java index faee4a7c6ba..be34c2ccdb2 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/UpiForm.java @@ -22,7 +22,6 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.UpiAccount; @@ -58,7 +57,7 @@ public UpiForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAg @Override public void addFormForAddAccount() { // this payment method is only for India/INR - account.setSingleTradeCurrency(CurrencyUtil.getAllIfscBankCurrencies().get(0)); + account.setSingleTradeCurrency(account.getSupportedCurrencies().get(0)); CountryUtil.findCountryByCode("IN").ifPresent(c -> account.setCountry(c)); gridRowFrom = gridRow + 1; diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/VerseForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/VerseForm.java index 180b610c0e4..9684482da7e 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/VerseForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/VerseForm.java @@ -21,7 +21,6 @@ import bisq.desktop.util.FormBuilder; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.payment.PaymentAccount; import bisq.core.payment.VerseAccount; @@ -80,7 +79,7 @@ private void addCurrenciesGrid(boolean isEditable) { flowPane.setId("flow-pane-checkboxes-non-editable-bg"); } - CurrencyUtil.getAllVerseCurrencies().forEach(currency -> + paymentAccount.getSupportedCurrencies().forEach(currency -> fillUpFlowPaneWithCurrencies(isEditable, flowPane, currency, account)); } diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java index 3ce4abbba76..4160d08a452 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java @@ -103,7 +103,7 @@ import bisq.core.locale.Res; import bisq.core.offer.OfferRestrictions; import bisq.core.payment.AmazonGiftCardAccount; -import bisq.core.payment.AustraliaPayid; +import bisq.core.payment.AustraliaPayidAccount; import bisq.core.payment.CashByMailAccount; import bisq.core.payment.CashDepositAccount; import bisq.core.payment.ClearXchangeAccount; @@ -346,7 +346,7 @@ private void onSaveNewAccount(PaymentAccount paymentAccount) { .actionButtonText(Res.get("shared.iUnderstand")) .onAction(() -> doSaveNewAccount(paymentAccount)) .show(); - } else if (paymentAccount instanceof AustraliaPayid) { + } else if (paymentAccount instanceof AustraliaPayidAccount) { new Popup().information(Res.get("payment.payid.info", currencyName, currencyName)) .width(900) .closeButtonText(Res.get("shared.cancel")) From e43a8aed36d3d659ac366bd8814f9645a5016cb1 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 20 Apr 2022 21:05:58 +0200 Subject: [PATCH 28/35] Fix handling of preferred currency --- .../offerbook/BtcOfferBookViewModel.java | 21 ++++++++++++++++++- .../offerbook/OtherOfferBookViewModel.java | 9 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java index bbfeecaceb2..78bd50abfda 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java @@ -53,6 +53,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -131,7 +132,25 @@ Predicate getCurrencyAndMethodPredicate(OfferDirection direct @Override TradeCurrency getDefaultTradeCurrency() { - return GlobalSettings.getDefaultTradeCurrency(); + TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency(); + + if (CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode())) { + 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 CurrencyUtil.getMainFiatCurrencies().stream().sorted((o1, o2) -> + Boolean.compare(!hasPaymentAccountForCurrency(o1), + !hasPaymentAccountForCurrency(o2))).collect(Collectors.toList()).get(0); + } } @Override diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java index b1192e58076..29b0272e672 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java @@ -27,6 +27,7 @@ import bisq.core.btc.wallet.BsqWalletService; import bisq.core.locale.CryptoCurrency; import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.GlobalSettings; import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferDirection; @@ -133,6 +134,14 @@ Predicate getCurrencyAndMethodPredicate(OfferDirection direct @Override TradeCurrency getDefaultTradeCurrency() { + TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency(); + + if (!CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode()) && + !defaultTradeCurrency.equals(GUIUtil.BSQ) && + !defaultTradeCurrency.equals(GUIUtil.TOP_ALTCOIN)) { + return defaultTradeCurrency; + } + ObservableList tradeCurrencies = FXCollections.observableArrayList(getTradeCurrencies()); if (!tradeCurrencies.isEmpty()) { // drop show all entry and select first currency with payment account available From 0894037622b9a2357111f00a18b46bc2e0c90d9a Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 20 Apr 2022 21:57:16 +0200 Subject: [PATCH 29/35] Add safeguard for already stored crypto currencies in preferences by older versions --- .../desktop/main/offer/offerbook/BtcOfferBookViewModel.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java index 78bd50abfda..d8ee8542256 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java @@ -155,6 +155,9 @@ TradeCurrency getDefaultTradeCurrency() { @Override String getCurrencyCodeFromPreferences(OfferDirection direction) { - return direction == OfferDirection.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode(); + // validate if previous stored currencies are Fiat ones + String currencyCode = direction == OfferDirection.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode(); + + return CurrencyUtil.isFiatCurrency(currencyCode) ? currencyCode : null; } } From 89926d1efb3520b7af3d2f7129a7da9b13f6cc11 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 20 Apr 2022 22:34:39 +0200 Subject: [PATCH 30/35] Improve help icon --- desktop/src/main/java/bisq/desktop/bisq.css | 8 ++++++++ .../main/java/bisq/desktop/components/TitledGroupBg.java | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/bisq.css b/desktop/src/main/java/bisq/desktop/bisq.css index 6ec01b80390..2b9c1a6a636 100644 --- a/desktop/src/main/java/bisq/desktop/bisq.css +++ b/desktop/src/main/java/bisq/desktop/bisq.css @@ -856,6 +856,14 @@ tree-table-view:focused { -fx-fill: -bs-text-color; } +.link-icon { + -fx-fill: -bs-color-gray-ccc; +} + +.link-icon:hover { + -fx-fill: -fx-accent; +} + /******************************************************************************* * * * Tooltip * diff --git a/desktop/src/main/java/bisq/desktop/components/TitledGroupBg.java b/desktop/src/main/java/bisq/desktop/components/TitledGroupBg.java index f29c483759e..a17afe23397 100644 --- a/desktop/src/main/java/bisq/desktop/components/TitledGroupBg.java +++ b/desktop/src/main/java/bisq/desktop/components/TitledGroupBg.java @@ -20,12 +20,13 @@ import bisq.desktop.util.FormBuilder; import bisq.desktop.util.GUIUtil; -import de.jensd.fx.fontawesome.AwesomeIcon; +import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; +import javafx.scene.text.Text; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -38,7 +39,7 @@ public class TitledGroupBg extends Pane { private final HBox box; private final Label label; private final StringProperty text = new SimpleStringProperty(); - private Label helpIcon; + private Text helpIcon; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -89,8 +90,8 @@ public void setText(String text) { public void setHelpUrl(String helpUrl) { if (helpIcon == null) { - helpIcon = FormBuilder.getSmallIcon(AwesomeIcon.QUESTION); - helpIcon.getStyleClass().addAll("show-hand", "highlight"); + helpIcon = FormBuilder.getIcon(MaterialDesignIcon.HELP_CIRCLE_OUTLINE, "1em"); + helpIcon.getStyleClass().addAll("icon", "link-icon"); box.getChildren().add(helpIcon); } From 3ce374e7bb1d7f61b20b4ca906e8e90c76766fb4 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Thu, 21 Apr 2022 10:11:20 +0200 Subject: [PATCH 31/35] Unify tab handling --- .../main/java/bisq/desktop/main/offer/OfferView.java | 10 +++++----- .../desktop/main/offer/offerbook/OfferBookView.java | 4 ++++ .../main/offer/offerbook/OfferBookViewModel.java | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index 2499faf9b87..74398890213 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -250,32 +250,32 @@ private void loadView(Class viewClass, } if (viewClass == BtcOfferBookView.class) { btcOfferBookView = (BtcOfferBookView) viewLoader.load(BtcOfferBookView.class); - btcOfferBookTab.setContent(btcOfferBookView.getRoot()); btcOfferBookView.setOfferActionHandler(offerActionHandler); btcOfferBookView.setDirection(direction); - tabPane.getSelectionModel().select(btcOfferBookTab); btcOfferBookView.onTabSelected(true); + tabPane.getSelectionModel().select(btcOfferBookTab); + btcOfferBookTab.setContent(btcOfferBookView.getRoot()); } else if (viewClass == BsqOfferBookView.class) { bsqOfferBookView = (BsqOfferBookView) viewLoader.load(BsqOfferBookView.class); bsqOfferBookView.setOfferActionHandler(offerActionHandler); bsqOfferBookView.setDirection(direction); + bsqOfferBookView.onTabSelected(true); tabPane.getSelectionModel().select(bsqOfferBookTab); bsqOfferBookTab.setContent(bsqOfferBookView.getRoot()); - bsqOfferBookView.onTabSelected(true); } else if (viewClass == TopAltcoinOfferBookView.class) { topAltcoinOfferBookView = (TopAltcoinOfferBookView) viewLoader.load(TopAltcoinOfferBookView.class); topAltcoinOfferBookView.setOfferActionHandler(offerActionHandler); topAltcoinOfferBookView.setDirection(direction); + topAltcoinOfferBookView.onTabSelected(true); tabPane.getSelectionModel().select(topAltcoinOfferBookTab); topAltcoinOfferBookTab.setContent(topAltcoinOfferBookView.getRoot()); - topAltcoinOfferBookView.onTabSelected(true); } else if (viewClass == OtherOfferBookView.class) { otherOfferBookView = (OtherOfferBookView) viewLoader.load(OtherOfferBookView.class); otherOfferBookView.setOfferActionHandler(offerActionHandler); otherOfferBookView.setDirection(direction); + otherOfferBookView.onTabSelected(true); tabPane.getSelectionModel().select(otherOfferBookTab); otherOfferBookTab.setContent(otherOfferBookView.getRoot()); - otherOfferBookView.onTabSelected(true); } } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index d5a2c9525e2..ff31fc0dca2 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -601,11 +601,15 @@ public void setOfferActionHandler(OfferView.OfferActionHandler offerActionHandle } public void onTabSelected(boolean isSelected) { + if (model.isTabSelected == isSelected) { + return; + } model.onTabSelected(isSelected); if (isSelected) { updateCurrencyComboBoxFromModel(); root.requestFocus(); + updateCreateOfferButton(); } updateCreateOfferButton(); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java index 8e9753dea87..e59ba45db6e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookViewModel.java @@ -136,7 +136,7 @@ abstract class OfferBookViewModel extends ActivatableViewModel { PaymentMethod selectedPaymentMethod = getShowAllEntryForPaymentMethod(); - private boolean isTabSelected; + boolean isTabSelected; final BooleanProperty showAllTradeCurrenciesProperty = new SimpleBooleanProperty(true); final BooleanProperty disableMatchToggle = new SimpleBooleanProperty(); final IntegerProperty maxPlacesForAmount = new SimpleIntegerProperty(); From 2233f73a7bee8760fcc6a25cac1844c727123fd5 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Thu, 21 Apr 2022 10:32:27 +0200 Subject: [PATCH 32/35] Fix Codacy complaints --- .../src/main/java/bisq/core/payment/PaymentAccountUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java index 1cec80bdc5c..ab4224b8861 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccountUtil.java @@ -69,7 +69,7 @@ public static ObservableList getPossiblePaymentAccounts(Offer of public static boolean isAmountValidForOffer(Offer offer, PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService) { - boolean hasChargebackRisk = PaymentMethod.hasChargebackRisk(offer.getPaymentMethod(), offer.getCurrencyCode()); + boolean hasChargebackRisk = hasChargebackRisk(offer.getPaymentMethod(), offer.getCurrencyCode()); boolean hasValidAccountAgeWitness = accountAgeWitnessService.getMyTradeLimit(paymentAccount, offer.getCurrencyCode(), offer.getMirroredDirection()) >= offer.getMinAmount().value; return !hasChargebackRisk || hasValidAccountAgeWitness; @@ -252,8 +252,8 @@ public static String getCountryCode(PaymentAccount paymentAccount) { } public static boolean isCryptoCurrencyAccount(PaymentAccount paymentAccount) { - return (paymentAccount != null && paymentAccount.getPaymentMethod().equals(PaymentMethod.BLOCK_CHAINS) || - paymentAccount != null && paymentAccount.getPaymentMethod().equals(PaymentMethod.BLOCK_CHAINS_INSTANT)); + return (paymentAccount != null && paymentAccount.getPaymentMethod().equals(BLOCK_CHAINS) || + paymentAccount != null && paymentAccount.getPaymentMethod().equals(BLOCK_CHAINS_INSTANT)); } public static Optional findPaymentAccount(PaymentAccountPayload paymentAccountPayload, From 4ce861add1f79c3750353ec024d9cb23e29e746b Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 22 Apr 2022 09:37:49 +0200 Subject: [PATCH 33/35] Add create and take offer title --- .../src/main/java/bisq/desktop/main/offer/OfferViewUtil.java | 4 ++++ .../desktop/main/offer/bisq_v1/MutableOfferDataModel.java | 2 +- .../bisq/desktop/main/offer/bisq_v1/MutableOfferView.java | 2 +- .../desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java | 4 ++-- .../offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java | 2 +- .../main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java | 2 +- .../main/portfolio/duplicateoffer/DuplicateOfferView.java | 5 +++++ .../bisq/desktop/main/portfolio/editoffer/EditOfferView.java | 4 ++-- .../desktop/main/portfolio/editoffer/EditOfferViewModel.java | 5 +++++ 9 files changed, 22 insertions(+), 8 deletions(-) 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 6a33ea27497..d97ef45ea12 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java @@ -146,6 +146,10 @@ public static boolean isShownAsSellOffer(Offer offer) { return isShownAsSellOffer(offer.getCurrencyCode(), offer.getDirection()); } + public static boolean isShownAsSellOffer(TradeCurrency tradeCurrency, OfferDirection direction) { + return isShownAsSellOffer(tradeCurrency.getCode(), direction); + } + public static boolean isShownAsSellOffer(String currencyCode, OfferDirection direction) { return CurrencyUtil.isFiatCurrency(currencyCode) == (direction == OfferDirection.SELL); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java index 83477489fa4..1464cb7f5aa 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java @@ -481,7 +481,7 @@ boolean isMinAmountLessOrEqualAmount() { return true; } - OfferDirection getDirection() { + public OfferDirection getDirection() { return direction; } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index c0e2fdec1ed..ce6cd07d069 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -1059,7 +1059,7 @@ private void addGridPane() { } private void addPaymentGroup() { - paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.chooseTradingAccount")); + paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.createOffer")); GridPane.setColumnSpan(paymentTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index fab3f1a9bf5..4334c6de69f 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -817,12 +817,12 @@ private void addGridPane() { } private void addPaymentGroup() { - TitledGroupBg paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("takeOffer.paymentInfo")); + TitledGroupBg paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.takeOffer")); GridPane.setColumnSpan(paymentAccountTitledGroupBg, 2); final Tuple4, Label, TextField, HBox> paymentAccountTuple = addComboBoxTopLabelTextField(gridPane, gridRow, Res.get("shared.chooseTradingAccount"), - Res.get("shared.paymentMethod"), Layout.FIRST_ROW_DISTANCE); + Res.get("shared.chooseTradingAccount"), Layout.FIRST_ROW_DISTANCE); paymentAccountsComboBox = paymentAccountTuple.first; HBox.setMargin(paymentAccountsComboBox, new Insets(Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0)); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index a499aa7749d..b4d63ed70f4 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -436,7 +436,7 @@ protected void removeBindings() { @Override protected void addPaymentAccountGroup() { - paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.chooseTradingAccount")); + paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.createOffer")); GridPane.setColumnSpan(paymentAccountTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java index b4cf34adc30..c65cd37a5c0 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/take_offer/BsqSwapTakeOfferView.java @@ -446,7 +446,7 @@ protected void removeSubscriptions() { @Override protected void addPaymentAccountGroup() { - paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("takeOffer.paymentInfo")); + paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.takeOffer")); GridPane.setColumnSpan(paymentAccountTitledGroupBg, 2); // We use the addComboBoxTopLabelTextField only for convenience for having the expected layout diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java index b6850c27acb..ec42b77fc85 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/duplicateoffer/DuplicateOfferView.java @@ -34,6 +34,8 @@ import javax.inject.Named; +import javafx.geometry.Insets; + import javafx.collections.ObservableList; @FxmlView @@ -58,6 +60,9 @@ protected void initialize() { protected void doActivate() { super.doActivate(); + // Workaround to fix margin on top of amount group + gridPane.setPadding(new Insets(-20, 25, -1, 25)); + updatePriceToggle(); // To force re-validation of payment account validation diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java index 59a9cd0bec9..7f9db5a0c8c 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java @@ -245,8 +245,8 @@ private void addConfirmEditGroup() { private void updateElementsWithDirection() { ImageView iconView = new ImageView(); - iconView.setId(model.isSellOffer() ? "image-sell-white" : "image-buy-white"); + iconView.setId(model.isShownAsSellOffer() ? "image-sell-white" : "image-buy-white"); confirmButton.setGraphic(iconView); - confirmButton.setId(model.isSellOffer() ? "sell-button-big" : "buy-button-big"); + confirmButton.setId(model.isShownAsSellOffer() ? "sell-button-big" : "buy-button-big"); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java index 24a86037973..0504ac60423 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java @@ -18,6 +18,7 @@ package bisq.desktop.main.portfolio.editoffer; import bisq.desktop.Navigation; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.offer.bisq_v1.MutableOfferViewModel; import bisq.desktop.util.validation.BsqValidator; import bisq.desktop.util.validation.BtcValidator; @@ -128,4 +129,8 @@ public void triggerFocusOutOnAmountFields() { // do not update BTC Amount or minAmount here // issue 2798: "after a few edits of offer the BTC amount has increased" } + + public boolean isShownAsSellOffer() { + return OfferViewUtil.isShownAsSellOffer(getTradeCurrency(), dataModel.getDirection()); + } } From 4447435e5f1e1e862402674dea931a299c5791bf Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 22 Apr 2022 10:01:35 +0200 Subject: [PATCH 34/35] Switch to open offers after creating a new offer --- .../resources/i18n/displayStrings.properties | 2 -- .../bisq/desktop/main/offer/OfferView.java | 2 +- .../main/offer/bisq_v1/MutableOfferView.java | 21 +++++++++-------- .../create_offer/BsqSwapCreateOfferView.java | 23 +++++++++++-------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index cc5e2932148..a5b56056d98 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -433,7 +433,6 @@ offerbook.info.sellAboveMarketPrice=You will get {0} more than the current marke offerbook.info.buyBelowMarketPrice=You will pay {0} less than the current market price (updated every minute). offerbook.info.buyAtFixedPrice=You will buy at this fixed price. offerbook.info.sellAtFixedPrice=You will sell at this fixed price. -offerbook.info.noArbitrationInUserLanguage=In case of a dispute, please note that arbitration for this offer will be handled in {0}. Language is currently set to {1}. offerbook.info.roundedFiatVolume=The amount was rounded to increase the privacy of your trade. offerbook.info.accountCreated.headline=Congratulations offerbook.info.accountCreated.message=You''ve just successfully created a BSQ payment account.\n\ @@ -585,7 +584,6 @@ takeOffer.takeOfferFundWalletInfo.headline=Fund your trade takeOffer.takeOfferFundWalletInfo.tradeAmount=- Trade amount: {0} \n takeOffer.takeOfferFundWalletInfo.msg=You need to deposit {0} to take this offer.\n\nThe amount is the sum of:\n{1}- Your security deposit: {2}\n- Trading fee: {3}\n- Total mining fees: {4}\n\nYou can choose between two options when funding your trade:\n- Use your Bisq wallet (convenient, but transactions may be linkable) OR\n- Transfer from an external wallet (potentially more private)\n\nYou will see all funding options and details after closing this popup. takeOffer.alreadyPaidInFunds=If you have already paid in funds you can withdraw it in the \"Funds/Send funds\" screen. -takeOffer.paymentInfo=Payment info takeOffer.setAmountPrice=Set amount takeOffer.alreadyFunded.askCancel=You have already funded that offer.\nIf you cancel now, your funds will be moved to your local Bisq wallet and are available for withdrawal in the \"Funds/Send funds\" screen.\nAre you sure you want to cancel? takeOffer.failed.offerNotAvailable=Take offer request failed because the offer is not available anymore. Maybe another trader has taken the offer in the meantime. diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index 74398890213..6aa139d6aaa 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -309,10 +309,10 @@ private void loadCreateViewClass(OfferBookView offerBookView, ((ClosableView) view).setCloseHandler(() -> { offerBookView.enableCreateOfferButton(); ((SelectableView) view).onTabSelected(false); + //reset tab navigation.navigateTo(MainView.class, this.getClass(), viewClass); }); - // close handler from close on create offer action marketOfferBookTab.setContent(view.getRoot()); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index ce6cd07d069..060840d7196 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -812,18 +812,12 @@ private void createListeners() { .feedback(Res.get("createOffer.success.info")) .dontShowAgainId(key) .actionButtonTextWithGoTo("navigation.portfolio.myOpenOffers") - .onAction(() -> { - UserThread.runAfter(() -> - navigation.navigateTo(MainView.class, PortfolioView.class, - OpenOffersView.class), - 100, TimeUnit.MILLISECONDS); - close(); - }) - .onClose(this::close) + .onAction(this::closeAndGoToOpenOffers) + .onClose(this::closeAndGoToOpenOffers) .show(), 1); } else { - close(); + closeAndGoToOpenOffers(); } } }; @@ -947,6 +941,15 @@ private void createListeners() { }); } + private void closeAndGoToOpenOffers() { + //go to open offers + UserThread.runAfter(() -> + navigation.navigateTo(MainView.class, PortfolioView.class, + OpenOffersView.class), + 1, TimeUnit.SECONDS); + close(); + } + private void setIsCurrencyForMakerFeeBtc(boolean isCurrencyForMakerFeeBtc) { model.setIsCurrencyForMakerFeeBtc(isCurrencyForMakerFeeBtc); if (DevEnv.isDaoActivated()) { diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index b4d63ed70f4..af190cf5b1b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -315,18 +315,12 @@ protected void createListeners() { .feedback(Res.get("createOffer.success.info")) .dontShowAgainId(key) .actionButtonTextWithGoTo("navigation.portfolio.myOpenOffers") - .onAction(() -> { - UserThread.runAfter(() -> - navigation.navigateTo(MainView.class, PortfolioView.class, - OpenOffersView.class), - 100, TimeUnit.MILLISECONDS); - close(); - }) - .onClose(this::close) + .onAction(this::closeAndGoToOpenOffers) + .onClose(this::closeAndGoToOpenOffers) .show(), - 100, TimeUnit.MILLISECONDS); + 1, TimeUnit.SECONDS); } else { - close(); + closeAndGoToOpenOffers(); } } }; @@ -608,4 +602,13 @@ protected void checkForMissingFunds(Coin missing) { .show(); } } + + private void closeAndGoToOpenOffers() { + //go to open offers + UserThread.runAfter(() -> + navigation.navigateTo(MainView.class, PortfolioView.class, + OpenOffersView.class), + 1, TimeUnit.SECONDS); + close(); + } } From 7ad2dd0ba6789bb7e4a7bf56a22b9b4f9a33d850 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Fri, 22 Apr 2022 10:41:15 +0200 Subject: [PATCH 35/35] Set preferred currency as top altcoin If it is a crypto currency and not a fiat currency --- .../offerbook/OfferBookChartViewModel.java | 10 ++++------ .../bisq/desktop/main/offer/OfferView.java | 20 +++++++++++-------- .../desktop/main/offer/OfferViewUtil.java | 11 +++++----- .../offer/bisq_v1/MutableOfferDataModel.java | 6 ++---- .../bisq_v1/createoffer/CreateOfferView.java | 15 +++++++------- .../create_offer/BsqSwapCreateOfferView.java | 3 +-- .../offerbook/OtherOfferBookViewModel.java | 8 ++++---- .../TopAltcoinOfferBookViewModel.java | 8 +++++++- .../settings/preferences/PreferencesView.java | 1 + .../main/java/bisq/desktop/util/GUIUtil.java | 10 +++++++++- 10 files changed, 52 insertions(+), 40 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java index cd85cd23569..6fd869d6f10 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/market/offerbook/OfferBookChartViewModel.java @@ -24,10 +24,8 @@ import bisq.desktop.main.offer.OfferView; import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.offer.SellOfferView; -import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.offer.offerbook.OfferBook; import bisq.desktop.main.offer.offerbook.OfferBookListItem; -import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.settings.SettingsView; import bisq.desktop.main.settings.preferences.PreferencesView; import bisq.desktop.util.CurrencyList; @@ -413,15 +411,15 @@ private void updateScreenCurrencyInPreferences(OfferDirection direction) { if (isSellOffer(direction)) { if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) { preferences.setBuyScreenCurrencyCode(getCurrencyCode()); - } else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && - !getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + } else if (!getCurrencyCode().equals(GUIUtil.BSQ.getCode()) && + !getCurrencyCode().equals(GUIUtil.TOP_ALTCOIN.getCode())) { preferences.setBuyScreenCryptoCurrencyCode(getCurrencyCode()); } } else { if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) { preferences.setSellScreenCurrencyCode(getCurrencyCode()); - } else if (!getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode()) && - !getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + } else if (!getCurrencyCode().equals(GUIUtil.BSQ.getCode()) && + !getCurrencyCode().equals(GUIUtil.TOP_ALTCOIN.getCode())) { preferences.setSellScreenCryptoCurrencyCode(getCurrencyCode()); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java index 6aa139d6aaa..3d3c7a7c05b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferView.java @@ -27,12 +27,10 @@ import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView; import bisq.desktop.main.offer.bsq_swap.take_offer.BsqSwapTakeOfferView; import bisq.desktop.main.offer.offerbook.BsqOfferBookView; -import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookView; import bisq.desktop.main.offer.offerbook.OtherOfferBookView; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; -import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.GUIUtil; import bisq.core.locale.CurrencyUtil; @@ -172,6 +170,12 @@ protected void activate() { if (btcOfferBookView == null) { navigation.navigateTo(MainView.class, this.getClass(), BtcOfferBookView.class); } + + GUIUtil.updateTopAltcoin(preferences); + + if (topAltcoinOfferBookTab != null) { + topAltcoinOfferBookTab.setText(GUIUtil.TOP_ALTCOIN.getCode()); + } } @Override @@ -205,7 +209,7 @@ private void loadView(Class viewClass, } else if (data instanceof BsqSwapOfferPayload) { loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, PaymentMethod.BSQ_SWAP, (BsqSwapOfferPayload) data); } else { - tradeCurrency = BsqOfferBookViewModel.BSQ; + tradeCurrency = GUIUtil.BSQ; loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(bsqOfferBookTab); @@ -215,7 +219,7 @@ private void loadView(Class viewClass, } else if (childViewClass == TakeOfferView.class) { loadTakeViewClass(viewClass, childViewClass, topAltcoinOfferBookTab); } else { - tradeCurrency = TopAltcoinOfferBookViewModel.TOP_ALTCOIN; + tradeCurrency = GUIUtil.TOP_ALTCOIN; loadCreateViewClass(topAltcoinOfferBookView, viewClass, childViewClass, topAltcoinOfferBookTab, (PaymentMethod) data, null); } tabPane.getSelectionModel().select(topAltcoinOfferBookTab); @@ -239,9 +243,9 @@ private void loadView(Class viewClass, if (btcOfferBookTab == null) { btcOfferBookTab = new Tab(Res.getBaseCurrencyName().toUpperCase()); btcOfferBookTab.setClosable(false); - bsqOfferBookTab = new Tab(BsqOfferBookViewModel.BSQ.getCode()); + bsqOfferBookTab = new Tab(GUIUtil.BSQ.getCode()); bsqOfferBookTab.setClosable(false); - topAltcoinOfferBookTab = new Tab(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()); + topAltcoinOfferBookTab = new Tab(GUIUtil.TOP_ALTCOIN.getCode()); topAltcoinOfferBookTab.setClosable(false); otherOfferBookTab = new Tab(Res.get("shared.other").toUpperCase()); otherOfferBookTab.setClosable(false); @@ -363,9 +367,9 @@ private void showCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentM Class> offerBookViewClass; if (CurrencyUtil.isFiatCurrency(currencyCode)) { offerBookViewClass = BtcOfferBookView.class; - } else if (currencyCode.equals(BsqOfferBookViewModel.BSQ.getCode())) { + } else if (currencyCode.equals(GUIUtil.BSQ.getCode())) { offerBookViewClass = BsqOfferBookView.class; - } else if (currencyCode.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + } else if (currencyCode.equals(GUIUtil.TOP_ALTCOIN.getCode())) { offerBookViewClass = TopAltcoinOfferBookView.class; } else { offerBookViewClass = OtherOfferBookView.class; 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 d97ef45ea12..847bcc747ae 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/OfferViewUtil.java @@ -23,13 +23,12 @@ import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.main.MainView; import bisq.desktop.main.offer.offerbook.BsqOfferBookView; -import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.offer.offerbook.BtcOfferBookView; import bisq.desktop.main.offer.offerbook.OfferBookView; import bisq.desktop.main.offer.offerbook.OtherOfferBookView; import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookView; -import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.overlays.popups.Popup; +import bisq.desktop.util.GUIUtil; import bisq.core.locale.CryptoCurrency; import bisq.core.locale.CurrencyUtil; @@ -132,9 +131,9 @@ private static void openBuyBsqOfferBook(Navigation navigation) { Class> offerBookViewClazz; if (CurrencyUtil.isFiatCurrency(currencyCode)) { offerBookViewClazz = BtcOfferBookView.class; - } else if (currencyCode.equals(BsqOfferBookViewModel.BSQ.getCode())) { + } else if (currencyCode.equals(GUIUtil.BSQ.getCode())) { offerBookViewClazz = BsqOfferBookView.class; - } else if (currencyCode.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())) { + } else if (currencyCode.equals(GUIUtil.TOP_ALTCOIN.getCode())) { offerBookViewClazz = TopAltcoinOfferBookView.class; } else { offerBookViewClazz = OtherOfferBookView.class; @@ -169,7 +168,7 @@ public static TradeCurrency getAnyOfMainCryptoCurrencies() { @NotNull public static Stream getMainCryptoCurrencies() { return CurrencyUtil.getMainCryptoCurrencies().stream().filter(cryptoCurrency -> - !Objects.equals(cryptoCurrency.getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()) && - !Objects.equals(cryptoCurrency.getCode(), BsqOfferBookViewModel.BSQ.getCode())); + !Objects.equals(cryptoCurrency.getCode(), GUIUtil.TOP_ALTCOIN.getCode()) && + !Objects.equals(cryptoCurrency.getCode(), GUIUtil.BSQ.getCode())); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java index 1464cb7f5aa..68ff7444745 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java @@ -18,8 +18,6 @@ package bisq.desktop.main.offer.bisq_v1; import bisq.desktop.Navigation; -import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; -import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -289,8 +287,8 @@ private Optional getAnyPaymentAccount() { } else { return paymentAccounts.stream().filter(paymentAccount1 -> paymentAccount1.getPaymentMethod().isAltcoin() && paymentAccount1.getTradeCurrency().isPresent() && - !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), BsqOfferBookViewModel.BSQ.getCode()) && - !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())).findAny(); + !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), GUIUtil.BSQ.getCode()) && + !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), GUIUtil.TOP_ALTCOIN.getCode())).findAny(); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java index 2f4d7995e2b..52918c9b674 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java @@ -21,9 +21,8 @@ import bisq.desktop.common.view.FxmlView; import bisq.desktop.main.offer.OfferView; import bisq.desktop.main.offer.bisq_v1.MutableOfferView; -import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; -import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel; import bisq.desktop.main.overlays.windows.OfferDetailsWindow; +import bisq.desktop.util.GUIUtil; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; @@ -70,16 +69,16 @@ public void initWithData(OfferDirection direction, protected ObservableList filterPaymentAccounts(ObservableList paymentAccounts) { return FXCollections.observableArrayList( paymentAccounts.stream().filter(paymentAccount -> { - if (model.getTradeCurrency().equals(BsqOfferBookViewModel.BSQ)) { - return Objects.equals(paymentAccount.getSingleTradeCurrency(), BsqOfferBookViewModel.BSQ); - } else if (model.getTradeCurrency().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN)) { - return Objects.equals(paymentAccount.getSingleTradeCurrency(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN); + if (model.getTradeCurrency().equals(GUIUtil.BSQ)) { + return Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.BSQ); + } else if (model.getTradeCurrency().equals(GUIUtil.TOP_ALTCOIN)) { + return Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.TOP_ALTCOIN); } else if (CurrencyUtil.isFiatCurrency(model.getTradeCurrency().getCode())) { return !paymentAccount.getPaymentMethod().isAltcoin(); } else { return paymentAccount.getPaymentMethod().isAltcoin() && - !(Objects.equals(paymentAccount.getSingleTradeCurrency(), BsqOfferBookViewModel.BSQ) || - Objects.equals(paymentAccount.getSingleTradeCurrency(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN)); + !(Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.BSQ) || + Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.TOP_ALTCOIN)); } }).collect(Collectors.toList())); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java index af190cf5b1b..230c0c552a4 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/create_offer/BsqSwapCreateOfferView.java @@ -29,7 +29,6 @@ import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.offer.SelectableView; import bisq.desktop.main.offer.bsq_swap.BsqSwapOfferView; -import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; import bisq.desktop.main.portfolio.PortfolioView; @@ -175,7 +174,7 @@ public void initWithData(OfferDirection direction, model.initWithData(offerPayload != null ? offerPayload.getDirection() : offerDirection, offerPayload); - if (OfferViewUtil.isShownAsBuyOffer(offerDirection, BsqOfferBookViewModel.BSQ)) { + if (OfferViewUtil.isShownAsBuyOffer(offerDirection, GUIUtil.BSQ)) { actionButton.setId("buy-button-big"); actionButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), BSQ)); nextButton.setId("buy-button"); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java index 29b0272e672..65f01694874 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java @@ -122,8 +122,8 @@ Predicate getCurrencyAndMethodPredicate(OfferDirection direct boolean directionResult = offer.getDirection() == direction; boolean currencyResult = CurrencyUtil.isCryptoCurrency(offer.getCurrencyCode()) && ((showAllTradeCurrenciesProperty.get() && - !offer.getCurrencyCode().equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode()) && - !offer.getCurrencyCode().equals(BsqOfferBookViewModel.BSQ.getCode())) || + !offer.getCurrencyCode().equals(GUIUtil.TOP_ALTCOIN.getCode()) && + !offer.getCurrencyCode().equals(GUIUtil.BSQ.getCode())) || offer.getCurrencyCode().equals(selectedTradeCurrency.getCode())); boolean paymentMethodResult = showAllPaymentMethods || offer.getPaymentMethod().equals(selectedPaymentMethod); @@ -166,7 +166,7 @@ String getCurrencyCodeFromPreferences(OfferDirection direction) { @NotNull private Predicate withoutBSQAndTopAltcoin() { return cryptoCurrency -> - !cryptoCurrency.equals(BsqOfferBookViewModel.BSQ) && - !cryptoCurrency.equals(TopAltcoinOfferBookViewModel.TOP_ALTCOIN); + !cryptoCurrency.equals(GUIUtil.BSQ) && + !cryptoCurrency.equals(GUIUtil.TOP_ALTCOIN); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java index 7f4eda49a17..5a81b95b880 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java @@ -54,7 +54,7 @@ public class TopAltcoinOfferBookViewModel extends OfferBookViewModel { - public static final TradeCurrency TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN; + public static TradeCurrency TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN; @Inject public TopAltcoinOfferBookViewModel(User user, @@ -77,6 +77,12 @@ public TopAltcoinOfferBookViewModel(User user, super(user, openOfferManager, offerBook, preferences, walletsSetup, p2PService, priceFeedService, closedTradableManager, bsqSwapTradeManager, accountAgeWitnessService, navigation, priceUtil, offerFilterService, btcFormatter, bsqFormatter, bsqWalletService, coreApi); } + @Override + protected void activate() { + super.activate(); + TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN; + } + @Override void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code) { // No need to store anything as it is just one Altcoin offers anyway diff --git a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java index 819c26ed84c..d12eec46fc3 100644 --- a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java +++ b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java @@ -944,6 +944,7 @@ private void activateDisplayCurrencies() { TradeCurrency selectedItem = preferredTradeCurrencyComboBox.getSelectionModel().getSelectedItem(); if (selectedItem != null) preferences.setPreferredTradeCurrency(selectedItem); + GUIUtil.updateTopAltcoin(preferences); }); fiatCurrenciesComboBox.setItems(allFiatCurrencies); diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index 7d91064d987..49d12c83f38 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -169,7 +169,7 @@ public class GUIUtil { public final static int AMOUNT_DECIMALS = 4; public final static TradeCurrency BSQ = CurrencyUtil.getTradeCurrency("BSQ").get(); - public final static TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get(); + public static TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get(); private static FeeService feeService; private static Preferences preferences; @@ -1249,4 +1249,12 @@ public static void setDefaultTwoColumnConstraintsForGridPane(GridPane gridPane) columnConstraints2.setHgrow(Priority.ALWAYS); gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2); } + + public static void updateTopAltcoin(Preferences preferences) { + TradeCurrency tradeCurrency = preferences.getPreferredTradeCurrency(); + if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode()) || tradeCurrency.equals(BSQ)) { + return; + } + TOP_ALTCOIN = tradeCurrency; + } }