Use only EUR when creating a SEPA payment account - additional refactoring

This commit is contained in:
lukasz 2019-12-26 11:27:48 +01:00
parent 3f0d882a25
commit e20a2711f8
No known key found for this signature in database
GPG key ID: 7FFDB4B31012B93E
3 changed files with 8 additions and 34 deletions

View file

@ -6,6 +6,7 @@ import bisq.desktop.util.FormBuilder;
import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.locale.Country; import bisq.core.locale.Country;
import bisq.core.locale.CurrencyUtil; import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.Res; import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency; import bisq.core.locale.TradeCurrency;
import bisq.core.payment.CountryBasedPaymentAccount; import bisq.core.payment.CountryBasedPaymentAccount;
@ -40,11 +41,13 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
final List<CheckBox> euroCountryCheckBoxes = new ArrayList<>(); final List<CheckBox> euroCountryCheckBoxes = new ArrayList<>();
final List<CheckBox> nonEuroCountryCheckBoxes = new ArrayList<>(); final List<CheckBox> nonEuroCountryCheckBoxes = new ArrayList<>();
private TextField currencyTextField; private TextField currencyTextField;
private ComboBox<TradeCurrency> currencyComboBox;
InputTextField ibanInputTextField; InputTextField ibanInputTextField;
private FiatCurrency euroCurrency = CurrencyUtil.getFiatCurrency("EUR").get();
GeneralSepaForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, InputValidator inputValidator, GridPane gridPane, int gridRow, CoinFormatter formatter) { GeneralSepaForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, InputValidator inputValidator, GridPane gridPane, int gridRow, CoinFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
paymentAccount.setSingleTradeCurrency(euroCurrency);
} }
@Override @Override
@ -71,8 +74,6 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
countryComboBox.setOnAction(e -> { countryComboBox.setOnAction(e -> {
Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem(); Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
paymentAccount.setCountry(selectedItem); paymentAccount.setCountry(selectedItem);
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(selectedItem.code);
setupCurrency(selectedItem, currency);
updateCountriesSelection(euroCountryCheckBoxes); updateCountriesSelection(euroCountryCheckBoxes);
updateCountriesSelection(nonEuroCountryCheckBoxes); updateCountriesSelection(nonEuroCountryCheckBoxes);
@ -80,16 +81,6 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
}); });
} }
void updateCurrencyFormElements(CountryBasedPaymentAccount paymentAccount) {
TradeCurrency currency = CurrencyUtil.getFiatCurrency("EUR").get();
currencyTextField.setVisible(true);
currencyTextField.setManaged(true);
currencyComboBox.setVisible(false);
currencyComboBox.setManaged(false);
paymentAccount.setSingleTradeCurrency(currency);
currencyTextField.setText(Res.get("payment.currencyWithSymbol", currency.getNameAndCode()));
}
void addCountriesGrid(String title, List<CheckBox> checkBoxList, void addCountriesGrid(String title, List<CheckBox> checkBoxList,
List<Country> dataProvider) { List<Country> dataProvider) {
FlowPane flowPane = FormBuilder.addTopLabelFlowPane(gridPane, ++gridRow, title, 0).second; FlowPane flowPane = FormBuilder.addTopLabelFlowPane(gridPane, ++gridRow, title, 0).second;
@ -106,19 +97,17 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
hBox.setSpacing(10); hBox.setSpacing(10);
ComboBox<Country> countryComboBox = new JFXComboBox<>(); ComboBox<Country> countryComboBox = new JFXComboBox<>();
currencyComboBox = new JFXComboBox<>();
currencyTextField = new JFXTextField(""); currencyTextField = new JFXTextField("");
currencyTextField.setEditable(false); currencyTextField.setEditable(false);
currencyTextField.setMouseTransparent(true); currencyTextField.setMouseTransparent(true);
currencyTextField.setFocusTraversable(false); currencyTextField.setFocusTraversable(false);
currencyTextField.setMinWidth(300); currencyTextField.setMinWidth(300);
currencyTextField.setVisible(false); currencyTextField.setVisible(true);
currencyTextField.setManaged(false); currencyTextField.setManaged(true);
currencyComboBox.setVisible(false); currencyTextField.setText(Res.get("payment.currencyWithSymbol", euroCurrency.getNameAndCode()));
currencyComboBox.setManaged(false);
hBox.getChildren().addAll(countryComboBox, currencyTextField, currencyComboBox); hBox.getChildren().addAll(countryComboBox, currencyTextField);
addTopLabelWithVBox(gridPane, ++gridRow, Res.get("payment.bank.country"), hBox, 0); addTopLabelWithVBox(gridPane, ++gridRow, Res.get("payment.bank.country"), hBox, 0);
@ -137,8 +126,6 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
return countryComboBox; return countryComboBox;
} }
abstract void setupCurrency(Country country, TradeCurrency currency);
abstract void updateCountriesSelection(List<CheckBox> checkBoxList); abstract void updateCountriesSelection(List<CheckBox> checkBoxList);
} }

View file

@ -126,17 +126,11 @@ public class SepaForm extends GeneralSepaForm {
if (CountryUtil.getAllSepaCountries().contains(country)) { if (CountryUtil.getAllSepaCountries().contains(country)) {
countryComboBox.getSelectionModel().select(country); countryComboBox.getSelectionModel().select(country);
sepaAccount.setCountry(country); sepaAccount.setCountry(country);
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(country.code);
setupCurrency(country, currency);
} }
updateFromInputs(); updateFromInputs();
} }
@Override
void setupCurrency(Country country, TradeCurrency currency) {
updateCurrencyFormElements(sepaAccount);
}
private void addEuroCountriesGrid() { private void addEuroCountriesGrid() {
addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes, addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes,

View file

@ -126,18 +126,11 @@ public class SepaInstantForm extends GeneralSepaForm {
if (CountryUtil.getAllSepaInstantCountries().contains(country)) { if (CountryUtil.getAllSepaInstantCountries().contains(country)) {
countryComboBox.getSelectionModel().select(country); countryComboBox.getSelectionModel().select(country);
sepaInstantAccount.setCountry(country); sepaInstantAccount.setCountry(country);
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(country.code);
setupCurrency(country, currency);
} }
updateFromInputs(); updateFromInputs();
} }
@Override
void setupCurrency(Country country, TradeCurrency currency) {
updateCurrencyFormElements(sepaInstantAccount);
}
private void addEuroCountriesGrid() { private void addEuroCountriesGrid() {
addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes, addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes,
CountryUtil.getAllSepaInstantEuroCountries()); CountryUtil.getAllSepaInstantEuroCountries());