Skip to content

Commit 043c341

Browse files
authored
Merge pull request Expensify#65845 from callstack-internal/getBankAccountRoute-perf
perf: getBankAccountRoute usage optimization
2 parents 720442f + 2c5d44b commit 043c341

13 files changed

Lines changed: 35 additions & 81 deletions

File tree

src/components/KYCWall/BaseKYCWall.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import getClickedTargetLocation from '@libs/getClickedTargetLocation';
1010
import Log from '@libs/Log';
1111
import Navigation from '@libs/Navigation/Navigation';
1212
import {hasExpensifyPaymentMethod} from '@libs/PaymentUtils';
13-
import {isExpenseReport as isExpenseReportReportUtils, isIOUReport} from '@libs/ReportUtils';
13+
import {getBankAccountRoute, isExpenseReport as isExpenseReportReportUtils, isIOUReport} from '@libs/ReportUtils';
1414
import {kycWallRef} from '@userActions/PaymentMethods';
1515
import {createWorkspaceFromIOUPayment} from '@userActions/Policy/Policy';
1616
import {setKYCWallSource} from '@userActions/Wallet';
@@ -52,6 +52,7 @@ function KYCWall({
5252
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
5353
const [bankAccountList = getEmptyObject<BankAccountList>()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
5454
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true});
55+
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, {canBeMissing: true});
5556

5657
const anchorRef = useRef<HTMLDivElement | View>(null);
5758
const transferBalanceButtonRef = useRef<HTMLDivElement | View | null>(null);
@@ -122,10 +123,11 @@ function KYCWall({
122123

123124
return;
124125
}
125-
Navigation.navigate(addBankAccountRoute);
126+
const bankAccountRoute = addBankAccountRoute ?? getBankAccountRoute(chatReport);
127+
Navigation.navigate(bankAccountRoute);
126128
}
127129
},
128-
[addBankAccountRoute, addDebitCardRoute, iouReport, onSelectPaymentMethod],
130+
[addBankAccountRoute, addDebitCardRoute, chatReport, iouReport, onSelectPaymentMethod],
129131
);
130132

131133
/**

src/components/KYCWall/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type PaymentMethod = ValueOf<typeof CONST.PAYMENT_METHODS>;
2323

2424
type KYCWallProps = {
2525
/** Route for the Add Bank Account screen for a given navigation stack */
26-
addBankAccountRoute: Route;
26+
addBankAccountRoute?: Route;
2727

2828
/** Route for the Add Debit Card screen for a given navigation stack */
2929
addDebitCardRoute?: Route;

