Skip to content

Commit

Permalink
Revolut account should accept only phone number
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
beingindot committed Dec 12, 2019
1 parent 14bec2f commit 0ee88af
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/bisq/core/locale/CountryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public static List<Country> getAllSepaEuroCountries() {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
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;
Expand All @@ -32,19 +34,29 @@
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) {
Expand Down Expand Up @@ -74,6 +86,12 @@ public RevolutForm(PaymentAccount paymentAccount, AccountAgeWitnessService accou
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) -> {
Expand All @@ -84,6 +102,42 @@ public void addFormForAddAccount() {
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();
});
}

private void addCurrenciesGrid(boolean isEditable) {
Expand Down Expand Up @@ -122,7 +176,7 @@ public void addFormForDisplayAccount() {
@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& validator.validate(account.getAccountId()).isValid
&& validator.validate(account.getAccountId(), selectedCountry.code).isValid
&& account.getTradeCurrencies().size() > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 0ee88af

Please sign in to comment.