diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 6c14e5265759..e474c9f26ee4 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -240,7 +240,8 @@ function KYCWall({ const invoiceReceiverPolicyID = getInvoiceReceiverPolicyID(chatReport); const invoiceReceiverPolicy = invoiceReceiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`] : undefined; - const bankAccountRoute = addBankAccountRoute ?? getBankAccountRoute(chatReport, invoiceReceiverPolicy?.areInvoicesEnabled); + const resolvedAddBankAccountRoute = typeof addBankAccountRoute === 'function' ? addBankAccountRoute() : addBankAccountRoute; + const bankAccountRoute = resolvedAddBankAccountRoute ?? getBankAccountRoute(chatReport, invoiceReceiverPolicy?.areInvoicesEnabled); Navigation.navigate(bankAccountRoute); } }, diff --git a/src/components/KYCWall/types.ts b/src/components/KYCWall/types.ts index a13480bbd9c2..7047adda3064 100644 --- a/src/components/KYCWall/types.ts +++ b/src/components/KYCWall/types.ts @@ -32,8 +32,8 @@ type ContinueActionParams = { }; type KYCWallProps = { - /** Route for the Add Bank Account screen for a given navigation stack */ - addBankAccountRoute?: Route; + /** Route for the Add Bank Account screen for a given navigation stack. Pass a function to defer building the route (e.g. its backTo) until the moment of the press. */ + addBankAccountRoute?: Route | (() => Route | undefined); /** Route for the Add Debit Card screen for a given navigation stack */ addDebitCardRoute?: Route; diff --git a/src/components/Search/SearchBulkActionsButton.tsx b/src/components/Search/SearchBulkActionsButton.tsx index 02254fe1a283..6a99cc26620e 100644 --- a/src/components/Search/SearchBulkActionsButton.tsx +++ b/src/components/Search/SearchBulkActionsButton.tsx @@ -160,7 +160,9 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS} iouReport={selectedIOUReport} addBankAccountRoute={ - isCurrentSelectedExpenseReport ? ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute({policyID: currentSelectedPolicyID, backTo: Navigation.getActiveRoute()}) : undefined + isCurrentSelectedExpenseReport + ? () => ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute({policyID: currentSelectedPolicyID, backTo: Navigation.getActiveRoute()}) + : undefined } onSuccessfulKYC={(paymentType) => { confirmPayment?.(paymentType, pendingPaymentAdditionalDataRef.current); diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 2c5d205c68d6..300e4483fbc9 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -676,7 +676,7 @@ function SettlementButton({ isDisabled={isOffline} source={CONST.KYC_WALL_SOURCE.REPORT} chatReportID={chatReportID} - addBankAccountRoute={isExpenseReport ? ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute({policyID: iouReport?.policyID, backTo: Navigation.getActiveRoute()}) : undefined} + addBankAccountRoute={isExpenseReport ? () => ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute({policyID: iouReport?.policyID, backTo: Navigation.getActiveRoute()}) : undefined} iouReport={iouReport} policy={lastPaymentPolicy} anchorAlignment={kycWallAnchorAlignment}