Skip to content

Commit

Permalink
SEPA Account - possibility to modify account name
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzmaker123 committed Jan 10, 2022
1 parent b3bf190 commit 1da71f6
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 9 deletions.
10 changes: 9 additions & 1 deletion 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 @@ -248,7 +252,11 @@ public String getMessageForAccountCreation() {
return null;
}

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

public void revertChanges() {
setAccountName(getPersistedAccountName());
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/bisq/core/payment/SepaAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ 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();
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/bisq/core/payment/SepaInstantAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ 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 @@ -140,6 +140,11 @@ public void removeAcceptedCountry(String countryCode) {
acceptedCountryCodes.remove(countryCode);
}

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

public void revertChanges() {
acceptedCountryCodes.clear();
acceptedCountryCodes.addAll(persistedAcceptedCountryCodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public void removeAcceptedCountry(String countryCode) {
acceptedCountryCodes.remove(countryCode);
}

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

public void revertChanges() {
acceptedCountryCodes.clear();
acceptedCountryCodes.addAll(persistedAcceptedCountryCodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public abstract class GeneralSepaForm extends PaymentMethodForm {
static final String IBAN = "IBAN";

private TextField currencyTextField;
InputTextField ibanInputTextField;

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

Expand All @@ -55,7 +54,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 Down Expand Up @@ -139,4 +138,6 @@ public Country fromString(String s) {
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void addFormForAddAccount() {
updateFromInputs();
});

ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN);
InputTextField ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN);
ibanInputTextField.setTextFormatter(new TextFormatter<>(new IBANNormalizer()));
ibanInputTextField.setValidator(ibanValidator);
ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
Expand Down Expand Up @@ -139,7 +139,7 @@ public void updateAllInputsValid() {
@Override
public void addFormForDisplayAccount() {
gridRowFrom = gridRow;
addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), sepaAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
addAccountNameTextFieldWithAutoFillToggleButton();
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"),
Res.get(sepaAccount.getPaymentMethod().getId()));
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.owner"), sepaAccount.getHolderName());
Expand Down Expand Up @@ -170,4 +170,9 @@ void addAcceptedCountry(String countryCode) {
boolean isCountryAccepted(String countryCode) {
return sepaAccount.getAcceptedCountryCodes().contains(countryCode);
}

@Override
protected String getIban() {
return sepaAccount.getIban();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void addFormForAddAccount() {
updateFromInputs();
});

ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN);
InputTextField ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN);
ibanInputTextField.setTextFormatter(new TextFormatter<>(new IBANNormalizer()));
ibanInputTextField.setValidator(ibanValidator);
ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
Expand Down Expand Up @@ -140,7 +140,7 @@ public void updateAllInputsValid() {
@Override
public void addFormForDisplayAccount() {
gridRowFrom = gridRow;
addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), sepaInstantAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
addAccountNameTextFieldWithAutoFillToggleButton();
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"),
Res.get(sepaInstantAccount.getPaymentMethod().getId()));
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.owner"), sepaInstantAccount.getHolderName());
Expand Down Expand Up @@ -171,4 +171,9 @@ void addAcceptedCountry(String countryCode) {
boolean isCountryAccepted(String countryCode) {
return sepaInstantAccount.getAcceptedCountryCodes().contains(countryCode);
}

@Override
protected String getIban() {
return sepaInstantAccount.getIban();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void onSaveNewAccount(PaymentAccount paymentAccount) {
}

public void onUpdateAccount(PaymentAccount paymentAccount) {
paymentAccount.onPersistChanges();
user.requestPersistence();
}

Expand Down

0 comments on commit 1da71f6

Please sign in to comment.