diff --git a/core/src/main/java/haveno/core/payment/PaymentAccount.java b/core/src/main/java/haveno/core/payment/PaymentAccount.java index 8dda8fdedd..1b25377b29 100644 --- a/core/src/main/java/haveno/core/payment/PaymentAccount.java +++ b/core/src/main/java/haveno/core/payment/PaymentAccount.java @@ -388,12 +388,7 @@ public PaymentAccountForm toForm() { PaymentAccountForm form = new PaymentAccountForm(PaymentAccountForm.FormId.valueOf(paymentMethod.getId())); for (PaymentAccountFormField.FieldId fieldId : getInputFieldIds()) { PaymentAccountFormField field = getEmptyFormField(fieldId); - Object value = jsonMap.get(HavenoUtils.toCamelCase(field.getId().toString())); - if (value instanceof List) { // TODO: list should already be serialized to comma delimited string in PaymentAccount.toJson() (PaymentAccountTypeAdapter?) - field.setValue(String.join(",", (List) value)); - } else { - field.setValue((String) value); - } + field.setValue((String) jsonMap.get(HavenoUtils.toCamelCase(field.getId().toString()))); form.getFields().add(field); } return form; diff --git a/core/src/main/java/haveno/core/payment/PaymentAccountTypeAdapter.java b/core/src/main/java/haveno/core/payment/PaymentAccountTypeAdapter.java index 0160a1a736..be07ce8df4 100644 --- a/core/src/main/java/haveno/core/payment/PaymentAccountTypeAdapter.java +++ b/core/src/main/java/haveno/core/payment/PaymentAccountTypeAdapter.java @@ -139,6 +139,10 @@ private void writeComments(JsonWriter out, PaymentAccount account) throws IOExce private void writeInnerMutableFields(JsonWriter out, PaymentAccount account) { + if (account instanceof CountryBasedPaymentAccount) { + writeAcceptedCountryCodesField(out, account); + } + if (account.hasMultipleCurrencies()) { writeTradeCurrenciesField(out, account); writeSelectedTradeCurrencyField(out, account); @@ -176,7 +180,16 @@ private void writeTradeCurrenciesField(JsonWriter out, PaymentAccount account) { String fieldName = "tradeCurrencies"; log.debug("Append form with non-settable field: {}", fieldName); out.name(fieldName); - out.value("comma delimited currency code list, e.g., gbp,eur,jpy,usd"); + List tradeCurrencies = account.getTradeCurrencies(); + if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) { + String tradeCurrenciesValue = tradeCurrencies.stream() + .map(TradeCurrency::getCode) // convert each currency to its code. + .reduce((c1, c2) -> c1 + "," + c2) // create a comma-delimited string. + .orElse(""); + out.value(tradeCurrenciesValue); + } else { + out.value(""); // if no currencies exist, write an empty string. + } } catch (Exception ex) { String errMsg = format("cannot create a new %s json form", account.getClass().getSimpleName()); @@ -202,6 +215,34 @@ private void writeSelectedTradeCurrencyField(JsonWriter out, PaymentAccount acco } } + private void writeAcceptedCountryCodesField(JsonWriter out, PaymentAccount account) { + try { + String fieldName = "acceptedCountryCodes"; + log.debug("Append form with non-settable field: {}", fieldName); + out.name(fieldName); + + if (account instanceof CountryBasedPaymentAccount) { + List acceptedCountries = ((CountryBasedPaymentAccount) account).getAcceptedCountries(); + if (acceptedCountries != null && !acceptedCountries.isEmpty()) { + String countryCodesValue = acceptedCountries.stream() + .map(e -> e.code) // convert each country to its code. + .reduce((c1, c2) -> c1 + "," + c2) // create a comma-delimited string. + .orElse(""); + out.value(countryCodesValue); + } else { + out.value(""); // if no countries exist, write an empty string. + } + } else { + out.value(""); // default empty value for non-country-based accounts. + } + } catch (Exception ex) { + String errMsg = format("cannot create a new %s json form", + account.getClass().getSimpleName()); + log.error(capitalize(errMsg) + ".", ex); + throw new IllegalStateException("programmer error: " + errMsg); + } + } + @Override public PaymentAccount read(JsonReader in) throws IOException { PaymentAccount account = initNewPaymentAccount();