Skip to content

Commit

Permalink
SEPA Account - possibility to modify accepted countries
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzmaker123 committed Jan 10, 2022
1 parent ce76389 commit b3bf190
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 143 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/payment/PaymentAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,8 @@ public String getMessageForSeller() {
public String getMessageForAccountCreation() {
return null;
}

public void revertChanges() {

}
}
5 changes: 5 additions & 0 deletions core/src/main/java/bisq/core/payment/SepaAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public void addAcceptedCountry(String countryCode) {
public void removeAcceptedCountry(String countryCode) {
((SepaAccountPayload) paymentAccountPayload).removeAcceptedCountry(countryCode);
}

@Override
public void revertChanges() {
((SepaAccountPayload) paymentAccountPayload).revertChanges();
}
}
5 changes: 5 additions & 0 deletions core/src/main/java/bisq/core/payment/SepaInstantAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public void addAcceptedCountry(String countryCode) {
public void removeAcceptedCountry(String countryCode) {
((SepaInstantAccountPayload) paymentAccountPayload).removeAcceptedCountry(countryCode);
}

@Override
public void revertChanges() {
((SepaInstantAccountPayload) paymentAccountPayload).revertChanges();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class SepaAccountPayload extends CountryBasedPaymentAccountPayload

// Don't use a set here as we need a deterministic ordering, otherwise the contract hash does not match
private final List<String> acceptedCountryCodes;
private final List<String> persistedAcceptedCountryCodes = new ArrayList<>();

public SepaAccountPayload(String paymentMethod, String id, List<Country> acceptedCountries) {
super(paymentMethod, id);
Expand Down Expand Up @@ -90,6 +91,7 @@ private SepaAccountPayload(String paymentMethodName,
this.bic = bic;
this.email = email;
this.acceptedCountryCodes = acceptedCountryCodes;
persistedAcceptedCountryCodes.addAll(acceptedCountryCodes);
}

@Override
Expand Down Expand Up @@ -138,6 +140,11 @@ public void removeAcceptedCountry(String countryCode) {
acceptedCountryCodes.remove(countryCode);
}

public void revertChanges() {
acceptedCountryCodes.clear();
acceptedCountryCodes.addAll(persistedAcceptedCountryCodes);
}

@Override
public String getPaymentDetails() {
return Res.get(paymentMethodId) + " - " + Res.getWithCol("payment.account.owner") + " " + holderName + ", IBAN: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class SepaInstantAccountPayload extends CountryBasedPaymentAccountP

// Don't use a set here as we need a deterministic ordering, otherwise the contract hash does not match
private final List<String> acceptedCountryCodes;
private final List<String> persistedAcceptedCountryCodes = new ArrayList<>();

public SepaInstantAccountPayload(String paymentMethod, String id, List<Country> acceptedCountries) {
super(paymentMethod, id);
Expand Down Expand Up @@ -87,6 +88,7 @@ private SepaInstantAccountPayload(String paymentMethodName,
this.iban = iban;
this.bic = bic;
this.acceptedCountryCodes = acceptedCountryCodes;
persistedAcceptedCountryCodes.addAll(acceptedCountryCodes);
}

@Override
Expand Down Expand Up @@ -133,6 +135,11 @@ public void removeAcceptedCountry(String countryCode) {
acceptedCountryCodes.remove(countryCode);
}

public void revertChanges() {
acceptedCountryCodes.clear();
acceptedCountryCodes.addAll(persistedAcceptedCountryCodes);
}

@Override
public String getPaymentDetails() {
return Res.get(paymentMethodId) + " - " + Res.getWithCol("payment.account.owner") + " " + holderName + ", IBAN: " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bisq.desktop.components.paymentmethods;

import bisq.desktop.components.AutoTooltipCheckBox;
import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;

Expand All @@ -22,13 +23,13 @@
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;

import javafx.util.StringConverter;

import java.util.ArrayList;
import java.util.List;

import static bisq.desktop.util.FormBuilder.addTopLabelWithVBox;
Expand All @@ -38,8 +39,6 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
static final String BIC = "BIC";
static final String IBAN = "IBAN";

final List<CheckBox> euroCountryCheckBoxes = new ArrayList<>();
final List<CheckBox> nonEuroCountryCheckBoxes = new ArrayList<>();
private TextField currencyTextField;
InputTextField ibanInputTextField;

Expand Down Expand Up @@ -75,21 +74,34 @@ void setCountryComboBoxAction(ComboBox<Country> countryComboBox, CountryBasedPay
Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
paymentAccount.setCountry(selectedItem);

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

void addCountriesGrid(String title, List<CheckBox> checkBoxList,
List<Country> dataProvider) {
void addCountriesGrid(String title, List<Country> countries) {
FlowPane flowPane = FormBuilder.addTopLabelFlowPane(gridPane, ++gridRow, title, 0).second;

flowPane.setId("flow-pane-checkboxes-bg");

dataProvider.forEach(country ->
fillUpFlowPaneWithCountries(checkBoxList, flowPane, country));
updateCountriesSelection(checkBoxList);
countries.forEach(country -> {
CheckBox checkBox = new AutoTooltipCheckBox(country.code);
checkBox.setUserData(country.code);
checkBox.setSelected(isCountryAccepted(country.code));
checkBox.setMouseTransparent(false);
checkBox.setMinWidth(45);
checkBox.setMaxWidth(45);
checkBox.setTooltip(new Tooltip(country.name));
checkBox.setOnAction(event -> {
if (checkBox.isSelected()) {
addAcceptedCountry(country.code);
} else {
removeAcceptedCountry(country.code);
}

updateAllInputsValid();
});
flowPane.getChildren().add(checkBox);
});
}

ComboBox<Country> addCountrySelection() {
Expand Down Expand Up @@ -126,6 +138,5 @@ public Country fromString(String s) {
return countryComboBox;
}

abstract void updateCountriesSelection(List<CheckBox> checkBoxList);

abstract boolean isCountryAccepted(String countryCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,27 +312,6 @@ void fillUpFlowPaneWithCurrencies(boolean isEditable, FlowPane flowPane,
flowPane.getChildren().add(checkBox);
}

void fillUpFlowPaneWithCountries(List<CheckBox> checkBoxList, FlowPane flowPane, Country country) {
final String countryCode = country.code;
CheckBox checkBox = new AutoTooltipCheckBox(countryCode);
checkBox.setUserData(countryCode);
checkBoxList.add(checkBox);
checkBox.setMouseTransparent(false);
checkBox.setMinWidth(45);
checkBox.setMaxWidth(45);
checkBox.setTooltip(new Tooltip(country.name));
checkBox.setOnAction(event -> {
if (checkBox.isSelected()) {
addAcceptedCountry(countryCode);
} else {
removeAcceptedCountry(countryCode);
}

updateAllInputsValid();
});
flowPane.getChildren().add(checkBox);
}

protected abstract void autoFillNameTextField();

public abstract void addFormForAddAccount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.PaymentAccount;
Expand All @@ -37,17 +36,12 @@
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.validation.InputValidator;

import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;

import javafx.collections.FXCollections;

import java.util.List;

import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField;
import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon;
import static bisq.desktop.util.FormBuilder.addTopLabelTextField;
Expand Down Expand Up @@ -116,8 +110,8 @@ public void addFormForAddAccount() {

setCountryComboBoxAction(countryComboBox, sepaAccount);

addEuroCountriesGrid();
addNonEuroCountriesGrid();
addCountriesGrid(Res.get("payment.accept.euro"), CountryUtil.getAllSepaEuroCountries());
addCountriesGrid(Res.get("payment.accept.nonEuro"), CountryUtil.getAllSepaNonEuroCountries());
addLimitations(false);
addAccountNameTextFieldWithAutoFillToggleButton();

Expand All @@ -131,39 +125,6 @@ public void addFormForAddAccount() {
updateFromInputs();
}


private void addEuroCountriesGrid() {
addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes,
CountryUtil.getAllSepaEuroCountries());
}

private void addNonEuroCountriesGrid() {
addCountriesGrid(Res.get("payment.accept.nonEuro"), nonEuroCountryCheckBoxes,
CountryUtil.getAllSepaNonEuroCountries());
}

@Override
void updateCountriesSelection(List<CheckBox> checkBoxList) {
checkBoxList.forEach(checkBox -> {
String countryCode = (String) checkBox.getUserData();
TradeCurrency selectedCurrency = sepaAccount.getSelectedTradeCurrency();
if (selectedCurrency == null) {
Country country = CountryUtil.getDefaultCountry();
if (CountryUtil.getAllSepaCountries().contains(country))
selectedCurrency = CurrencyUtil.getCurrencyByCountryCode(country.code);
}

boolean selected;
if (selectedCurrency != null) {
selected = true;
sepaAccount.addAcceptedCountry(countryCode);
} else {
selected = sepaAccount.getAcceptedCountryCodes().contains(countryCode);
}
checkBox.setSelected(selected);
});
}

@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
Expand All @@ -189,19 +150,9 @@ public void addFormForDisplayAccount() {
TradeCurrency singleTradeCurrency = sepaAccount.getSingleTradeCurrency();
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null";
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);
String countries;
Tooltip tooltip = null;
if (CountryUtil.containsAllSepaEuroCountries(sepaAccount.getAcceptedCountryCodes())) {
countries = Res.get("shared.allEuroCountries");
} else {
countries = CountryUtil.getCodesString(sepaAccount.getAcceptedCountryCodes());
tooltip = new Tooltip(CountryUtil.getNamesByCodesString(sepaAccount.getAcceptedCountryCodes()));
}
TextField acceptedCountries = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.accepted.countries"), countries).second;
if (tooltip != null) {
acceptedCountries.setMouseTransparent(false);
acceptedCountries.setTooltip(tooltip);
}

addCountriesGrid(Res.get("payment.accept.euro"), CountryUtil.getAllSepaEuroCountries());
addCountriesGrid(Res.get("payment.accept.nonEuro"), CountryUtil.getAllSepaNonEuroCountries());
addLimitations(true);
}

Expand All @@ -214,4 +165,9 @@ void removeAcceptedCountry(String countryCode) {
void addAcceptedCountry(String countryCode) {
sepaAccount.addAcceptedCountry(countryCode);
}

@Override
boolean isCountryAccepted(String countryCode) {
return sepaAccount.getAcceptedCountryCodes().contains(countryCode);
}
}
Loading

0 comments on commit b3bf190

Please sign in to comment.