From 6c855239f1efbc7ab9a079c177292309297c2ca1 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 6 Sep 2022 15:13:56 +0100 Subject: [PATCH 01/12] rm deprecated validateBankAccount --- src/libs/actions/BankAccounts.js | 1 - .../actions/ReimbursementAccount/index.js | 2 - .../validateBankAccount.js | 54 ------------------- src/libs/deprecatedAPI.js | 6 --- 4 files changed, 63 deletions(-) delete mode 100644 src/libs/actions/ReimbursementAccount/validateBankAccount.js diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 43b8b7d2c056..c597429a2614 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -13,7 +13,6 @@ export { setBankAccountFormValidationErrors, resetReimbursementAccount, resetFreePlanBankAccount, - validateBankAccount, hideBankAccountErrors, setWorkspaceIDForReimbursementAccount, setBankAccountSubStep, 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 26a25ff2c9e7..ee971b76b0ba 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} From d46606ed1a61c1845faa5da1fab89a295d734204 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 6 Sep 2022 15:20:48 +0100 Subject: [PATCH 02/12] create new api method --- src/CONST.js | 1 + src/libs/actions/BankAccounts.js | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/CONST.js b/src/CONST.js index a575a51cf1c6..867b719bdb5d 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -97,6 +97,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 c597429a2614..eb85cb28f20a 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -113,9 +113,43 @@ 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: { + errors: null, + achData: { + state: CONST.BANK_ACCOUNT.STATE.OPEN, + currentStep: CONST.BANK_ACCOUNT.STEP.ENABLE, + }, + }, + }], + failureData: [{ + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + achData: { + state: CONST.BANK_ACCOUNT.STATE.VERIFYING, + currentStep: CONST.BANK_ACCOUNT.STEP.VALIDATION, + }, + }, + }], + }); +} + export { addPersonalBankAccount, deletePaymentBankAccount, clearPersonalBankAccount, clearPlaid, + validateBankAccount, }; From 513ac116c03b584acc74e33622702c396fe1aa8d Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 6 Sep 2022 15:35:22 +0100 Subject: [PATCH 03/12] fix lint --- src/libs/deprecatedAPI.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index ee971b76b0ba..1604ccb27765 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -597,7 +597,6 @@ function GetStatementPDF(parameters) { export { BankAccount_SetupWithdrawal, - BankAccount_Validate, ChangePassword, CreateChatReport, CreateLogin, From 85b2f50d5230e6685ea81835cb484551cf58c47b Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 6 Sep 2022 15:52:21 +0100 Subject: [PATCH 04/12] fix lint --- src/pages/ReimbursementAccount/ValidationStep.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/ReimbursementAccount/ValidationStep.js b/src/pages/ReimbursementAccount/ValidationStep.js index 4a827780018c..e78aafee36d8 100644 --- a/src/pages/ReimbursementAccount/ValidationStep.js +++ b/src/pages/ReimbursementAccount/ValidationStep.js @@ -27,6 +27,7 @@ import Section from '../../components/Section'; import CONST from '../../CONST'; import Button from '../../components/Button'; import MenuItem from '../../components/MenuItem'; +import OfflineWithFeedback from '../../components/OfflineWithFeedback'; const propTypes = { ...withLocalizePropTypes, @@ -175,6 +176,10 @@ class ValidationStep extends React.Component { shouldShowBackButton shouldShowStepCounter={!isVerifying} /> + {/* */} {maxAttemptsReached && ( From 2857702c458d9f660ccdba5a7cb8229d91b55c4f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 6 Sep 2022 15:53:17 +0100 Subject: [PATCH 05/12] rm unused component --- src/pages/ReimbursementAccount/ValidationStep.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pages/ReimbursementAccount/ValidationStep.js b/src/pages/ReimbursementAccount/ValidationStep.js index e78aafee36d8..4a827780018c 100644 --- a/src/pages/ReimbursementAccount/ValidationStep.js +++ b/src/pages/ReimbursementAccount/ValidationStep.js @@ -27,7 +27,6 @@ import Section from '../../components/Section'; import CONST from '../../CONST'; import Button from '../../components/Button'; import MenuItem from '../../components/MenuItem'; -import OfflineWithFeedback from '../../components/OfflineWithFeedback'; const propTypes = { ...withLocalizePropTypes, @@ -176,10 +175,6 @@ class ValidationStep extends React.Component { shouldShowBackButton shouldShowStepCounter={!isVerifying} /> - {/* */} {maxAttemptsReached && ( From d58f41bcfcbc0c906b27dc2831b6b9a3e23970d9 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 7 Sep 2022 13:16:55 +0100 Subject: [PATCH 06/12] add proptypes, loading state, change to pattern c --- src/libs/actions/BankAccounts.js | 18 +++++++++--------- .../ReimbursementAccountForm.js | 2 +- .../reimbursementAccountPropTypes.js | 6 ++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index eb85cb28f20a..eb95a22e1d7e 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -126,21 +126,21 @@ function validateBankAccount(bankAccountID, validateCode) { onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, value: { - errors: null, - achData: { - state: CONST.BANK_ACCOUNT.STATE.OPEN, - currentStep: CONST.BANK_ACCOUNT.STEP.ENABLE, - }, + isLoading: true, + }, + }], + successData: [{ + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: false, }, }], failureData: [{ onyxMethod: CONST.ONYX.METHOD.MERGE, key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, value: { - achData: { - state: CONST.BANK_ACCOUNT.STATE.VERIFYING, - currentStep: CONST.BANK_ACCOUNT.STEP.VALIDATION, - }, + isLoading: false, }, }], }); diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js index 4969ccd77c45..25179e16e8c2 100644 --- a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js +++ b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js @@ -60,7 +60,7 @@ class ReimbursementAccountForm extends React.Component { }} message={this.props.reimbursementAccount.error} 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, ])), }); From 55c9fdd4e7a87126466bdee9902066e48ce943f9 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 7 Sep 2022 15:29:09 +0100 Subject: [PATCH 07/12] display errors --- src/pages/ReimbursementAccount/ReimbursementAccountForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js index 25179e16e8c2..f7e29bdd2ced 100644 --- a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js +++ b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js @@ -58,7 +58,7 @@ class ReimbursementAccountForm extends React.Component { onFixTheErrorsLinkPressed={() => { this.form.scrollTo({y: 0, animated: true}); }} - message={this.props.reimbursementAccount.error} + message={this.props.reimbursementAccount.error || _.values(this.props.reimbursementAccount.errors)[0]} isMessageHtml={this.props.reimbursementAccount.isErrorHtml} isLoading={this.props.reimbursementAccount.loading || this.props.reimbursementAccount.isLoading} /> From dd75b944a9c0de00e1aa25ae600364ffc16ebfc4 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 7 Sep 2022 15:30:20 +0100 Subject: [PATCH 08/12] rm error on resubmit --- src/libs/actions/BankAccounts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index eb95a22e1d7e..38c63a9a7723 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -127,6 +127,7 @@ function validateBankAccount(bankAccountID, validateCode) { key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, value: { isLoading: true, + errors: null, }, }], successData: [{ From ab9fb29779fd252c0ee3bfaa58d50d9b0a29e981 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 14 Sep 2022 15:12:52 -0600 Subject: [PATCH 09/12] add errorutils --- src/pages/ReimbursementAccount/ReimbursementAccountForm.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js index f7e29bdd2ced..5b44e4b55571 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 */ @@ -58,7 +59,7 @@ class ReimbursementAccountForm extends React.Component { onFixTheErrorsLinkPressed={() => { this.form.scrollTo({y: 0, animated: true}); }} - message={this.props.reimbursementAccount.error || _.values(this.props.reimbursementAccount.errors)[0]} + message={this.props.reimbursementAccount.error || ErrorUtils.getLastestErrorMessage(this.props.reimbursementAccount.errors)} isMessageHtml={this.props.reimbursementAccount.isErrorHtml} isLoading={this.props.reimbursementAccount.loading || this.props.reimbursementAccount.isLoading} /> From f6dd0d7b8da5b9f2aedce6a6e23faa401842e4f8 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 14 Sep 2022 15:15:03 -0600 Subject: [PATCH 10/12] fix function name --- src/pages/ReimbursementAccount/ReimbursementAccountForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js index 5b44e4b55571..3542131a5710 100644 --- a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js +++ b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js @@ -59,7 +59,7 @@ class ReimbursementAccountForm extends React.Component { onFixTheErrorsLinkPressed={() => { this.form.scrollTo({y: 0, animated: true}); }} - message={this.props.reimbursementAccount.error || ErrorUtils.getLastestErrorMessage(this.props.reimbursementAccount.errors)} + message={this.props.reimbursementAccount.error || ErrorUtils.getLatestErrorMessage(this.props.reimbursementAccount.errors)} isMessageHtml={this.props.reimbursementAccount.isErrorHtml} isLoading={this.props.reimbursementAccount.loading || this.props.reimbursementAccount.isLoading} /> From 3c097924a3403d1db36f3e8fded9b668f36143b3 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 14 Sep 2022 15:56:47 -0600 Subject: [PATCH 11/12] use correct error path, create getErrorMessage --- src/pages/ReimbursementAccount/ReimbursementAccountForm.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js index 3542131a5710..48c24e620a29 100644 --- a/src/pages/ReimbursementAccount/ReimbursementAccountForm.js +++ b/src/pages/ReimbursementAccount/ReimbursementAccountForm.js @@ -34,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; @@ -59,7 +64,7 @@ class ReimbursementAccountForm extends React.Component { onFixTheErrorsLinkPressed={() => { this.form.scrollTo({y: 0, animated: true}); }} - message={this.props.reimbursementAccount.error || ErrorUtils.getLatestErrorMessage(this.props.reimbursementAccount.errors)} + message={this.getErrorMessage()} isMessageHtml={this.props.reimbursementAccount.isErrorHtml} isLoading={this.props.reimbursementAccount.loading || this.props.reimbursementAccount.isLoading} /> From 5ed68a88b722a944020c1739ed53bf17388ecc19 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 15 Sep 2022 09:13:47 -0600 Subject: [PATCH 12/12] rm unused consts --- src/CONST.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index dc1a653bcd4e..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