Skip to content

Commit

Permalink
Use only EUR when creating a SEPA payment account (#3833)
Browse files Browse the repository at this point in the history
* Use only EUR when creating a SEPA payment account

* Use only EUR when creating a SEPA payment account - additional refactoring
  • Loading branch information
ripcurlx authored Jan 3, 2020
2 parents ae2e06d + e20a271 commit fdec61e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 64 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 All @@ -25,8 +26,6 @@
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;

import javafx.collections.FXCollections;

import javafx.util.StringConverter;

import java.util.ArrayList;
Expand All @@ -42,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 @@ -73,50 +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(TradeCurrency currency, boolean isSepaCountry, CountryBasedPaymentAccount paymentAccount) {
if (isSepaCountry) {
currencyTextField.setVisible(true);
currencyTextField.setManaged(true);
currencyComboBox.setVisible(false);
currencyComboBox.setManaged(false);
paymentAccount.setSingleTradeCurrency(currency);
currencyTextField.setText(Res.get("payment.currencyWithSymbol", currency.getNameAndCode()));
} else {
currencyComboBox.setVisible(true);
currencyComboBox.setManaged(true);
currencyTextField.setVisible(false);
currencyTextField.setManaged(false);
currencyComboBox.setItems(FXCollections.observableArrayList(currency,
CurrencyUtil.getFiatCurrency("EUR").get()));
currencyComboBox.setOnAction(e2 -> {
paymentAccount.setSingleTradeCurrency(currencyComboBox.getSelectionModel().getSelectedItem());
updateCountriesSelection(euroCountryCheckBoxes);
autoFillNameTextField();
});
currencyComboBox.setConverter(new StringConverter<>() {
@Override
public String toString(TradeCurrency currency) {
return currency != null ? currency.getNameAndCode() : Res.get("shared.na");
}

@Override
public TradeCurrency fromString(String string) {
return null;
}
});
currencyComboBox.getSelectionModel().select(0);
}
}

void addCountriesGrid(String title, List<CheckBox> checkBoxList,
List<Country> dataProvider) {
FlowPane flowPane = FormBuilder.addTopLabelFlowPane(gridPane, ++gridRow, title, 0).second;
Expand All @@ -133,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 @@ -164,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,19 +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) {
final boolean isSepaCountry = CountryUtil.getAllSepaEuroCountries().contains(country);

updateCurrencyFormElements(currency, isSepaCountry, 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,19 +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) {
final boolean isSepaInstantCountry = CountryUtil.getAllSepaInstantEuroCountries().contains(country);
updateCurrencyFormElements(currency, isSepaInstantCountry, sepaInstantAccount);
}

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

0 comments on commit fdec61e

Please sign in to comment.