Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEPA Account - editable account name and accepted countries #5930

Merged
merged 3 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/src/main/java/bisq/core/payment/PaymentAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public abstract class PaymentAccount implements PersistablePayload {
public PaymentAccountPayload paymentAccountPayload;
@Setter
protected String accountName;
@Setter
protected String persistedAccountName;

protected final List<TradeCurrency> tradeCurrencies = new ArrayList<>();
@Setter
@Nullable
Expand Down Expand Up @@ -117,6 +120,7 @@ public static PaymentAccount fromProto(protobuf.PaymentAccount proto, CoreProtoR
account.setId(proto.getId());
account.setCreationDate(proto.getCreationDate());
account.setAccountName(proto.getAccountName());
account.setPersistedAccountName(proto.getAccountName());
account.getTradeCurrencies().addAll(tradeCurrencies);
account.setPaymentAccountPayload(coreProtoResolver.fromProto(proto.getPaymentAccountPayload()));

Expand Down Expand Up @@ -247,4 +251,12 @@ public String getMessageForSeller() {
public String getMessageForAccountCreation() {
return null;
}

public void onPersistChanges() {
setPersistedAccountName(getAccountName());
}

public void revertChanges() {
setAccountName(getPersistedAccountName());
}
}
12 changes: 12 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,16 @@ public void addAcceptedCountry(String countryCode) {
public void removeAcceptedCountry(String countryCode) {
((SepaAccountPayload) paymentAccountPayload).removeAcceptedCountry(countryCode);
}

@Override
public void onPersistChanges() {
super.onPersistChanges();
((SepaAccountPayload) paymentAccountPayload).onPersistChanges();
}

@Override
public void revertChanges() {
super.revertChanges();
((SepaAccountPayload) paymentAccountPayload).revertChanges();
}
}
12 changes: 12 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,16 @@ public void addAcceptedCountry(String countryCode) {
public void removeAcceptedCountry(String countryCode) {
((SepaInstantAccountPayload) paymentAccountPayload).removeAcceptedCountry(countryCode);
}

@Override
public void onPersistChanges() {
super.onPersistChanges();
((SepaInstantAccountPayload) paymentAccountPayload).onPersistChanges();
}

@Override
public void revertChanges() {
super.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,16 @@ public void removeAcceptedCountry(String countryCode) {
acceptedCountryCodes.remove(countryCode);
}

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

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,16 @@ public void removeAcceptedCountry(String countryCode) {
acceptedCountryCodes.remove(countryCode);
}

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

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,6 +1,6 @@
package bisq.desktop.components.paymentmethods;

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

import bisq.core.account.witness.AccountAgeWitnessService;
Expand All @@ -22,14 +22,15 @@
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 java.util.Optional;

import static bisq.desktop.util.FormBuilder.addTopLabelWithVBox;

Expand All @@ -38,16 +39,17 @@ 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;

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

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

Optional<FiatCurrency> euroCurrencyOptional = CurrencyUtil.getFiatCurrency("EUR");

if (euroCurrencyOptional.isPresent()) {
this.euroCurrency = euroCurrencyOptional.get();
paymentAccount.setSingleTradeCurrency(euroCurrency);
}
}

@Override
Expand All @@ -56,7 +58,7 @@ protected void autoFillNameTextField() {
TradeCurrency singleTradeCurrency = this.paymentAccount.getSingleTradeCurrency();
String currency = singleTradeCurrency != null ? singleTradeCurrency.getCode() : null;
if (currency != null) {
String iban = ibanInputTextField.getText();
String iban = getIban();
if (iban.length() > 9)
iban = StringUtils.abbreviate(iban, 9);
String method = Res.get(paymentAccount.getPaymentMethod().getId());
Expand All @@ -75,29 +77,42 @@ 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() {
HBox hBox = new HBox();

hBox.setSpacing(10);
ComboBox<Country> countryComboBox = new JFXComboBox<>();
currencyTextField = new JFXTextField("");
TextField currencyTextField = new JFXTextField("");
currencyTextField.setEditable(false);
currencyTextField.setMouseTransparent(true);
currencyTextField.setFocusTraversable(false);
Expand Down Expand Up @@ -126,6 +141,7 @@ public Country fromString(String s) {
return countryComboBox;
}

abstract void updateCountriesSelection(List<CheckBox> checkBoxList);
abstract boolean isCountryAccepted(String countryCode);

protected abstract String getIban();
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,21 @@ public TradeCurrency fromString(String s) {
}

protected void addAccountNameTextFieldWithAutoFillToggleButton() {
boolean isEditMode = paymentAccount.getPersistedAccountName() != null;
Tuple3<Label, InputTextField, ToggleButton> tuple = addTopLabelInputTextFieldSlideToggleButton(gridPane, ++gridRow,
Res.get("payment.account.name"), Res.get("payment.useCustomAccountName"));
accountNameTextField = tuple.second;
accountNameTextField.setPrefWidth(300);
accountNameTextField.setEditable(false);
accountNameTextField.setEditable(isEditMode);
accountNameTextField.setValidator(inputValidator);
accountNameTextField.setFocusTraversable(false);
accountNameTextField.setText(paymentAccount.getAccountName());
accountNameTextField.textProperty().addListener((ov, oldValue, newValue) -> {
paymentAccount.setAccountName(newValue);
updateAllInputsValid();
});
useCustomAccountNameToggleButton = tuple.third;
useCustomAccountNameToggleButton.setSelected(false);
useCustomAccountNameToggleButton.setSelected(isEditMode);
useCustomAccountNameToggleButton.setOnAction(e -> {
boolean selected = useCustomAccountNameToggleButton.isSelected();
accountNameTextField.setEditable(selected);
Expand Down Expand Up @@ -312,27 +314,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
Loading