Skip to content

Commit

Permalink
Merge pull request #6230 from Expensify/marcaaron-vbaRefactor
Browse files Browse the repository at this point in the history
Improve VBA logic
  • Loading branch information
marcaaron committed Dec 1, 2021
2 parents c2b96c1 + 8f5a450 commit 0360fd7
Show file tree
Hide file tree
Showing 17 changed files with 1,517 additions and 887 deletions.
2 changes: 1 addition & 1 deletion src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class AddPlaidBankAccount extends React.Component {
token={this.props.plaidLinkToken}
onSuccess={({publicToken, metadata}) => {
Log.info('[PlaidLink] Success!');
BankAccounts.getPlaidBankAccounts(publicToken, metadata.institution.name);
BankAccounts.fetchPlaidBankAccounts(publicToken, metadata.institution.name);
this.setState({institution: metadata.institution});
}}
onError={(error) => {
Expand Down
23 changes: 23 additions & 0 deletions src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ function isValidLengthForFirstOrLastName(name) {
return name.length <= 50;
}

/**
* Checks the given number is a valid US Routing Number
* using ABA routingNumber checksum algorithm: http://www.brainjar.com/js/validation/
* @param {String} number
* @returns {Boolean}
*/
function isValidRoutingNumber(number) {
let n = 0;
for (let i = 0; i < number.length; i += 3) {
n += (parseInt(number.charAt(i), 10) * 3)
+ (parseInt(number.charAt(i + 1), 10) * 7)
+ parseInt(number.charAt(i + 2), 10);
}

// If the resulting sum is an even multiple of ten (but not zero),
// the ABA routing number is valid.
if (n !== 0 && n % 10 === 0) {
return true;
}
return false;
}

export {
meetsAgeRequirements,
isValidAddress,
Expand All @@ -293,4 +315,5 @@ export {
isNumericWithSpecialChars,
isValidLengthForFirstOrLastName,
isValidPaypalUsername,
isValidRoutingNumber,
};
Loading

0 comments on commit 0360fd7

Please sign in to comment.