From 9adaa96fc435de40f43773435931a960ab44175b Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Fri, 6 Aug 2021 15:04:57 -0700 Subject: [PATCH 1/4] Autofill previously entered accounting and routing numbers --- src/libs/actions/BankAccounts.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index b3f016ac3ab4..775ae2adf5a1 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -328,6 +328,11 @@ function fetchUserWallet() { * @param {String} [stepToOpen] */ function fetchFreePlanVerifiedBankAccount(stepToOpen) { + const oldACHData = { + accountNumber: reimbursementAccountInSetup.accountNumber || '', + routingNumber: reimbursementAccountInSetup.routingNumber || '', + }; + // We are using set here since we will rely on data from the server (not local data) to populate the VBA flow // and determine which step to navigate to. Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: true}); @@ -478,7 +483,18 @@ function fetchFreePlanVerifiedBankAccount(stepToOpen) { goToWithdrawalAccountSetupStep(currentStep, achData); }) .finally(() => { - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false}); + const dataToMerge = { + loading: false, + }; + + // If we didn't get a routingNumber and accountNumber from the response and we have previously saved + // values, autofill them + if (!reimbursementAccountInSetup.routingNumber && !reimbursementAccountInSetup.accountNumber + && oldACHData.routingNumber && oldACHData.accountNumber) { + dataToMerge.achData = oldACHData; + } + + Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, dataToMerge); }); }); } From 4b9ff3f4285c3abef8326f02c40ba9892c32927f Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Mon, 9 Aug 2021 12:36:41 -0700 Subject: [PATCH 2/4] fix incorrect center-align --- src/pages/ReimbursementAccount/CompanyStep.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index c0fc39effba9..17ba221df5a5 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -137,9 +137,7 @@ class CompanyStep extends React.Component { /> - - {this.props.translate('companyStep.subtitle')} - + {this.props.translate('companyStep.subtitle')} Date: Mon, 9 Aug 2021 13:32:24 -0700 Subject: [PATCH 3/4] ensure merge finishes before continuing --- src/libs/actions/BankAccounts.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 775ae2adf5a1..1e64727e5dce 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -619,8 +619,16 @@ function setupWithdrawalAccount(data) { API.BankAccount_SetupWithdrawal(newACHData) .then((response) => { - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, achData: {...newACHData}}); - + // Ensure that we don't continue until the merge is complete, this prevents the achData from getting + // overwritten later on in the flow before this merge happens + return Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, { + loading: false, + achData: {...newACHData}, + }) + .then(() => { + return Promise.resolve(response); + }); + }).then((response) => { const currentStep = newACHData.currentStep; let achData = lodashGet(response, 'achData', {}); let error = lodashGet(achData, CONST.BANK_ACCOUNT.VERIFICATIONS.ERROR_MESSAGE); From f5bb5345f0319deeec2d9d64d78363a3daecadcf Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Mon, 9 Aug 2021 13:48:47 -0700 Subject: [PATCH 4/4] lint and comments --- src/libs/actions/BankAccounts.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 1e64727e5dce..513045372f31 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -618,17 +618,18 @@ function setupWithdrawalAccount(data) { } API.BankAccount_SetupWithdrawal(newACHData) + /* eslint-disable arrow-body-style */ .then((response) => { - // Ensure that we don't continue until the merge is complete, this prevents the achData from getting - // overwritten later on in the flow before this merge happens + // Without this block, we can call merge again with the achData before this merge finishes, resulting in + // the original achData overwriting the data we're trying to set here. With this block, we ensure that the + // newACHData is set in Onyx before we call merge on the reimbursementAccount key again. return Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, { loading: false, achData: {...newACHData}, }) - .then(() => { - return Promise.resolve(response); - }); - }).then((response) => { + .then(() => Promise.resolve(response)); + }) + .then((response) => { const currentStep = newACHData.currentStep; let achData = lodashGet(response, 'achData', {}); let error = lodashGet(achData, CONST.BANK_ACCOUNT.VERIFICATIONS.ERROR_MESSAGE);