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 47b7afaa1fb..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; @@ -85,6 +84,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 @@ -183,325 +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 getMatureMarketCurrencies() { ArrayList currencies = new ArrayList<>(Arrays.asList( new FiatCurrency("EUR"), @@ -532,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; } } @@ -572,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; @@ -717,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) @@ -734,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; } @@ -806,4 +486,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/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java index 121d5108e47..57136ad6929 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()); } @@ -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; @@ -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/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/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 b01b71bbfeb..7c20e29097f 100644 --- a/core/src/main/java/bisq/core/payment/AliPayAccount.java +++ b/core/src/main/java/bisq/core/payment/AliPayAccount.java @@ -18,17 +18,24 @@ package bisq.core.payment; 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(new FiatCurrency("CNY")); + 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 78% rename from core/src/main/java/bisq/core/payment/AustraliaPayid.java rename to core/src/main/java/bisq/core/payment/AustraliaPayidAccount.java index a64c62b42ac..a09a62209c8 100644 --- a/core/src/main/java/bisq/core/payment/AustraliaPayid.java +++ b/core/src/main/java/bisq/core/payment/AustraliaPayidAccount.java @@ -18,14 +18,22 @@ package bisq.core.payment; 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(new FiatCurrency("AUD")); + 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 acd4f6b6a5d..c88ad24b8a3 100644 --- a/core/src/main/java/bisq/core/payment/CashAppAccount.java +++ b/core/src/main/java/bisq/core/payment/CashAppAccount.java @@ -18,20 +18,27 @@ package bisq.core.payment; 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(new FiatCurrency("USD")); + 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 29f8d5329e4..1481f7cb067 100644 --- a/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java +++ b/core/src/main/java/bisq/core/payment/ChaseQuickPayAccount.java @@ -18,20 +18,27 @@ package bisq.core.payment; 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(new FiatCurrency("USD")); + 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 397aeb44f0d..72b572b3744 100644 --- a/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java +++ b/core/src/main/java/bisq/core/payment/ClearXchangeAccount.java @@ -18,17 +18,24 @@ package bisq.core.payment; 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(new FiatCurrency("USD")); + 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 3c4f124c662..e31e321c126 100644 --- a/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java +++ b/core/src/main/java/bisq/core/payment/FasterPaymentsAccount.java @@ -18,17 +18,24 @@ package bisq.core.payment; 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(new FiatCurrency("GBP")); + 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 dba8ee82f11..ca79105c0e1 100644 --- a/core/src/main/java/bisq/core/payment/HalCashAccount.java +++ b/core/src/main/java/bisq/core/payment/HalCashAccount.java @@ -18,17 +18,24 @@ package bisq.core.payment; 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(new FiatCurrency("EUR")); + 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 b4b5f8310ac..0fece8b1113 100644 --- a/core/src/main/java/bisq/core/payment/InteracETransferAccount.java +++ b/core/src/main/java/bisq/core/payment/InteracETransferAccount.java @@ -18,17 +18,25 @@ package bisq.core.payment; 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(new FiatCurrency("CAD")); + 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 8aa952d074d..99ff306d99f 100644 --- a/core/src/main/java/bisq/core/payment/JapanBankAccount.java +++ b/core/src/main/java/bisq/core/payment/JapanBankAccount.java @@ -18,97 +18,100 @@ package bisq.core.payment; 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(new FiatCurrency("JPY")); + 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 4e67c334731..e85bf70071e 100644 --- a/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java +++ b/core/src/main/java/bisq/core/payment/MoneyBeamAccount.java @@ -18,18 +18,25 @@ package bisq.core.payment; 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(new FiatCurrency("EUR")); + 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 fc810b017d4..ab4224b8861 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,8 @@ import javax.annotation.Nullable; +import static bisq.core.payment.payload.PaymentMethod.*; + @Slf4j public class PaymentAccountUtil { @@ -65,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; @@ -106,6 +110,120 @@ public static ArrayList getAcceptedCountryCodes(PaymentAccount paymentAc return acceptedCountryCodes; } + public static List getTradeCurrencies(PaymentMethod paymentMethod) { + switch (paymentMethod.getId()) { + case ADVANCED_CASH_ID: + return AdvancedCashAccount.SUPPORTED_CURRENCIES; + case AMAZON_GIFT_CARD_ID: + return AmazonGiftCardAccount.SUPPORTED_CURRENCIES; + case CAPITUAL_ID: + return CapitualAccount.SUPPORTED_CURRENCIES; + case MONEY_GRAM_ID: + return MoneyGramAccount.SUPPORTED_CURRENCIES; + case PAXUM_ID: + return PaxumAccount.SUPPORTED_CURRENCIES; + case PAYSERA_ID: + return PayseraAccount.SUPPORTED_CURRENCIES; + case REVOLUT_ID: + return RevolutAccount.SUPPORTED_CURRENCIES; + case SWIFT_ID: + return SwiftAccount.SUPPORTED_CURRENCIES; + case TRANSFERWISE_ID: + return TransferwiseAccount.SUPPORTED_CURRENCIES; + case UPHOLD_ID: + return UpholdAccount.SUPPORTED_CURRENCIES; + case INTERAC_E_TRANSFER_ID: + return InteracETransferAccount.SUPPORTED_CURRENCIES; + case STRIKE_ID: + return StrikeAccount.SUPPORTED_CURRENCIES; + case TIKKIE_ID: + return TikkieAccount.SUPPORTED_CURRENCIES; + case ALI_PAY_ID: + return AliPayAccount.SUPPORTED_CURRENCIES; + case NEQUI_ID: + return NequiAccount.SUPPORTED_CURRENCIES; + case IMPS_ID: + case NEFT_ID: + case PAYTM_ID: + case RTGS_ID: + case UPI_ID: + return IfscBasedAccount.SUPPORTED_CURRENCIES; + case BIZUM_ID: + return BizumAccount.SUPPORTED_CURRENCIES; + case MONEY_BEAM_ID: + return MoneyBeamAccount.SUPPORTED_CURRENCIES; + case PIX_ID: + return PixAccount.SUPPORTED_CURRENCIES; + case SATISPAY_ID: + return SatispayAccount.SUPPORTED_CURRENCIES; + case CHASE_QUICK_PAY_ID: + return ChaseQuickPayAccount.SUPPORTED_CURRENCIES; + case US_POSTAL_MONEY_ORDER_ID: + return USPostalMoneyOrderAccount.SUPPORTED_CURRENCIES; + case VENMO_ID: + return VenmoAccount.SUPPORTED_CURRENCIES; + case JAPAN_BANK_ID: + return JapanBankAccount.SUPPORTED_CURRENCIES; + case WECHAT_PAY_ID: + return WeChatPayAccount.SUPPORTED_CURRENCIES; + case CLEAR_X_CHANGE_ID: + return ClearXchangeAccount.SUPPORTED_CURRENCIES; + case AUSTRALIA_PAYID_ID: + return AustraliaPayidAccount.SUPPORTED_CURRENCIES; + case PERFECT_MONEY_ID: + return PerfectMoneyAccount.SUPPORTED_CURRENCIES; + case HAL_CASH_ID: + return HalCashAccount.SUPPORTED_CURRENCIES; + case SWISH_ID: + return SwishAccount.SUPPORTED_CURRENCIES; + case CASH_APP_ID: + return CashAppAccount.SUPPORTED_CURRENCIES; + case POPMONEY_ID: + return PopmoneyAccount.SUPPORTED_CURRENCIES; + case PROMPT_PAY_ID: + return PromptPayAccount.SUPPORTED_CURRENCIES; + case SEPA_ID: + return SepaAccount.SUPPORTED_CURRENCIES; + case SEPA_INSTANT_ID: + 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 WesternUnionAccount.SUPPORTED_CURRENCIES; + case FASTER_PAYMENTS_ID: + return FasterPaymentsAccount.SUPPORTED_CURRENCIES; + case DOMESTIC_WIRE_TRANSFER_ID: + return DomesticWireTransferAccount.SUPPORTED_CURRENCIES; + case ACH_TRANSFER_ID: + return AchTransferAccount.SUPPORTED_CURRENCIES; + case CELPAY_ID: + return CelPayAccount.SUPPORTED_CURRENCIES; + case MONESE_ID: + return MoneseAccount.SUPPORTED_CURRENCIES; + case TRANSFERWISE_USD_ID: + return TransferwiseUsdAccount.SUPPORTED_CURRENCIES; + case VERSE_ID: + return VerseAccount.SUPPORTED_CURRENCIES; + 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; @@ -134,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, 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 0abc12f367f..dbd8355f504 100644 --- a/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java +++ b/core/src/main/java/bisq/core/payment/PerfectMoneyAccount.java @@ -18,17 +18,24 @@ 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.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(new FiatCurrency("USD")); + 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 c6f534c24eb..3ebc60449c2 100644 --- a/core/src/main/java/bisq/core/payment/PopmoneyAccount.java +++ b/core/src/main/java/bisq/core/payment/PopmoneyAccount.java @@ -18,18 +18,25 @@ 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.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(new FiatCurrency("USD")); + 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 89ed2102d31..00a3d771cd0 100644 --- a/core/src/main/java/bisq/core/payment/PromptPayAccount.java +++ b/core/src/main/java/bisq/core/payment/PromptPayAccount.java @@ -18,17 +18,24 @@ 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.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(new FiatCurrency("THB")); + 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 e3236300403..4a4427454a4 100644 --- a/core/src/main/java/bisq/core/payment/SwishAccount.java +++ b/core/src/main/java/bisq/core/payment/SwishAccount.java @@ -18,17 +18,24 @@ 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.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(new FiatCurrency("SEK")); + 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 af8f577e65b..c8cad3e163d 100644 --- a/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java +++ b/core/src/main/java/bisq/core/payment/USPostalMoneyOrderAccount.java @@ -18,17 +18,24 @@ 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.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(new FiatCurrency("USD")); + 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 cd546601442..2de0e193935 100644 --- a/core/src/main/java/bisq/core/payment/VenmoAccount.java +++ b/core/src/main/java/bisq/core/payment/VenmoAccount.java @@ -18,20 +18,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.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(new FiatCurrency("USD")); + 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 f4ef6f64406..a8faf79a2c1 100644 --- a/core/src/main/java/bisq/core/payment/WeChatPayAccount.java +++ b/core/src/main/java/bisq/core/payment/WeChatPayAccount.java @@ -18,18 +18,24 @@ 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.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(new FiatCurrency("CNY")); + 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/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/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..a5b56056d98 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,8 @@ shared.iConfirm=I confirm 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 @@ -233,8 +234,8 @@ shared.enabled=Enabled #################################################################### mainView.menu.market=Market -mainView.menu.buyBtc=Buy BTC -mainView.menu.sellBtc=Sell BTC +mainView.menu.buy=Buy +mainView.menu.sell=Sell mainView.menu.portfolio=Portfolio mainView.menu.funds=Funds mainView.menu.support=Support @@ -301,10 +302,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 @@ -337,17 +338,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,16 +380,10 @@ 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 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} @@ -399,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? @@ -439,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\ @@ -460,8 +453,12 @@ 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 +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 @@ -496,6 +493,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 @@ -554,6 +552,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. @@ -577,13 +577,13 @@ 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" 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. @@ -1333,6 +1333,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 @@ -2821,7 +2822,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/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/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/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); } 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 bb1d8dc16cf..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,12 +23,11 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; 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 +58,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(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 f8782b79a8b..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.FiatCurrency; 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(new FiatCurrency("INR")); + 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 8e9dbb2d7a8..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,12 +23,11 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.locale.CountryUtil; -import bisq.core.locale.FiatCurrency; 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 +58,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(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 772f709bff3..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.FiatCurrency; 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(new FiatCurrency("INR")); + 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 1cd1cc9988b..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.FiatCurrency; 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(new FiatCurrency("BRL")); + 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 37641b04faa..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.FiatCurrency; 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(new FiatCurrency("EUR")); + 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 f4067a23503..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.FiatCurrency; 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(new FiatCurrency("USD")); - 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 0c47afd4ce4..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.FiatCurrency; 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(new FiatCurrency("EUR")); - 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 6155a99cbc3..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.FiatCurrency; 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(new FiatCurrency("USD")); - 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 13090e19e25..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.FiatCurrency; 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(new FiatCurrency("INR")); + 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/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()); 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")) 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..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,9 +25,6 @@ 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.OfferBookListItem; import bisq.desktop.util.CurrencyListItem; import bisq.desktop.util.DisplayUtils; @@ -85,9 +81,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; @@ -108,7 +102,6 @@ public class OfferBookChartView extends ActivatableViewAndModel seriesBuy, seriesSell; - private final Navigation navigation; private final CoinFormatter formatter; private TableView buyOfferTableView; private TableView sellOfferTableView; @@ -118,19 +111,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)); }; @@ -142,11 +135,9 @@ public class OfferBookChartView extends ActivatableViewAndModel() { - 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 +240,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 +270,7 @@ public Number fromString(String string) { } static class CurrencyListItemStringConverter extends StringConverter { - private ComboBox comboBox; + private final ComboBox comboBox; CurrencyListItemStringConverter(ComboBox comboBox) { this.comboBox = comboBox; @@ -322,14 +297,8 @@ private void createListener() { currencyComboBox.getSelectionModel().select(model.getSelectedCurrencyListItem().get()); }; - buyTableRowSelectionListener = (observable, oldValue, newValue) -> { - 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(); } @@ -389,33 +358,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) { @@ -605,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 ? @@ -672,15 +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 -> { - if (isSellOffer) { - model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode()); - navigation.navigateTo(MainView.class, BuyOfferView.class); - } else { - model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode()); - navigation.navigateTo(MainView.class, SellOfferView.class); - } - }); + button.setOnAction(e -> model.goToOfferView(direction)); Region spacer = new Region(); @@ -699,18 +657,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..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 @@ -20,6 +20,10 @@ 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.OfferBook; import bisq.desktop.main.offer.offerbook.OfferBookListItem; import bisq.desktop.main.settings.SettingsView; @@ -194,11 +198,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 @@ -238,13 +251,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; } @@ -293,7 +306,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 +318,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 +349,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 +394,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); @@ -396,4 +406,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(GUIUtil.BSQ.getCode()) && + !getCurrencyCode().equals(GUIUtil.TOP_ALTCOIN.getCode())) { + preferences.setBuyScreenCryptoCurrencyCode(getCurrencyCode()); + } + } else { + if (CurrencyUtil.isFiatCurrency(getCurrencyCode())) { + preferences.setSellScreenCurrencyCode(getCurrencyCode()); + } 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/BuyOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/BuyOfferView.java index f473ec71461..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,13 +36,11 @@ public class BuyOfferView extends OfferView { public BuyOfferView(ViewLoader viewLoader, Navigation navigation, Preferences preferences, - ArbitratorManager arbitratorManager, User user, P2PService p2PService) { super(viewLoader, navigation, preferences, - arbitratorManager, user, p2PService, OfferDirection.BUY); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/ClosableView.java b/desktop/src/main/java/bisq/desktop/main/offer/ClosableView.java new file mode 100644 index 00000000000..e1499e5fd4f --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/ClosableView.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 ClosableView { + public void setCloseHandler(OfferView.CloseHandler closeHandler); +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/InitializableViewWithTakeOfferData.java b/desktop/src/main/java/bisq/desktop/main/offer/InitializableViewWithTakeOfferData.java new file mode 100644 index 00000000000..4c4e2a2cf9a --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/InitializableViewWithTakeOfferData.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 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 1aad98f66a0..3d3c7a7c05b 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; @@ -47,27 +48,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 java.util.stream.Collectors; + +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; public abstract class OfferView extends ActivatableView { - private OfferBookView offerBookView; - private CreateOfferView createOfferView; - private BsqSwapCreateOfferView bsqSwapCreateOfferView; - private TakeOfferView takeOfferView; - private BsqSwapTakeOfferView bsqSwapTakeOfferView; - private AnchorPane createOfferPane, takeOfferPane; - private Tab takeOfferTab, createOfferTab, offerBookTab; + private OfferBookView btcOfferBookView, bsqOfferBookView, topAltcoinOfferBookView, otherOfferBookView; + + private Tab btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab; private final ViewLoader viewLoader; private final Navigation navigation; @@ -75,20 +69,16 @@ 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; - private boolean createOfferViewOpen, takeOfferViewOpen; private Navigation.Listener navigationListener; private ChangeListener tabChangeListener; - private ListChangeListener tabListChangeListener; private OfferView.OfferActionHandler offerActionHandler; protected OfferView(ViewLoader viewLoader, Navigation navigation, Preferences preferences, - ArbitratorManager arbitratorManager, User user, P2PService p2PService, OfferDirection direction) { @@ -98,72 +88,71 @@ protected OfferView(ViewLoader viewLoader, this.user = user; this.p2PService = p2PService; this.direction = direction; - this.arbitratorManager = arbitratorManager; } @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) { - if (newValue.equals(createOfferTab) && createOfferView != null) { - 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(offerBookTab) && offerBookView != null) { - offerBookView.onTabSelected(true); + if (newValue.equals(btcOfferBookTab)) { + if (btcOfferBookView != null) { + btcOfferBookView.onTabSelected(true); + } else { + loadView(BtcOfferBookView.class, null, null); + } + } else if (newValue.equals(bsqOfferBookTab)) { + if (bsqOfferBookView != null) { + bsqOfferBookView.onTabSelected(true); + } else { + loadView(BsqOfferBookView.class, null, null); + } + } else if (newValue.equals(topAltcoinOfferBookTab)) { + if (topAltcoinOfferBookView != null) { + topAltcoinOfferBookView.onTabSelected(true); + } else { + loadView(TopAltcoinOfferBookView.class, null, null); + } + } else if (newValue.equals(otherOfferBookTab)) { + if (otherOfferBookView != null) { + otherOfferBookView.onTabSelected(true); + } else { + loadView(OtherOfferBookView.class, null, null); + } } } 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(takeOfferTab) && takeOfferView != null) { - takeOfferView.onTabSelected(false); - } else if (oldValue.equals(takeOfferTab) && bsqSwapTakeOfferView != null) { - bsqSwapTakeOfferView.onTabSelected(false); - } else if (oldValue.equals(offerBookTab) && offerBookView != null) { - offerBookView.onTabSelected(false); + 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); } } }; - tabListChangeListener = change -> { - change.next(); - List removedTabs = change.getRemoved(); - if (removedTabs.size() == 1) { - if (removedTabs.get(0).getContent().equals(createOfferPane)) - onCreateOfferViewRemoved(); - else if (removedTabs.get(0).getContent().equals(takeOfferPane)) - onTakeOfferViewRemoved(); - } - }; 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) { - if (takeOfferViewOpen) { - root.getTabs().remove(takeOfferTab); - } - if (canCreateOrTakeOffer(CurrencyUtil.getTradeCurrency(offer.getCurrencyCode()).get())) { - openTakeOffer(offer); + Optional optionalTradeCurrency = CurrencyUtil.getTradeCurrency(offer.getCurrencyCode()); + if (optionalTradeCurrency.isPresent() && canCreateOrTakeOffer(optionalTradeCurrency.get())) { + showTakeOffer(offer); } } }; @@ -177,10 +166,15 @@ protected void activate() { tradeCurrency = tradeCurrencyOptional.orElseGet(GlobalSettings::getDefaultTradeCurrency); 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); + } + + GUIUtil.updateTopAltcoin(preferences); + + if (topAltcoinOfferBookTab != null) { + topAltcoinOfferBookTab.setText(GUIUtil.TOP_ALTCOIN.getCode()); } } @@ -188,167 +182,199 @@ 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, @Nullable Object data) { + private void loadView(Class viewClass, + Class childViewClass, + @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) { + if (childViewClass == null) { + btcOfferBookTab.setContent(btcOfferBookView.getRoot()); + } 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 if (childViewClass == TakeOfferView.class) { + loadTakeViewClass(viewClass, childViewClass, bsqOfferBookTab); + } else if (data instanceof BsqSwapOfferPayload) { + loadCreateViewClass(bsqOfferBookView, viewClass, childViewClass, bsqOfferBookTab, PaymentMethod.BSQ_SWAP, (BsqSwapOfferPayload) data); + } else { + tradeCurrency = GUIUtil.BSQ; + 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 if (childViewClass == TakeOfferView.class) { + loadTakeViewClass(viewClass, childViewClass, topAltcoinOfferBookTab); + } else { + tradeCurrency = GUIUtil.TOP_ALTCOIN; + 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 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() ? OfferViewUtil.getAnyOfMainCryptoCurrencies() : tradeCurrencyOptional.get(); + } + loadCreateViewClass(otherOfferBookView, viewClass, childViewClass, otherOfferBookTab, (PaymentMethod) data, null); + } + tabPane.getSelectionModel().select(otherOfferBookTab); } 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(Res.getBaseCurrencyName().toUpperCase()); + btcOfferBookTab.setClosable(false); + bsqOfferBookTab = new Tab(GUIUtil.BSQ.getCode()); + bsqOfferBookTab.setClosable(false); + topAltcoinOfferBookTab = new Tab(GUIUtil.TOP_ALTCOIN.getCode()); + topAltcoinOfferBookTab.setClosable(false); + otherOfferBookTab = new Tab(Res.get("shared.other").toUpperCase()); + otherOfferBookTab.setClosable(false); + + tabPane.getTabs().addAll(btcOfferBookTab, bsqOfferBookTab, topAltcoinOfferBookTab, otherOfferBookTab); + } + if (viewClass == BtcOfferBookView.class) { + btcOfferBookView = (BtcOfferBookView) viewLoader.load(BtcOfferBookView.class); + btcOfferBookView.setOfferActionHandler(offerActionHandler); + btcOfferBookView.setDirection(direction); + 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()); + } 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()); + } 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()); + } } - } 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; - } 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); } } - protected boolean canCreateOrTakeOffer(TradeCurrency tradeCurrency) { - return GUIUtil.isBootstrappedOrShowPopup(p2PService) && - GUIUtil.canCreateOrTakeOfferOrShowPopup(user, navigation, tradeCurrency); + private void loadCreateViewClass(OfferBookView offerBookView, + Class viewClass, + Class childViewClass, + Tab marketOfferBookTab, + @Nullable PaymentMethod paymentMethod, + @Nullable BsqSwapOfferPayload payload) { + if (tradeCurrency == null) { + return; + } + + 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 != 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); + } else { + view = viewLoader.load(childViewClass); + ((CreateOfferView) view).initWithData(direction, tradeCurrency, offerActionHandler); + } + + ((SelectableView) view).onTabSelected(true); + + ((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()); } - 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 void loadTakeViewClass(Class viewClass, + Class childViewClass, + Tab marketOfferBookTab) { + + if (offer == null) { + return; + } + + 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); + + // close handler from close on take offer action + ((ClosableView) view).setCloseHandler(() -> { + ((SelectableView) view).onTabSelected(false); + navigation.navigateTo(MainView.class, this.getClass(), viewClass); + }); + marketOfferBookTab.setContent(view.getRoot()); } - private String getArbitrationLanguages() { - return arbitratorManager.getObservableMap().values().stream() - .flatMap(arbitrator -> arbitrator.getLanguageCodes().stream()) - .distinct() - .map(LanguageUtil::getDisplayName) - .collect(Collectors.joining(", ")); + protected boolean canCreateOrTakeOffer(TradeCurrency tradeCurrency) { + return GUIUtil.isBootstrappedOrShowPopup(p2PService) && + GUIUtil.canCreateOrTakeOfferOrShowPopup(user, navigation, tradeCurrency); } - private void openTakeOffer(Offer offer) { - takeOfferViewOpen = true; + private void showTakeOffer(Offer offer) { this.offer = offer; - if (offer.isBsqSwapOffer()) { - navigation.navigateTo(MainView.class, this.getClass(), BsqSwapTakeOfferView.class); - } else { - navigation.navigateTo(MainView.class, this.getClass(), TakeOfferView.class); - } - } - private void openCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMethod) { - createOfferViewOpen = true; - 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(offer.getCurrencyCode()); + navigation.navigateTo(MainView.class, this.getClass(), offerBookViewClass, TakeOfferView.class); } - private void onCreateOfferViewRemoved() { - createOfferViewOpen = false; - if (createOfferView != null) { - createOfferView.onClose(); - createOfferView = null; - } - if (bsqSwapCreateOfferView != null) { - bsqSwapCreateOfferView = null; - } - offerBookView.enableCreateOfferButton(); + private void showCreateOffer(TradeCurrency tradeCurrency, PaymentMethod paymentMethod) { + this.tradeCurrency = tradeCurrency; - navigation.navigateTo(MainView.class, this.getClass(), OfferBookView.class); + Class> offerBookViewClass = getOfferBookViewClassFor(tradeCurrency.getCode()); + navigation.navigateToWithData(paymentMethod, MainView.class, this.getClass(), offerBookViewClass, CreateOfferView.class); } - private void onTakeOfferViewRemoved() { - offer = null; - takeOfferViewOpen = false; - if (takeOfferView != null) { - takeOfferView.onClose(); - takeOfferView = null; - } - if (bsqSwapTakeOfferView != null) { - bsqSwapTakeOfferView = null; + @NotNull + private Class> getOfferBookViewClassFor(String currencyCode) { + Class> offerBookViewClass; + if (CurrencyUtil.isFiatCurrency(currencyCode)) { + offerBookViewClass = BtcOfferBookView.class; + } else if (currencyCode.equals(GUIUtil.BSQ.getCode())) { + offerBookViewClass = BsqOfferBookView.class; + } else if (currencyCode.equals(GUIUtil.TOP_ALTCOIN.getCode())) { + offerBookViewClass = TopAltcoinOfferBookView.class; + } else { + offerBookViewClass = OtherOfferBookView.class; } - - navigation.navigateTo(MainView.class, this.getClass(), OfferBookView.class); + return offerBookViewClass; } public interface OfferActionHandler { 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 60% 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 712a8fdd20b..847bcc747ae 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,19 +15,27 @@ * 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.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.overlays.popups.Popup; +import bisq.desktop.util.GUIUtil; +import bisq.core.locale.CryptoCurrency; +import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; -import bisq.core.user.Preferences; +import bisq.core.locale.TradeCurrency; +import bisq.core.offer.Offer; +import bisq.core.offer.OfferDirection; import bisq.common.UserThread; import bisq.common.util.Tuple2; @@ -43,7 +51,11 @@ import javafx.geometry.VPos; 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 { @@ -84,14 +96,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 +111,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 +122,53 @@ 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 Class> getOfferBookViewClass(String currencyCode) { + Class> offerBookViewClazz; + if (CurrencyUtil.isFiatCurrency(currencyCode)) { + offerBookViewClazz = BtcOfferBookView.class; + } else if (currencyCode.equals(GUIUtil.BSQ.getCode())) { + offerBookViewClazz = BsqOfferBookView.class; + } else if (currencyCode.equals(GUIUtil.TOP_ALTCOIN.getCode())) { + offerBookViewClazz = TopAltcoinOfferBookView.class; + } else { + offerBookViewClazz = OtherOfferBookView.class; + } + return offerBookViewClazz; + } + + 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); + } + + public static boolean isShownAsBuyOffer(Offer offer) { + return !isShownAsSellOffer(offer); + } + + public static boolean isShownAsBuyOffer(OfferDirection direction, TradeCurrency tradeCurrency) { + return !isShownAsSellOffer(tradeCurrency.getCode(), direction); + } + + public static TradeCurrency getAnyOfMainCryptoCurrencies() { + return getMainCryptoCurrencies().findAny().get(); + } + + @NotNull + public static Stream getMainCryptoCurrencies() { + return CurrencyUtil.getMainCryptoCurrencies().stream().filter(cryptoCurrency -> + !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/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/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/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java index 2389ebfb9eb..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 @@ -81,6 +81,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 +89,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 +250,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 +280,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(), GUIUtil.BSQ.getCode()) && + !Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), GUIUtil.TOP_ALTCOIN.getCode())).findAny(); + } + } + protected PaymentAccount getPreselectedPaymentAccount() { return preferences.getSelectedPaymentAccountForCreateOffer(); } @@ -405,7 +420,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 { @@ -464,7 +479,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 6363347063e..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 @@ -35,7 +35,10 @@ 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.OfferViewUtil; +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 +107,7 @@ import javafx.event.EventHandler; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.util.StringConverter; @@ -121,11 +125,11 @@ 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; -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 +141,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 +221,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 +256,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 +331,29 @@ 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.getCode()); + } + 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.getCode()); + } + nextButton.setId("sell-button"); + fundFromSavingsWalletButton.setId("sell-button"); } + placeOfferButton.updateText(placeOfferButtonLabel); 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().getCode())); + } else { + placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), + model.getTradeCurrency().getCode())); + } + } }; placeOfferCompletedListener = (o, oldValue, newValue) -> { @@ -784,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(); } } }; @@ -919,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()) { @@ -1031,7 +1062,7 @@ private void addGridPane() { } private void addPaymentGroup() { - paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.selectTradingAccount")); + paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.createOffer")); GridPane.setColumnSpan(paymentTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); @@ -1040,7 +1071,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")); @@ -1106,8 +1137,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); @@ -1235,7 +1265,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()); @@ -1554,4 +1584,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..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 @@ -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; @@ -268,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( @@ -589,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(); @@ -981,6 +994,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/createoffer/CreateOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/createoffer/CreateOfferView.java index 0ad84c2c006..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 @@ -19,9 +19,15 @@ 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.overlays.windows.OfferDetailsWindow; +import bisq.desktop.util.GUIUtil; +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 +37,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 +54,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(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(), GUIUtil.BSQ) || + Objects.equals(paymentAccount.getSingleTradeCurrency(), GUIUtil.TOP_ALTCOIN)); + } + }).collect(Collectors.toList())); + } } 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 057547912f4..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 @@ -36,8 +36,11 @@ 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.ClosableView; +import bisq.desktop.main.offer.InitializableViewWithTakeOfferData; import bisq.desktop.main.offer.OfferView; -import bisq.desktop.main.offer.bisq_v1.OfferViewUtil; +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; import bisq.desktop.main.overlays.windows.GenericMessageWindow; @@ -52,7 +55,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; @@ -117,12 +119,12 @@ 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; @FxmlView -public class TakeOfferView extends ActivatableViewAndModel { +public class TakeOfferView extends ActivatableViewAndModel implements ClosableView, InitializableViewWithTakeOfferData, SelectableView { private final Navigation navigation; private final CoinFormatter formatter; private final BsqFormatter bsqFormatter; @@ -131,7 +133,8 @@ public class TakeOfferView extends ActivatableViewAndModel, Label, TextField, HBox> paymentAccountTuple = addComboBoxTopLabelTextField(gridPane, - gridRow, Res.get("shared.selectTradingAccount"), - Res.get("shared.paymentMethod"), Layout.FIRST_ROW_DISTANCE); + gridRow, Res.get("shared.chooseTradingAccount"), + Res.get("shared.chooseTradingAccount"), Layout.FIRST_ROW_DISTANCE); paymentAccountsComboBox = paymentAccountTuple.first; HBox.setMargin(paymentAccountsComboBox, new Insets(Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0)); @@ -882,8 +886,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); @@ -920,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) { @@ -1015,7 +1016,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()); @@ -1292,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); } } @@ -1342,5 +1341,15 @@ private GridPane createInfoPopover() { return infoGridPane; } + + @NotNull + private String getTakeOfferLabel(Offer offer, String direction) { + return offer.isFiatOffer() ? + Res.get("takeOffer.takeOfferButton", direction) : + Res.get("takeOffer.takeOfferButtonAltcoin", + direction, + offer.getCurrencyCode()); + } + } 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..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; @@ -167,6 +166,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); @@ -201,9 +211,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); @@ -325,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 @@ -477,12 +492,6 @@ private void updateButtonDisableState() { private void addBindings() { volume.bind(createStringBinding(() -> VolumeUtil.formatVolume(dataModel.volume.get()), dataModel.volume)); - - if (dataModel.getDirection() == OfferDirection.SELL) { - volumeDescriptionLabel.set(Res.get("createOffer.amountPriceBox.buy.volumeDescription", dataModel.getCurrencyCode())); - } else { - volumeDescriptionLabel.set(Res.get("createOffer.amountPriceBox.sell.volumeDescription", dataModel.getCurrencyCode())); - } totalToPay.bind(createStringBinding(() -> btcFormatter.formatCoinWithCode(dataModel.getTotalToPayAsCoin().get()), dataModel.getTotalToPayAsCoin())); } @@ -614,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/bsq_swap/BsqSwapOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bsq_swap/BsqSwapOfferView.java index 623044694b3..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,6 +24,7 @@ import bisq.desktop.components.FundsTextField; import bisq.desktop.components.InputTextField; import bisq.desktop.components.TitledGroupBg; +import bisq.desktop.main.offer.ClosableView; 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 ClosableView { protected final Navigation navigation; protected final BsqSwapOfferDetailsWindow bsqSwapOfferDetailsWindow; 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)); } 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..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 @@ -26,6 +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.bsq_swap.BsqSwapOfferView; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; @@ -82,7 +84,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; @@ -167,22 +169,24 @@ 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, GUIUtil.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.volumeDescriptionAltcoin", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescriptionAltcoin")); } 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.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); - } @@ -310,18 +314,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(); } } }; @@ -431,7 +429,7 @@ protected void removeBindings() { @Override protected void addPaymentAccountGroup() { - paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.selectTradingAccount")); + paymentAccountTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("offerbook.createOffer")); GridPane.setColumnSpan(paymentAccountTitledGroupBg, 2); HBox paymentGroupBox = new HBox(); @@ -440,7 +438,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 +457,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)); @@ -603,4 +601,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(); + } } 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..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 @@ -25,6 +25,9 @@ import bisq.desktop.components.InputTextField; 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.bsq_swap.BsqSwapOfferView; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.BsqSwapOfferDetailsWindow; @@ -72,7 +75,7 @@ import static bisq.desktop.util.FormBuilder.*; @FxmlView -public class BsqSwapTakeOfferView extends BsqSwapOfferView { +public class BsqSwapTakeOfferView extends BsqSwapOfferView implements InitializableViewWithTakeOfferData, SelectableView { private HBox minAmountHBox; private Label offerAvailabilityLabel; private TextField paymentMethodTextField, currencyTextField, priceTextField, @@ -152,18 +155,18 @@ 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")); + 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"); - actionButton.updateText(Res.get("takeOffer.takeOfferButton", Res.get("shared.sell"))); - volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.sell.volumeDescription", BSQ)); - amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.buy.amountDescription")); + volumeDescriptionLabel.setText(Res.get("createOffer.amountPriceBox.buy.volumeDescriptionAltcoin", BSQ)); + amountDescriptionLabel.setText(Res.get("takeOffer.amountPriceBox.sell.amountDescriptionAltcoin")); } paymentMethodTextField.setText(PaymentMethod.BSQ_SWAP.getDisplayString()); @@ -443,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/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..c66dc7b35a8 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookView.java @@ -0,0 +1,79 @@ +/* + * 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", BsqOfferBookViewModel.BSQ.getCode(), Res.getBaseCurrencyCode()) : + Res.get("offerbook.availableOffersToSell", BsqOfferBookViewModel.BSQ.getCode(), Res.getBaseCurrencyCode()); + } + + @Override + protected void activate() { + model.onSetTradeCurrency(BsqOfferBookViewModel.BSQ); + + super.activate(); + + currencyComboBoxContainer.setVisible(false); + currencyComboBoxContainer.setManaged(false); + } + + @Override + String getTradeCurrencyCode() { + return 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 new file mode 100644 index 00000000000..ec8107ce702 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BsqOfferBookViewModel.java @@ -0,0 +1,123 @@ +/* + * 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.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.trade.bsq_swap.BsqSwapTradeManager; +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 = GUIUtil.BSQ; + + @Inject + public BsqOfferBookViewModel(User user, + OpenOfferManager openOfferManager, + OfferBook offerBook, + Preferences preferences, + WalletsSetup walletsSetup, + 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, bsqSwapTradeManager, 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 + 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.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..809e89eb3ea --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookView.java @@ -0,0 +1,69 @@ +/* + * 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", Res.getBaseCurrencyCode(), Res.get("shared.fiat")) : + Res.get("offerbook.availableOffersToSell", Res.getBaseCurrencyCode(), Res.get("shared.fiat")); + + + } + + @Override + String getTradeCurrencyCode() { + return Res.getBaseCurrencyCode(); + } +} 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..d8ee8542256 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/BtcOfferBookViewModel.java @@ -0,0 +1,163 @@ +/* + * 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.GlobalSettings; +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.trade.bsq_swap.BsqSwapTradeManager; +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.List; +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, + 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, bsqSwapTradeManager, 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() && offer.isFiatOffer()) || + offer.getCurrencyCode().equals(selectedTradeCurrency.getCode()); + boolean paymentMethodResult = showAllPaymentMethods || + offer.getPaymentMethod().equals(selectedPaymentMethod); + boolean notMyOfferOrShowMyOffersActivated = !isMyOffer(offerBookListItem.getOffer()) || preferences.isShowOwnOffersInOfferBook(); + return directionResult && currencyResult && paymentMethodResult && notMyOfferOrShowMyOffersActivated; + }; + } + + @Override + TradeCurrency getDefaultTradeCurrency() { + TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency(); + + if (CurrencyUtil.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 + String getCurrencyCodeFromPreferences(OfferDirection direction) { + // validate if previous stored currencies are Fiat ones + String currencyCode = direction == OfferDirection.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode(); + + return CurrencyUtil.isFiatCurrency(currencyCode) ? currencyCode : null; + } +} 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..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 @@ -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.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; @@ -118,14 +112,14 @@ import javafx.util.StringConverter; import java.util.Comparator; +import java.util.Map; import java.util.Optional; import org.jetbrains.annotations.NotNull; 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 +131,7 @@ public class OfferBookView extends ActivatableViewAndModel currencyComboBox; + protected AutocompleteComboBox currencyComboBox; private AutocompleteComboBox paymentMethodComboBox; private AutoTooltipButton createOfferButton; private AutoTooltipSlideToggleButton matchingOffersToggle; @@ -157,19 +151,19 @@ public class OfferBookView extends ActivatableViewAndModel> currencyBoxTuple = FormBuilder.addTopLabelAutocompleteComboBox( Res.get("offerbook.filterByCurrency")); + currencyComboBoxContainer = currencyBoxTuple.first; currencyComboBox = currencyBoxTuple.third; currencyComboBox.setPrefWidth(270); @@ -216,7 +211,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(""); createOfferButton.setMinHeight(40); createOfferButton.setGraphicTextGap(10); @@ -295,7 +290,7 @@ public void initialize() { if (price2 == null || price1 == null) { return 0; } - if (model.getDirection() == OfferDirection.SELL) { + if (OfferViewUtil.isShownAsSellOffer(model.getSelectedTradeCurrency().getCode(), model.getDirection())) { return price1.compareTo(price2); } else { return price2.compareTo(price1); @@ -340,15 +335,19 @@ 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"); + 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"); @@ -360,6 +359,11 @@ protected void activate() { if (currencyComboBox.getEditor().getText().isEmpty()) currencyComboBox.getSelectionModel().select(SHOW_ALL); model.onSetTradeCurrency(currencyComboBox.getSelectionModel().getSelectedItem()); + paymentMethodComboBox.setAutocompleteItems(model.getPaymentMethods()); + model.updateSelectedPaymentMethod(); + updatePaymentMethodComboBoxEditor(); + model.onSetPaymentMethod(paymentMethodComboBox.getSelectionModel().getSelectedItem()); + updateCreateOfferButton(); }); updateCurrencyComboBoxFromModel(); @@ -401,18 +405,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 +443,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 { @@ -583,41 +590,10 @@ 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"); 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) { @@ -625,12 +601,17 @@ 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(); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -642,12 +623,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(); @@ -797,7 +780,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")) @@ -902,13 +885,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"); @@ -916,13 +900,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); @@ -930,7 +914,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"); @@ -1110,6 +1094,7 @@ public TableCell call(TableColumn call(TableColumn call(TableColumn onTakeOffer(offer)); button2.setManaged(false); @@ -1316,4 +1295,12 @@ private Region getSpacer() { HBox.setHgrow(spacer, Priority.ALWAYS); return spacer; } + + private void updateCreateOfferButton() { + createOfferButton.setText(Res.get("offerbook.createNewOffer", + model.getDirection() == OfferDirection.BUY ? Res.get("shared.buy") : Res.get("shared.sell"), + getTradeCurrencyCode()).toUpperCase()); + } + + abstract String getTradeCurrencyCode(); } 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..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 @@ -34,7 +34,6 @@ import bisq.core.locale.CountryUtil; import bisq.core.locale.CryptoCurrency; import bisq.core.locale.CurrencyUtil; -import bisq.core.locale.GlobalSettings; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.monetary.Price; @@ -68,10 +67,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 +97,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; @@ -141,7 +136,7 @@ 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(); @@ -156,7 +151,6 @@ class OfferBookViewModel extends ActivatableViewModel { // Constructor, lifecycle /////////////////////////////////////////////////////////////////////////////////////////// - @Inject public OfferBookViewModel(User user, OpenOfferManager openOfferManager, OfferBook offerBook, @@ -170,7 +164,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) { @@ -237,14 +231,13 @@ public OfferBookViewModel(User user, protected void activate() { filteredItems.addListener(filterItemsListener); - updateSelectedTradeCurrency(); - if (user != null) { disableMatchToggle.set(user.getPaymentAccounts() == null || user.getPaymentAccounts().isEmpty()); } useOffersMatchingMyAccountsFilter = !disableMatchToggle.get() && isShowOffersMatchingMyAccounts(); fillCurrencies(); + updateSelectedTradeCurrency(); preferences.getTradeCurrenciesAsObservable().addListener(tradeCurrencyListChangeListener); offerBook.fillOfferBookListItems(); filterOffers(); @@ -297,14 +290,13 @@ else if (!showAllEntry) { setMarketPriceFeedCurrency(); filterOffers(); - if (direction == OfferDirection.BUY) - preferences.setBuyScreenCurrencyCode(code); - else - preferences.setSellScreenCurrencyCode(code); + saveSelectedCurrencyCodeInPreferences(direction, code); } } - void onSetPaymentMethod(PaymentMethod paymentMethod) { + abstract void saveSelectedCurrencyCodeInPreferences(OfferDirection direction, String code); + + protected void onSetPaymentMethod(PaymentMethod paymentMethod) { if (paymentMethod == null) return; @@ -381,11 +373,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); } @@ -424,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) { @@ -453,7 +452,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) { @@ -549,7 +548,7 @@ Optional 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()); } @@ -557,28 +556,24 @@ 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 /////////////////////////////////////////////////////////////////////////////////////////// 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() { @@ -594,23 +589,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 @@ -631,7 +616,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 -> { @@ -706,18 +691,27 @@ 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); 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)); + } + + 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..edc92ae2f70 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookView.java @@ -0,0 +1,67 @@ +/* + * 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", Res.get("shared.otherAssets"), Res.getBaseCurrencyCode()) : + Res.get("offerbook.availableOffersToSell", Res.get("shared.otherAssets"), Res.getBaseCurrencyCode()); + } + + @Override + String getTradeCurrencyCode() { + return model.showAllTradeCurrenciesProperty.get() ? "" : model.getSelectedTradeCurrency().getCode(); + } +} 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..65f01694874 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OtherOfferBookViewModel.java @@ -0,0 +1,172 @@ +/* + * 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.main.offer.OfferViewUtil; +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.GlobalSettings; +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.trade.bsq_swap.BsqSwapTradeManager; +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.List; +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, + 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, bsqSwapTradeManager, 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(GUIUtil.TOP_ALTCOIN.getCode()) && + !offer.getCurrencyCode().equals(GUIUtil.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 + 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 + 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(); + } + + @NotNull + private Predicate withoutBSQAndTopAltcoin() { + return cryptoCurrency -> + !cryptoCurrency.equals(GUIUtil.BSQ) && + !cryptoCurrency.equals(GUIUtil.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..1a1644a738c --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookView.java @@ -0,0 +1,77 @@ +/* + * 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(), Res.getBaseCurrencyCode()) : + Res.get("offerbook.availableOffersToSell", TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode(), Res.getBaseCurrencyCode()); + } + + @Override + protected void activate() { + model.onSetTradeCurrency(TopAltcoinOfferBookViewModel.TOP_ALTCOIN); + + super.activate(); + + currencyComboBoxContainer.setVisible(false); + currencyComboBoxContainer.setManaged(false); + } + + @Override + String getTradeCurrencyCode() { + return TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode(); + } +} 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..5a81b95b880 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/TopAltcoinOfferBookViewModel.java @@ -0,0 +1,128 @@ +/* + * 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.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.trade.bsq_swap.BsqSwapTradeManager; +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 TradeCurrency TOP_ALTCOIN = GUIUtil.TOP_ALTCOIN; + + @Inject + public TopAltcoinOfferBookViewModel(User user, + OpenOfferManager openOfferManager, + OfferBook offerBook, + Preferences preferences, + WalletsSetup walletsSetup, + 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, 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 + } + + @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 + TradeCurrency getDefaultTradeCurrency() { + return TOP_ALTCOIN; + } + + @Override + String getCurrencyCodeFromPreferences(OfferDirection direction) { + return TOP_ALTCOIN.getCode(); + } +} 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..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 @@ -19,6 +19,7 @@ import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.BusyAnimation; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.Layout; @@ -46,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; @@ -252,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(); }); @@ -264,14 +259,15 @@ private void addContent() { } private void addConfirmAndCancelButtons(boolean isPlaceOffer) { - boolean isBuyOffer = offer.isBuyOffer(); + boolean isBuyOffer = OfferViewUtil.isShownAsBuyOffer(offer); boolean isBuyerRole = isPlaceOffer == isBuyOffer; + String tradeCurrencyByCode = 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"), tradeCurrencyByCode) : + Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.sell"), tradeCurrencyByCode); 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"), tradeCurrencyByCode) : + Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.sell"), tradeCurrencyByCode); 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/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 a67be3fb433..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 @@ -22,6 +22,7 @@ import bisq.desktop.components.BusyAnimation; import bisq.desktop.components.TitledGroupBg; import bisq.desktop.components.TxIdTextField; +import bisq.desktop.main.offer.OfferViewUtil; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -61,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; @@ -375,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(); }); @@ -387,14 +383,27 @@ private void addContent() { } private void addConfirmAndCancelButtons(boolean isPlaceOffer) { - boolean isBuyOffer = offer.isBuyOffer(); + boolean isBuyOffer = OfferViewUtil.isShownAsBuyOffer(offer); boolean isBuyerRole = isPlaceOffer == isBuyOffer; + String tradeCurrencyByCode = offer.getCurrencyCode(); String placeOfferButtonText = isBuyerRole ? - Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) : - Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell")); + offer.isFiatOffer() ? + Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) : + Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.buy"), + tradeCurrencyByCode) : + offer.isFiatOffer() ? + Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell")) : + Res.get("offerDetailsWindow.confirm.makerAltcoin", Res.get("shared.sell"), + tradeCurrencyByCode); String takeOfferButtonText = isBuyerRole ? - Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) : - Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell")); + offer.isFiatOffer() ? + Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) : + Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.buy"), + tradeCurrencyByCode) : + offer.isFiatOffer() ? + Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell")) : + Res.get("offerDetailsWindow.confirm.takerAltcoin", Res.get("shared.sell"), + tradeCurrencyByCode); 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/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; } 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..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 @@ -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,20 @@ import javax.inject.Named; +import javafx.geometry.Insets; + +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); } @@ -55,12 +60,20 @@ 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 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..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 @@ -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 /////////////////////////////////////////////////////////////////////////////////////////// @@ -237,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()); + } } 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); } 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..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 @@ -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)) { @@ -941,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/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 diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index d663f7873e7..49d12c83f38 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 static TradeCurrency TOP_ALTCOIN = CurrencyUtil.getTradeCurrency("XMR").get(); + private static FeeService feeService; private static Preferences preferences; @@ -1247,4 +1250,11 @@ public static void setDefaultTwoColumnConstraintsForGridPane(GridPane gridPane) 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; + } } 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..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 @@ -238,7 +238,7 @@ public void testMaxCharactersForAmountWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForAmount.intValue()); } @@ -252,7 +252,7 @@ public void testMaxCharactersForAmount() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); @@ -270,7 +270,7 @@ public void testMaxCharactersForAmountRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); @@ -289,7 +289,7 @@ public void testMaxCharactersForVolumeWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForVolume.intValue()); } @@ -303,7 +303,7 @@ public void testMaxCharactersForVolume() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); @@ -321,7 +321,7 @@ public void testMaxCharactersForVolumeRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); @@ -340,7 +340,7 @@ public void testMaxCharactersForPriceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForPrice.intValue()); } @@ -354,7 +354,7 @@ public void testMaxCharactersForPrice() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); @@ -372,7 +372,7 @@ public void testMaxCharactersForPriceDistanceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); - final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue()); } @@ -407,7 +407,7 @@ public void testMaxCharactersForPriceDistance() { item4.getOffer().setPriceFeedService(priceFeedService); offerBookListItems.addAll(item1, item2); - final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); model.activate(); @@ -428,7 +428,7 @@ 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, + final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); final OfferBookListItem item = make(btcBuyItem.but( 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 {