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.
This commit is contained in:
beingindot 2019-12-12 17:01:14 +05:30
parent 14bec2ff4b
commit da683e8b49
No known key found for this signature in database
GPG key ID: 66884C4B3A4B5942
3 changed files with 76 additions and 7 deletions

View file

@ -44,6 +44,18 @@ public class CountryUtil {
return list;
}
public static List<Country> getAllRevolutCountries() {
List<Country> 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<Country> getAllSepaInstantEuroCountries() {
return getAllSepaEuroCountries();
}

View file

@ -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<Country> 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<Country> addCountrySelection() {
HBox hBox = new HBox();
hBox.setSpacing(5);
ComboBox<Country> 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<Country> 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);
}
}

View file

@ -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);
}
}