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

Improve VBA logic #6230

Merged
merged 20 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 14 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
4 changes: 2 additions & 2 deletions src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import PlaidLink from './PlaidLink';
import {
clearPlaidBankAccountsAndToken,
fetchPlaidLinkToken,
getPlaidBankAccounts,
fetchPlaidBankAccounts,
setBankAccountFormValidationErrors,
showBankAccountErrorModal,
} from '../libs/actions/BankAccounts';
Expand Down Expand Up @@ -165,7 +165,7 @@ class AddPlaidBankAccount extends React.Component {
token={this.props.plaidLinkToken}
onSuccess={({publicToken, metadata}) => {
Log.info('[PlaidLink] Success!');
getPlaidBankAccounts(publicToken, metadata.institution.name);
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 @@ -248,6 +248,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 @@ -265,4 +287,5 @@ export {
isNumericWithSpecialChars,
isValidLengthForFirstOrLastName,
isValidPaypalUsername,
isValidRoutingNumber,
};
Loading