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

Add Validation to BankAccount + CompanyStep + better handling for Plaid #3686

Merged
merged 17 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@ const CONST = {
IOS: 'https://apps.apple.com/us/app/expensify-cash/id1530278510',
DESKTOP: 'https://expensify.cash/Expensify.cash.dmg',
},
DATE: {
MOMENT_FORMAT_STRING: 'YYYY-MM-DD',
},
SMS: {
DOMAIN: '@expensify.sms',
},
BANK_ACCOUNT: {
PLAID: {
ALLOWED_THROTTLED_COUNT: 2,
ERROR: {
TOO_MANY_ATTEMPTS: 'Too many attempts',
},
},
ERROR: {
MISSING_ROUTING_NUMBER: '402 Missing routingNumber',
MAX_ROUTING_NUMBER: '402 Maximum Size Exceeded routingNumber',
MISSING_INCORPORATION_STATE: '402 Missing incorporationState in additionalData',
MISSING_INCORPORATION_TYPE: '402 Missing incorporationType in additionalData',
},
STEP: {
// In the order they appear in the VBA flow
BANK_ACCOUNT: 'BankAccountStep',
Expand Down Expand Up @@ -70,6 +85,7 @@ const CONST = {
HOVERED: 'hovered',
PRESSED: 'pressed',
COMPLETE: 'complete',
DISABLED: 'disabled',
},
COUNTRY: {
US: 'US',
Expand Down Expand Up @@ -170,6 +186,7 @@ const CONST = {
TIMEZONE: 'timeZone',
FREE_PLAN_BANK_ACCOUNT_ID: 'expensify_freePlanBankAccountID',
ACH_DATA_THROTTLED: 'expensify_ACHData_throttled',
BANK_ACCOUNT_GET_THROTTLED: 'private_throttledHistory_BankAccount_Get',
},
DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'},
DEFAULT_ACCOUNT_DATA: {error: '', success: '', loading: false},
Expand Down Expand Up @@ -284,6 +301,10 @@ const CONST = {
US_PHONE: /^\+1\d{10}$/,
PHONE_E164_PLUS: /^\+?[1-9]\d{1,14}$/,
NON_ALPHA_NUMERIC: /[^A-Za-z0-9+]/g,
PO_BOX: /\\b[P|p]?(OST|ost)?\\.?\\s*[O|o|0]?(ffice|FFICE)?\\.?\\s*[B|b][O|o|0]?[X|x]?\\.?\\s+[#]?(\\d+)\\b/,
ANY_VALUE: /^.+$/,
ZIP_CODE: /[0-9]{5}(?:[- ][0-9]{4})?/,
INDUSTRY_CODE: /^[0-9]{6}$/,
},

GROWL: {
Expand Down
9 changes: 3 additions & 6 deletions src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ class AddPlaidBankAccount extends React.Component {

render() {
const accounts = this.getAccounts();
const options = _.chain(accounts)
.filter(account => !account.alreadyExists)
.map((account, index) => ({
value: index, label: `${account.addressName} ${account.accountNumber}`,
}))
.value();
const options = _.map(accounts, (account, index) => ({
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
value: index, label: `${account.addressName} ${account.accountNumber}`,
}));

return (
<>
Expand Down
52 changes: 33 additions & 19 deletions src/components/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const propTypes = {

/** The fill color to pass into the icon. */
iconFill: PropTypes.string,

/** Should we disable this menu item? */
disabled: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -58,6 +61,7 @@ const defaultProps = {
iconRight: ArrowRight,
iconStyles: [],
iconFill: undefined,
disabled: false,
};

const MenuItem = ({
Expand All @@ -73,35 +77,42 @@ const MenuItem = ({
description,
iconStyles,
iconFill,
disabled,
}) => (
<Pressable
onPress={onPress}
onPress={(e) => {
if (disabled) {
return;
}

onPress(e);
}}
style={({hovered, pressed}) => ([
styles.createMenuItem,
getButtonBackgroundColorStyle(getButtonState(hovered, pressed)),
getButtonBackgroundColorStyle(getButtonState(hovered, pressed, success, disabled)),
wrapperStyle,
])}
>
{({hovered, pressed}) => (
<>
<View style={styles.flexRow}>
{icon && (
<View
style={[
styles.createMenuIcon,
...iconStyles,
]}
>
<Icon
src={icon}
width={iconWidth}
height={iconHeight}
fill={iconFill || getIconFillColor(getButtonState(hovered, pressed, success))}
/>
</View>
<View
style={[
styles.createMenuIcon,
...iconStyles,
]}
>
<Icon
src={icon}
width={iconWidth}
height={iconHeight}
fill={iconFill || getIconFillColor(getButtonState(hovered, pressed, success, disabled))}
/>
</View>
)}
<View style={[styles.justifyContentCenter, styles.menuItemTextContainer]}>
<Text style={[styles.createMenuText, styles.ml3]}>
<Text style={[styles.createMenuText, styles.ml3, (disabled ? styles.disabledText : undefined)]}>
{title}
</Text>
{description && (
Expand All @@ -112,9 +123,12 @@ const MenuItem = ({
</View>
</View>
{shouldShowRightIcon && (
<View style={styles.createMenuIcon}>
<Icon src={iconRight} fill={getIconFillColor(getButtonState(hovered, pressed))} />
</View>
<View style={styles.createMenuIcon}>
<Icon
src={iconRight}
fill={getIconFillColor(getButtonState(hovered, pressed, success, disabled))}
/>
</View>
)}
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Onfido/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Onfido extends React.Component {
onComplete: this.props.onSuccess,
onError: () => {
this.props.onUserExit();
Growl.show(this.props.translate('onfidoStep.genericError'), CONST.GROWL.ERROR);
Growl.error(this.props.translate('onfidoStep.genericError'));
},
onUserExit: this.props.onUserExit,
onModalRequestClose: () => {},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Onfido/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Onfido extends React.Component {
.catch((error) => {
if (error.message === CONST.ONFIDO.ERROR.USER_CANCELLED) {
this.props.onUserExit();
Growl.show(this.props.translate('onfidoStep.genericError'), CONST.GROWL.ERROR);
Growl.error(this.props.translate('onfidoStep.genericError'));
}
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/TextInputFocusable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import _ from 'underscore';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import Growl from '../../libs/Growl';
import themeColors from '../../styles/themes/default';
import CONST from '../../CONST';

const propTypes = {
/** Maximum number of lines in the text input */
Expand Down Expand Up @@ -230,7 +229,7 @@ class TextInputFocusable extends React.Component {
.then(this.props.onPasteFile)
.catch(() => {
const errorDesc = this.props.translate('textInputFocusable.problemGettingImageYouPasted');
Growl.show(errorDesc, CONST.GROWL.ERROR);
Growl.error(errorDesc);

/*
* Since we intercepted the user-triggered paste event to check for attachments,
Expand Down
16 changes: 16 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ export default {
checkHelpLine: 'Your routing number and account number can be found on a check for the account.',
hasPhoneLoginError: 'To add a verified bank account please ensure your primary login is a valid email and try again. You can add your phone number as a secondary login.',
hasBeenThrottledError: ({fromNow}) => `For security reasons, we're taking a break from bank account setup so you can double-check your company information. Please try again ${fromNow}. Sorry!`,
error: {
noBankAccountAvailable: 'Sorry, no bank account is available',
taxID: 'Please enter a valid Tax ID Number',
website: 'Please enter a valid website',
zipCode: 'Please enter a valid zip code',
addressStreet: 'Please enter a valid address street that is not a PO Box',
incorporationDate: 'Please enter a valid incorporation date',
incorporationState: 'Please enter a valid Incorporation State',
industryCode: 'Please enter a valid industry classification code',
restrictedBusiness: 'Please confirm company is not on the list of restricted businesses',
routingNumber: 'Please enter a valid Routing Number',
companyType: 'Please enter a valid Company Type',
tooManyAttempts: 'Due to a high number of login attempts, this option has been temporarily disabled for 24 hours. Please try again later or manually enter details instead.',
},
},
addPersonalBankAccountPage: {
enterPassword: 'Enter password',
Expand Down Expand Up @@ -351,6 +365,8 @@ export default {
industryClassificationCode: 'Industry Classification Code',
confirmCompanyIsNot: 'I confirm that this company is not on the',
listOfRestrictedBusinesses: 'list of restricted businesses',
incorporationDatePlaceholder: 'Start date (yyyy-mm-dd)',
companyPhonePlaceholder: '10 digits, no hyphens',
},
requestorStep: {
headerTitle: 'Requestor Information',
Expand Down
16 changes: 16 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ export default {
checkHelpLine: 'Su número de ruta y número de cuenta se pueden encontrar en un cheque para la cuenta.',
hasPhoneLoginError: 'Para agregar una cuenta bancaria verificada, asegúrese de que su inicio de sesión principal sea un correo electrónico válido y vuelva a intentarlo. Puede agregar su número de teléfono como inicio de sesión secundario.',
hasBeenThrottledError: ({fromNow}) => `Por razones de seguridad, nos tomamos un descanso de la configuración de la cuenta bancaria para que pueda verificar la información de su empresa. Inténtalo de nuevo ${fromNow}. ¡Lo siento!`,
error: {
noBankAccountAvailable: 'Lo sentimos, no hay ninguna cuenta bancaria disponible',
taxID: 'Ingrese un número de identificación fiscal válido',
website: 'Ingrese un sitio web válido',
zipCode: 'Ingrese un código postal válido',
addressStreet: 'Ingrese una calle de dirección válida que no sea un apartado postal',
incorporationDate: 'Ingrese una fecha de incorporación válida',
incorporationState: 'Ingrese un estado de incorporación válido',
industryCode: 'Ingrese un código de clasificación de industria válido',
restrictedBusiness: 'Confirme que la empresa no está en la lista de negocios restringidos',
routingNumber: 'Ingrese un número de ruta válido',
companyType: 'Ingrese un tipo de compañía válido',
tooManyAttempts: 'Debido a la gran cantidad de intentos de inicio de sesión, esta opción se ha desactivado temporalmente durante 24 horas. Vuelva a intentarlo más tarde o introduzca los detalles manualmente.',
},
},
addPersonalBankAccountPage: {
enterPassword: 'Escribe una contraseña',
Expand Down Expand Up @@ -351,5 +365,7 @@ export default {
industryClassificationCode: 'Código de Clasificación Industrial',
confirmCompanyIsNot: 'Confirmo que esta empresa no está en el',
listOfRestrictedBusinesses: 'lista de negocios restringidos',
incorporationDatePlaceholder: 'Fecha de inicio (aaaa-mm-dd)',
companyPhonePlaceholder: '10 dígitos, sin guiones',
},
};
14 changes: 13 additions & 1 deletion src/libs/Growl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@ function show(bodyText, type, duration = CONST.GROWL.DURATION) {
growlRef.current.show(bodyText, type, duration);
}

/**
* Show error growl
*
* @param {String} bodyText
* @param {Number} [duration]
*/
function error(bodyText, duration = CONST.GROWL.DURATION) {
show(bodyText, CONST.GROWL.ERROR, duration);
}

export default {show};
export default {
show,
error,
};
40 changes: 40 additions & 0 deletions src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import moment from 'moment';
import CONST from '../CONST';

/**
* Validating that this is a valid address (PO boxes are not allowed)
*
* @param {String} value
* @returns {Boolean}
*/
function isValidAddress(value) {
if (!CONST.REGEX.ANY_VALUE.test(value)) {
return false;
}

return !CONST.REGEX.PO_BOX.test(value);
}

/**
* Validate date fields
*
* @param {String} date
* @returns {Boolean} true if valid
*/
function isValidDate(date) {
return moment(date).isValid();
}

/**
* @param {String} code
* @returns {Boolean}
*/
function isValidIndustryCode(code) {
return CONST.REGEX.INDUSTRY_CODE.test(code);
}

export {
isValidAddress,
isValidDate,
isValidIndustryCode,
};
Loading