diff --git a/core/src/main/java/io/bitsquare/locale/BankUtil.java b/core/src/main/java/io/bitsquare/locale/BankUtil.java index 20152e769b..791674e25d 100644 --- a/core/src/main/java/io/bitsquare/locale/BankUtil.java +++ b/core/src/main/java/io/bitsquare/locale/BankUtil.java @@ -44,6 +44,7 @@ public class BankUtil { switch (countryCode) { case "GB": case "US": + case "BR": return false; default: return true; @@ -54,6 +55,7 @@ public class BankUtil { switch (countryCode) { case "GB": case "US": + case "BR": log.warn("BankId must not be used for country " + countryCode); default: return "Bank nr. or BIC/SWIFT:"; @@ -66,6 +68,7 @@ public class BankUtil { switch (countryCode) { case "GB": case "US": + case "BR": return true; default: return true; @@ -78,6 +81,8 @@ public class BankUtil { return "UK Sort code:"; case "US": return "Routing Number:"; + case "BR": + return "Branch code:"; case "CA": return "Transit Number:"; default: @@ -98,6 +103,7 @@ public class BankUtil { switch (countryCode) { case "GB": case "US": + case "BR": return "Account number:"; default: return "Account nr. or IBAN:"; @@ -108,6 +114,7 @@ public class BankUtil { public static boolean isAccountTypeRequired(String countryCode) { switch (countryCode) { case "US": + case "BR": return true; default: return false; @@ -117,6 +124,7 @@ public class BankUtil { public static String getAccountTypeLabel(String countryCode) { switch (countryCode) { case "US": + case "BR": return "Account type:"; default: return ""; @@ -126,6 +134,7 @@ public class BankUtil { public static List getAccountTypeValues(String countryCode) { switch (countryCode) { case "US": + case "BR": return Arrays.asList("Checking", "Savings"); default: return new ArrayList<>(); @@ -147,7 +156,7 @@ public class BankUtil { public static String getHolderIdLabel(String countryCode) { switch (countryCode) { case "BR": - return "CPF Number:"; + return "Tax Registration Number (CPF):"; case "CL": return "RUT Number:"; default: diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/BankForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/BankForm.java index 6584026399..579a32c787 100644 --- a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/BankForm.java +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/BankForm.java @@ -77,16 +77,22 @@ abstract class BankForm extends PaymentMethodForm { addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Country of bank:", CountryUtil.getNameAndCode(countryCode)); String bankCodeLabel = BankUtil.getBankIdLabel(countryCode); - if (BankUtil.isBankNameRequired(countryCode) && BankUtil.isBankIdRequired(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)) + } 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)) + } else if (BankUtil.isBankIdRequired(countryCode)) { addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, bankCodeLabel, bankAccountContractData.getBankId()); + } String accountNrLabel = BankUtil.getAccountNrLabel(countryCode); - String branchCodeLabel = BankUtil.getBranchIdLabel(countryCode); String accountTypeLabel = BankUtil.getAccountTypeLabel(countryCode); String accountTypeString = ""; @@ -94,13 +100,14 @@ abstract class BankForm extends PaymentMethodForm { if (BankUtil.isAccountTypeRequired(countryCode)) { accountTypeString = " (" + bankAccountContractData.getAccountType() + ")"; - accountTypeLabelString = " (" + accountTypeLabel + ")"; + accountTypeLabelString = " (" + accountTypeLabel.substring(0, accountTypeLabel.length() - 1) + "):"; } - if (BankUtil.isBranchIdRequired(countryCode)) + if (!branchCodeDisplayed && BankUtil.isBranchIdRequired(countryCode)) addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, branchCodeLabel, bankAccountContractData.getBranchId()); if (BankUtil.isAccountNrRequired(countryCode)) - addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, accountNrLabel + accountTypeLabelString, bankAccountContractData.getAccountNr() + accountTypeString); + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, accountNrLabel.substring(0, accountNrLabel.length() - 1) + + accountTypeLabelString, bankAccountContractData.getAccountNr() + accountTypeString); return gridRow; } diff --git a/gui/src/main/java/io/bitsquare/gui/util/validation/AccountNrValidator.java b/gui/src/main/java/io/bitsquare/gui/util/validation/AccountNrValidator.java index e3473eaa07..d7b9ae5c85 100644 --- a/gui/src/main/java/io/bitsquare/gui/util/validation/AccountNrValidator.java +++ b/gui/src/main/java/io/bitsquare/gui/util/validation/AccountNrValidator.java @@ -36,6 +36,11 @@ public final class AccountNrValidator extends BankValidator { return super.validate(input); else return new ValidationResult(false, BSResources.get("validation.accountNr", "4 - 17")); + case "BR": + if (isStringInRange(input, 1, 20)) + return super.validate(input); + else + return new ValidationResult(false, BSResources.get("validation.accountNrChars", "1 - 20")); default: return super.validate(input); } diff --git a/gui/src/main/java/io/bitsquare/gui/util/validation/BranchIdValidator.java b/gui/src/main/java/io/bitsquare/gui/util/validation/BranchIdValidator.java index 95e7ab5d79..6ca52babba 100644 --- a/gui/src/main/java/io/bitsquare/gui/util/validation/BranchIdValidator.java +++ b/gui/src/main/java/io/bitsquare/gui/util/validation/BranchIdValidator.java @@ -23,17 +23,25 @@ import io.bitsquare.locale.BSResources; public final class BranchIdValidator extends BankValidator { @Override public ValidationResult validate(String input) { + int length; switch (countryCode) { case "GB": - if (isNumberWithFixedLength(input, 6)) + length = 6; + if (isNumberWithFixedLength(input, length)) return super.validate(input); else - return new ValidationResult(false, BSResources.get("validation.sortCode", "Sort code", 6)); + return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", "Sort code", length)); case "US": - if (isNumberWithFixedLength(input, 9)) + length = 9; + if (isNumberWithFixedLength(input, length)) return super.validate(input); else - return new ValidationResult(false, BSResources.get("validation.sortCode", "Routing number", 9)); + return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", "Routing number", 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")); default: return super.validate(input); } diff --git a/gui/src/main/java/io/bitsquare/gui/util/validation/InputValidator.java b/gui/src/main/java/io/bitsquare/gui/util/validation/InputValidator.java index 5fb43471d6..94b2e7df0f 100644 --- a/gui/src/main/java/io/bitsquare/gui/util/validation/InputValidator.java +++ b/gui/src/main/java/io/bitsquare/gui/util/validation/InputValidator.java @@ -77,4 +77,12 @@ public class InputValidator { protected boolean isNumberInRange(String input, int minLength, int maxLength) { return isPositiveNumber(input) && input.length() >= minLength && input.length() <= maxLength; } + + protected boolean isStringWithFixedLength(String input, int length) { + return input != null && input.length() == length; + } + + protected boolean isStringInRange(String input, int minLength, int maxLength) { + return input != null && input.length() >= minLength && input.length() <= maxLength; + } } diff --git a/gui/src/main/resources/i18n/displayStrings.properties b/gui/src/main/resources/i18n/displayStrings.properties index e46b85b80b..e30cad7949 100644 --- a/gui/src/main/resources/i18n/displayStrings.properties +++ b/gui/src/main/resources/i18n/displayStrings.properties @@ -27,8 +27,10 @@ validation.btc.toSmall=Input results in a bitcoin value with a fraction of the s validation.btc.toLarge=Input larger as maximum trading amount of {0} is not allowed. validation.passwordTooShort=The password you entered is too short. It needs to have min. 8 characters. validation.passwordTooLong=The password you entered is too long. It cannot be longer as 50 characters. -validation.sortCode={0} must consist of {1} numbers +validation.sortCodeNumber={0} must consist of {1} numbers +validation.sortCodeChars={0} must consist of {1} characters validation.accountNr=Account number must consist of {0} numbers +validation.accountNrChars=Account number must consist of {0} characters # Create offer createOffer.amount.prompt=Enter amount in BTC