Skip to content
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
31 changes: 28 additions & 3 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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);
});
});
}
Expand Down Expand Up @@ -602,9 +618,18 @@ function setupWithdrawalAccount(data) {
}

API.BankAccount_SetupWithdrawal(newACHData)
/* eslint-disable arrow-body-style */
Comment thread
roryabraham marked this conversation as resolved.
.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