mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Refactor didReadCountryField to set country on MoneyGram acct
MoneyGram is not a CountryBasedPaymentAccount, but it does have a country field.
This commit is contained in:
parent
636fac9170
commit
23bfa2e7fc
@ -21,6 +21,7 @@ package bisq.core.api.model;
|
||||
import bisq.core.locale.Country;
|
||||
import bisq.core.locale.FiatCurrency;
|
||||
import bisq.core.payment.CountryBasedPaymentAccount;
|
||||
import bisq.core.payment.MoneyGramAccount;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
|
||||
@ -285,23 +286,32 @@ class PaymentAccountTypeAdapter extends TypeAdapter<PaymentAccount> {
|
||||
}
|
||||
|
||||
private boolean didReadCountryField(JsonReader in, PaymentAccount account, String fieldName) {
|
||||
if (account.isCountryBasedPaymentAccount() && fieldName.equals("country")) {
|
||||
// Read the country code, and use it to set the account's country and single
|
||||
// trade currency fields.
|
||||
if (!fieldName.equals("country"))
|
||||
return false;
|
||||
|
||||
String countryCode = nextStringOrNull(in);
|
||||
Optional<Country> country = findCountryByCode(countryCode);
|
||||
if (country.isPresent()) {
|
||||
|
||||
if (account.isCountryBasedPaymentAccount()) {
|
||||
((CountryBasedPaymentAccount) account).setCountry(country.get());
|
||||
FiatCurrency fiatCurrency = getCurrencyByCountryCode(checkNotNull(countryCode));
|
||||
account.setSingleTradeCurrency(fiatCurrency);
|
||||
} else if (account.isMoneyGramAccount()) {
|
||||
((MoneyGramAccount) account).setCountry(country.get());
|
||||
} else {
|
||||
String errMsg = format("cannot set the country on a %s",
|
||||
paymentAccountType.getSimpleName());
|
||||
log.error(StringUtils.capitalize(errMsg) + ".");
|
||||
throw new IllegalStateException("programmer error: " + errMsg);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
format("'%s' is an invalid country code.", countryCode));
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Class<? extends PaymentAccountPayload> getPaymentAccountPayloadType() {
|
||||
@ -315,7 +325,6 @@ class PaymentAccountTypeAdapter extends TypeAdapter<PaymentAccount> {
|
||||
paymentAccountType.getSimpleName());
|
||||
log.error(StringUtils.capitalize(errMsg) + ".", ex);
|
||||
throw new IllegalStateException("programmer error: " + errMsg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user