From da683e8b4934461175d928cd4fd3baa5b5ea31f9 Mon Sep 17 00:00:00 2001 From: beingindot Date: Thu, 12 Dec 2019 17:01:14 +0530 Subject: [PATCH] Revolut account should accept only phone number For issue #3728 Till now we used to accept email or phone number Now we are accepting only phone number in input though for display we will provide backward compatibility. Added list of countries accepted from official revolut website https://www.revolut.com/en-US/help/getting-started/verifying-identity/what-countries-are-supported Based on the country selected, we will validate the given phone number input. --- .../java/bisq/core/locale/CountryUtil.java | 12 ++++ .../paymentmethods/RevolutForm.java | 61 ++++++++++++++++++- .../util/validation/RevolutValidator.java | 10 ++- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/bisq/core/locale/CountryUtil.java b/core/src/main/java/bisq/core/locale/CountryUtil.java index 44320b8f5c..3a3f9ced56 100644 --- a/core/src/main/java/bisq/core/locale/CountryUtil.java +++ b/core/src/main/java/bisq/core/locale/CountryUtil.java @@ -44,6 +44,18 @@ public class CountryUtil { return list; } + public static List getAllRevolutCountries() { + List list = new ArrayList<>(); + String[] codes = {"AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", + "DE", "GR", "HU", "IS", "IE", "IT", "LV", "LI", "LT", "LU", "MT", "NL", + "NO", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "GB", + "AU", "CA", "SG", "CH", "US"}; + populateCountryListByCodes(list, codes); + list.sort((a, b) -> a.name.compareTo(b.name)); + + return list; + } + public static List getAllSepaInstantEuroCountries() { return getAllSepaEuroCountries(); } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java index a51943240b..6a4ca7279f 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/RevolutForm.java @@ -23,6 +23,8 @@ import bisq.desktop.util.Layout; import bisq.desktop.util.validation.RevolutValidator; 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.payment.PaymentAccount; @@ -32,19 +34,29 @@ import bisq.core.payment.payload.RevolutAccountPayload; import bisq.core.util.coin.CoinFormatter; import bisq.core.util.validation.InputValidator; +import com.jfoenix.controls.JFXComboBox; + +import javafx.scene.control.ComboBox; import javafx.scene.control.TextField; import javafx.scene.layout.FlowPane; import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; + +import javafx.collections.FXCollections; + +import javafx.util.StringConverter; import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField; import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon; import static bisq.desktop.util.FormBuilder.addTopLabelFlowPane; import static bisq.desktop.util.FormBuilder.addTopLabelTextField; +import static bisq.desktop.util.FormBuilder.addTopLabelWithVBox; public class RevolutForm extends PaymentMethodForm { private final RevolutAccount account; private RevolutValidator validator; private InputTextField accountIdInputTextField; + private Country selectedCountry; public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) { @@ -74,6 +86,12 @@ public class RevolutForm extends PaymentMethodForm { public void addFormForAddAccount() { gridRowFrom = gridRow + 1; + // country selection is added only to prevent anymore email id input and + // solely to validate the given phone number + ComboBox countryComboBox = addCountrySelection(); + setCountryComboBoxAction(countryComboBox); + countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRevolutCountries())); + accountIdInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.revolut.phoneNr")); accountIdInputTextField.setValidator(validator); accountIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { @@ -84,6 +102,47 @@ public class RevolutForm extends PaymentMethodForm { addCurrenciesGrid(true); addLimitations(false); addAccountNameTextFieldWithAutoFillToggleButton(); + + //set default country as selected + selectedCountry = CountryUtil.getDefaultCountry(); + if (CountryUtil.getAllRevolutCountries().contains(selectedCountry)) { + countryComboBox.getSelectionModel().select(selectedCountry); + } + } + + ComboBox addCountrySelection() { + HBox hBox = new HBox(); + + hBox.setSpacing(5); + ComboBox countryComboBox = new JFXComboBox<>(); + hBox.getChildren().add(countryComboBox); + + addTopLabelWithVBox(gridPane, ++gridRow, Res.get("payment.bank.country"), hBox, 0); + + countryComboBox.setPromptText(Res.get("payment.select.bank.country")); + countryComboBox.setConverter(new StringConverter<>() { + @Override + public String toString(Country country) { + return country.name + " (" + country.code + ")"; + } + + @Override + public Country fromString(String s) { + return null; + } + }); + return countryComboBox; + } + + void setCountryComboBoxAction(ComboBox countryComboBox) { + countryComboBox.setOnAction(e -> { + selectedCountry = countryComboBox.getSelectionModel().getSelectedItem(); + updateFromInputs(); + accountIdInputTextField.resetValidation(); + accountIdInputTextField.validate(); + accountIdInputTextField.requestFocus(); + countryComboBox.requestFocus(); + }); } private void addCurrenciesGrid(boolean isEditable) { @@ -122,7 +181,7 @@ public class RevolutForm extends PaymentMethodForm { @Override public void updateAllInputsValid() { allInputsValid.set(isAccountNameValid() - && validator.validate(account.getAccountId()).isValid + && validator.validate(account.getAccountId(), selectedCountry.code).isValid && account.getTradeCurrencies().size() > 0); } } diff --git a/desktop/src/main/java/bisq/desktop/util/validation/RevolutValidator.java b/desktop/src/main/java/bisq/desktop/util/validation/RevolutValidator.java index 855db46e1e..44eea0023d 100644 --- a/desktop/src/main/java/bisq/desktop/util/validation/RevolutValidator.java +++ b/desktop/src/main/java/bisq/desktop/util/validation/RevolutValidator.java @@ -17,13 +17,11 @@ package bisq.desktop.util.validation; -import bisq.core.util.validation.InputValidator; +public final class RevolutValidator extends PhoneNumberValidator { -public final class RevolutValidator extends InputValidator { - - @Override - public ValidationResult validate(String input) { - // TODO + public ValidationResult validate(String input, String code) { + super.setIsoCountryCode(code); return super.validate(input); } + }