src/components/MoneyReportHeader.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {getSecondaryReportActions} from '@libs/ReportSecondaryActionUtils';
3232
import {
3333
changeMoneyRequestHoldStatus,
3434
getArchiveReason,
35-
getBankAccountRoute,
3635
getIntegrationIcon,
3736
getIntegrationNameFromExportMessage as getIntegrationNameFromExportMessageUtils,
3837
getNextApproverAccountID,
@@ -320,7 +319,6 @@ function MoneyReportHeader({
320319
const optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep;
321320

322321
const shouldShowNextStep = isFromPaidPolicy && !isInvoiceReport && !shouldShowStatusBar;
323-
const bankAccountRoute = getBankAccountRoute(chatReport);
324322
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton);
325323
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);
326324
const {isDelegateAccessRestricted, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext);
@@ -484,7 +482,6 @@ function MoneyReportHeader({
484482
const {formattedAmount: totalAmount} = hasOnlyHeldExpenses ? getAmount(CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW) : getAmount(CONST.REPORT.PRIMARY_ACTIONS.PAY);
485483

486484
const paymentButtonOptions = usePaymentOptions({
487-
addBankAccountRoute: bankAccountRoute,
488485
currency: moneyRequestReport?.currency,
489486
iouReport: moneyRequestReport,
490487
chatReportID: chatReport?.reportID,
@@ -564,7 +561,6 @@ function MoneyReportHeader({
564561
iouReport={moneyRequestReport}
565562
onPress={confirmPayment}
566563
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
567-
addBankAccountRoute={bankAccountRoute}
568564
shouldHidePaymentOptions={!shouldShowPayButton}
569565
shouldShowApproveButton={shouldShowApproveButton}
570566
shouldDisableApproveButton={shouldDisableApproveButton}
@@ -934,7 +930,6 @@ function MoneyReportHeader({
934930
<KYCWall
935931
onSuccessfulKYC={(payment) => confirmPayment(payment)}
936932
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
937-
addBankAccountRoute={bankAccountRoute}
938933
isDisabled={isOffline}
939934
source={CONST.KYC_WALL_SOURCE.REPORT}
940935
chatReportID={chatReport?.reportID}

src/components/MoneyRequestConfirmationList.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import CONST from '@src/CONST';
5656
import type {TranslationPaths} from '@src/languages/types';
5757
import ONYXKEYS from '@src/ONYXKEYS';
5858
import ROUTES from '@src/ROUTES';
59-
import type {Route} from '@src/ROUTES';
6059
import type * as OnyxTypes from '@src/types/onyx';
6160
import type {Attendee, Participant} from '@src/types/onyx/IOU';
6261
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
@@ -125,9 +124,6 @@ type MoneyRequestConfirmationListProps = {
125124
/** Number of expenses to be created */
126125
expensesNumber?: number;
127126

128-
/** Depending on expense report or personal IOU report, respective bank account route */
129-
bankAccountRoute?: Route;
130-
131127
/** The policyID of the request */
132128
policyID?: string;
133129

@@ -209,7 +205,6 @@ function MoneyRequestConfirmationList({
209205
selectedParticipants: selectedParticipantsProp,
210206
payeePersonalDetails: payeePersonalDetailsProp,
211207
isReadOnly = false,
212-
bankAccountRoute = '',
213208
policyID,
214209
reportID = '',
215210
receiptPath = '',
@@ -994,7 +989,7 @@ function MoneyRequestConfirmationList({
994989
pressOnEnter
995990
onPress={confirm}
996991
enablePaymentsRoute={ROUTES.IOU_SEND_ENABLE_PAYMENTS}
997-
addBankAccountRoute={bankAccountRoute}
992+
chatReportID={reportID}
998993
shouldShowPersonalBankAccountOption
999994
currency={iouCurrencyCode}
1000995
policyID={policyID}
@@ -1064,7 +1059,6 @@ function MoneyRequestConfirmationList({
10641059
isReadOnly,
10651060
iouType,
10661061
confirm,
1067-
bankAccountRoute,
10681062
iouCurrencyCode,
10691063
policyID,
10701064
isConfirmed,
@@ -1080,6 +1074,7 @@ function MoneyRequestConfirmationList({
10801074
shouldShowProductTrainingTooltip,
10811075
renderProductTrainingTooltip,
10821076
isConfirming,
1077+
reportID,
10831078
]);
10841079

10851080
const listFooterContent = (
@@ -1175,7 +1170,6 @@ export default memo(
11751170
deepEqual(prevProps.selectedParticipants, nextProps.selectedParticipants) &&
11761171
deepEqual(prevProps.payeePersonalDetails, nextProps.payeePersonalDetails) &&
11771172
prevProps.isReadOnly === nextProps.isReadOnly &&
1178-
prevProps.bankAccountRoute === nextProps.bankAccountRoute &&
11791173
prevProps.policyID === nextProps.policyID &&
11801174
prevProps.reportID === nextProps.reportID &&
11811175
prevProps.receiptPath === nextProps.receiptPath &&

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {getConnectedIntegration} from '@libs/PolicyUtils';
3838
import {getReportPreviewAction} from '@libs/ReportPreviewActionUtils';
3939
import {
4040
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
41-
getBankAccountRoute,
4241
getDisplayNameForParticipant,
4342
getInvoicePayerName,
4443
getMoneyReportPreviewName,
@@ -283,8 +282,6 @@ function MoneyRequestReportPreviewContent({
283282
managerID,
284283
]);
285284

286-
const bankAccountRoute = getBankAccountRoute(chatReport);
287-
288285
/*
289286
Show subtitle if at least one of the expenses is not being smart scanned, and either:
290287
- There is more than one expense – in this case, the "X expenses, Y scanning" subtitle is shown;
@@ -527,7 +524,6 @@ function MoneyRequestReportPreviewContent({
527524
onPaymentOptionsHide={onPaymentOptionsHide}
528525
confirmApproval={confirmApproval}
529526
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
530-
addBankAccountRoute={bankAccountRoute}
531527
shouldHidePaymentOptions={!shouldShowPayButton}
532528
kycWallAnchorAlignment={{
533529
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,

src/components/SettlementButton/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type SettlementButtonProps from './types';
2121

2222
function SettlementButton({
2323
addDebitCardRoute = ROUTES.IOU_SEND_ADD_DEBIT_CARD,
24-
addBankAccountRoute = '',
2524
kycWallAnchorAlignment = {
2625
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, // button is at left, so horizontal anchor is at LEFT
2726
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
@@ -69,7 +68,6 @@ function SettlementButton({
6968
const {isAccountLocked, showLockedAccountModal} = useContext(LockedAccountContext);
7069

7170
const paymentButtonOptions = usePaymentOptions({
72-
addBankAccountRoute,
7371
currency,
7472
iouReport,
7573
chatReportID,
@@ -100,7 +98,6 @@ function SettlementButton({
10098
<KYCWall
10199
onSuccessfulKYC={(paymentType) => onPress(paymentType)}
102100
enablePaymentsRoute={enablePaymentsRoute}
103-
addBankAccountRoute={addBankAccountRoute}
104101
addDebitCardRoute={addDebitCardRoute}
105102
isDisabled={isOffline}
106103
source={CONST.KYC_WALL_SOURCE.REPORT}

src/components/SettlementButton/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ type SettlementButtonProps = {
6262
/** The size of button size */
6363
buttonSize?: ButtonSizeValue;
6464

65-
/** Route for the Add Bank Account screen for a given navigation stack */
66-
addBankAccountRoute?: Route;
67-
6865
/** Route for the Add Debit Card screen for a given navigation stack */
6966
addDebitCardRoute?: Route;
7067

src/hooks/usePaymentOptions.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {formatPaymentMethods} from '@libs/PaymentUtils';
77
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
88
import {
99
doesReportBelongToWorkspace,
10+
getBankAccountRoute,
1011
isExpenseReport as isExpenseReportUtil,
1112
isIndividualInvoiceRoom as isIndividualInvoiceRoomUtil,
1213
isInvoiceReport as isInvoiceReportUtil,
@@ -26,7 +27,6 @@ type CurrencyType = TupleToUnion<typeof CONST.DIRECT_REIMBURSEMENT_CURRENCIES>;
2627

2728
type UsePaymentOptionsProps = Pick<
2829
SettlementButtonProps,
29-
| 'addBankAccountRoute'
3030
| 'currency'
3131
| 'iouReport'
3232
| 'chatReportID'
@@ -45,7 +45,6 @@ type UsePaymentOptionsProps = Pick<
4545
* It dynamically generates payment or approval options to ensure the user interface reflects the correct actions possible for the user's current situation.
4646
*/
4747
function usePaymentOptions({
48-
addBankAccountRoute = '',
4948
currency = CONST.CURRENCY.USD,
5049
iouReport,
5150
chatReportID = '',
@@ -174,7 +173,10 @@ function usePaymentOptions({
174173
{
175174
text: translate('workspace.invoices.paymentMethods.addBankAccount'),
176175
icon: Expensicons.Bank,
177-
onSelected: () => Navigation.navigate(addBankAccountRoute),
176+
onSelected: () => {
177+
const bankAccountRoute = getBankAccountRoute(chatReport);
178+
Navigation.navigate(bankAccountRoute);
179+
},
178180
},
179181
],
180182
});
@@ -190,7 +192,10 @@ function usePaymentOptions({
190192
{
191193
text: translate('workspace.invoices.paymentMethods.addBankAccount'),
192194
icon: Expensicons.Bank,
193-
onSelected: () => Navigation.navigate(addBankAccountRoute),
195+
onSelected: () => {
196+
const bankAccountRoute = getBankAccountRoute(chatReport);
197+
Navigation.navigate(bankAccountRoute);
198+
},
194199
},
195200
{
196201
text: translate('iou.payElsewhere', {formattedAmount: ''}),

src/pages/iou/MoneyRequestAmountForm.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import Navigation from '@libs/Navigation/Navigation';
2222
import variables from '@styles/variables';
2323
import type {BaseTextInputRef} from '@src/components/TextInput/BaseTextInput/types';
2424
import CONST from '@src/CONST';
25-
import type {Route} from '@src/ROUTES';
2625
import ROUTES from '@src/ROUTES';
2726
import type {SelectedTabRequest} from '@src/types/onyx';
2827
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
@@ -51,9 +50,6 @@ type MoneyRequestAmountFormProps = {
5150
/** The policyID of the request */
5251
policyID?: string;
5352

54-
/** Depending on expense report or personal IOU report, respective bank account route */
55-
bankAccountRoute?: Route;
56-
5753
/** Whether the currency symbol is pressable */
5854
isCurrencyPressable?: boolean;
5955

@@ -68,6 +64,9 @@ type MoneyRequestAmountFormProps = {
6864

6965
/** Whether the user input should be kept or not */
7066
shouldKeepUserInput?: boolean;
67+
68+
/** The chatReportID of the request */
69+
chatReportID?: string;
7170
};
7271

7372
const isAmountInvalid = (amount: string) => !amount.length || parseFloat(amount) < 0.01;
@@ -88,11 +87,11 @@ function MoneyRequestAmountForm(
8887
skipConfirmation = false,
8988
iouType = CONST.IOU.TYPE.SUBMIT,
9089
policyID = '',
91-
bankAccountRoute = '',
9290
onCurrencyButtonPress,
9391
onSubmitButtonPress,
9492
selectedTab = CONST.TAB_REQUEST.MANUAL,
9593
shouldKeepUserInput = false,
94+
chatReportID,
9695
}: MoneyRequestAmountFormProps,
9796
forwardedRef: ForwardedRef<BaseTextInputRef>,
9897
) {
@@ -309,7 +308,6 @@ function MoneyRequestAmountForm(
309308
pressOnEnter
310309
onPress={submitAndNavigateToNextPage}
311310
enablePaymentsRoute={ROUTES.IOU_SEND_ENABLE_PAYMENTS}
312-
addBankAccountRoute={bankAccountRoute}
313311
addDebitCardRoute={ROUTES.IOU_SEND_ADD_DEBIT_CARD}
314312
currency={currency ?? CONST.CURRENCY.USD}
315313
policyID={policyID}
@@ -325,6 +323,7 @@ function MoneyRequestAmountForm(
325323
}}
326324
shouldShowPersonalBankAccountOption
327325
enterKeyEventListenerPriority={1}
326+
chatReportID={chatReportID}
328327
/>
329328
) : (
330329
<Button

src/pages/iou/request/step/IOURequestStepAmount.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {navigateToParticipantPage} from '@libs/IOUUtils';
1212
import Navigation from '@libs/Navigation/Navigation';
1313
import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils';
1414
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
15-
import {getBankAccountRoute, getPolicyExpenseChat, getTransactionDetails, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
15+
import {getPolicyExpenseChat, getTransactionDetails, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
1616
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
1717
import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getRequestType, getTaxValue} from '@libs/TransactionUtils';
1818
import MoneyRequestAmountForm from '@pages/iou/MoneyRequestAmountForm';
@@ -318,14 +318,14 @@ function IOURequestStepAmount({
318318
skipConfirmation={shouldSkipConfirmation ?? false}
319319
iouType={iouType}
320320
policyID={policy?.id}
321-
bankAccountRoute={getBankAccountRoute(report)}
322321
ref={(e) => {
323322
textInput.current = e;
324323
}}
325324
shouldKeepUserInput={transaction?.shouldShowOriginalAmount}
326325
onCurrencyButtonPress={navigateToCurrencySelectionPage}
327326
onSubmitButtonPress={saveAmountAndCurrency}
328327
selectedTab={iouRequestType}
328+
chatReportID={reportID}
329329
/>
330330
</StepScreenWrapper>
331331
);

0 commit comments

Comments
 (0)