Skip to content

Commit

Permalink
Use only EUR when creating a SEPA payment account - additional refact…
Browse files Browse the repository at this point in the history
…oring
  • Loading branch information
lusarz committed Dec 26, 2019
1 parent 3f0d882 commit e20a271
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -40,11 +41,13 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
final List<CheckBox> euroCountryCheckBoxes = new ArrayList<>();
final List<CheckBox> nonEuroCountryCheckBoxes = new ArrayList<>();
private TextField currencyTextField;
private ComboBox<TradeCurrency> currencyComboBox;
InputTextField ibanInputTextField;

private FiatCurrency euroCurrency = CurrencyUtil.getFiatCurrency("EUR").get();

GeneralSepaForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, InputValidator inputValidator, GridPane gridPane, int gridRow, CoinFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
paymentAccount.setSingleTradeCurrency(euroCurrency);
}

@Override
Expand All @@ -71,25 +74,13 @@ void setCountryComboBoxAction(ComboBox<Country> countryComboBox, CountryBasedPay
countryComboBox.setOnAction(e -> {
Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
paymentAccount.setCountry(selectedItem);
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(selectedItem.code);
setupCurrency(selectedItem, currency);

updateCountriesSelection(euroCountryCheckBoxes);
updateCountriesSelection(nonEuroCountryCheckBoxes);
updateFromInputs();
});
}

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,
List<Country> dataProvider) {
FlowPane flowPane = FormBuilder.addTopLabelFlowPane(gridPane, ++gridRow, title, 0).second;
Expand All @@ -106,19 +97,17 @@ ComboBox<Country> addCountrySelection() {

hBox.setSpacing(10);
ComboBox<Country> countryComboBox = new JFXComboBox<>();
currencyComboBox = new JFXComboBox<>();
currencyTextField = new JFXTextField("");
currencyTextField.setEditable(false);
currencyTextField.setMouseTransparent(true);
currencyTextField.setFocusTraversable(false);
currencyTextField.setMinWidth(300);

currencyTextField.setVisible(false);
currencyTextField.setManaged(false);
currencyComboBox.setVisible(false);
currencyComboBox.setManaged(false);
currencyTextField.setVisible(true);
currencyTextField.setManaged(true);
currencyTextField.setText(Res.get("payment.currencyWithSymbol", euroCurrency.getNameAndCode()));

hBox.getChildren().addAll(countryComboBox, currencyTextField, currencyComboBox);
hBox.getChildren().addAll(countryComboBox, currencyTextField);

addTopLabelWithVBox(gridPane, ++gridRow, Res.get("payment.bank.country"), hBox, 0);

Expand All @@ -137,8 +126,6 @@ public Country fromString(String s) {
return countryComboBox;
}

abstract void setupCurrency(Country country, TradeCurrency currency);

abstract void updateCountriesSelection(List<CheckBox> checkBoxList);

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,11 @@ public void addFormForAddAccount() {
if (CountryUtil.getAllSepaCountries().contains(country)) {
countryComboBox.getSelectionModel().select(country);
sepaAccount.setCountry(country);
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(country.code);
setupCurrency(country, currency);
}

updateFromInputs();
}

@Override
void setupCurrency(Country country, TradeCurrency currency) {
updateCurrencyFormElements(sepaAccount);
}

private void addEuroCountriesGrid() {
addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,11 @@ public void addFormForAddAccount() {
if (CountryUtil.getAllSepaInstantCountries().contains(country)) {
countryComboBox.getSelectionModel().select(country);
sepaInstantAccount.setCountry(country);
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(country.code);
setupCurrency(country, currency);
}

updateFromInputs();
}

@Override
void setupCurrency(Country country, TradeCurrency currency) {
updateCurrencyFormElements(sepaInstantAccount);
}

private void addEuroCountriesGrid() {
addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes,
CountryUtil.getAllSepaInstantEuroCountries());
Expand Down

0 comments on commit e20a271

Please sign in to comment.