diff --git a/core/src/main/java/bisq/core/payment/PaymentAccount.java b/core/src/main/java/bisq/core/payment/PaymentAccount.java index 0bcb93104f..970abf414c 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccount.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccount.java @@ -247,4 +247,8 @@ public abstract class PaymentAccount implements PersistablePayload { public String getMessageForAccountCreation() { return null; } + + public void revertChanges() { + + } } diff --git a/core/src/main/java/bisq/core/payment/SepaAccount.java b/core/src/main/java/bisq/core/payment/SepaAccount.java index d7c551f3f1..f3deb1eb91 100644 --- a/core/src/main/java/bisq/core/payment/SepaAccount.java +++ b/core/src/main/java/bisq/core/payment/SepaAccount.java @@ -78,4 +78,9 @@ public final class SepaAccount extends CountryBasedPaymentAccount implements Ban public void removeAcceptedCountry(String countryCode) { ((SepaAccountPayload) paymentAccountPayload).removeAcceptedCountry(countryCode); } + + @Override + public void revertChanges() { + ((SepaAccountPayload) paymentAccountPayload).revertChanges(); + } } diff --git a/core/src/main/java/bisq/core/payment/SepaInstantAccount.java b/core/src/main/java/bisq/core/payment/SepaInstantAccount.java index 9479a1b6a5..50caaafd09 100644 --- a/core/src/main/java/bisq/core/payment/SepaInstantAccount.java +++ b/core/src/main/java/bisq/core/payment/SepaInstantAccount.java @@ -78,4 +78,9 @@ public final class SepaInstantAccount extends CountryBasedPaymentAccount impleme public void removeAcceptedCountry(String countryCode) { ((SepaInstantAccountPayload) paymentAccountPayload).removeAcceptedCountry(countryCode); } + + @Override + public void revertChanges() { + ((SepaInstantAccountPayload) paymentAccountPayload).revertChanges(); + } } diff --git a/core/src/main/java/bisq/core/payment/payload/SepaAccountPayload.java b/core/src/main/java/bisq/core/payment/payload/SepaAccountPayload.java index 59425e1bcf..4405fa6aac 100644 --- a/core/src/main/java/bisq/core/payment/payload/SepaAccountPayload.java +++ b/core/src/main/java/bisq/core/payment/payload/SepaAccountPayload.java @@ -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 acceptedCountryCodes; + private final List persistedAcceptedCountryCodes = new ArrayList<>(); public SepaAccountPayload(String paymentMethod, String id, List acceptedCountries) { super(paymentMethod, id); @@ -90,6 +91,7 @@ public final class SepaAccountPayload extends CountryBasedPaymentAccountPayload this.bic = bic; this.email = email; this.acceptedCountryCodes = acceptedCountryCodes; + persistedAcceptedCountryCodes.addAll(acceptedCountryCodes); } @Override @@ -138,6 +140,11 @@ public final class SepaAccountPayload extends CountryBasedPaymentAccountPayload 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: " + diff --git a/core/src/main/java/bisq/core/payment/payload/SepaInstantAccountPayload.java b/core/src/main/java/bisq/core/payment/payload/SepaInstantAccountPayload.java index 54cffcd78d..29cde1b748 100644 --- a/core/src/main/java/bisq/core/payment/payload/SepaInstantAccountPayload.java +++ b/core/src/main/java/bisq/core/payment/payload/SepaInstantAccountPayload.java @@ -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 acceptedCountryCodes; + private final List persistedAcceptedCountryCodes = new ArrayList<>(); public SepaInstantAccountPayload(String paymentMethod, String id, List acceptedCountries) { super(paymentMethod, id); @@ -87,6 +88,7 @@ public final class SepaInstantAccountPayload extends CountryBasedPaymentAccountP this.iban = iban; this.bic = bic; this.acceptedCountryCodes = acceptedCountryCodes; + persistedAcceptedCountryCodes.addAll(acceptedCountryCodes); } @Override @@ -133,6 +135,11 @@ public final class SepaInstantAccountPayload extends CountryBasedPaymentAccountP 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: " + diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java index 5435e9e4c9..98aa982691 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralSepaForm.java @@ -1,5 +1,6 @@ package bisq.desktop.components.paymentmethods; +import bisq.desktop.components.AutoTooltipCheckBox; import bisq.desktop.components.InputTextField; import bisq.desktop.util.FormBuilder; @@ -22,13 +23,13 @@ import com.jfoenix.controls.JFXTextField; 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; @@ -38,8 +39,6 @@ public abstract class GeneralSepaForm extends PaymentMethodForm { static final String BIC = "BIC"; static final String IBAN = "IBAN"; - final List euroCountryCheckBoxes = new ArrayList<>(); - final List nonEuroCountryCheckBoxes = new ArrayList<>(); private TextField currencyTextField; InputTextField ibanInputTextField; @@ -75,21 +74,34 @@ public abstract class GeneralSepaForm extends PaymentMethodForm { Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem(); paymentAccount.setCountry(selectedItem); - updateCountriesSelection(euroCountryCheckBoxes); - updateCountriesSelection(nonEuroCountryCheckBoxes); updateFromInputs(); }); } - void addCountriesGrid(String title, List checkBoxList, - List dataProvider) { + void addCountriesGrid(String title, List 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 addCountrySelection() { @@ -126,6 +138,5 @@ public abstract class GeneralSepaForm extends PaymentMethodForm { return countryComboBox; } - abstract void updateCountriesSelection(List checkBoxList); - + abstract boolean isCountryAccepted(String countryCode); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java index 5909dd0f54..96698b0a0e 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/PaymentMethodForm.java @@ -312,27 +312,6 @@ public abstract class PaymentMethodForm { flowPane.getChildren().add(checkBox); } - void fillUpFlowPaneWithCountries(List 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(); diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java index b4e74e47bf..af9aa3ee40 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaForm.java @@ -27,7 +27,6 @@ import bisq.desktop.util.normalization.IBANNormalizer; 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; @@ -37,17 +36,12 @@ import bisq.core.payment.payload.SepaAccountPayload; 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; @@ -116,8 +110,8 @@ public class SepaForm extends GeneralSepaForm { setCountryComboBoxAction(countryComboBox, sepaAccount); - addEuroCountriesGrid(); - addNonEuroCountriesGrid(); + addCountriesGrid(Res.get("payment.accept.euro"), CountryUtil.getAllSepaEuroCountries()); + addCountriesGrid(Res.get("payment.accept.nonEuro"), CountryUtil.getAllSepaNonEuroCountries()); addLimitations(false); addAccountNameTextFieldWithAutoFillToggleButton(); @@ -131,39 +125,6 @@ public class SepaForm extends GeneralSepaForm { 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 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() @@ -189,19 +150,9 @@ public class SepaForm extends GeneralSepaForm { 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); } @@ -214,4 +165,9 @@ public class SepaForm extends GeneralSepaForm { void addAcceptedCountry(String countryCode) { sepaAccount.addAcceptedCountry(countryCode); } + + @Override + boolean isCountryAccepted(String countryCode) { + return sepaAccount.getAcceptedCountryCodes().contains(countryCode); + } } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaInstantForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaInstantForm.java index 36de590229..05b5966df8 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaInstantForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/SepaInstantForm.java @@ -27,7 +27,6 @@ import bisq.desktop.util.normalization.IBANNormalizer; 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; @@ -37,16 +36,12 @@ import bisq.core.payment.payload.SepaInstantAccountPayload; 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; @@ -116,8 +111,8 @@ public class SepaInstantForm extends GeneralSepaForm { setCountryComboBoxAction(countryComboBox, sepaInstantAccount); - addEuroCountriesGrid(); - addNonEuroCountriesGrid(); + addCountriesGrid(Res.get("payment.accept.euro"), CountryUtil.getAllSepaEuroCountries()); + addCountriesGrid(Res.get("payment.accept.nonEuro"), CountryUtil.getAllSepaNonEuroCountries()); addLimitations(false); addAccountNameTextFieldWithAutoFillToggleButton(); @@ -131,38 +126,6 @@ public class SepaInstantForm extends GeneralSepaForm { updateFromInputs(); } - private void addEuroCountriesGrid() { - addCountriesGrid(Res.get("payment.accept.euro"), euroCountryCheckBoxes, - CountryUtil.getAllSepaInstantEuroCountries()); - } - - private void addNonEuroCountriesGrid() { - addCountriesGrid(Res.get("payment.accept.nonEuro"), nonEuroCountryCheckBoxes, - CountryUtil.getAllSepaInstantNonEuroCountries()); - } - - @Override - void updateCountriesSelection(List checkBoxList) { - checkBoxList.forEach(checkBox -> { - String countryCode = (String) checkBox.getUserData(); - TradeCurrency selectedCurrency = sepaInstantAccount.getSelectedTradeCurrency(); - if (selectedCurrency == null) { - Country country = CountryUtil.getDefaultCountry(); - if (CountryUtil.getAllSepaInstantCountries().contains(country)) - selectedCurrency = CurrencyUtil.getCurrencyByCountryCode(country.code); - } - - boolean selected; - if (selectedCurrency != null) { - selected = true; - sepaInstantAccount.addAcceptedCountry(countryCode); - } else { - selected = sepaInstantAccount.getAcceptedCountryCodes().contains(countryCode); - } - checkBox.setSelected(selected); - }); - } - @Override public void updateAllInputsValid() { allInputsValid.set(isAccountNameValid() @@ -188,19 +151,9 @@ public class SepaInstantForm extends GeneralSepaForm { TradeCurrency singleTradeCurrency = sepaInstantAccount.getSingleTradeCurrency(); String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode); - String countries; - Tooltip tooltip = null; - if (CountryUtil.containsAllSepaInstantEuroCountries(sepaInstantAccount.getAcceptedCountryCodes())) { - countries = Res.get("shared.allEuroCountries"); - } else { - countries = CountryUtil.getCodesString(sepaInstantAccount.getAcceptedCountryCodes()); - tooltip = new Tooltip(CountryUtil.getNamesByCodesString(sepaInstantAccount.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); } @@ -213,4 +166,9 @@ public class SepaInstantForm extends GeneralSepaForm { void addAcceptedCountry(String countryCode) { sepaInstantAccount.addAcceptedCountry(countryCode); } + + @Override + boolean isCountryAccepted(String countryCode) { + return sepaInstantAccount.getAcceptedCountryCodes().contains(countryCode); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java index b114c4cbbc..a228300f77 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java @@ -124,6 +124,10 @@ class FiatAccountsDataModel extends ActivatableDataModel { accountAgeWitnessService.signAndPublishSameNameAccounts(); } + public void onUpdateAccount(PaymentAccount paymentAccount) { + user.requestPersistence(); + } + public boolean onDeleteAccount(PaymentAccount paymentAccount) { boolean usedInOpenOffers = openOfferManager.getObservableList().stream() .anyMatch(openOffer -> openOffer.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId())); diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java index bad77df7d8..a0a13e4cb2 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java @@ -386,6 +386,16 @@ public class FiatAccountsView extends PaymentAccountsView tuple = add2ButtonsAfterGroup(root, ++gridRow, Res.get("shared.deleteAccount"), Res.get("shared.cancel")); - Button deleteAccountButton = tuple.first; + Tuple3 tuple = add3ButtonsAfterGroup( + root, + ++gridRow, + Res.get("shared.save"), + Res.get("shared.deleteAccount"), + Res.get("shared.cancel") + ); + Button updateButton = tuple.first; + updateButton.setOnAction(event -> onUpdateAccount(paymentMethodForm.getPaymentAccount())); + Button deleteAccountButton = tuple.second; deleteAccountButton.setOnAction(event -> onDeleteAccount(paymentMethodForm.getPaymentAccount())); - Button cancelButton = tuple.second; - cancelButton.setOnAction(event -> removeSelectAccountForm()); + Button cancelButton = tuple.third; + cancelButton.setOnAction(event -> onCancelSelectedAccount(paymentMethodForm.getPaymentAccount())); GridPane.setRowSpan(accountTitledGroupBg, paymentMethodForm.getRowSpan()); model.onSelectAccount(paymentAccount); } @@ -638,5 +656,14 @@ public class FiatAccountsView extends PaymentAccountsView