mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-20 23:56:30 -04:00
Customize bank form for countries: GB, US, BR, NZ, AU, CA, SE, MX, HK
This commit is contained in:
parent
bb3c950833
commit
77ae3a590f
@ -25,6 +25,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BankUtil {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BankUtil.class);
|
||||
|
||||
// BankName
|
||||
@ -32,12 +33,28 @@ public class BankUtil {
|
||||
switch (countryCode) {
|
||||
case "GB":
|
||||
case "US":
|
||||
case "NZ":
|
||||
case "AU":
|
||||
case "CA":
|
||||
case "SE":
|
||||
case "HK":
|
||||
return false;
|
||||
case "MX":
|
||||
case "BR":
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getBankNameLabel(String countryCode) {
|
||||
switch (countryCode) {
|
||||
case "BR":
|
||||
return "Bank name:";
|
||||
default:
|
||||
return "Bank name (optional):";
|
||||
}
|
||||
}
|
||||
|
||||
// BankId
|
||||
public static boolean isBankIdRequired(String countryCode) {
|
||||
@ -45,7 +62,14 @@ public class BankUtil {
|
||||
case "GB":
|
||||
case "US":
|
||||
case "BR":
|
||||
case "NZ":
|
||||
case "AU":
|
||||
case "SE":
|
||||
return false;
|
||||
case "CA":
|
||||
case "MX":
|
||||
case "HK":
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@ -53,12 +77,13 @@ public class BankUtil {
|
||||
|
||||
public static String getBankIdLabel(String countryCode) {
|
||||
switch (countryCode) {
|
||||
case "GB":
|
||||
case "US":
|
||||
case "BR":
|
||||
log.warn("BankId must not be used for country " + countryCode);
|
||||
case "CA":
|
||||
return "Institution Number:";
|
||||
case "MX":
|
||||
case "HK":
|
||||
return "Bank code:";
|
||||
default:
|
||||
return "Bank nr. or BIC/SWIFT:";
|
||||
return "Bank nr. (e.g. BIC or SWIFT) (optional):";
|
||||
}
|
||||
|
||||
}
|
||||
@ -69,7 +94,14 @@ public class BankUtil {
|
||||
case "GB":
|
||||
case "US":
|
||||
case "BR":
|
||||
case "AU":
|
||||
case "CA":
|
||||
return true;
|
||||
case "NZ":
|
||||
case "MX":
|
||||
case "HK":
|
||||
case "SE":
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@ -83,6 +115,8 @@ public class BankUtil {
|
||||
return "Routing Number:";
|
||||
case "BR":
|
||||
return "Branch code:";
|
||||
case "AU":
|
||||
return "BSB code:";
|
||||
case "CA":
|
||||
return "Transit Number:";
|
||||
default:
|
||||
@ -104,9 +138,17 @@ public class BankUtil {
|
||||
case "GB":
|
||||
case "US":
|
||||
case "BR":
|
||||
case "NZ":
|
||||
case "AU":
|
||||
case "CA":
|
||||
case "HK":
|
||||
return "Account number:";
|
||||
case "SE":
|
||||
return "Bankgiro number:";
|
||||
case "MX":
|
||||
return "CLABE:";
|
||||
default:
|
||||
return "Account nr. or IBAN:";
|
||||
return "Account nr. (e.g. IBAN):";
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,6 +157,7 @@ public class BankUtil {
|
||||
switch (countryCode) {
|
||||
case "US":
|
||||
case "BR":
|
||||
case "CA":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@ -125,6 +168,7 @@ public class BankUtil {
|
||||
switch (countryCode) {
|
||||
case "US":
|
||||
case "BR":
|
||||
case "CA":
|
||||
return "Account type:";
|
||||
default:
|
||||
return "";
|
||||
@ -135,6 +179,7 @@ public class BankUtil {
|
||||
switch (countryCode) {
|
||||
case "US":
|
||||
case "BR":
|
||||
case "CA":
|
||||
return Arrays.asList("Checking", "Savings");
|
||||
default:
|
||||
return new ArrayList<>();
|
||||
@ -163,4 +208,22 @@ public class BankUtil {
|
||||
return "Personal ID:";
|
||||
}
|
||||
}
|
||||
|
||||
// Validation
|
||||
public static boolean useValidation(String countryCode) {
|
||||
switch (countryCode) {
|
||||
case "GB":
|
||||
case "US":
|
||||
case "BR":
|
||||
case "AU":
|
||||
case "CA":
|
||||
case "NZ":
|
||||
case "MX":
|
||||
case "HK":
|
||||
case "SE":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,13 +52,12 @@ public abstract class BankAccountContractData extends CountryBasedPaymentAccount
|
||||
|
||||
@Override
|
||||
public String getPaymentDetailsForTradePopup() {
|
||||
String holderIdString = BankUtil.isHolderIdRequired(countryCode) ? (BankUtil.getHolderIdLabel(countryCode) + ": " + holderTaxId + "\n") : "";
|
||||
|
||||
String bankName = BankUtil.isBankNameRequired(countryCode) ? "Bank name: " + this.bankName + "\n" : "";
|
||||
String bankId = BankUtil.isBankIdRequired(countryCode) ? BankUtil.getBankIdLabel(countryCode) + this.bankId + "\n" : "";
|
||||
String branchId = BankUtil.isBranchIdRequired(countryCode) ? BankUtil.getBranchIdLabel(countryCode) + this.branchId + "\n" : "";
|
||||
String accountNr = BankUtil.isAccountNrRequired(countryCode) ? BankUtil.getAccountNrLabel(countryCode) + this.accountNr + "\n" : "";
|
||||
String accountType = BankUtil.isAccountTypeRequired(countryCode) ? BankUtil.getAccountTypeLabel(countryCode) + this.accountType + "\n" : "";
|
||||
String bankName = BankUtil.isBankNameRequired(countryCode) ? BankUtil.getBankNameLabel(countryCode) + " " + this.bankName + "\n" : "";
|
||||
String bankId = BankUtil.isBankIdRequired(countryCode) ? BankUtil.getBankIdLabel(countryCode) + " " + this.bankId + "\n" : "";
|
||||
String branchId = BankUtil.isBranchIdRequired(countryCode) ? BankUtil.getBranchIdLabel(countryCode) + " " + this.branchId + "\n" : "";
|
||||
String accountNr = BankUtil.isAccountNrRequired(countryCode) ? BankUtil.getAccountNrLabel(countryCode) + " " + this.accountNr + "\n" : "";
|
||||
String accountType = BankUtil.isAccountTypeRequired(countryCode) ? BankUtil.getAccountTypeLabel(countryCode) + " " + this.accountType + "\n" : "";
|
||||
String holderIdString = BankUtil.isHolderIdRequired(countryCode) ? (BankUtil.getHolderIdLabel(countryCode) + " " + holderTaxId + "\n") : "";
|
||||
|
||||
return "Holder name: " + holderName + "\n" +
|
||||
bankName +
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.bitsquare.gui.components;
|
||||
|
||||
import io.bitsquare.common.UserThread;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.transformation.FilteredList;
|
||||
@ -22,11 +21,11 @@ public class SearchComboBox<T> extends ComboBox<T> {
|
||||
filteredList = new FilteredList<>(items);
|
||||
setEditable(true);
|
||||
|
||||
itemsProperty().addListener(new WeakChangeListener<>((observable, oldValue, newValue) -> {
|
||||
itemsProperty().addListener((observable, oldValue, newValue) -> {
|
||||
filteredList = new FilteredList<>(newValue);
|
||||
setItems(filteredList);
|
||||
}));
|
||||
getEditor().textProperty().addListener(new WeakChangeListener<>((observable, oldValue, newValue) -> {
|
||||
});
|
||||
getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (!filteredList.stream().filter(item -> getConverter().toString(item).equals(newValue)).
|
||||
findAny().isPresent()) {
|
||||
UserThread.execute(() -> {
|
||||
@ -37,6 +36,6 @@ public class SearchComboBox<T> extends ComboBox<T> {
|
||||
show();
|
||||
});
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@ import io.bitsquare.payment.AliPayAccount;
|
||||
import io.bitsquare.payment.AliPayAccountContractData;
|
||||
import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -60,10 +59,10 @@ public class AliPayForm extends PaymentMethodForm {
|
||||
|
||||
accountNrInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Account nr.:").second;
|
||||
accountNrInputTextField.setValidator(aliPayValidator);
|
||||
accountNrInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
aliPayAccount.setAccountNr(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
|
||||
addLabelTextField(gridPane, ++gridRow, "Currency:", aliPayAccount.getSingleTradeCurrency().getNameAndCode());
|
||||
addAllowedPeriod();
|
||||
|
@ -24,7 +24,7 @@ import io.bitsquare.gui.components.InputTextField;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.gui.util.Layout;
|
||||
import io.bitsquare.gui.util.validation.AccountNrValidator;
|
||||
import io.bitsquare.gui.util.validation.BankValidator;
|
||||
import io.bitsquare.gui.util.validation.BankIdValidator;
|
||||
import io.bitsquare.gui.util.validation.BranchIdValidator;
|
||||
import io.bitsquare.gui.util.validation.InputValidator;
|
||||
import io.bitsquare.locale.*;
|
||||
@ -32,7 +32,6 @@ import io.bitsquare.payment.BankAccountContractData;
|
||||
import io.bitsquare.payment.CountryBasedPaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
@ -63,51 +62,127 @@ abstract class BankForm extends PaymentMethodForm {
|
||||
private Tuple2<Label, ComboBox> accountTypeTuple;
|
||||
private Label accountTypeLabel;
|
||||
private ComboBox<String> accountTypeComboBox;
|
||||
private boolean validatorsApplied;
|
||||
|
||||
static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) {
|
||||
BankAccountContractData bankAccountContractData = (BankAccountContractData) paymentAccountContractData;
|
||||
BankAccountContractData data = (BankAccountContractData) paymentAccountContractData;
|
||||
String countryCode = ((BankAccountContractData) paymentAccountContractData).getCountryCode();
|
||||
|
||||
if (bankAccountContractData.getHolderTaxId() != null)
|
||||
if (data.getHolderTaxId() != null)
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Account holder name / " + BankUtil.getHolderIdLabel(countryCode),
|
||||
bankAccountContractData.getHolderName() + " / " + bankAccountContractData.getHolderTaxId());
|
||||
data.getHolderName() + " / " + data.getHolderTaxId());
|
||||
else
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Account holder name:", bankAccountContractData.getHolderName());
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Account holder name:", data.getHolderName());
|
||||
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Country of bank:", CountryUtil.getNameAndCode(countryCode));
|
||||
|
||||
String bankCodeLabel = BankUtil.getBankIdLabel(countryCode);
|
||||
String branchCodeLabel = BankUtil.getBranchIdLabel(countryCode);
|
||||
boolean branchCodeDisplayed = false;
|
||||
if (BankUtil.isBankNameRequired(countryCode) && BankUtil.isBankIdRequired(countryCode)) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Bank name / " + bankCodeLabel,
|
||||
bankAccountContractData.getBankName() + " / " + bankAccountContractData.getBankId());
|
||||
} else if (BankUtil.isBankNameRequired(countryCode) && !BankUtil.isBankIdRequired(countryCode) && BankUtil.isBranchIdRequired(countryCode)) {
|
||||
branchCodeDisplayed = true;
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Bank name / " + branchCodeLabel,
|
||||
bankAccountContractData.getBankName() + " / " + bankAccountContractData.getBranchId());
|
||||
} else if (BankUtil.isBankNameRequired(countryCode)) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Bank name:", bankAccountContractData.getBankName());
|
||||
} else if (BankUtil.isBankIdRequired(countryCode)) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, bankCodeLabel, bankAccountContractData.getBankId());
|
||||
}
|
||||
// We don't want to display more than 6 rows to avoid scrolling, so if we get too many fields we combine them horizontally
|
||||
int nrRows = 0;
|
||||
if (BankUtil.isBankNameRequired(countryCode))
|
||||
nrRows++;
|
||||
if (BankUtil.isBankIdRequired(countryCode))
|
||||
nrRows++;
|
||||
if (BankUtil.isBranchIdRequired(countryCode))
|
||||
nrRows++;
|
||||
if (BankUtil.isAccountNrRequired(countryCode))
|
||||
nrRows++;
|
||||
if (BankUtil.isAccountTypeRequired(countryCode))
|
||||
nrRows++;
|
||||
|
||||
String bankNameLabel = BankUtil.getBankNameLabel(countryCode);
|
||||
String bankIdLabel = BankUtil.getBankIdLabel(countryCode);
|
||||
String branchIdLabel = BankUtil.getBranchIdLabel(countryCode);
|
||||
String accountNrLabel = BankUtil.getAccountNrLabel(countryCode);
|
||||
String accountTypeLabel = BankUtil.getAccountTypeLabel(countryCode);
|
||||
|
||||
String accountTypeString = "";
|
||||
String accountTypeLabelString = "";
|
||||
|
||||
if (BankUtil.isAccountTypeRequired(countryCode)) {
|
||||
accountTypeString = " (" + bankAccountContractData.getAccountType() + ")";
|
||||
accountTypeLabelString = " (" + accountTypeLabel.substring(0, accountTypeLabel.length() - 1) + "):";
|
||||
boolean accountNrAccountTypeCombined = false;
|
||||
boolean bankNameBankIdCombined = false;
|
||||
boolean bankIdBranchIdCombined = false;
|
||||
boolean bankNameBranchIdCombined = false;
|
||||
boolean branchIdAccountNrCombined = false;
|
||||
if (nrRows > 2) {
|
||||
// Try combine AccountNr + AccountType
|
||||
accountNrAccountTypeCombined = BankUtil.isAccountNrRequired(countryCode) && BankUtil.isAccountTypeRequired(countryCode);
|
||||
if (accountNrAccountTypeCombined)
|
||||
nrRows--;
|
||||
|
||||
if (nrRows > 2) {
|
||||
// Next we try BankName + BankId
|
||||
bankNameBankIdCombined = BankUtil.isBankNameRequired(countryCode) && BankUtil.isBankIdRequired(countryCode);
|
||||
if (bankNameBankIdCombined)
|
||||
nrRows--;
|
||||
|
||||
if (nrRows > 2) {
|
||||
// Next we try BankId + BranchId
|
||||
bankIdBranchIdCombined = !bankNameBankIdCombined && BankUtil.isBankIdRequired(countryCode) && BankUtil.isBranchIdRequired(countryCode);
|
||||
if (bankIdBranchIdCombined)
|
||||
nrRows--;
|
||||
|
||||
if (nrRows > 2) {
|
||||
// Next we try BankId + BranchId
|
||||
bankNameBranchIdCombined = !bankNameBankIdCombined && !bankIdBranchIdCombined &&
|
||||
BankUtil.isBankNameRequired(countryCode) && BankUtil.isBranchIdRequired(countryCode);
|
||||
if (bankNameBranchIdCombined)
|
||||
nrRows--;
|
||||
|
||||
if (nrRows > 2) {
|
||||
branchIdAccountNrCombined = !bankNameBranchIdCombined && !bankIdBranchIdCombined && !accountNrAccountTypeCombined &&
|
||||
BankUtil.isBranchIdRequired(countryCode) && BankUtil.isAccountNrRequired(countryCode);
|
||||
if (branchIdAccountNrCombined)
|
||||
nrRows--;
|
||||
|
||||
if (nrRows > 2)
|
||||
log.warn("We still have too many rows....");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!branchCodeDisplayed && BankUtil.isBranchIdRequired(countryCode))
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, branchCodeLabel, bankAccountContractData.getBranchId());
|
||||
if (BankUtil.isAccountNrRequired(countryCode))
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, accountNrLabel.substring(0, accountNrLabel.length() - 1) +
|
||||
accountTypeLabelString, bankAccountContractData.getAccountNr() + accountTypeString);
|
||||
if (bankNameBankIdCombined) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow,
|
||||
bankNameLabel.substring(0, bankNameLabel.length() - 1) + " / " + bankIdLabel.substring(0, bankIdLabel.length() - 1) + ":",
|
||||
data.getBankName() + " / " + data.getBankId());
|
||||
}
|
||||
if (bankNameBranchIdCombined) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow,
|
||||
bankNameLabel.substring(0, bankNameLabel.length() - 1) + " / " + branchIdLabel.substring(0, branchIdLabel.length() - 1) + ":",
|
||||
data.getBankName() + " / " + data.getBranchId());
|
||||
}
|
||||
|
||||
if (!bankNameBankIdCombined && !bankNameBranchIdCombined && BankUtil.isBankNameRequired(countryCode))
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, bankNameLabel, data.getBankName());
|
||||
|
||||
if (!bankNameBankIdCombined && !bankNameBranchIdCombined && !branchIdAccountNrCombined && bankIdBranchIdCombined) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow,
|
||||
bankIdLabel.substring(0, bankIdLabel.length() - 1) + " / " + branchIdLabel.substring(0, branchIdLabel.length() - 1) + ":",
|
||||
data.getBankId() + " / " + data.getBranchId());
|
||||
}
|
||||
|
||||
if (!bankNameBankIdCombined && !bankIdBranchIdCombined && BankUtil.isBankIdRequired(countryCode))
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, bankIdLabel, data.getBankId());
|
||||
|
||||
if (!bankNameBranchIdCombined && !bankIdBranchIdCombined && branchIdAccountNrCombined) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow,
|
||||
branchIdLabel.substring(0, branchIdLabel.length() - 1) + " / " + accountNrLabel.substring(0, accountNrLabel.length() - 1) + ":",
|
||||
data.getBranchId() + " / " + data.getAccountNr());
|
||||
}
|
||||
|
||||
if (!bankNameBranchIdCombined && !bankIdBranchIdCombined && !branchIdAccountNrCombined && BankUtil.isBranchIdRequired(countryCode))
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, branchIdLabel, data.getBranchId());
|
||||
|
||||
if (!branchIdAccountNrCombined && accountNrAccountTypeCombined) {
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow,
|
||||
accountNrLabel.substring(0, accountNrLabel.length() - 1) + " / " + accountTypeLabel,
|
||||
data.getAccountNr() + " / " + data.getAccountType());
|
||||
}
|
||||
|
||||
if (!branchIdAccountNrCombined && !accountNrAccountTypeCombined && BankUtil.isAccountNrRequired(countryCode))
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, accountNrLabel, data.getAccountNr());
|
||||
|
||||
if (!accountNrAccountTypeCombined && BankUtil.isAccountTypeRequired(countryCode))
|
||||
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, accountTypeLabel, data.getAccountType());
|
||||
|
||||
return gridRow;
|
||||
}
|
||||
@ -199,6 +274,7 @@ abstract class BankForm extends PaymentMethodForm {
|
||||
branchIdLabel.setText(BankUtil.getBranchIdLabel(countryCode));
|
||||
accountNrLabel.setText(BankUtil.getAccountNrLabel(countryCode));
|
||||
accountTypeLabel.setText(BankUtil.getAccountTypeLabel(countryCode));
|
||||
holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));
|
||||
|
||||
bankNameInputTextField.setText("");
|
||||
bankIdInputTextField.setText("");
|
||||
@ -207,58 +283,65 @@ abstract class BankForm extends PaymentMethodForm {
|
||||
accountTypeComboBox.getSelectionModel().clearSelection();
|
||||
accountTypeComboBox.setItems(FXCollections.observableArrayList(BankUtil.getAccountTypeValues(countryCode)));
|
||||
|
||||
if (BankUtil.useValidation(countryCode) && !validatorsApplied) {
|
||||
validatorsApplied = true;
|
||||
holderIdInputTextField.setValidator(inputValidator);
|
||||
bankNameInputTextField.setValidator(inputValidator);
|
||||
bankIdInputTextField.setValidator(new BankIdValidator(countryCode));
|
||||
branchIdInputTextField.setValidator(new BranchIdValidator(countryCode));
|
||||
accountNrInputTextField.setValidator(new AccountNrValidator(countryCode));
|
||||
} else {
|
||||
validatorsApplied = false;
|
||||
holderIdInputTextField.setValidator(null);
|
||||
bankNameInputTextField.setValidator(null);
|
||||
bankIdInputTextField.setValidator(null);
|
||||
branchIdInputTextField.setValidator(null);
|
||||
accountNrInputTextField.setValidator(null);
|
||||
}
|
||||
holderNameInputTextField.resetValidation();
|
||||
holderIdInputTextField.resetValidation();
|
||||
bankNameInputTextField.resetValidation();
|
||||
bankIdInputTextField.resetValidation();
|
||||
branchIdInputTextField.resetValidation();
|
||||
accountNrInputTextField.resetValidation();
|
||||
|
||||
if (holderIdInputTextField != null) {
|
||||
holderIdInputTextField.resetValidation();
|
||||
holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));
|
||||
boolean requiresHolderId = BankUtil.isHolderIdRequired(countryCode);
|
||||
if (requiresHolderId) {
|
||||
holderNameInputTextField.minWidthProperty().unbind();
|
||||
holderNameInputTextField.setMinWidth(300);
|
||||
} else {
|
||||
holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
|
||||
holderIdInputTextField.setText("");
|
||||
}
|
||||
holderIdLabel.setVisible(requiresHolderId);
|
||||
holderIdLabel.setManaged(requiresHolderId);
|
||||
holderIdInputTextField.setVisible(requiresHolderId);
|
||||
holderIdInputTextField.setManaged(requiresHolderId);
|
||||
}
|
||||
|
||||
bankNameTuple.second.resetValidation();
|
||||
bankIdTuple.second.resetValidation();
|
||||
branchIdTuple.second.resetValidation();
|
||||
accountNrTuple.second.resetValidation();
|
||||
boolean requiresHolderId = BankUtil.isHolderIdRequired(countryCode);
|
||||
if (requiresHolderId) {
|
||||
holderNameInputTextField.minWidthProperty().unbind();
|
||||
holderNameInputTextField.setMinWidth(300);
|
||||
} else {
|
||||
holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
|
||||
holderIdInputTextField.setText("");
|
||||
}
|
||||
holderIdLabel.setVisible(requiresHolderId);
|
||||
holderIdLabel.setManaged(requiresHolderId);
|
||||
holderIdInputTextField.setVisible(requiresHolderId);
|
||||
holderIdInputTextField.setManaged(requiresHolderId);
|
||||
|
||||
boolean bankNameRequired = BankUtil.isBankNameRequired(countryCode);
|
||||
bankNameTuple.first.setVisible(bankNameRequired);
|
||||
bankNameTuple.first.setManaged(bankNameRequired);
|
||||
bankNameTuple.second.setVisible(bankNameRequired);
|
||||
bankNameTuple.second.setManaged(bankNameRequired);
|
||||
bankNameInputTextField.setVisible(bankNameRequired);
|
||||
bankNameInputTextField.setManaged(bankNameRequired);
|
||||
|
||||
boolean bankIdRequired = BankUtil.isBankIdRequired(countryCode);
|
||||
bankIdTuple.first.setVisible(bankIdRequired);
|
||||
bankIdTuple.first.setManaged(bankIdRequired);
|
||||
bankIdTuple.second.setVisible(bankIdRequired);
|
||||
bankIdTuple.second.setManaged(bankIdRequired);
|
||||
bankIdInputTextField.setVisible(bankIdRequired);
|
||||
bankIdInputTextField.setManaged(bankIdRequired);
|
||||
|
||||
boolean branchIdRequired = BankUtil.isBranchIdRequired(countryCode);
|
||||
branchIdTuple.first.setVisible(branchIdRequired);
|
||||
branchIdTuple.first.setManaged(branchIdRequired);
|
||||
branchIdTuple.second.setVisible(branchIdRequired);
|
||||
branchIdTuple.second.setManaged(branchIdRequired);
|
||||
((BankValidator) branchIdTuple.second.getValidator()).setCountryCode(bankAccountContractData.getCountryCode());
|
||||
branchIdInputTextField.setVisible(branchIdRequired);
|
||||
branchIdInputTextField.setManaged(branchIdRequired);
|
||||
|
||||
boolean accountNrRequired = BankUtil.isAccountNrRequired(countryCode);
|
||||
accountNrTuple.first.setVisible(accountNrRequired);
|
||||
accountNrTuple.first.setManaged(accountNrRequired);
|
||||
accountNrTuple.second.setVisible(accountNrRequired);
|
||||
accountNrTuple.second.setManaged(accountNrRequired);
|
||||
((BankValidator) accountNrTuple.second.getValidator()).setCountryCode(bankAccountContractData.getCountryCode());
|
||||
accountNrInputTextField.setVisible(accountNrRequired);
|
||||
accountNrInputTextField.setManaged(accountNrRequired);
|
||||
|
||||
boolean accountTypeRequired = BankUtil.isAccountTypeRequired(countryCode);
|
||||
accountTypeTuple.first.setVisible(accountTypeRequired);
|
||||
@ -286,43 +369,39 @@ abstract class BankForm extends PaymentMethodForm {
|
||||
|
||||
bankNameTuple = addLabelInputTextField(gridPane, ++gridRow, "Bank name:");
|
||||
bankNameInputTextField = bankNameTuple.second;
|
||||
bankNameInputTextField.setValidator(inputValidator);
|
||||
bankNameInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
|
||||
bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
bankAccountContractData.setBankName(newValue);
|
||||
updateFromInputs();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
bankIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
|
||||
bankIdLabel = bankIdTuple.first;
|
||||
bankIdInputTextField = bankIdTuple.second;
|
||||
bankIdInputTextField.setValidator(inputValidator);
|
||||
bankIdInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
bankAccountContractData.setBankId(newValue);
|
||||
updateFromInputs();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
branchIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
|
||||
branchIdLabel = branchIdTuple.first;
|
||||
branchIdInputTextField = branchIdTuple.second;
|
||||
branchIdInputTextField.setValidator(new BranchIdValidator());
|
||||
branchIdInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
bankAccountContractData.setBranchId(newValue);
|
||||
updateFromInputs();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
accountNrTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
|
||||
accountNrLabel = accountNrTuple.first;
|
||||
accountNrInputTextField = accountNrTuple.second;
|
||||
accountNrInputTextField.setValidator(new AccountNrValidator());
|
||||
accountNrInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
bankAccountContractData.setAccountNr(newValue);
|
||||
updateFromInputs();
|
||||
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
accountTypeTuple = addLabelComboBox(gridPane, ++gridRow, "");
|
||||
accountTypeLabel = accountTypeTuple.first;
|
||||
@ -352,12 +431,12 @@ abstract class BankForm extends PaymentMethodForm {
|
||||
Tuple4<Label, InputTextField, Label, InputTextField> tuple = addLabelInputTextFieldLabelInputTextField(gridPane, ++gridRow, "Account holder name:", BankUtil.getHolderIdLabel(""));
|
||||
holderNameInputTextField = tuple.second;
|
||||
holderNameInputTextField.setMinWidth(300);
|
||||
holderNameInputTextField.setValidator(inputValidator);
|
||||
holderNameInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
bankAccountContractData.setHolderName(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
|
||||
holderNameInputTextField.setValidator(inputValidator);
|
||||
|
||||
holderIdLabel = tuple.third;
|
||||
holderIdLabel.setVisible(false);
|
||||
@ -366,11 +445,10 @@ abstract class BankForm extends PaymentMethodForm {
|
||||
holderIdInputTextField = tuple.forth;
|
||||
holderIdInputTextField.setVisible(false);
|
||||
holderIdInputTextField.setManaged(false);
|
||||
holderIdInputTextField.setValidator(inputValidator);
|
||||
holderIdInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
holderIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
bankAccountContractData.setHolderTaxId(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -409,37 +487,38 @@ abstract class BankForm extends PaymentMethodForm {
|
||||
@Override
|
||||
public void updateAllInputsValid() {
|
||||
boolean result = isAccountNameValid()
|
||||
&& holderNameInputTextField.getValidator().validate(bankAccountContractData.getHolderName()).isValid
|
||||
&& paymentAccount.getSingleTradeCurrency() != null
|
||||
&& getCountryBasedPaymentAccount().getCountry() != null;
|
||||
&& getCountryBasedPaymentAccount().getCountry() != null
|
||||
&& holderNameInputTextField.getValidator().validate(bankAccountContractData.getHolderName()).isValid;
|
||||
|
||||
String countryCode = bankAccountContractData.getCountryCode();
|
||||
if (BankUtil.isBankNameRequired(countryCode))
|
||||
result &= bankNameInputTextField.getValidator().validate(bankAccountContractData.getBankName()).isValid;
|
||||
if (validatorsApplied && BankUtil.useValidation(countryCode)) {
|
||||
if (BankUtil.isBankNameRequired(countryCode))
|
||||
result &= bankNameInputTextField.getValidator().validate(bankAccountContractData.getBankName()).isValid;
|
||||
|
||||
if (BankUtil.isBankIdRequired(countryCode))
|
||||
result &= bankIdInputTextField.getValidator().validate(bankAccountContractData.getBankId()).isValid;
|
||||
if (BankUtil.isBankIdRequired(countryCode))
|
||||
result &= bankIdInputTextField.getValidator().validate(bankAccountContractData.getBankId()).isValid;
|
||||
|
||||
if (BankUtil.isBranchIdRequired(countryCode))
|
||||
result &= branchIdInputTextField.getValidator().validate(bankAccountContractData.getBranchId()).isValid;
|
||||
if (BankUtil.isBranchIdRequired(countryCode))
|
||||
result &= branchIdInputTextField.getValidator().validate(bankAccountContractData.getBranchId()).isValid;
|
||||
|
||||
if (BankUtil.isAccountNrRequired(countryCode))
|
||||
result &= accountNrInputTextField.getValidator().validate(bankAccountContractData.getAccountNr()).isValid;
|
||||
if (BankUtil.isAccountNrRequired(countryCode))
|
||||
result &= accountNrInputTextField.getValidator().validate(bankAccountContractData.getAccountNr()).isValid;
|
||||
|
||||
if (BankUtil.isAccountTypeRequired(countryCode))
|
||||
result &= bankAccountContractData.getAccountType() != null;
|
||||
|
||||
if (getCountryBasedPaymentAccount().getCountry() != null &&
|
||||
BankUtil.isHolderIdRequired(getCountryBasedPaymentAccount().getCountry().code))
|
||||
result &= holderIdInputTextField.getValidator().validate(bankAccountContractData.getHolderTaxId()).isValid;
|
||||
if (BankUtil.isAccountTypeRequired(countryCode))
|
||||
result &= bankAccountContractData.getAccountType() != null;
|
||||
|
||||
if (BankUtil.isHolderIdRequired(countryCode))
|
||||
result &= holderIdInputTextField.getValidator().validate(bankAccountContractData.getHolderTaxId()).isValid;
|
||||
}
|
||||
allInputsValid.set(result);
|
||||
}
|
||||
|
||||
protected void addHolderNameAndIdForDisplayAccount() {
|
||||
if (BankUtil.isHolderIdRequired(bankAccountContractData.getCountryCode())) {
|
||||
String countryCode = bankAccountContractData.getCountryCode();
|
||||
if (BankUtil.isHolderIdRequired(countryCode)) {
|
||||
Tuple4<Label, TextField, Label, TextField> tuple = addLabelTextFieldLabelTextField(gridPane, ++gridRow,
|
||||
"Account holder name:", BankUtil.getHolderIdLabel(bankAccountContractData.getCountryCode()));
|
||||
"Account holder name:", BankUtil.getHolderIdLabel(countryCode));
|
||||
TextField holderNameTextField = tuple.second;
|
||||
holderNameTextField.setText(bankAccountContractData.getHolderName());
|
||||
holderNameTextField.setMinWidth(300);
|
||||
|
@ -30,7 +30,6 @@ import io.bitsquare.payment.CryptoCurrencyAccount;
|
||||
import io.bitsquare.payment.CryptoCurrencyAccountContractData;
|
||||
import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
@ -81,10 +80,10 @@ public class BlockChainForm extends PaymentMethodForm {
|
||||
addressInputTextField = tuple2.second;
|
||||
addressInputTextField.setValidator(altCoinAddressValidator);
|
||||
|
||||
addressInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
addressInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
cryptoCurrencyAccount.setAddress(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
|
||||
addAllowedPeriod();
|
||||
addAccountNameTextFieldWithAutoFillCheckBox();
|
||||
|
@ -28,7 +28,6 @@ import io.bitsquare.payment.OKPayAccount;
|
||||
import io.bitsquare.payment.OKPayAccountContractData;
|
||||
import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.control.CheckBox;
|
||||
@ -67,10 +66,10 @@ public class OKPayForm extends PaymentMethodForm {
|
||||
|
||||
accountNrInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Wallet ID:").second;
|
||||
accountNrInputTextField.setValidator(okPayValidator);
|
||||
accountNrInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
okPayAccount.setAccountNr(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
|
||||
addCurrenciesGrid(true);
|
||||
addAllowedPeriod();
|
||||
|
@ -27,7 +27,6 @@ import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
@ -92,10 +91,10 @@ public abstract class PaymentMethodForm {
|
||||
accountNameTextField.setEditable(false);
|
||||
accountNameTextField.setValidator(inputValidator);
|
||||
accountNameTextField.setFocusTraversable(false);
|
||||
accountNameTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
accountNameTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
paymentAccount.setAccountName(newValue);
|
||||
updateAllInputsValid();
|
||||
}));
|
||||
});
|
||||
useCustomAccountNameCheckBox = tuple.third;
|
||||
useCustomAccountNameCheckBox.setSelected(false);
|
||||
useCustomAccountNameCheckBox.setOnAction(e -> {
|
||||
|
@ -27,7 +27,6 @@ import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import io.bitsquare.payment.PerfectMoneyAccount;
|
||||
import io.bitsquare.payment.PerfectMoneyAccountContractData;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -61,10 +60,10 @@ public class PerfectMoneyForm extends PaymentMethodForm {
|
||||
|
||||
accountNrInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Account nr.:").second;
|
||||
accountNrInputTextField.setValidator(perfectMoneyValidator);
|
||||
accountNrInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
perfectMoneyAccount.setAccountNr(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
|
||||
addLabelTextField(gridPane, ++gridRow, "Currency:", perfectMoneyAccount.getSingleTradeCurrency().getNameAndCode());
|
||||
addAllowedPeriod();
|
||||
|
@ -25,7 +25,6 @@ import io.bitsquare.locale.BankUtil;
|
||||
import io.bitsquare.payment.CountryBasedPaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
@ -52,10 +51,10 @@ public class SameBankForm extends BankForm {
|
||||
Tuple2<Label, InputTextField> tuple = addLabelInputTextField(gridPane, ++gridRow, "Account holder name:");
|
||||
InputTextField holderNameInputTextField = tuple.second;
|
||||
holderNameInputTextField.setValidator(inputValidator);
|
||||
holderNameInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
bankAccountContractData.setHolderName(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,6 @@ import io.bitsquare.gui.util.validation.IBANValidator;
|
||||
import io.bitsquare.gui.util.validation.InputValidator;
|
||||
import io.bitsquare.locale.*;
|
||||
import io.bitsquare.payment.*;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
@ -81,25 +80,25 @@ public class SepaForm extends PaymentMethodForm {
|
||||
|
||||
InputTextField holderNameInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Account holder name:").second;
|
||||
holderNameInputTextField.setValidator(inputValidator);
|
||||
holderNameInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
sepaAccount.setHolderName(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
|
||||
ibanInputTextField = addLabelInputTextField(gridPane, ++gridRow, "IBAN:").second;
|
||||
ibanInputTextField.setValidator(ibanValidator);
|
||||
ibanInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
sepaAccount.setIban(newValue);
|
||||
updateFromInputs();
|
||||
|
||||
}));
|
||||
});
|
||||
bicInputTextField = addLabelInputTextField(gridPane, ++gridRow, "BIC/SWIFT:").second;
|
||||
bicInputTextField.setValidator(bicValidator);
|
||||
bicInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
bicInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
sepaAccount.setBic(newValue);
|
||||
updateFromInputs();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
addLabel(gridPane, ++gridRow, "Country of your Bank:");
|
||||
|
@ -27,7 +27,6 @@ import io.bitsquare.payment.PaymentAccount;
|
||||
import io.bitsquare.payment.PaymentAccountContractData;
|
||||
import io.bitsquare.payment.SwishAccount;
|
||||
import io.bitsquare.payment.SwishAccountContractData;
|
||||
import javafx.beans.value.WeakChangeListener;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -62,17 +61,17 @@ public class SwishForm extends PaymentMethodForm {
|
||||
|
||||
InputTextField holderNameInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Account holder name:").second;
|
||||
holderNameInputTextField.setValidator(inputValidator);
|
||||
holderNameInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
swishAccount.setHolderName(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
|
||||
mobileNrInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Mobile nr.:").second;
|
||||
mobileNrInputTextField.setValidator(swishValidator);
|
||||
mobileNrInputTextField.textProperty().addListener(new WeakChangeListener<>((ov, oldValue, newValue) -> {
|
||||
mobileNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
|
||||
swishAccount.setMobileNr(newValue);
|
||||
updateFromInputs();
|
||||
}));
|
||||
});
|
||||
|
||||
addLabelTextField(gridPane, ++gridRow, "Currency:", swishAccount.getSingleTradeCurrency().getNameAndCode());
|
||||
addAllowedPeriod();
|
||||
|
@ -19,18 +19,24 @@ package io.bitsquare.gui.util.validation;
|
||||
|
||||
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.BankUtil;
|
||||
|
||||
public final class AccountNrValidator extends BankValidator {
|
||||
public AccountNrValidator(String countryCode) {
|
||||
super(countryCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult validate(String input) {
|
||||
String message;
|
||||
int length;
|
||||
String input2;
|
||||
switch (countryCode) {
|
||||
case "GB":
|
||||
if (isNumberWithFixedLength(input, 8))
|
||||
length = 8;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.accountNr", 8));
|
||||
return new ValidationResult(false, BSResources.get("validation.accountNr", length));
|
||||
case "US":
|
||||
if (isNumberInRange(input, 4, 17))
|
||||
return super.validate(input);
|
||||
@ -41,9 +47,43 @@ public final class AccountNrValidator extends BankValidator {
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.accountNrChars", "1 - 20"));
|
||||
case "NZ":
|
||||
input2 = input != null ? input.replaceAll("-", "") : null;
|
||||
if (isNumberInRange(input2, 15, 16))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, "Account number must be of format: 03-1587-0050000-00");
|
||||
case "AU":
|
||||
if (isNumberInRange(input, 4, 10))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.accountNr", "4 - 10"));
|
||||
case "CA":
|
||||
if (isNumberInRange(input, 7, 12))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.accountNr", "7 - 12"));
|
||||
case "MX":
|
||||
length = 18;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", getLabel(), length));
|
||||
case "HK":
|
||||
input2 = input != null ? input.replaceAll("-", "") : null;
|
||||
if (isNumberInRange(input2, 9, 12))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, "Account number must be of format: 005-231289-112");
|
||||
default:
|
||||
return super.validate(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getLabel() {
|
||||
String label = BankUtil.getAccountNrLabel(countryCode);
|
||||
return label.substring(0, label.length() - 1);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.gui.util.validation;
|
||||
|
||||
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.BankUtil;
|
||||
|
||||
public final class BankIdValidator extends BankValidator {
|
||||
public BankIdValidator(String countryCode) {
|
||||
super(countryCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult validate(String input) {
|
||||
int length;
|
||||
|
||||
switch (countryCode) {
|
||||
case "CA":
|
||||
length = 3;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.bankIdNumber", getLabel(), length));
|
||||
case "HK":
|
||||
length = 3;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.bankIdNumber", getLabel(), length));
|
||||
default:
|
||||
return super.validate(input);
|
||||
}
|
||||
}
|
||||
|
||||
private String getLabel() {
|
||||
String label = BankUtil.getBankIdLabel(countryCode);
|
||||
return label.substring(0, label.length() - 1);
|
||||
}
|
||||
|
||||
}
|
@ -25,7 +25,7 @@ public abstract class BankValidator extends InputValidator {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
public BankValidator(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
|
@ -19,34 +19,57 @@ package io.bitsquare.gui.util.validation;
|
||||
|
||||
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.BankUtil;
|
||||
|
||||
public final class BranchIdValidator extends BankValidator {
|
||||
|
||||
public BranchIdValidator(String countryCode) {
|
||||
super(countryCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult validate(String input) {
|
||||
int length;
|
||||
String label = BankUtil.getBankIdLabel(countryCode);
|
||||
switch (countryCode) {
|
||||
case "GB":
|
||||
length = 6;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", "Sort code", length));
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", getLabel(), length));
|
||||
case "US":
|
||||
length = 9;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", "Routing number", length));
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", getLabel(), length));
|
||||
case "BR":
|
||||
if (isStringInRange(input, 2, 6))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeChars", "Branch code", "2 - 6"));
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeChars", getLabel(), "2 - 6"));
|
||||
case "AU":
|
||||
length = 6;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeChars", getLabel(), length));
|
||||
case "CA":
|
||||
length = 5;
|
||||
if (isNumberWithFixedLength(input, length))
|
||||
return super.validate(input);
|
||||
else
|
||||
return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", getLabel(), length));
|
||||
default:
|
||||
return super.validate(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getLabel() {
|
||||
String label = BankUtil.getBranchIdLabel(countryCode);
|
||||
return label.substring(0, label.length() - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package io.bitsquare.gui.util.validation;
|
||||
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
public class InputValidator {
|
||||
|
||||
@ -64,7 +63,7 @@ public class InputValidator {
|
||||
|
||||
protected boolean isPositiveNumber(String input) {
|
||||
try {
|
||||
return input != null && NumberUtils.isNumber(input) && Long.parseLong(input) >= 0;
|
||||
return input != null && Long.parseLong(input) >= 0;
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ validation.passwordTooShort=The password you entered is too short. It needs to h
|
||||
validation.passwordTooLong=The password you entered is too long. It cannot be longer as 50 characters.
|
||||
validation.sortCodeNumber={0} must consist of {1} numbers
|
||||
validation.sortCodeChars={0} must consist of {1} characters
|
||||
validation.bankIdNumber={0} must consist of {1} numbers
|
||||
validation.accountNr=Account number must consist of {0} numbers
|
||||
validation.accountNrChars=Account number must consist of {0} characters
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user