diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 8181dc468256..ea9fb7db65ac 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -84,6 +84,13 @@ type OpenPersonalBankAccountSetupViewProps = { isUserValidated?: boolean; }; +type VBBAOnyxKey = + | typeof ONYXKEYS.REIMBURSEMENT_ACCOUNT + | typeof ONYXKEYS.NVP_LAST_PAYMENT_METHOD + | typeof ONYXKEYS.ONFIDO_TOKEN + | typeof ONYXKEYS.ONFIDO_APPLICANT_ID + | typeof ONYXKEYS.RAM_ONLY_PLAID_LINK_TOKEN; + function clearPlaid(): Promise { Onyx.set(ONYXKEYS.RAM_ONLY_PLAID_LINK_TOKEN, ''); Onyx.set(ONYXKEYS.PLAID_CURRENT_EVENT, null); @@ -176,7 +183,35 @@ function updateAddPersonalBankAccountDraft(bankData: Partial { +function getVBBADataForOnyx(currentStep?: BankAccountStep, shouldShowLoading = true): OnyxData { + const failureData: Array> = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: false, + errors: getMicroSecondOnyxErrorWithTranslationKey('walletPage.addBankAccountFailure'), + }, + }, + { + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.RAM_ONLY_PLAID_LINK_TOKEN, + value: null, + }, + ]; + if (currentStep !== CONST.BANK_ACCOUNT.STEP.REQUESTOR) { + failureData.push({ + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.ONFIDO_TOKEN, + value: null, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.SET, + key: ONYXKEYS.ONFIDO_APPLICANT_ID, + value: null, + }); + } + return { optimisticData: [ { @@ -204,16 +239,7 @@ function getVBBADataForOnyx(currentStep?: BankAccountStep, shouldShowLoading = t }, }, ], - failureData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - value: { - isLoading: false, - errors: getMicroSecondOnyxErrorWithTranslationKey('walletPage.addBankAccountFailure'), - }, - }, - ], + failureData, }; } @@ -224,10 +250,7 @@ function addBusinessWebsiteForDraft(websiteUrl: string) { /** * Get the Onyx data required to set the last used payment method to VBBA for a given policyID */ -function getOnyxDataForConnectingVBBAAndLastPaymentMethod( - policyID?: string, - lastPaymentMethod?: LastPaymentMethodType | string, -): OnyxData { +function getOnyxDataForConnectingVBBAAndLastPaymentMethod(policyID?: string, lastPaymentMethod?: LastPaymentMethodType | string): OnyxData { const onyxData = getVBBADataForOnyx(); const lastUsedPaymentMethod = typeof lastPaymentMethod === 'string' ? lastPaymentMethod : lastPaymentMethod?.expense?.name;