Skip to content

Commit

Permalink
Merge pull request #4477 from Expensify/joe-save-bank-details
Browse files Browse the repository at this point in the history
Autofill previously entered accounting and routing numbers
  • Loading branch information
Julesssss authored Aug 10, 2021
2 parents 4350c9a + a905816 commit 1de3e10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
31 changes: 28 additions & 3 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,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});
Expand Down Expand Up @@ -479,7 +484,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);
});
});
}
Expand Down Expand Up @@ -615,9 +631,18 @@ function setupWithdrawalAccount(data) {
}

API.BankAccount_SetupWithdrawal(newACHData)
/* eslint-disable arrow-body-style */
.then((response) => {
// 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(() => Promise.resolve(response));
})
.then((response) => {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, achData: {...newACHData}});

const currentStep = newACHData.currentStep;
let achData = lodashGet(response, 'achData', {});
let error = lodashGet(achData, CONST.BANK_ACCOUNT.VERIFICATIONS.ERROR_MESSAGE);
Expand Down
4 changes: 1 addition & 3 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ class CompanyStep extends React.Component {
/>
<ScrollView style={[styles.flex1, styles.w100]}>
<View style={[styles.p4]}>
<View style={[styles.alignItemsCenter]}>
<Text>{this.props.translate('companyStep.subtitle')}</Text>
</View>
<Text>{this.props.translate('companyStep.subtitle')}</Text>
<ExpensiTextInput
label={this.props.translate('companyStep.legalBusinessName')}
containerStyles={[styles.mt4]}
Expand Down

0 comments on commit 1de3e10

Please sign in to comment.