-
Notifications
You must be signed in to change notification settings - Fork 13
fix: should be clearer for US users how to enter their bank account #514
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -34,7 +34,9 @@ const GeneralRecipientInput = ({ placeholder, recipient, onUpdate, className }: | |||||||||||||||||||||||||||
type = 'iban' | ||||||||||||||||||||||||||||
isValid = await utils.validateBankAccount(recipient) | ||||||||||||||||||||||||||||
if (!isValid) errorMessage.current = 'Invalid IBAN, country not supported' | ||||||||||||||||||||||||||||
} else if (/^[0-9]{6,17}$/.test(recipient)) { | ||||||||||||||||||||||||||||
} else if (/^[0-9]{6,26}$/.test(recipient)) { | ||||||||||||||||||||||||||||
// routing number: 9 digits | ||||||||||||||||||||||||||||
// account number: 8-12 digits (can go up to 17) | ||||||||||||||||||||||||||||
type = 'us' | ||||||||||||||||||||||||||||
isValid = await utils.validateBankAccount(recipient) | ||||||||||||||||||||||||||||
if (!isValid) errorMessage.current = 'Invalid US account number' | ||||||||||||||||||||||||||||
Comment on lines
+37
to
42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding routing number validation To further improve validation accuracy and user experience, consider adding specific routing number validation. Add a helper function to validate the routing number format: const isValidRoutingNumber = (routing: string): boolean => {
if (!/^\d{9}$/.test(routing)) return false;
// Implement checksum validation
// Each routing number contains a checksum as its last digit
const digits = routing.split('').map(Number);
const checksum = (
7 * (digits[0] + digits[3] + digits[6]) +
3 * (digits[1] + digits[4] + digits[7]) +
9 * (digits[2] + digits[5])
) % 10;
return checksum === digits[8];
}; Then update the validation: } else if (/^[0-9]{9}[0-9]{8,12}$/.test(recipient)) {
type = 'us'
+ const routingNumber = recipient.slice(0, 9);
+ if (!isValidRoutingNumber(routingNumber)) {
+ errorMessage.current = 'Invalid routing number. Please check and try again.';
+ return false;
+ }
isValid = await utils.validateBankAccount(recipient) Strengthen the US bank account validation logic The current validation has several potential issues:
Consider implementing this more robust validation: -} else if (/^[0-9]{6,26}$/.test(recipient)) {
- // routing number: 9 digits
- // account number: 8-12 digits (can go up to 17)
+} else if (/^[0-9]{9}[0-9]{8,12}$/.test(recipient)) {
+ // Validate US bank account format:
+ // First 9 digits: routing number
+ // Following 8-12 digits: account number
type = 'us'
isValid = await utils.validateBankAccount(recipient)
- if (!isValid) errorMessage.current = 'Invalid US account number'
+ if (!isValid) errorMessage.current = 'Please enter your 9-digit routing number followed by your 8-12 digit account number' This change:
📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,8 @@ export const GlobaLinkAccountComponent = ({ accountNumber, onCompleted }: IGloba | |
|
||
if (isIBAN(sanitizedAccountNumber)) { | ||
setAccountDetailsValue('type', 'iban') | ||
} else if (/^[0-9]{6,17}$/.test(sanitizedAccountNumber)) { | ||
// this code is also repeated in GeneralRecipientInput.tsx | ||
} else if (/^[0-9]{6,26}$/.test(sanitizedAccountNumber)) { | ||
Comment on lines
+101
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Extract shared validation logic into a common utility. The comment indicates code duplication between components. Consider extracting the bank account validation logic into a shared utility function to improve maintainability. // Create a new file: src/utils/bankValidation.ts
+export const validateBankAccountFormat = (accountNumber: string): { isValid: boolean; type: 'iban' | 'us' | null } => {
+ const sanitizedAccount = accountNumber.replaceAll(/\s/g, '').toLowerCase()
+ if (isIBAN(sanitizedAccount)) {
+ return { isValid: true, type: 'iban' }
+ }
+ if (/^[0-9]{6,26}$/.test(sanitizedAccount)) {
+ return { isValid: true, type: 'us' }
+ }
+ return { isValid: false, type: null }
+}
// In LinkAccountComponent and GeneralRecipientInput:
-// this code is also repeated in GeneralRecipientInput.tsx
-} else if (/^[0-9]{6,26}$/.test(sanitizedAccountNumber)) {
+const validation = validateBankAccountFormat(accountNumber)
+if (validation.isValid) {
+ setAccountDetailsValue('type', validation.type)
|
||
setAccountDetailsValue('type', 'us') | ||
} else { | ||
setIbanFormError('accountNumber', { message: 'Invalid account number' }) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: These checks may prove not to be enough down the line (as more geographies are added, maybe there is overlap in format detection). For now, I'm good with this.