From 2692910ea2ec0d5134dc1ded1d22a26955040f2a Mon Sep 17 00:00:00 2001 From: Getabalew Tesfaye Date: Wed, 18 Oct 2023 11:41:52 +0300 Subject: [PATCH 1/4] fix navigate to enable-payment page after adding Bank account --- src/components/SettlementButton.js | 3 +++ src/libs/actions/BankAccounts.ts | 8 ++++++++ src/libs/actions/PaymentMethods.ts | 6 +++--- src/pages/AddPersonalBankAccountPage.js | 10 ++++++++-- src/types/onyx/PersonalBankAccount.ts | 6 ++++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 043c27de9a48..4cda74bd9e4b 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(true, ROUTES.ENABLE_PAYMENTS); return; } diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 249d7de9293a..d3abd73142bd 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(shouldContinueKYCOnSuccess: boolean, onSuccessFallbackRoute: string) { + Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {shouldContinueKYCOnSuccess, 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..ef4d3330f48a 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,15 @@ class AddPersonalBankAccountPage extends React.Component { BankAccounts.addPersonalBankAccount(selectedPlaidBankAccount); } - exitFlow() { + exitFlow(shouldContinue = false) { const exitReportID = lodashGet(this.props, 'personalBankAccount.exitReportID'); + const shouldContinueKYCOnSuccess = lodashGet(this.props, 'personalBankAccount.shouldContinueKYCOnSuccess', false); + const onSuccessFallbackRoute = lodashGet(this.props, 'personalBankAccount.onSuccessFallbackRoute', ''); + if (exitReportID) { Navigation.dismissModal(exitReportID); + } else if (shouldContinue && onSuccessFallbackRoute && shouldContinueKYCOnSuccess) { + PaymentMethods.continueSetup(onSuccessFallbackRoute); } else { Navigation.goBack(ROUTES.SETTINGS_WALLET); } @@ -115,7 +121,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)} /> ) : (
Date: Wed, 18 Oct 2023 12:54:02 +0300 Subject: [PATCH 2/4] run prettier --- src/pages/AddPersonalBankAccountPage.js | 2 +- src/types/onyx/PersonalBankAccount.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/AddPersonalBankAccountPage.js b/src/pages/AddPersonalBankAccountPage.js index ef4d3330f48a..b492e10f3e35 100644 --- a/src/pages/AddPersonalBankAccountPage.js +++ b/src/pages/AddPersonalBankAccountPage.js @@ -17,7 +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"; +import * as PaymentMethods from '../libs/actions/PaymentMethods'; const propTypes = { ...withLocalizePropTypes, diff --git a/src/types/onyx/PersonalBankAccount.ts b/src/types/onyx/PersonalBankAccount.ts index fbcf8c1c1c39..14fdcce10bba 100644 --- a/src/types/onyx/PersonalBankAccount.ts +++ b/src/types/onyx/PersonalBankAccount.ts @@ -17,10 +17,10 @@ type PersonalBankAccount = { exitReportID?: string; /** Whether the flow should continue to kyc on success */ - shouldContinueKYCOnSuccess?: boolean, + shouldContinueKYCOnSuccess?: boolean; /** The route to navigate to onSuccess */ - onSuccessFallbackRoute?: string, + onSuccessFallbackRoute?: string; }; export default PersonalBankAccount; From 5f78a2238eb828f72346873da774874f1fda0aee Mon Sep 17 00:00:00 2001 From: Getabalew Tesfaye Date: Wed, 18 Oct 2023 13:22:33 +0300 Subject: [PATCH 3/4] run prettier --- src/components/SettlementButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 4cda74bd9e4b..4debe2355197 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -16,7 +16,7 @@ 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"; +import ROUTES from '../ROUTES'; const propTypes = { /** Callback to execute when this button is pressed. Receives a single payment type argument. */ From 5d73a1f35562104ba300b0166053c2582b4c2f12 Mon Sep 17 00:00:00 2001 From: Getabalew Tesfaye Date: Wed, 18 Oct 2023 18:02:27 +0300 Subject: [PATCH 4/4] remove redundant parameter --- src/components/SettlementButton.js | 2 +- src/libs/actions/BankAccounts.ts | 4 ++-- src/pages/AddPersonalBankAccountPage.js | 3 +-- src/types/onyx/PersonalBankAccount.ts | 5 +---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 4debe2355197..67673d664ac3 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -193,7 +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(true, ROUTES.ENABLE_PAYMENTS); + BankAccounts.setPersonalBankAccountContinueKYCOnSuccess(ROUTES.ENABLE_PAYMENTS); return; } diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index d3abd73142bd..a0d035292773 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -58,8 +58,8 @@ function openPersonalBankAccountSetupView(exitReportID: string) { /** * Whether after adding a bank account we should continue with the KYC flow */ -function setPersonalBankAccountContinueKYCOnSuccess(shouldContinueKYCOnSuccess: boolean, onSuccessFallbackRoute: string) { - Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {shouldContinueKYCOnSuccess, onSuccessFallbackRoute}); +function setPersonalBankAccountContinueKYCOnSuccess(onSuccessFallbackRoute: string) { + Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {onSuccessFallbackRoute}); } function clearPersonalBankAccount() { diff --git a/src/pages/AddPersonalBankAccountPage.js b/src/pages/AddPersonalBankAccountPage.js index b492e10f3e35..a560a467bc7b 100644 --- a/src/pages/AddPersonalBankAccountPage.js +++ b/src/pages/AddPersonalBankAccountPage.js @@ -89,12 +89,11 @@ class AddPersonalBankAccountPage extends React.Component { exitFlow(shouldContinue = false) { const exitReportID = lodashGet(this.props, 'personalBankAccount.exitReportID'); - const shouldContinueKYCOnSuccess = lodashGet(this.props, 'personalBankAccount.shouldContinueKYCOnSuccess', false); const onSuccessFallbackRoute = lodashGet(this.props, 'personalBankAccount.onSuccessFallbackRoute', ''); if (exitReportID) { Navigation.dismissModal(exitReportID); - } else if (shouldContinue && onSuccessFallbackRoute && shouldContinueKYCOnSuccess) { + } else if (shouldContinue && onSuccessFallbackRoute) { PaymentMethods.continueSetup(onSuccessFallbackRoute); } else { Navigation.goBack(ROUTES.SETTINGS_WALLET); diff --git a/src/types/onyx/PersonalBankAccount.ts b/src/types/onyx/PersonalBankAccount.ts index 14fdcce10bba..14b0f8cedecd 100644 --- a/src/types/onyx/PersonalBankAccount.ts +++ b/src/types/onyx/PersonalBankAccount.ts @@ -16,10 +16,7 @@ type PersonalBankAccount = { /** Any reportID we should redirect to at the end of the flow */ exitReportID?: string; - /** Whether the flow should continue to kyc on success */ - shouldContinueKYCOnSuccess?: boolean; - - /** The route to navigate to onSuccess */ + /** The route to redirect after adding PBA successfully */ onSuccessFallbackRoute?: string; };