diff --git a/apitest/src/test/java/bisq/apitest/method/payment/AbstractPaymentAccountTest.java b/apitest/src/test/java/bisq/apitest/method/payment/AbstractPaymentAccountTest.java index 92b8e8309ca..d1aa90b3ad3 100644 --- a/apitest/src/test/java/bisq/apitest/method/payment/AbstractPaymentAccountTest.java +++ b/apitest/src/test/java/bisq/apitest/method/payment/AbstractPaymentAccountTest.java @@ -146,8 +146,7 @@ protected final void verifyEmptyForm(File jsonForm, String paymentMethodId, Stri Object.class); assertNotNull(emptyForm); - // TODO remove 'false' condition to enable creation of SWIFT accounts in future PR. - if (false && paymentMethodId.equals("SWIFT_ID")) { + if (paymentMethodId.equals("SWIFT_ID")) { assertEquals(getSwiftFormComments(), emptyForm.get(PROPERTY_NAME_JSON_COMMENTS)); } else { assertEquals(PROPERTY_VALUE_JSON_COMMENTS, emptyForm.get(PROPERTY_NAME_JSON_COMMENTS)); @@ -216,24 +215,16 @@ protected final String getCompletedFormAsJsonString() { protected final String getCommaDelimitedFiatCurrencyCodes(Collection fiatCurrencies) { return fiatCurrencies.stream() - .sorted(TradeCurrency::compareTo) // note: sorted by ccy name, not ccy code + .sorted(Comparator.comparing(TradeCurrency::getCode)) .map(c -> c.getCurrency().getCurrencyCode()) .collect(Collectors.joining(",")); } - protected final String getCommaDelimitedTradeCurrencyCodes(List tradeCurrencies) { - return tradeCurrencies.stream() - .sorted(Comparator.comparing(TradeCurrency::getCode)) // sorted by code - .map(c -> c.getCode()) - .collect(Collectors.joining(",")); - } - protected final List getSwiftFormComments() { List comments = new ArrayList<>(); comments.addAll(PROPERTY_VALUE_JSON_COMMENTS); - // List wrappedSwiftComments = Res.getWrappedAsList("payment.swift.info", 110); - // comments.addAll(wrappedSwiftComments); - // comments.add("See https://bisq.wiki/SWIFT"); + List wrappedSwiftComments = Res.getWrappedAsList("payment.swift.info.account", 110); + comments.addAll(wrappedSwiftComments); return comments; } 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 ec54bf33276..c1d446895d7 100644 --- a/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java +++ b/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java @@ -17,6 +17,7 @@ package bisq.apitest.method.payment; +import bisq.core.locale.FiatCurrency; import bisq.core.locale.TradeCurrency; import bisq.core.payment.AdvancedCashAccount; import bisq.core.payment.AliPayAccount; @@ -43,6 +44,7 @@ import bisq.core.payment.SepaAccount; import bisq.core.payment.SepaInstantAccount; import bisq.core.payment.SpecificBanksAccount; +import bisq.core.payment.SwiftAccount; import bisq.core.payment.SwishAccount; import bisq.core.payment.TransferwiseAccount; import bisq.core.payment.USPostalMoneyOrderAccount; @@ -53,12 +55,14 @@ import bisq.core.payment.payload.CashDepositAccountPayload; import bisq.core.payment.payload.SameBankAccountPayload; import bisq.core.payment.payload.SpecificBanksAccountPayload; +import bisq.core.payment.payload.SwiftAccountPayload; import io.grpc.StatusRuntimeException; import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -79,6 +83,7 @@ import static bisq.cli.table.builder.TableType.PAYMENT_ACCOUNT_TBL; import static bisq.core.locale.CurrencyUtil.*; import static bisq.core.payment.payload.PaymentMethod.*; +import static java.util.Comparator.comparing; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; @@ -806,7 +811,6 @@ public void testCreateSpecificBanksAccount(TestInfo testInfo) { print(paymentAccount); } - /* @Test public void testCreateSwiftAccount(TestInfo testInfo) { // https://www.theswiftcodes.com @@ -816,7 +820,8 @@ public void testCreateSwiftAccount(TestInfo testInfo) { PROPERTY_NAME_BANK_SWIFT_CODE); COMPLETED_FORM_MAP.put(PROPERTY_NAME_PAYMENT_METHOD_ID, SWIFT_ID); COMPLETED_FORM_MAP.put(PROPERTY_NAME_ACCOUNT_NAME, "IT Swift Acct w/ DE Intermediary"); - String allFiatCodes = getCommaDelimitedFiatCurrencyCodes(getAllSortedFiatCurrencies()); + Collection swiftCurrenciesSortedByCode = getAllSortedFiatCurrencies(comparing(TradeCurrency::getCode)); + String allFiatCodes = getCommaDelimitedFiatCurrencyCodes(swiftCurrenciesSortedByCode); COMPLETED_FORM_MAP.put(PROPERTY_NAME_TRADE_CURRENCIES, allFiatCodes); COMPLETED_FORM_MAP.put(PROPERTY_NAME_SELECTED_TRADE_CURRENCY, EUR); COMPLETED_FORM_MAP.put(PROPERTY_NAME_BANK_SWIFT_CODE, "PASCITMMFIR"); @@ -839,7 +844,7 @@ public void testCreateSwiftAccount(TestInfo testInfo) { String jsonString = getCompletedFormAsJsonString(getSwiftFormComments()); SwiftAccount paymentAccount = (SwiftAccount) createPaymentAccount(aliceClient, jsonString); verifyUserPayloadHasPaymentAccountWithId(aliceClient, paymentAccount.getId()); - verifyAccountTradeCurrencies(getAllSortedFiatCurrencies(), paymentAccount); + verifyAccountTradeCurrencies(swiftCurrenciesSortedByCode, paymentAccount); assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SELECTED_TRADE_CURRENCY), paymentAccount.getSelectedTradeCurrency().getCode()); verifyCommonFormEntries(paymentAccount); @@ -863,7 +868,6 @@ public void testCreateSwiftAccount(TestInfo testInfo) { assertEquals(COMPLETED_FORM_MAP.get(PROPERTY_NAME_SALT), paymentAccount.getSaltAsHex()); print(paymentAccount); } - */ @Test public void testCreateSwishAccount(TestInfo testInfo) { diff --git a/apitest/src/test/java/bisq/apitest/scenario/PaymentAccountTest.java b/apitest/src/test/java/bisq/apitest/scenario/PaymentAccountTest.java index 8d03b7dd470..0dc42bac35e 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/PaymentAccountTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/PaymentAccountTest.java @@ -70,7 +70,7 @@ public void testCreatePaymentAccount(TestInfo testInfo) { test.testCreateSepaInstantAccount(testInfo); test.testCreateSepaAccount(testInfo); test.testCreateSpecificBanksAccount(testInfo); - // test.testCreateSwiftAccount(testInfo); + test.testCreateSwiftAccount(testInfo); test.testCreateSwishAccount(testInfo); test.testCreateTransferwiseAccountWith1TradeCurrency(testInfo); 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 00b0654145f..0613bd0060b 100644 --- a/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java +++ b/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java @@ -20,6 +20,7 @@ import bisq.core.locale.Country; import bisq.core.locale.FiatCurrency; +import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.payment.CountryBasedPaymentAccount; import bisq.core.payment.MoneyGramAccount; @@ -31,8 +32,6 @@ import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; -import org.apache.commons.lang3.StringUtils; - import java.io.IOException; import java.util.ArrayList; @@ -62,6 +61,7 @@ import static java.util.Collections.unmodifiableMap; import static java.util.Comparator.comparing; import static java.util.stream.Collectors.toList; +import static org.apache.commons.lang3.StringUtils.capitalize; @Slf4j class PaymentAccountTypeAdapter extends TypeAdapter { @@ -130,16 +130,13 @@ private void writeComments(JsonWriter out, PaymentAccount account) throws IOExce for (String s : JSON_COMMENTS) { out.value(s); } - /* - if (account.isSwiftAccount()) { + if (account.hasPaymentMethodWithId("SWIFT_ID")) { // Add extra comments for more complex swift account form. - List wrappedSwiftComments = Res.getWrappedAsList("payment.swift.info", 110); + List wrappedSwiftComments = Res.getWrappedAsList("payment.swift.info.account", 110); for (String line : wrappedSwiftComments) { out.value(line); } - out.value("See https://bisq.wiki/SWIFT"); } - */ out.endArray(); } @@ -170,7 +167,7 @@ private void writeInnerMutableFields(JsonWriter out, PaymentAccount account) { } catch (Exception ex) { String errMsg = format("cannot create a new %s json form", account.getClass().getSimpleName()); - log.error(StringUtils.capitalize(errMsg) + ".", ex); + log.error(capitalize(errMsg) + ".", ex); throw new IllegalStateException("programmer error: " + errMsg); } }); @@ -189,7 +186,7 @@ private void writeTradeCurrenciesField(JsonWriter out, PaymentAccount account) { } catch (Exception ex) { String errMsg = format("cannot create a new %s json form", account.getClass().getSimpleName()); - log.error(StringUtils.capitalize(errMsg) + ".", ex); + log.error(capitalize(errMsg) + ".", ex); throw new IllegalStateException("programmer error: " + errMsg); } } @@ -206,7 +203,7 @@ private void writeSelectedTradeCurrencyField(JsonWriter out, PaymentAccount acco } catch (Exception ex) { String errMsg = format("cannot create a new %s json form", account.getClass().getSimpleName()); - log.error(StringUtils.capitalize(errMsg) + ".", ex); + log.error(capitalize(errMsg) + ".", ex); throw new IllegalStateException("programmer error: " + errMsg); } } @@ -319,7 +316,7 @@ private String nextStringOrNull(JsonReader in) { } } catch (IOException ex) { String errMsg = "cannot see next string in json reader"; - log.error(StringUtils.capitalize(errMsg) + ".", ex); + log.error(capitalize(errMsg) + ".", ex); throw new IllegalStateException("programmer error: " + errMsg); } } @@ -335,7 +332,7 @@ private Long nextLongOrNull(JsonReader in) { } } catch (IOException ex) { String errMsg = "cannot see next long in json reader"; - log.error(StringUtils.capitalize(errMsg) + ".", ex); + log.error(capitalize(errMsg) + ".", ex); throw new IllegalStateException("programmer error: " + errMsg); } } @@ -394,8 +391,10 @@ 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()));*/ + 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)) @@ -468,7 +467,7 @@ private boolean didReadCountryField(JsonReader in, PaymentAccount account, Strin } else { String errMsg = format("cannot set the country on a %s", paymentAccountType.getSimpleName()); - log.error(StringUtils.capitalize(errMsg) + "."); + log.error(capitalize(errMsg) + "."); throw new IllegalStateException("programmer error: " + errMsg); } @@ -489,7 +488,7 @@ private Class getPaymentAccountPayloadType() { } catch (Exception ex) { String errMsg = format("cannot get the payload class for %s", paymentAccountType.getSimpleName()); - log.error(StringUtils.capitalize(errMsg) + ".", ex); + log.error(capitalize(errMsg) + ".", ex); throw new IllegalStateException("programmer error: " + errMsg); } } @@ -506,7 +505,7 @@ private PaymentAccount initNewPaymentAccount() { | InvocationTargetException ex) { String errMsg = format("cannot instantiate a new %s", paymentAccountType.getSimpleName()); - log.error(StringUtils.capitalize(errMsg) + ".", ex); + log.error(capitalize(errMsg) + ".", ex); throw new IllegalStateException("programmer error: " + errMsg); } } diff --git a/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index 85dddaf38cc..7a572fc79f8 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -82,7 +82,13 @@ public static void setBaseCurrencyCode(String baseCurrencyCode) { } public static Collection getAllSortedFiatCurrencies() { - return fiatCurrencyMapSupplier.get().values(); + return fiatCurrencyMapSupplier.get().values(); // sorted by currency name + } + + public static Collection getAllSortedFiatCurrencies(Comparator comparator) { + return (List) getAllSortedFiatCurrencies().stream() + .sorted(comparator) // sorted by comparator param + .collect(Collectors.toList()); } private static Map createFiatCurrencyMap() { diff --git a/core/src/main/java/bisq/core/payment/SwiftAccount.java b/core/src/main/java/bisq/core/payment/SwiftAccount.java index d43a4ef836d..5b3c2af2160 100644 --- a/core/src/main/java/bisq/core/payment/SwiftAccount.java +++ b/core/src/main/java/bisq/core/payment/SwiftAccount.java @@ -20,9 +20,9 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.FiatCurrency; import bisq.core.locale.TradeCurrency; -import bisq.core.payment.payload.SwiftAccountPayload; 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.List; @@ -34,6 +34,7 @@ public final class SwiftAccount extends PaymentAccount { public SwiftAccount() { super(PaymentMethod.SWIFT); + selectAllTradeCurrencies(); } @Override @@ -45,13 +46,6 @@ public SwiftAccountPayload getPayload() { return ((SwiftAccountPayload) this.paymentAccountPayload); } - public void selectAllTradeCurrencies() { - List currencyCodesSorted = CurrencyUtil.getAllSortedFiatCurrencies().stream() - .sorted(Comparator.comparing(TradeCurrency::getCode)) - .collect(Collectors.toList()); - tradeCurrencies.addAll(currencyCodesSorted); - } - public String getMessageForBuyer() { return "payment.swift.info.buyer"; } @@ -63,4 +57,11 @@ public String getMessageForSeller() { 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); + } } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SwiftForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SwiftForm.java index 13c6bcd2641..0dc088c0a07 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SwiftForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SwiftForm.java @@ -74,7 +74,6 @@ public SwiftForm(PaymentAccount paymentAccount, @Override public void addFormForAddAccount() { - ((SwiftAccount) paymentAccount).selectAllTradeCurrencies(); gridRowFrom = gridRow + 1; addFieldsForBankEdit(true, this::setBankSwiftCode, this::setBankName, this::setBankBranch, this::setBankAddress); addFieldsForBankEdit(false, this::setIntermediarySwiftCode, this::setIntermediaryName, this::setIntermediaryBranch, this::setIntermediaryAddress);