diff --git a/src/CONST.js b/src/CONST.js index 89fc0e3e8317..c0b07509bd72 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -52,8 +52,6 @@ const CONST = { MAX_ROUTING_NUMBER: '402 Maximum Size Exceeded routingNumber', MISSING_INCORPORATION_STATE: '402 Missing incorporationState in additionalData', MISSING_INCORPORATION_TYPE: '402 Missing incorporationType in additionalData', - MAX_VALIDATION_ATTEMPTS_REACHED: 'Validation for this bank account has been disabled due to too many incorrect attempts. Please contact us.', - INCORRECT_VALIDATION_AMOUNTS: 'The validate code you entered is incorrect, please try again.', }, STEP: { // In the order they appear in the VBA flow @@ -97,6 +95,7 @@ const CONST = { STATE: { VERIFYING: 'VERIFYING', PENDING: 'PENDING', + OPEN: 'OPEN', }, MAX_LENGTH: { SSN: 4, diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index d2242b028962..7b52777e6e18 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -14,7 +14,6 @@ export { setBankAccountFormValidationErrors, resetReimbursementAccount, resetFreePlanBankAccount, - validateBankAccount, hideBankAccountErrors, setWorkspaceIDForReimbursementAccount, setBankAccountSubStep, @@ -159,9 +158,44 @@ function deletePaymentBankAccount(bankAccountID) { }); } +/** + * @param {Number} bankAccountID + * @param {String} validateCode + */ +function validateBankAccount(bankAccountID, validateCode) { + API.write('ValidateBankAccountWithTransactions', { + bankAccountID, + validateCode, + }, { + optimisticData: [{ + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: true, + errors: null, + }, + }], + successData: [{ + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: false, + }, + }], + failureData: [{ + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: false, + }, + }], + }); +} + export { addPersonalBankAccount, deletePaymentBankAccount, clearPersonalBankAccount, clearPlaid, + validateBankAccount, }; diff --git a/src/libs/actions/ReimbursementAccount/index.js b/src/libs/actions/ReimbursementAccount/index.js index 40481a15a06a..50bbae591692 100644 --- a/src/libs/actions/ReimbursementAccount/index.js +++ b/src/libs/actions/ReimbursementAccount/index.js @@ -1,6 +1,5 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../../ONYXKEYS'; -import validateBankAccount from './validateBankAccount'; import setupWithdrawalAccount from './setupWithdrawalAccount'; import fetchFreePlanVerifiedBankAccount from './fetchFreePlanVerifiedBankAccount'; import resetFreePlanBankAccount from './resetFreePlanBankAccount'; @@ -57,7 +56,6 @@ export { setupWithdrawalAccount, fetchFreePlanVerifiedBankAccount, resetFreePlanBankAccount, - validateBankAccount, setBankAccountSubStep, hideBankAccountErrors, setWorkspaceIDForReimbursementAccount, diff --git a/src/libs/actions/ReimbursementAccount/validateBankAccount.js b/src/libs/actions/ReimbursementAccount/validateBankAccount.js deleted file mode 100644 index ace044899289..000000000000 --- a/src/libs/actions/ReimbursementAccount/validateBankAccount.js +++ /dev/null @@ -1,54 +0,0 @@ -import Onyx from 'react-native-onyx'; -import ONYXKEYS from '../../../ONYXKEYS'; -import * as DeprecatedAPI from '../../deprecatedAPI'; -import BankAccount from '../../models/BankAccount'; -import CONST from '../../../CONST'; -import * as Localize from '../../Localize'; -import * as errors from './errors'; - -/** - * @param {Number} bankAccountID - * @param {String} validateCode - */ -function validateBankAccount(bankAccountID, validateCode) { - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: true}); - - DeprecatedAPI.BankAccount_Validate({bankAccountID, validateCode}) - .then((response) => { - if (response.jsonCode === 200) { - Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, null); - DeprecatedAPI.User_IsUsingExpensifyCard() - .then(({isUsingExpensifyCard}) => { - const reimbursementAccount = { - loading: false, - error: '', - achData: {state: BankAccount.STATE.OPEN}, - }; - - reimbursementAccount.achData.currentStep = CONST.BANK_ACCOUNT.STEP.ENABLE; - Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, reimbursementAccount); - }); - return; - } - - // User has input the validate code incorrectly many times so we will return early in this case and not let them enter the amounts again. - if (response.message === CONST.BANK_ACCOUNT.ERROR.MAX_VALIDATION_ATTEMPTS_REACHED) { - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, maxAttemptsReached: true}); - return; - } - - // If the validation amounts entered were incorrect, show specific error - if (response.message === CONST.BANK_ACCOUNT.ERROR.INCORRECT_VALIDATION_AMOUNTS) { - errors.showBankAccountErrorModal(Localize.translateLocal('bankAccount.error.validationAmounts')); - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false}); - return; - } - - // We are generically showing any other backend errors that might pop up in the validate step - errors.showBankAccountErrorModal(response.message); - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false}); - }); -} - -export default validateBankAccount; diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index dffae4360b76..08ec5972cb9e 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -412,12 +412,6 @@ function Policy_Employees_Merge(parameters) { return Network.post(commandName, {...parameters, returnPersonalDetails: true}); } -function BankAccount_Validate(parameters) { - const commandName = 'ValidateBankAccount'; - requireParameters(['bankAccountID', 'validateCode'], parameters, commandName); - return Network.post(commandName, parameters, CONST.NETWORK.METHOD.POST); -} - /** * @param {*} parameters * @returns {Promise} @@ -592,7 +586,6 @@ function GetStatementPDF(parameters) { export { BankAccount_SetupWithdrawal, - BankAccount_Validate, ChangePassword, CreateChatReport, CreateLogin, diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js index 4969ccd77c45..48c24e620a29 100644 --- a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js +++ b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js @@ -13,6 +13,7 @@ import FormAlertWithSubmitButton from '../../components/FormAlertWithSubmitButto import CONST from '../../CONST'; import FormScrollView from '../../components/FormScrollView'; import * as BankAccounts from '../../libs/actions/BankAccounts'; +import * as ErrorUtils from '../../libs/ErrorUtils'; const propTypes = { /** Data for the bank account actively being set up */ @@ -33,6 +34,11 @@ class ReimbursementAccountForm extends React.Component { BankAccounts.resetReimbursementAccount(); } + getErrorMessage() { + const latestErrorMessage = ErrorUtils.getLatestErrorMessage(this.props.reimbursementAccount); + return this.props.reimbursementAccount.error || (typeof latestErrorMessage === 'string' ? latestErrorMessage : ''); + } + render() { const isErrorVisible = _.size(lodashGet(this.props, 'reimbursementAccount.errors', {})) > 0 || lodashGet(this.props, 'reimbursementAccount.error', '').length > 0; @@ -58,9 +64,9 @@ class ReimbursementAccountForm extends React.Component { onFixTheErrorsLinkPressed={() => { this.form.scrollTo({y: 0, animated: true}); }} - message={this.props.reimbursementAccount.error} + message={this.getErrorMessage()} isMessageHtml={this.props.reimbursementAccount.isErrorHtml} - isLoading={this.props.reimbursementAccount.loading} + isLoading={this.props.reimbursementAccount.loading || this.props.reimbursementAccount.isLoading} /> ); diff --git a/src/pages/ReimbursementAccount/reimbursementAccountPropTypes.js b/src/pages/ReimbursementAccount/reimbursementAccountPropTypes.js index 2f9595d8baf0..79e7dff36a3d 100644 --- a/src/pages/ReimbursementAccount/reimbursementAccountPropTypes.js +++ b/src/pages/ReimbursementAccount/reimbursementAccountPropTypes.js @@ -31,5 +31,11 @@ export default PropTypes.shape({ errors: PropTypes.objectOf(PropTypes.oneOfType([ PropTypes.bool, PropTypes.arrayOf(PropTypes.objectOf(PropTypes.bool)), + + /** + * Errors from api calls on the specific user + * {: 'error message', : 'error message 2'} + */ + PropTypes.string, ])), });