Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revolut account should accept only phone number #3777

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,47 @@ 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();
updateFromInputs();
accountIdInputTextField.resetValidation();
accountIdInputTextField.validate();
accountIdInputTextField.requestFocus();
countryComboBox.requestFocus();
});
}

private void addCurrenciesGrid(boolean isEditable) {
Expand Down Expand Up @@ -122,7 +181,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);
}

}