diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 043c27de9a48..67673d664ac3 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -15,6 +15,8 @@ import KYCWall from './KYCWall'; import withNavigation from './withNavigation'; import * as Expensicons from './Icon/Expensicons'; import ButtonWithDropdownMenu from './ButtonWithDropdownMenu'; +import * as BankAccounts from '../libs/actions/BankAccounts'; +import ROUTES from '../ROUTES'; const propTypes = { /** Callback to execute when this button is pressed. Receives a single payment type argument. */ @@ -191,6 +193,7 @@ function SettlementButton({ const selectPaymentType = (event, iouPaymentType, triggerKYCFlow) => { if (iouPaymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY || iouPaymentType === CONST.IOU.PAYMENT_TYPE.VBBA) { triggerKYCFlow(event, iouPaymentType); + BankAccounts.setPersonalBankAccountContinueKYCOnSuccess(ROUTES.ENABLE_PAYMENTS); return; } diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 249d7de9293a..a0d035292773 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -55,6 +55,13 @@ function openPersonalBankAccountSetupView(exitReportID: string) { }); } +/** + * Whether after adding a bank account we should continue with the KYC flow + */ +function setPersonalBankAccountContinueKYCOnSuccess(onSuccessFallbackRoute: string) { + Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {onSuccessFallbackRoute}); +} + function clearPersonalBankAccount() { clearPlaid(); Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {}); @@ -431,6 +438,7 @@ export { connectBankAccountWithPlaid, deletePaymentBankAccount, handlePlaidError, + setPersonalBankAccountContinueKYCOnSuccess, openPersonalBankAccountSetupView, clearReimbursementAccount, openReimbursementAccountPage, diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts index c532d0fbeb63..fe1b5ebe10e9 100644 --- a/src/libs/actions/PaymentMethods.ts +++ b/src/libs/actions/PaymentMethods.ts @@ -22,14 +22,14 @@ const kycWallRef = createRef(); /** * When we successfully add a payment method or pass the KYC checks we will continue with our setup action if we have one set. */ -function continueSetup() { +function continueSetup(fallbackRoute = ROUTES.HOME) { if (!kycWallRef.current?.continue) { - Navigation.goBack(ROUTES.HOME); + Navigation.goBack(fallbackRoute); return; } // Close the screen (Add Debit Card, Add Bank Account, or Enable Payments) on success and continue with setup - Navigation.goBack(ROUTES.HOME); + Navigation.goBack(fallbackRoute); kycWallRef.current.continue(); } diff --git a/src/pages/AddPersonalBankAccountPage.js b/src/pages/AddPersonalBankAccountPage.js index 7c04970c3980..a560a467bc7b 100644 --- a/src/pages/AddPersonalBankAccountPage.js +++ b/src/pages/AddPersonalBankAccountPage.js @@ -17,6 +17,7 @@ import Form from '../components/Form'; import ROUTES from '../ROUTES'; import * as PlaidDataProps from './ReimbursementAccount/plaidDataPropTypes'; import ConfirmationPage from '../components/ConfirmationPage'; +import * as PaymentMethods from '../libs/actions/PaymentMethods'; const propTypes = { ...withLocalizePropTypes, @@ -86,10 +87,14 @@ class AddPersonalBankAccountPage extends React.Component { BankAccounts.addPersonalBankAccount(selectedPlaidBankAccount); } - exitFlow() { + exitFlow(shouldContinue = false) { const exitReportID = lodashGet(this.props, 'personalBankAccount.exitReportID'); + const onSuccessFallbackRoute = lodashGet(this.props, 'personalBankAccount.onSuccessFallbackRoute', ''); + if (exitReportID) { Navigation.dismissModal(exitReportID); + } else if (shouldContinue && onSuccessFallbackRoute) { + PaymentMethods.continueSetup(onSuccessFallbackRoute); } else { Navigation.goBack(ROUTES.SETTINGS_WALLET); } @@ -115,7 +120,7 @@ class AddPersonalBankAccountPage extends React.Component { description={this.props.translate('addPersonalBankAccountPage.successMessage')} shouldShowButton buttonText={this.props.translate('common.continue')} - onButtonPress={this.exitFlow} + onButtonPress={() => this.exitFlow(true)} /> ) : (