diff --git a/src/components/AddExistingExpenseFooter.tsx b/src/components/AddExistingExpenseFooter.tsx index e5c4c11abf9a..ab1f26456178 100644 --- a/src/components/AddExistingExpenseFooter.tsx +++ b/src/components/AddExistingExpenseFooter.tsx @@ -79,6 +79,7 @@ function AddExistingExpenseFooter({selectedIds, report, reportToConfirm, policy, afterTransition: () => { if (report && isIOUReport(report)) { convertBulkTrackedExpensesToIOU({ + getCurrencyDecimals, transactions, iouReport: report, chatReport, diff --git a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx index 94d523564397..1f8fe135f298 100644 --- a/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx +++ b/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx @@ -141,7 +141,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo const chatReportPolicy = usePolicy(chatReport?.policyID); const lastWorkspaceNumber = useLastWorkspaceNumber(); - const {convertToDisplayString} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); @@ -196,6 +196,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo } else if (isInvoiceReport) { startAnimation(); payInvoice({ + getCurrencyDecimals, paymentMethodType: type, chatReport, invoiceReport: moneyRequestReport, @@ -219,6 +220,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo } else { startAnimation(); payMoneyRequest({ + getCurrencyDecimals, paymentType: type, chatReport, iouReport: moneyRequestReport, @@ -427,6 +429,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo const onPaymentSelect = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => { const runPaymentSelection = () => selectPaymentType({ + getCurrencyDecimals, event, iouPaymentType, triggerKYCFlow, diff --git a/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx b/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx index aec75e6fdb3f..7c398357739d 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx +++ b/src/components/MoneyReportHeaderPrimaryAction/PayPrimaryAction.tsx @@ -77,7 +77,7 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) { const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`); const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID); const getChatReportActions = usePayChatReportActions(chatReport, existingB2BInvoiceReport); - const {convertToDisplayString} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const isTrackIntentUser = isTrackOnboardingChoice(introSelected?.choice); const isInvoiceReport = isInvoiceReportUtil(moneyRequestReport); @@ -144,6 +144,7 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) { } else if (isInvoiceReport) { startAnimation(); payInvoice({ + getCurrencyDecimals, paymentMethodType: type, chatReport, invoiceReport: moneyRequestReport, @@ -167,6 +168,7 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) { } else { startAnimation(); payMoneyRequest({ + getCurrencyDecimals, paymentType: type, chatReport, iouReport: moneyRequestReport, diff --git a/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx b/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx index 1a316b4f1dca..2a64948419c6 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx +++ b/src/components/MoneyReportHeaderPrimaryAction/SubmitPrimaryAction.tsx @@ -8,6 +8,7 @@ import {useSearchQueryContext, useSearchResultsContext} from '@components/Search import useConfirmModal from '@hooks/useConfirmModal'; import useConfirmPendingRTERAndProceed from '@hooks/useConfirmPendingRTERAndProceed'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; @@ -68,6 +69,7 @@ function SubmitPrimaryAction({reportID}: SubmitPrimaryActionProps) { function SubmitPrimaryActionContent({reportID}: SubmitPrimaryActionProps) { const {isSubmittingAnimationRunning, stopAnimation, startSubmittingAnimation} = usePaymentAnimationsContext(); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {isOffline} = useNetwork(); const {accountID, email} = useCurrentUserPersonalDetails(); const {isBetaEnabled} = usePermissions(); @@ -155,6 +157,7 @@ function SubmitPrimaryActionContent({reportID}: SubmitPrimaryActionProps) { } submitReport({ + getCurrencyDecimals, expenseReport: moneyRequestReport, policy, currentUserAccountIDParam: accountID, diff --git a/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts b/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts index ade400696ab6..7efbb5184e10 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts +++ b/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts @@ -1,6 +1,7 @@ import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider'; import {useMoneyReportHeaderModals} from '@components/MoneyReportHeaderModalsContext'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useOnyx from '@hooks/useOnyx'; @@ -22,6 +23,7 @@ import {personalDetailsLoginSelector} from '@selectors/PersonalDetails'; function useConfirmApproval(reportID: string | undefined, startApprovedAnimation: () => void) { const {accountID, email} = useCurrentUserPersonalDetails(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {isBetaEnabled} = usePermissions(); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); @@ -57,6 +59,7 @@ function useConfirmApproval(reportID: string | undefined, startApprovedAnimation startApprovedAnimation(); } approveMoneyRequest({ + getCurrencyDecimals, expenseReport: moneyRequestReport, expenseReportPolicy: policy, currentUserAccountIDParam: accountID, diff --git a/src/components/MoneyRequestHeaderSecondaryActions.tsx b/src/components/MoneyRequestHeaderSecondaryActions.tsx index f2281aeb1d18..4eb215dd6292 100644 --- a/src/components/MoneyRequestHeaderSecondaryActions.tsx +++ b/src/components/MoneyRequestHeaderSecondaryActions.tsx @@ -255,6 +255,7 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined; duplicateTransactionAction({ + getCurrencyDecimals, transaction: item, optimisticChatReportID, optimisticIOUReportID, diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx index 9d5dc41ace2a..97559a5a5e22 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx @@ -55,7 +55,7 @@ function PayActionButton() { const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); const lastWorkspaceNumber = useLastWorkspaceNumber(); - const {convertToDisplayString} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const {iouReportID, chatReportID, chatReport, transactions} = useReportPreviewData(); const {isPaidAnimationRunning, isApprovedAnimationRunning} = useReportPreviewAnimationState(); @@ -102,6 +102,7 @@ function PayActionButton() { if (isInvoiceReportUtils(iouReport)) { startAnimation(); payInvoice({ + getCurrencyDecimals, paymentMethodType: type, chatReport: currentChatReport, invoiceReport: iouReport, @@ -124,6 +125,7 @@ function PayActionButton() { }); } else { payMoneyRequest({ + getCurrencyDecimals, paymentType: type, chatReport: currentChatReport, iouReport, diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx index 27e76d72a3b5..8533079fb6d9 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/SubmitActionButton.tsx @@ -3,6 +3,7 @@ import {ReportSubmitToPopoverAnchor, useOpenReportSubmitToPopover} from '@compon import useConfirmModal from '@hooks/useConfirmModal'; import useConfirmPendingRTERAndProceed from '@hooks/useConfirmPendingRTERAndProceed'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -45,6 +46,7 @@ function SubmitActionButton() { function SubmitActionButtonContent() { const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {showConfirmModal} = useConfirmModal(); const currentUserDetails = useCurrentUserPersonalDetails(); const currentUserAccountID = currentUserDetails.accountID; @@ -94,6 +96,7 @@ function SubmitActionButtonContent() { } submitReport({ + getCurrencyDecimals, expenseReport: iouReport, policy, currentUserAccountIDParam: currentUserAccountID, diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts b/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts index 14db511e4c23..7ed2e561bbb1 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/useConfirmApproveReportAction.ts @@ -4,6 +4,7 @@ */ import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; @@ -24,6 +25,7 @@ import {useReportPreviewActions, useReportPreviewActionState} from './MoneyReque function useConfirmApproveReportAction(actionButtonData: ReturnType, transactions: Transaction[], hasViolations: boolean) { const currentUserDetails = useCurrentUserPersonalDetails(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {isBetaEnabled} = usePermissions(); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); @@ -41,6 +43,7 @@ function useConfirmApproveReportAction(actionButtonData: ReturnType({ transactionsWithoutPendingDelete.length > 0 && transactionsWithoutPendingDelete.every((transaction) => selectedTransactions[transaction.keyForList]?.isSelected); const isSelected = liveRowSelected || areAllReportTransactionsSelected; const {translate} = useLocalize(); - const {convertToDisplayString} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const {isLargeScreenWidth} = useResponsiveLayout(); const {currentSearchHash, currentSearchKey} = useSearchQueryContext(); const {currentSearchResults} = useSearchResultsContext(); @@ -245,6 +245,7 @@ function ExpenseReportListItemInner({ const handleOnButtonPress = useCallback(() => { handleActionButtonPress({ + getCurrencyDecimals, hash: currentSearchHash, item: liveReportItem, goToItem: () => onSelectRow(reportItem as unknown as TItem), @@ -332,6 +333,7 @@ function ExpenseReportListItemInner({ showConfirmModal, translate, convertToDisplayString, + getCurrencyDecimals, currentUserAccountID, currentUserLogin, introSelected, diff --git a/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx b/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx index d83070b2aea3..8912b377b525 100644 --- a/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx +++ b/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx @@ -14,6 +14,7 @@ import {useRowSelection} from '@components/Search/SearchSelectionProvider'; import type {ListItem} from '@components/SelectionList/types'; import useConfirmModal from '@hooks/useConfirmModal'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -288,6 +289,7 @@ function ReportListItemHeaderInner({ const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {showConfirmModal} = useConfirmModal(); const {isSelected} = useRowSelection(reportItem.keyForList); const avatarBorderColor = @@ -298,6 +300,7 @@ function ReportListItemHeaderInner({ const handleOnButtonPress = (event?: ModifiedMouseEvent) => { handleActionButtonPress({ + getCurrencyDecimals, hash: currentSearchHash, item: reportItem, goToItem: () => onSelectRow(reportItem as unknown as TItem, event), diff --git a/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx b/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx index 821108d0ab66..e5e01ac60bd9 100644 --- a/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx @@ -9,6 +9,7 @@ import Text from '@components/Text'; import TransactionItemRow from '@components/TransactionItemRow'; import {useWideRHPActions} from '@components/WideRHPContextProvider'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -80,6 +81,7 @@ function TransactionGroupListExpandedImpl({ const {windowWidth} = useWindowDimensions(); const currentUserDetails = useCurrentUserPersonalDetails(); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const [isMobileSelectionModeEnabled] = useOnyx(ONYXKEYS.RAM_ONLY_MOBILE_SELECTION_MODE); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [betas] = useOnyx(ONYXKEYS.BETAS); @@ -198,6 +200,7 @@ function TransactionGroupListExpandedImpl({ if (!transactionItem?.reportAction?.childReportID) { if (isModifiedMousePress(event)) { const targetReportID = createAndOpenSearchTransactionThread({ + getCurrencyDecimals, item: transactionItem, introSelected, backTo, @@ -215,6 +218,7 @@ function TransactionGroupListExpandedImpl({ return; } createAndOpenSearchTransactionThread({ + getCurrencyDecimals, item: transactionItem, introSelected, backTo, diff --git a/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx b/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx index 12bb400ae57b..fdeb3e9900ba 100644 --- a/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx @@ -11,6 +11,7 @@ import useLiveRowCapabilities from '@components/Search/SearchList/ListItem/useLi import type {ListItem} from '@components/SelectionList/types'; import useConfirmModal from '@hooks/useConfirmModal'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -197,12 +198,14 @@ function TransactionListItemInner({ const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {showConfirmModal} = useConfirmModal(); const openReportSubmitToPopover = useOpenReportSubmitToPopover(); const {shouldDisableSearchSubmitPress, consumeIgnoreNextSearchSubmitPress} = useSearchSubmitPopoverGuard(); const handleActionButtonPress = (event?: Parameters[2]) => { handleActionButtonPressUtil({ + getCurrencyDecimals, hash: currentSearchHash, item: liveTransactionItem, goToItem: () => onSelectRow(item, transactionPreviewData, event), diff --git a/src/components/Search/SearchStaticList.tsx b/src/components/Search/SearchStaticList.tsx index 2bae1af32b09..9d8c87b7f618 100644 --- a/src/components/Search/SearchStaticList.tsx +++ b/src/components/Search/SearchStaticList.tsx @@ -77,7 +77,7 @@ function SearchStaticList({ const theme = useTheme(); const StyleUtils = useStyleUtils(); const {translate, localeCompare, formatPhoneNumber} = useLocalize(); - const {convertToDisplayString} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const session = useSession(); const accountID = session?.accountID ?? CONST.DEFAULT_NUMBER_ID; const email = session?.email; @@ -140,6 +140,7 @@ function SearchStaticList({ // They're only used for guided-setup onboarding data, which is gated behind introSelected/onboarding checks // that won't apply here - the user has already completed onboarding if they're submitting expenses. createAndOpenSearchTransactionThread({ + getCurrencyDecimals, item, introSelected: undefined, backTo, diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 20d711158799..49d6bd0746e8 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -5,6 +5,7 @@ import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton'; import {useWideRHPActions} from '@components/WideRHPContextProvider'; import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import type {ActionHandledType} from '@hooks/useHoldMenuSubmit'; import useLocalize from '@hooks/useLocalize'; @@ -187,6 +188,7 @@ function Search({ const previousReportActions = usePrevious(reportActions); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const searchListRef = useRef | null>(null); const savedSearchSelector = useCallback((searches: OnyxEntry) => searches?.[hash], [hash]); @@ -530,6 +532,7 @@ function Search({ const shouldOpenTransactionThread = !isOneTransactionReport(item.report) || item.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const shouldOpenTransactionThreadInNewTab = shouldOpenTransactionThread && isModifiedMousePress(event); const targetReportID = createAndOpenSearchTransactionThread({ + getCurrencyDecimals, item, introSelected, backTo, @@ -591,6 +594,7 @@ function Search({ if (item.isOneTransactionReport && firstTransaction && transactionPreviewData) { if (!firstTransaction?.reportAction?.childReportID) { createAndOpenSearchTransactionThread({ + getCurrencyDecimals, item: firstTransaction, introSelected, backTo, @@ -604,7 +608,7 @@ function Search({ shouldNavigate: false, }); } else { - setOptimisticDataForTransactionThreadPreview(firstTransaction, transactionPreviewData, firstTransaction?.reportAction?.childReportID); + setOptimisticDataForTransactionThreadPreview(firstTransaction, transactionPreviewData, getCurrencyDecimals, firstTransaction?.reportAction?.childReportID); } } @@ -659,7 +663,7 @@ function Search({ markReportRHPWidth(reportID, 'wide'); if (isTransactionItem && transactionPreviewData) { - setOptimisticDataForTransactionThreadPreview(transactionItem, transactionPreviewData, transactionItem?.reportAction?.childReportID); + setOptimisticDataForTransactionThreadPreview(transactionItem, transactionPreviewData, getCurrencyDecimals, transactionItem?.reportAction?.childReportID); } const route = ROUTES.SEARCH_REPORT.getRoute({reportID, backTo}); @@ -684,6 +688,7 @@ function Search({ searchResults?.search?.hasMoreResults, currentSearchKey, filteredData, + getCurrencyDecimals, ], ); diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 4ebbf4edcba9..8b3486942da4 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -10,6 +10,7 @@ import RenderHTML from '@components/RenderHTML'; import useActiveAdminPolicies from '@hooks/useActiveAdminPolicies'; import useConfirmModal from '@hooks/useConfirmModal'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLastWorkspaceNumber from '@hooks/useLastWorkspaceNumber'; @@ -115,6 +116,7 @@ function SettlementButton({ const icons = useMemoizedLazyExpensifyIcons(['CheckCircle', 'ThumbsUp', 'Bank', 'Cash', 'Wallet', 'Building', 'User']); const styles = useThemeStyles(); const {translate, localeCompare} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {isOffline} = useNetwork(); const policy = usePolicy(policyID); const expenseReportPolicy = usePolicy(iouReport?.policyID); @@ -506,6 +508,7 @@ function SettlementButton({ confirmApproval(); } else { approveMoneyRequest({ + getCurrencyDecimals, expenseReport: iouReport, expenseReportPolicy, currentUserAccountIDParam: accountID, diff --git a/src/hooks/useBulkDuplicateAction.ts b/src/hooks/useBulkDuplicateAction.ts index 5aa86c46b0ad..a935a54bccb0 100644 --- a/src/hooks/useBulkDuplicateAction.ts +++ b/src/hooks/useBulkDuplicateAction.ts @@ -15,6 +15,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {hasSeenTourSelector} from '@selectors/Onboarding'; import {validTransactionDraftsSelector} from '@selectors/TransactionDraft'; +import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDefaultExpensePolicy from './useDefaultExpensePolicy'; import useDelegateAccountID from './useDelegateAccountID'; @@ -41,6 +42,7 @@ function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allR const {accountID, login: currentUserLogin, localCurrencyCode} = useCurrentUserPersonalDetails(); const delegateAccountID = useDelegateAccountID(); const {formatPhoneNumber} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {clearSelectedTransactions} = useSearchSelectionActions(); const defaultExpensePolicy = useDefaultExpensePolicy(); const {isBetaEnabled} = usePermissions(); @@ -76,6 +78,7 @@ function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allR const handleDuplicate = () => { bulkDuplicateExpenses({ + getCurrencyDecimals, transactionIDs: selectedTransactionsKeys, allTransactions: allTransactions ?? {}, sourcePolicyIDMap, diff --git a/src/hooks/useDeleteTransactions.ts b/src/hooks/useDeleteTransactions.ts index 4c2e5a983ebd..3ab6c81a051e 100644 --- a/src/hooks/useDeleteTransactions.ts +++ b/src/hooks/useDeleteTransactions.ts @@ -309,6 +309,7 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac currentSearchHash !== undefined && currentSearchHash >= 0 ? getActiveGroupSearchHashes(currentSearchResults?.data, currentSearchQueryJSON) : []; updateSplitTransactions({ + getCurrencyDecimals, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, diff --git a/src/hooks/useExpenseActions.ts b/src/hooks/useExpenseActions.ts index 198d1b0d1b54..7213ea0d79e1 100644 --- a/src/hooks/useExpenseActions.ts +++ b/src/hooks/useExpenseActions.ts @@ -262,6 +262,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined; duplicateTransactionAction({ + getCurrencyDecimals, transaction: item, optimisticChatReportID, optimisticIOUReportID, diff --git a/src/hooks/useHoldMenuSubmit.ts b/src/hooks/useHoldMenuSubmit.ts index 7b2895f401a1..a5d618fa40af 100644 --- a/src/hooks/useHoldMenuSubmit.ts +++ b/src/hooks/useHoldMenuSubmit.ts @@ -18,6 +18,7 @@ import {delegateEmailSelector} from '@selectors/Account'; import {hasSeenTourSelector} from '@selectors/Onboarding'; import {personalDetailsLoginSelector} from '@selectors/PersonalDetails'; +import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDelegateAccountID from './useDelegateAccountID'; import useOnyx from './useOnyx'; @@ -58,6 +59,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment const isTrackIntentUser = isTrackOnboardingChoice(introSelected?.choice); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const currentUserDetails = useCurrentUserPersonalDetails(); + const {getCurrencyDecimals} = useCurrencyListActions(); const delegateAccountID = useDelegateAccountID(); const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.email ?? ''); @@ -83,6 +85,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment if (isApprove) { approveMoneyRequest({ + getCurrencyDecimals, expenseReport: currentMoneyRequestReport, currentUserAccountIDParam: currentUserDetails.accountID, currentUserEmailParam: currentUserDetails.email ?? '', @@ -102,6 +105,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment }); } else if (currentChatReport && paymentType) { payMoneyRequest({ + getCurrencyDecimals, paymentType, chatReport: currentChatReport, iouReport: currentMoneyRequestReport, diff --git a/src/hooks/useLifecycleActions.tsx b/src/hooks/useLifecycleActions.tsx index 3dd3fe3e163f..e20fae8144db 100644 --- a/src/hooks/useLifecycleActions.tsx +++ b/src/hooks/useLifecycleActions.tsx @@ -38,6 +38,7 @@ import React from 'react'; import useConfirmModal from './useConfirmModal'; import useConfirmPendingRTERAndProceed from './useConfirmPendingRTERAndProceed'; +import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDelegateAccountID from './useDelegateAccountID'; import {useMemoizedLazyExpensifyIcons} from './useLazyAsset'; @@ -110,6 +111,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, const {isOffline} = useNetwork(); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const styles = useThemeStyles(); const {showConfirmModal} = useConfirmModal(); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); @@ -174,6 +176,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, startApprovedAnimation(); } approveMoneyRequest({ + getCurrencyDecimals, expenseReport: moneyRequestReport, expenseReportPolicy: policy, currentUserAccountIDParam: accountID, @@ -226,6 +229,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, return; } submitReport({ + getCurrencyDecimals, expenseReport: moneyRequestReport, policy, currentUserAccountIDParam: accountID, @@ -309,7 +313,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, CONST.IOU.REPORT_ACTION_TYPE.PAY, () => { startAnimation(); - markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser); + markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser, getCurrencyDecimals); }, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, ); @@ -317,7 +321,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, } startAnimation(); - markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser); + markReportPaymentReceived(chatReport, moneyRequestReport, accountID, email ?? '', chatReportActions, isTrackIntentUser, getCurrencyDecimals); }, }, [CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE]: { @@ -352,7 +356,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, } } - unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, delegateEmail, isTrackIntentUser); + unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, delegateEmail, isTrackIntentUser, getCurrencyDecimals); }, }, [CONST.REPORT.SECONDARY_ACTIONS.CANCEL_PAYMENT]: { diff --git a/src/hooks/useReportActionsPagination.ts b/src/hooks/useReportActionsPagination.ts index 1b1f9c952bef..66f65895d20a 100644 --- a/src/hooks/useReportActionsPagination.ts +++ b/src/hooks/useReportActionsPagination.ts @@ -12,6 +12,7 @@ import type {OnyxEntry} from 'react-native-onyx'; import {useMemo, useState} from 'react'; +import {useCurrencyListActions} from './useCurrencyList'; import useNetwork from './useNetwork'; import useOnyx from './useOnyx'; import usePaginatedReportActions from './usePaginatedReportActions'; @@ -37,6 +38,7 @@ type UseReportActionsPaginationResult = { function useReportActionsPagination(reportID: string | undefined, reportActionIDFromRoute: string | undefined): UseReportActionsPaginationResult { const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const {isOffline} = useNetwork(); + const {getCurrencyDecimals} = useCurrencyListActions(); const parentReportAction = useParentReportAction(report); const [treatAsNoPaginationAnchor, setTreatAsNoPaginationAnchor] = useState(false); @@ -77,8 +79,8 @@ function useReportActionsPagination(reportID: string | undefined, reportActionID // and we also generate an expense action if the number of expenses in allReportActions is less than the total number of expenses // to display at least one expense action to match the total data. const reportActionsToDisplay = useMemo( - () => getReportActionsToDisplay(allReportActions, lastAction, report, reportPreviewAction, thread.transactionThreadReport, shouldAddCreatedAction), - [allReportActions, lastAction, report, reportPreviewAction, shouldAddCreatedAction, thread.transactionThreadReport], + () => getReportActionsToDisplay(allReportActions, lastAction, report, reportPreviewAction, thread.transactionThreadReport, shouldAddCreatedAction, getCurrencyDecimals), + [allReportActions, lastAction, report, reportPreviewAction, shouldAddCreatedAction, thread.transactionThreadReport, getCurrencyDecimals], ); const reportActions = useMemo( diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 1a1484172ce1..ca915e7755a1 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -959,6 +959,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { !!expenseReport.policyID && shouldRestrictUserBillableActions(reportPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID); approveMoneyRequest({ + getCurrencyDecimals, expenseReport, expenseReportPolicy: reportPolicy, currentUserAccountIDParam: accountID, @@ -1015,6 +1016,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { isTrackIntentUser, personalDetails, delegateAccountID, + getCurrencyDecimals, ]); const {expenseCount, uniqueReportCount} = useMemo(() => { @@ -1342,6 +1344,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const payChatReportID = shouldUseB2BInvoiceReport ? existingB2BInvoiceReport.reportID : chatReport.reportID; payInvoice({ + getCurrencyDecimals, paymentMethodType: paymentItem.paymentType as PaymentMethodType, chatReport, invoiceReport: iouReport, @@ -1369,6 +1372,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { } payMoneyRequest({ + getCurrencyDecimals, paymentType: paymentItem.paymentType as PaymentMethodType, chatReport, iouReport, @@ -1436,6 +1440,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { delegateAccountID, isTrackIntentUser, conciergeChat, + getCurrencyDecimals, ], ); diff --git a/src/hooks/useSelectionModePayment.ts b/src/hooks/useSelectionModePayment.ts index 9256023ebfd9..0c42b21a9f1a 100644 --- a/src/hooks/useSelectionModePayment.ts +++ b/src/hooks/useSelectionModePayment.ts @@ -30,6 +30,7 @@ import truncate from 'lodash/truncate'; import {useContext, useEffect, useRef} from 'react'; import useActiveAdminPolicies from './useActiveAdminPolicies'; +import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDelegateAccountID from './useDelegateAccountID'; import useLastWorkspaceNumber from './useLastWorkspaceNumber'; @@ -79,6 +80,7 @@ function useSelectionModePayment({ confirmApproval, }: UseSelectionModePaymentParams) { const {translate, localeCompare} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {isOffline} = useNetwork(); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); @@ -185,6 +187,7 @@ function useSelectionModePayment({ if (isInvoiceReport) { payInvoice({ + getCurrencyDecimals, paymentMethodType: type, chatReport, invoiceReport: moneyRequestReport, @@ -207,6 +210,7 @@ function useSelectionModePayment({ }); } else { payMoneyRequest({ + getCurrencyDecimals, paymentType: type, chatReport, iouReport: moneyRequestReport, @@ -299,6 +303,7 @@ function useSelectionModePayment({ const invokePaymentSelect = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => { selectPaymentType({ + getCurrencyDecimals, event, iouPaymentType, triggerKYCFlow, diff --git a/src/libs/IOUAmountSubmission.ts b/src/libs/IOUAmountSubmission.ts index 18dd8c5342f6..a3f6d7636bcc 100644 --- a/src/libs/IOUAmountSubmission.ts +++ b/src/libs/IOUAmountSubmission.ts @@ -1,5 +1,7 @@ import type {LocalizedTranslate} from '@components/LocaleContextProvider'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import CONST from '@src/CONST'; import type {IOUAction, IOUType} from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -103,6 +105,7 @@ type SubmitAmountArgs = { amountOwed: OnyxEntry; ownerBillingGracePeriodEnd: OnyxEntry; conciergeReportID: OnyxEntry; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; /** @@ -262,7 +265,7 @@ function buildReportParticipants(args: SubmitAmountArgs) { type ParticipantOption = ReturnType[number]; function submitSkipConfirmationPayment(args: SubmitAmountArgs, ctx: SubmitAmountContext, participants: ParticipantOption[]): void { - const {report, selectedCurrency, paymentMethod, quickAction, delegateAccountID} = args; + const {report, selectedCurrency, paymentMethod, quickAction, delegateAccountID, getCurrencyDecimals} = args; const {currentUserAccountID, newAmount: backendAmount} = ctx; const {optimisticChatReportID, chatReportID} = resolveOptimisticChatReportID([participants.at(0)?.accountID ?? CONST.DEFAULT_NUMBER_ID, currentUserAccountID], report); const sendMoneyParams = { @@ -276,6 +279,7 @@ function submitSkipConfirmationPayment(args: SubmitAmountArgs, ctx: SubmitAmount optimisticChatReportID, shouldStartTracking: false, delegateAccountID, + getCurrencyDecimals, }; const executeSendMoneyWrite = (overrides?: {shouldDeferForSearch?: boolean}) => { @@ -324,6 +328,7 @@ function submitSkipConfirmationExpense(args: SubmitAmountArgs, ctx: SubmitAmount action, currentUserPersonalDetails, isTrackIntentUser, + getCurrencyDecimals, } = args; const {currentUserAccountID, currentUserEmail, existingTransactionID, isASAPSubmitBetaEnabled, newAmount: backendAmount} = ctx; @@ -370,6 +375,7 @@ function submitSkipConfirmationExpense(args: SubmitAmountArgs, ctx: SubmitAmount optimisticTransactionID, delegateAccountID, reportActionsList: undefined, + getCurrencyDecimals, }); } else { const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined; @@ -409,6 +415,7 @@ function submitSkipConfirmationExpense(args: SubmitAmountArgs, ctx: SubmitAmount optimisticTransactionID, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); } cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, { diff --git a/src/libs/PaymentUtils.ts b/src/libs/PaymentUtils.ts index ec778dff621c..0aba0848554b 100644 --- a/src/libs/PaymentUtils.ts +++ b/src/libs/PaymentUtils.ts @@ -6,6 +6,8 @@ import type {PopoverMenuItem} from '@components/PopoverMenu'; import type {BankAccountMenuItem} from '@components/Search/types'; import type {PaymentActionParams} from '@components/SettlementButton/types'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import type {ThemeStyles} from '@styles/index'; import CONST from '@src/CONST'; @@ -55,6 +57,7 @@ type SelectPaymentTypeParams = { delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; ownerLogin: string | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type BusinessBankAccountOption = { @@ -230,6 +233,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => { delegateAccountID, isTrackIntentUser, ownerLogin, + getCurrencyDecimals, } = params; if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentAccountID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); @@ -266,6 +270,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => { delegateEmail, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); } return; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5593a0fa9101..5c7261e1de77 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -122,7 +122,7 @@ import {removeDraftTransactionsByIDs} from './actions/TransactionEdit'; import {getOnboardingMessages} from './actions/Welcome/OnboardingFlow'; import {convertAttendeesToArray} from './AttendeeUtils'; import {getCategoryGLCode} from './CategoryUtils'; -import {convertToDisplayString as convertToDisplayStringUtil, convertToDisplayStringEnLocale, getCurrencyDecimals as getCurrencyDecimalsUtil} from './CurrencyUtils'; +import {convertToDisplayStringEnLocale} from './CurrencyUtils'; import DateUtils from './DateUtils'; import {getEnvironmentURL} from './Environment/Environment'; import getEnvironment from './Environment/getEnvironment'; @@ -448,6 +448,7 @@ type BuildOptimisticIOUReportActionParams = { // TODO: delegateAccountIDParam will be made required when all callers pass the value (https://github.com/Expensify/App/issues/66425) delegateAccountIDParam?: number; isSubmitterMarkedPaymentReceived?: boolean; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type OptimisticIOUReportAction = Pick< @@ -749,6 +750,7 @@ type BaseOptimisticMoneyRequestEntities = { currentUserAccountID: number; // TODO: delegateAccountIDParam will be made required when all callers pass the value (https://github.com/Expensify/App/issues/66425) delegateAccountIDParam?: number; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type OptimisticMoneyRequestEntities = BaseOptimisticMoneyRequestEntities & {shouldGenerateTransactionThreadReport?: boolean}; @@ -995,6 +997,7 @@ type BuildOptimisticExpenseReportParams = { reportTransactions?: Record; createdTimestamp?: string; currencyList?: CurrencyList; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type ReportByPolicyMap = Record>; @@ -6900,12 +6903,13 @@ function buildOptimisticIOUReport( total: number, chatReportID: string | undefined, currency: string, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], isSendingMoney = false, parentReportActionID?: string, optimisticIOUReportID?: string, createdTimestamp?: string, ): OptimisticIOUReport { - const formattedTotal = convertToDisplayStringUtil(total, currency); + const formattedTotal = convertToDisplayStringEnLocale(total, currency, getCurrencyDecimals); const personalDetails = getPersonalDetailsForAccountID(payerAccountID); const payerEmail = 'login' in personalDetails ? personalDetails.login : ''; const policyID = chatReportID ? getReport(chatReportID, deprecatedAllReports)?.policyID : undefined; @@ -6958,8 +6962,9 @@ function buildOptimisticInvoiceReport( receiverName: string, total: number, currency: string, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], ): OptimisticExpenseReport { - const formattedTotal = convertToDisplayStringUtil(total, currency); + const formattedTotal = convertToDisplayStringEnLocale(total, currency, getCurrencyDecimals); const created = DateUtils.getDBTime(); const invoiceReport = { reportID: generateReportID(), @@ -7101,13 +7106,14 @@ function buildOptimisticExpenseReport({ reportTransactions, createdTimestamp, currencyList, + getCurrencyDecimals, }: BuildOptimisticExpenseReportParams): OptimisticExpenseReport { // The amount for Expense reports are stored as negative value in the database const storedTotal = total * -1; const storedNonReimbursableTotal = nonReimbursableTotal * -1; const report = chatReportID ? getReportOrDraftReport(chatReportID) : undefined; const policyName = getPolicyName({report}); - const formattedTotal = convertToDisplayStringUtil(storedTotal, currency, false, currencyList); + const formattedTotal = convertToDisplayStringEnLocale(storedTotal, currency, getCurrencyDecimals); // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 const policyReal = getPolicy(policyID); const policyDraft = allPolicyDrafts?.[`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`]; @@ -7487,6 +7493,7 @@ function buildOptimisticIOUReportAction(params: BuildOptimisticIOUReportActionPa reportActionID, delegateAccountIDParam, isSubmitterMarkedPaymentReceived, + getCurrencyDecimals, } = params; const actionReportID = iouReportID || generateReportID(); @@ -7563,7 +7570,7 @@ function buildOptimisticIOUReportAction(params: BuildOptimisticIOUReportActionPa }, ], avatar: getCurrentUserAvatar(), - message: getIOUReportActionMessage(iouReportID, type, amount, comment, currency, getCurrencyDecimalsUtil, paymentType, isSettlingUp, bankAccountID, payAsBusiness), + message: getIOUReportActionMessage(iouReportID, type, amount, comment, currency, getCurrencyDecimals, paymentType, isSettlingUp, bankAccountID, payAsBusiness), }; return iouReportAction; @@ -7578,6 +7585,7 @@ function buildOptimisticApprovedReportAction( expenseReportID: string, currentUserAccountID: number, delegateEmailParam: string | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], ): OptimisticApprovedReportAction { const originalMessage = { amount, @@ -7593,7 +7601,7 @@ function buildOptimisticApprovedReportAction( avatar: getCurrentUserAvatar(), isAttachmentOnly: false, originalMessage, - message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.APPROVED, Math.abs(amount), '', currency, getCurrencyDecimalsUtil), + message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.APPROVED, Math.abs(amount), '', currency, getCurrencyDecimals), person: [ { style: 'strong', @@ -7612,7 +7620,13 @@ function buildOptimisticApprovedReportAction( /** * Builds an optimistic APPROVED report action with a randomly generated reportActionID. */ -function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string, delegateEmailParam: string | undefined): OptimisticUnapprovedReportAction { +function buildOptimisticUnapprovedReportAction( + amount: number, + currency: string, + expenseReportID: string, + delegateEmailParam: string | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], +): OptimisticUnapprovedReportAction { const delegateAccountDetails = delegateEmailParam ? getPersonalDetailByEmail(delegateEmailParam) : undefined; return { actionName: CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, @@ -7625,7 +7639,7 @@ function buildOptimisticUnapprovedReportAction(amount: number, currency: string, currency, expenseReportID, }, - message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, Math.abs(amount), '', currency, getCurrencyDecimalsUtil), + message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.UNAPPROVED, Math.abs(amount), '', currency, getCurrencyDecimals), person: [ { style: 'strong', @@ -7844,6 +7858,7 @@ function buildOptimisticSubmittedReportAction( adminAccountID: number | undefined, workflow: ValueOf | undefined, delegateEmailParam: string | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], ): OptimisticSubmittedReportAction { const originalMessage = { amount, @@ -7862,7 +7877,7 @@ function buildOptimisticSubmittedReportAction( avatar: getCurrentUserAvatar(), isAttachmentOnly: false, originalMessage, - message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.SUBMITTED, Math.abs(amount), '', currency, getCurrencyDecimalsUtil), + message: getIOUReportActionMessage(expenseReportID, CONST.REPORT.ACTIONS.TYPE.SUBMITTED, Math.abs(amount), '', currency, getCurrencyDecimals), person: [ { style: 'strong', @@ -7890,6 +7905,7 @@ function buildOptimisticSubmittedReportAction( function buildOptimisticReportPreview( chatReport: OnyxInputOrEntry, iouReport: Report, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], comment = '', transaction: OnyxInputOrEntry = null, childReportID?: string, @@ -7897,7 +7913,7 @@ function buildOptimisticReportPreview( delegateAccountIDParam: number | undefined = undefined, ): ReportAction { const hasReceipt = hasReceiptTransactionUtils(transaction); - const message = getReportPreviewReportActionMessage({reportOrID: iouReport}, getCurrencyDecimalsUtil); + const message = getReportPreviewReportActionMessage({reportOrID: iouReport}, getCurrencyDecimals); const created = DateUtils.getDBTime(); const reportActorAccountID = (isInvoiceReport(iouReport) || isExpenseReport(iouReport) ? iouReport?.ownerAccountID : iouReport?.managerID) ?? -1; // Falls back to module-level delegateEmail (from Onyx.connect) for callers not yet migrated; will be removed in https://github.com/Expensify/App/issues/66425 @@ -8070,6 +8086,7 @@ function buildOptimisticDetachReceipt(reportID: string | undefined, transactionI function updateReportPreview( iouReport: OnyxEntry, reportPreviewAction: ReportAction, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], isPayRequest = false, comment = '', transaction?: OnyxEntry, @@ -8088,7 +8105,7 @@ function updateReportPreview( } } - const message = getReportPreviewReportActionMessage({reportOrID: iouReport, iouReportAction: reportPreviewAction}, getCurrencyDecimalsUtil); + const message = getReportPreviewReportActionMessage({reportOrID: iouReport, iouReportAction: reportPreviewAction}, getCurrencyDecimals); const originalMessage = getOriginalMessage(reportPreviewAction); return { ...reportPreviewAction, @@ -9191,6 +9208,7 @@ function buildOptimisticMoneyRequestEntities({ reportActionID, currentUserAccountID, delegateAccountIDParam, + getCurrencyDecimals, }: OptimisticMoneyRequestEntities): [ OptimisticCreatedReportAction, OptimisticCreatedReportAction, @@ -9213,6 +9231,7 @@ function buildOptimisticMoneyRequestEntities({ currency, comment, participants, + getCurrencyDecimals, transactionID, paymentType, iouReportID: iouReport.reportID, diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index b726c5fbd0ac..736ba1c0245c 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -2818,6 +2818,9 @@ type CreateAndOpenSearchTransactionThreadParams = { /** Whether to navigate to the transaction thread after creating it */ shouldNavigate?: boolean; + + /** Resolves decimal precision for a currency when formatting stored optimistic amounts */ + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; /** Creates transaction thread report and navigates to it from the search page */ @@ -2833,6 +2836,7 @@ function createAndOpenSearchTransactionThread({ IOUTransactionID, transactionPreviewData, shouldNavigate = true, + getCurrencyDecimals, }: CreateAndOpenSearchTransactionThreadParams): string | undefined { const isFromSelfDM = item.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const isDeleted = isDeletedTransaction(item); @@ -2841,7 +2845,7 @@ function createAndOpenSearchTransactionThread({ const previewData = transactionPreviewData ? {...transactionPreviewData, hasTransactionThreadReport: true} : {hasTransaction: false, hasParentReport: false, hasParentReportAction: false, hasTransactionThreadReport: true}; - setOptimisticDataForTransactionThreadPreview(item, previewData, IOUTransactionID); + setOptimisticDataForTransactionThreadPreview(item, previewData, getCurrencyDecimals, IOUTransactionID); const hasActualTransactionThread = iouReportAction?.childReportID && iouReportAction?.childReportID !== CONST.FAKE_REPORT_ID; let transactionThreadReport; diff --git a/src/libs/actions/IOU/Duplicate.ts b/src/libs/actions/IOU/Duplicate.ts index 3eefbaf01bc9..2a2887ba5dfc 100644 --- a/src/libs/actions/IOU/Duplicate.ts +++ b/src/libs/actions/IOU/Duplicate.ts @@ -778,6 +778,7 @@ type DuplicateExpenseTransactionParams = { delegateAccountID: number | undefined; policyTagList: OnyxTypes.PolicyTagLists; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags; }; @@ -808,6 +809,7 @@ function duplicateExpenseTransaction({ delegateAccountID, policyTagList, formatPhoneNumber, + getCurrencyDecimals, participantsPolicyTags, }: DuplicateExpenseTransactionParams) { if (!transaction) { @@ -860,6 +862,7 @@ function duplicateExpenseTransaction({ shouldDeferAutoSubmit, isTrackIntentUser, delegateAccountID, + getCurrencyDecimals, }; // If no workspace is provided the expense should be unreported @@ -1092,6 +1095,7 @@ function duplicateReport({ shouldDeferAutoSubmit: !isLastExpense, isTrackIntentUser, delegateAccountID, + getCurrencyDecimals, }; const result = createExpenseByType({ @@ -1144,6 +1148,7 @@ type BulkDuplicateExpensesParams = { delegateAccountID: number | undefined; policyTagList: OnyxTypes.PolicyTagLists; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags; }; @@ -1170,6 +1175,7 @@ function bulkDuplicateExpenses({ delegateAccountID, policyTagList, formatPhoneNumber, + getCurrencyDecimals, participantsPolicyTags, }: BulkDuplicateExpensesParams) { const transactionsToDuplicate = transactionIDs.map((id) => allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]).filter((t): t is OnyxTypes.Transaction => !!t); @@ -1270,6 +1276,7 @@ function bulkDuplicateExpenses({ delegateAccountID, policyTagList, formatPhoneNumber, + getCurrencyDecimals, participantsPolicyTags, }); diff --git a/src/libs/actions/IOU/Hold.ts b/src/libs/actions/IOU/Hold.ts index e5731308b81b..2abd57421d62 100644 --- a/src/libs/actions/IOU/Hold.ts +++ b/src/libs/actions/IOU/Hold.ts @@ -1,3 +1,5 @@ +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import * as API from '@libs/API'; import type {HoldMoneyRequestParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -662,6 +664,7 @@ function getReportFromHoldRequestsOnyxData({ betas, isApprovalFlow = false, delegateAccountID, + getCurrencyDecimals, }: { chatReport: OnyxTypes.Report; iouReport: OnyxEntry; @@ -671,6 +674,7 @@ function getReportFromHoldRequestsOnyxData({ betas: OnyxEntry; isApprovalFlow?: boolean; delegateAccountID: number | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }): { optimisticHoldReportID: string; optimisticHoldActionID: string; @@ -712,6 +716,7 @@ function getReportFromHoldRequestsOnyxData({ betas, reportTransactions, createdTimestamp, + getCurrencyDecimals, }) : buildOptimisticIOUReport( iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID, @@ -719,6 +724,7 @@ function getReportFromHoldRequestsOnyxData({ holdAmount, chatReport.reportID, iouReport?.currency ?? '', + getCurrencyDecimals, false, newParentReportActionID, undefined, @@ -728,6 +734,7 @@ function getReportFromHoldRequestsOnyxData({ const optimisticExpenseReportPreview = buildOptimisticReportPreview( chatReport, optimisticExpenseReport, + getCurrencyDecimals, '', firstHoldTransaction, optimisticExpenseReport.reportID, diff --git a/src/libs/actions/IOU/MoneyRequest.ts b/src/libs/actions/IOU/MoneyRequest.ts index bffe674960b6..340f7c51b153 100644 --- a/src/libs/actions/IOU/MoneyRequest.ts +++ b/src/libs/actions/IOU/MoneyRequest.ts @@ -101,6 +101,7 @@ type CreateTransactionParams = { currentUserLocalCurrency: string | undefined; isTrackIntentUser: boolean | undefined; delegateAccountID: number | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type SetMoneyRequestCommuterExclusionFieldsParams = { @@ -144,6 +145,7 @@ function createTransaction({ currentUserLocalCurrency, isTrackIntentUser, delegateAccountID, + getCurrencyDecimals, }: CreateTransactionParams) { const draftTransactionIDs = Object.keys(allTransactionDrafts ?? {}); @@ -206,6 +208,7 @@ function createTransaction({ currentUserLocalCurrency, delegateAccountID, reportActionsList: undefined, + getCurrencyDecimals, }); } else { const existingTransactionID = getExistingTransactionID(transaction?.linkedTrackedExpenseReportAction); @@ -252,6 +255,7 @@ function createTransaction({ optimisticTransactionID, isTrackIntentUser, delegateAccountID, + getCurrencyDecimals, }); } } diff --git a/src/libs/actions/IOU/MoneyRequestBuilder.ts b/src/libs/actions/IOU/MoneyRequestBuilder.ts index 6bf908bdcce5..019cf6211251 100644 --- a/src/libs/actions/IOU/MoneyRequestBuilder.ts +++ b/src/libs/actions/IOU/MoneyRequestBuilder.ts @@ -1,3 +1,5 @@ +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import DateUtils from '@libs/DateUtils'; import {getMicroSecondOnyxErrorObject, getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils'; import {isLocalFile} from '@libs/fileDownload/FileUtils'; @@ -194,6 +196,7 @@ type RequestMoneyInformation = { shouldDeferAutoSubmit?: boolean; delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type MoneyRequestInformationParams = { @@ -229,6 +232,7 @@ type MoneyRequestInformationParams = { personalDetails: OnyxEntry; isTrackIntentUser: boolean | undefined; delegateAccountID: number | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type MoneyRequestOptimisticParams = { @@ -284,6 +288,7 @@ type BuildOnyxDataForMoneyRequestParams = { /** Whether to skip the `pendingNewTransactionIDs` highlight rail because this flow never opens the expense report */ shouldSkipReportHighlightRail?: boolean; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type BuildOnyxDataForTestDriveIOUParams = { @@ -292,6 +297,7 @@ type BuildOnyxDataForTestDriveIOUParams = { chatOptimisticParams: MoneyRequestOptimisticParams['chat']; testDriveCommentReportActionID?: string; currentUserAccountIDParam: number; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; function buildMinimalTransactionForFormula( @@ -374,6 +380,7 @@ function buildOnyxDataForTestDriveIOU( reportActionID: testDriveIOUParams.iouOptimisticParams.action.reportActionID, // delegateAccountIDParam: will be threaded in PR 14; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425) delegateAccountIDParam: undefined, + getCurrencyDecimals: testDriveIOUParams.getCurrencyDecimals, }); const text = translateLocal('testDrive.employeeInviteMessage', getAllPersonalDetails()?.[testDriveIOUParams.currentUserAccountIDParam]?.firstName ?? ''); // delegateAccountIDParam: will be threaded in PR 15; buildOptimisticAddCommentReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425) @@ -447,6 +454,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR selfDMReportID, shouldSkipReportHighlightRail, isTrackIntentUser, + getCurrencyDecimals, } = moneyRequestParams; const {policy, policyCategories, policyTagList} = policyParams; const { @@ -753,6 +761,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR chatOptimisticParams: chat, testDriveCommentReportActionID, currentUserAccountIDParam, + getCurrencyDecimals, }); onyxData.optimisticData?.push(...testDriveOptimisticData); onyxData.successData?.push(...testDriveSuccessData); @@ -1276,6 +1285,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma betas, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, } = moneyRequestInformation; const {payeeAccountID = currentUserAccountIDParam, payeeEmail = currentUserEmailParam, participant} = participantParams; const {policy, policyCategories, policyTagList, policyRecentlyUsedCategories, policyRecentlyUsedTags} = policyParams; @@ -1406,8 +1416,9 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma optimisticIOUReportID: optimisticReportID, reportTransactions, betas, + getCurrencyDecimals, }) - : buildOptimisticIOUReport(payeeAccountID, payerAccountID, reportAmount, chatReport.reportID, currency, undefined, undefined, optimisticReportID); + : buildOptimisticIOUReport(payeeAccountID, payerAccountID, reportAmount, chatReport.reportID, currency, getCurrencyDecimals, undefined, undefined, optimisticReportID); } else if (isPolicyExpenseChat) { // Capture previous fresh reimbursable totals before mutating, so the diff applies whether or // not the iouReport already had reimbursableTotal/unheldReimbursableTotal populated locally. @@ -1594,6 +1605,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma } const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport, type: iouActionType, amount: iouActionAmount, @@ -1616,9 +1628,18 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { - reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction); + reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, false, comment, optimisticTransaction); } else { - reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction, undefined, optimisticReportPreviewActionID, delegateAccountID); + reportPreviewAction = buildOptimisticReportPreview( + chatReport, + iouReport, + getCurrencyDecimals, + comment, + optimisticTransaction, + undefined, + optimisticReportPreviewActionID, + delegateAccountID, + ); chatReport.lastVisibleActionCreated = reportPreviewAction.created; // Generated ReportPreview action is a parent report action of the iou report. @@ -1713,6 +1734,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma selfDMReportID, shouldSkipReportHighlightRail, isTrackIntentUser, + getCurrencyDecimals, }); return { diff --git a/src/libs/actions/IOU/PayMoneyRequest.ts b/src/libs/actions/IOU/PayMoneyRequest.ts index 0e4611f451a2..9337ea2c52f8 100644 --- a/src/libs/actions/IOU/PayMoneyRequest.ts +++ b/src/libs/actions/IOU/PayMoneyRequest.ts @@ -1,5 +1,7 @@ import type {PaymentMethod} from '@components/KYCWall/types'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import * as API from '@libs/API'; import type {MarkReportPaymentReceivedParams, PayInvoiceParams, PayMoneyRequestParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -73,6 +75,7 @@ type PayInvoiceArgs = { shouldPlaySuccessSound?: boolean; delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type PayMoneyRequestData = { @@ -121,6 +124,7 @@ type PayMoneyRequestFunctionParams = { delegateAccountID: number | undefined; chatReportActions: OnyxEntry; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; function mergeAdditionalPayOnyxData< @@ -166,6 +170,7 @@ function getPayMoneyRequestParams({ delegateAccountID, chatReportActions, isTrackIntentUser, + getCurrencyDecimals, }: { initialChatReport: OnyxTypes.Report; iouReport: OnyxEntry; @@ -190,6 +195,7 @@ function getPayMoneyRequestParams({ delegateAccountID: number | undefined; chatReportActions: OnyxEntry; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }): PayMoneyRequestData { // TODO: https://github.com/Expensify/App/issues/66512 // eslint-disable-next-line @typescript-eslint/no-deprecated @@ -281,6 +287,7 @@ function getPayMoneyRequestParams({ payAsBusiness, bankAccountID, delegateAccountIDParam: delegateAccountID, + getCurrencyDecimals, }); // In some instances, the report preview action might not be available to the payer (only whispered to the requestor) @@ -288,7 +295,7 @@ function getPayMoneyRequestParams({ let optimisticReportPreviewAction = null; const reportPreviewAction = getReportPreviewAction(chatReport.reportID, iouReport?.reportID, chatReportActions); if (reportPreviewAction) { - optimisticReportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, true); + optimisticReportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, true); } let optimisticNextStep = null; if (!isInvoiceReport) { @@ -486,7 +493,7 @@ function getPayMoneyRequestParams({ let optimisticHoldActionID; let optimisticHoldReportExpenseActionIDs; if (!full) { - const holdReportOnyxData = getReportFromHoldRequestsOnyxData({chatReport, iouReport, recipient, policy: reportPolicy, betas, delegateAccountID}); + const holdReportOnyxData = getReportFromHoldRequestsOnyxData({chatReport, iouReport, recipient, policy: reportPolicy, betas, delegateAccountID, getCurrencyDecimals}); onyxData.optimisticData?.push(...holdReportOnyxData.optimisticData); onyxData.successData?.push(...holdReportOnyxData.successData); @@ -782,6 +789,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) { delegateAccountID, chatReportActions, isTrackIntentUser, + getCurrencyDecimals, } = params; const policyForBillingRestriction = chatReportPolicy ?? (policy?.id === chatReport.policyID ? policy : undefined); if ( @@ -817,6 +825,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) { delegateAccountID, chatReportActions, isTrackIntentUser, + getCurrencyDecimals, }); // For now, we need to call the PayMoneyRequestWithWallet API since PayMoneyRequest was not updated to work with @@ -839,6 +848,7 @@ function markReportPaymentReceived( currentUserEmail: string, chatReportActions: OnyxEntry, isTrackIntentUser: boolean | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], ) { if (!chatReport || !iouReport) { return; @@ -859,6 +869,7 @@ function markReportPaymentReceived( iouReportID: iouReport.reportID, isSettlingUp: true, isSubmitterMarkedPaymentReceived: true, + getCurrencyDecimals, }); // buildOptimisticIOUReportAction formats the action's `message` as "paid ... elsewhere", so override it with @@ -870,7 +881,7 @@ function markReportPaymentReceived( optimisticIOUReportAction.message = [{html: receivedPaymentMessage, text: receivedPaymentMessage, isEdited: false, type: CONST.REPORT.MESSAGE.TYPE.COMMENT}]; const reportPreviewAction = getReportPreviewAction(chatReport.reportID, iouReport.reportID, chatReportActions); - const optimisticReportPreviewAction = reportPreviewAction ? updateReportPreview(iouReport, reportPreviewAction, true) : null; + const optimisticReportPreviewAction = reportPreviewAction ? updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, true) : null; const optimisticNextStep = buildOptimisticNextStep({report: iouReport, predictedNextStatus: CONST.REPORT.STATUS_NUM.REIMBURSED, isTrackIntentUser}); const optimisticData: Array> = [ @@ -1020,6 +1031,7 @@ function payInvoice({ shouldPlaySuccessSound = true, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }: PayInvoiceArgs) { const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID}; const { @@ -1057,6 +1069,7 @@ function payInvoice({ chatReportActions, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA; diff --git a/src/libs/actions/IOU/PerDiem.ts b/src/libs/actions/IOU/PerDiem.ts index 80f03d9b9a05..4a854e1bd7e8 100644 --- a/src/libs/actions/IOU/PerDiem.ts +++ b/src/libs/actions/IOU/PerDiem.ts @@ -1,5 +1,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import * as API from '@libs/API'; import type {CreatePerDiemRequestParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -244,6 +246,7 @@ type PerDiemExpenseInformation = { formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type PerDiemExpenseInformationParams = { @@ -268,6 +271,7 @@ type PerDiemExpenseInformationParams = { formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type PerDiemExpenseInformationForSelfDM = { @@ -281,6 +285,7 @@ type PerDiemExpenseInformationForSelfDM = { optimisticChatReportID: string; delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type PerDiemExpenseInformationForSelfDMResult = { @@ -325,6 +330,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI formatPhoneNumber, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, } = perDiemExpenseInformation; const {payeeAccountID = currentUserAccountIDParam, payeeEmail = currentUserEmailParam, participant} = participantParams; const {policy, policyCategories, policyTagList, policyRecentlyUsedCategories, policyRecentlyUsedTags} = policyParams; @@ -397,8 +403,9 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI optimisticIOUReportID: optimisticReportID, reportTransactions, betas, + getCurrencyDecimals, }) - : buildOptimisticIOUReport(payeeAccountID, payerAccountID, amount, chatReport.reportID, currency); + : buildOptimisticIOUReport(payeeAccountID, payerAccountID, amount, chatReport.reportID, currency, getCurrencyDecimals); } else if (isPolicyExpenseChat) { // Capture the previous reimbursable totals before the mutation so we can apply the diff // consistently regardless of whether the freshly tracked field was already populated. @@ -467,6 +474,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI // Note: The CREATED action for the IOU report must be optimistically generated before the IOU action so there's no chance that it appears after the IOU action in the chat const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount, @@ -484,9 +492,18 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { - reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction); + reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, false, comment, optimisticTransaction); } else { - reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction, undefined, optimisticReportPreviewActionID, delegateAccountID); + reportPreviewAction = buildOptimisticReportPreview( + chatReport, + iouReport, + getCurrencyDecimals, + comment, + optimisticTransaction, + undefined, + optimisticReportPreviewActionID, + delegateAccountID, + ); chatReport.lastVisibleActionCreated = reportPreviewAction.created; // Generated ReportPreview action is a parent report action of the iou report. @@ -566,6 +583,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI personalDetails, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); return { @@ -594,7 +612,8 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI * Gathers all the data needed to submit a per diem expense from self DM. */ function getPerDiemExpenseInformationForSelfDM(perDiemExpenseInformation: PerDiemExpenseInformationForSelfDM): PerDiemExpenseInformationForSelfDMResult { - const {selfDMReport, transactionParams, policy, currentUserAccountIDParam, currentUserEmailParam, quickAction, optimisticChatReportID, delegateAccountID} = perDiemExpenseInformation; + const {selfDMReport, transactionParams, policy, currentUserAccountIDParam, currentUserEmailParam, quickAction, optimisticChatReportID, delegateAccountID, getCurrencyDecimals} = + perDiemExpenseInformation; const {comment = '', currency, created, category, tag, customUnit, billable, attendees, reimbursable} = transactionParams; const amount = computePerDiemExpenseAmount(customUnit); @@ -742,6 +761,7 @@ function getPerDiemExpenseInformationForSelfDM(perDiemExpenseInformation: PerDie }; const [, , iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: chatReport, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount, @@ -926,6 +946,7 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf formatPhoneNumber, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, } = submitPerDiemExpenseInformation; const {currency, comment = '', category, tag, created, customUnit, attendees, isFromGlobalCreate} = transactionParams; @@ -980,6 +1001,7 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf formatPhoneNumber, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); const activeReportID = isMoneyRequestReport && Navigation.getTopmostReportId() === report?.reportID ? report?.reportID : chatReport.reportID; @@ -1049,8 +1071,18 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf * Submit a per diem expense from self DM */ function submitPerDiemExpenseForSelfDM(submitPerDiemExpenseInformation: PerDiemExpenseInformationForSelfDM) { - const {selfDMReport, policy, transactionParams, currentUserAccountIDParam, currentUserEmailParam, quickAction, optimisticChatReportID, delegateAccountID, isTrackIntentUser} = - submitPerDiemExpenseInformation; + const { + selfDMReport, + policy, + transactionParams, + currentUserAccountIDParam, + currentUserEmailParam, + quickAction, + optimisticChatReportID, + delegateAccountID, + isTrackIntentUser, + getCurrencyDecimals, + } = submitPerDiemExpenseInformation; const {currency, comment = '', category, tag, created, customUnit, attendees, billable, reimbursable} = transactionParams; if ( @@ -1065,6 +1097,7 @@ function submitPerDiemExpenseForSelfDM(submitPerDiemExpenseInformation: PerDiemE } const {chatReport, transaction, iouAction, transactionThreadReportID, createdReportActionIDForThread, onyxData} = getPerDiemExpenseInformationForSelfDM({ + getCurrencyDecimals, selfDMReport, policy, transactionParams, diff --git a/src/libs/actions/IOU/RejectMoneyRequest.ts b/src/libs/actions/IOU/RejectMoneyRequest.ts index e56afad081be..6c4ef8590a13 100644 --- a/src/libs/actions/IOU/RejectMoneyRequest.ts +++ b/src/libs/actions/IOU/RejectMoneyRequest.ts @@ -1,3 +1,5 @@ +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import * as API from '@libs/API'; import type {MarkTransactionViolationAsResolvedParams, RejectExpenseReportParams, RejectMoneyRequestParams, SetNameValuePairParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -111,18 +113,33 @@ function dismissRejectUseExplanation() { * - sharedRejectedToReportID: When rejecting multiple expenses sequentially, pass a single shared destination reportID so all rejections land in the same new report. * @returns optimisticData, successData, failureData, parameters, urlToNavigateBack */ -function prepareRejectMoneyRequestData( - transactionID: string, - reportID: string, - comment: string, - policy: OnyxEntry, - currentUserAccountIDParam: number, - currentUserLogin: string, - betas: OnyxEntry, - delegateAccountID: number | undefined, - options?: RejectMoneyRequestOptions, - shouldUseBulkAction?: boolean, -): RejectMoneyRequestData | undefined { +type PrepareRejectMoneyRequestDataParams = { + transactionID: string; + reportID: string; + comment: string; + policy: OnyxEntry; + currentUserAccountIDParam: number; + currentUserLogin: string; + betas: OnyxEntry; + delegateAccountID: number | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; + options?: RejectMoneyRequestOptions; + shouldUseBulkAction?: boolean; +}; + +function prepareRejectMoneyRequestData({ + transactionID, + reportID, + comment, + policy, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + getCurrencyDecimals, + options, + shouldUseBulkAction, +}: PrepareRejectMoneyRequestDataParams): RejectMoneyRequestData | undefined { const allTransactions = getAllTransactions(); const allReports = getAllReports(); // TODO: https://github.com/Expensify/App/issues/66512 @@ -386,6 +403,7 @@ function prepareRejectMoneyRequestData( rejectedToReportID = existingOpenReport.reportID; const [, , iouAction] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: movedToReport, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: transactionAmount, @@ -480,8 +498,10 @@ function prepareRejectMoneyRequestData( optimisticIOUReportID: rejectedToReportID, reportTransactions, betas, + getCurrencyDecimals, }); const [, createdActionForExpenseReport, iouAction] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: newExpenseReport, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: transactionAmount, @@ -496,7 +516,7 @@ function prepareRejectMoneyRequestData( delegateAccountIDParam: delegateAccountID, }); - reportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, newExpenseReport, undefined, transaction, undefined, undefined, delegateAccountID); + reportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, newExpenseReport, getCurrencyDecimals, undefined, transaction, undefined, undefined, delegateAccountID); movedTransactionAction = buildOptimisticMovedTransactionAction(childReportID, newExpenseReport.reportID); createdIOUReportActionID = iouAction.reportActionID; expenseMovedReportActionID = movedTransactionAction.reportActionID; @@ -920,9 +940,21 @@ function rejectMoneyRequest( currentUserLogin: string, betas: OnyxEntry, delegateAccountID: number | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], options?: RejectMoneyRequestOptions, ): Route | undefined { - const data = prepareRejectMoneyRequestData(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, options); + const data = prepareRejectMoneyRequestData({ + transactionID, + reportID, + comment, + policy, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + getCurrencyDecimals, + options, + }); if (!data) { return; } diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index 1cb4a0b029ad..de9551cd17dd 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -1,5 +1,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import * as API from '@libs/API'; import type { AddReportApproverParams, @@ -114,6 +116,7 @@ type ApproveMoneyRequestFunctionParams = { ownerLogin: string | undefined; additionalOnyxData?: AdditionalPayOnyxData; shouldPlaySuccessSound?: boolean; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type SubmitReportFunctionParams = { @@ -139,6 +142,7 @@ type SubmitReportFunctionParams = { * writes the generated PDF filename back into Onyx and the App auto-downloads it. Used by "Submit via PDF". */ shouldExportToPDF?: boolean; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; function canApproveIOU( @@ -461,6 +465,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { additionalOnyxData, shouldPlaySuccessSound = true, isTrackIntentUser, + getCurrencyDecimals, } = params; if (!expenseReport) { return; @@ -487,7 +492,14 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { if (hasHeldExpenses && !full && !!unheldTotal) { total = unheldTotal; } - const optimisticApprovedReportAction = buildOptimisticApprovedReportAction(total, expenseReport.currency ?? '', expenseReport.reportID, currentUserAccountIDParam, delegateEmail); + const optimisticApprovedReportAction = buildOptimisticApprovedReportAction( + total, + expenseReport.currency ?? '', + expenseReport.reportID, + currentUserAccountIDParam, + delegateEmail, + getCurrencyDecimals, + ); const isDEWPolicy = hasDynamicExternalWorkflow(expenseReportPolicy); const shouldAddOptimisticApproveAction = !isDEWPolicy || getIsOffline(); @@ -736,6 +748,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { isApprovalFlow: true, betas, delegateAccountID, + getCurrencyDecimals, }); optimisticData.push(...holdReportOnyxData.optimisticData); @@ -1136,12 +1149,19 @@ function unapproveExpenseReport( isASAPSubmitBetaEnabled: boolean, delegateEmail: string | undefined, isTrackIntentUser: boolean | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], ) { if (isEmptyObject(expenseReport)) { return; } - const optimisticUnapprovedReportAction = buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, delegateEmail); + const optimisticUnapprovedReportAction = buildOptimisticUnapprovedReportAction( + expenseReport.total ?? 0, + expenseReport.currency ?? '', + expenseReport.reportID, + delegateEmail, + getCurrencyDecimals, + ); const optimisticNextStep = buildOptimisticNextStep({ report: expenseReport, @@ -1285,6 +1305,7 @@ function submitReport({ managerAccountID: managerAccountIDFromPopover, shouldExportToPDF, isTrackIntentUser, + getCurrencyDecimals, }: SubmitReportFunctionParams) { if (!expenseReport) { return; @@ -1313,6 +1334,7 @@ function submitReport({ adminAccountID, policy?.approvalMode, delegateEmail, + getCurrencyDecimals, ); const isDEWPolicy = hasDynamicExternalWorkflow(policy); // For DEW policies, only add optimistic submit action when offline diff --git a/src/libs/actions/IOU/SendInvoice.ts b/src/libs/actions/IOU/SendInvoice.ts index d79eb812a11e..607a027c7f43 100644 --- a/src/libs/actions/IOU/SendInvoice.ts +++ b/src/libs/actions/IOU/SendInvoice.ts @@ -1,5 +1,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import * as API from '@libs/API'; import type {SendInvoiceParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -90,6 +92,7 @@ type SendInvoiceOptions = { senderPolicyTags: OnyxEntry; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; delegateAccountID: number | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type BuildOnyxDataForInvoiceParams = { @@ -636,6 +639,7 @@ function getSendInvoiceInformation({ senderPolicyTags, formatPhoneNumber, delegateAccountID, + getCurrencyDecimals, }: SendInvoiceOptions): SendInvoiceInformation { const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, taxValue, billable, comment, participants} = transaction ?? {}; const trimmedComment = (comment?.comment ?? '').trim(); @@ -669,6 +673,7 @@ function getSendInvoiceInformation({ receiver.displayName ?? (receiverParticipant as Participant)?.login ?? '', amount, currency, + getCurrencyDecimals, ); // STEP 3: Build optimistic receipt and transaction @@ -714,11 +719,21 @@ function getSendInvoiceInformation({ } // STEP 5: Build optimistic reportActions. - const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticInvoiceReport, trimmedComment, optimisticTransaction, undefined, undefined, delegateAccountID); + const reportPreviewAction = buildOptimisticReportPreview( + chatReport, + optimisticInvoiceReport, + getCurrencyDecimals, + trimmedComment, + optimisticTransaction, + undefined, + undefined, + delegateAccountID, + ); optimisticInvoiceReport.parentReportActionID = reportPreviewAction.reportActionID; chatReport.lastVisibleActionCreated = reportPreviewAction.created; const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: optimisticInvoiceReport, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount, @@ -786,6 +801,7 @@ function sendInvoice({ senderPolicyTags, formatPhoneNumber, delegateAccountID, + getCurrencyDecimals, }: SendInvoiceOptions) { const parsedComment = getParsedComment(transaction?.comment?.comment?.trim() ?? ''); if (transaction?.comment) { @@ -822,6 +838,7 @@ function sendInvoice({ senderPolicyTags: senderPolicyTags ?? {}, formatPhoneNumber, delegateAccountID, + getCurrencyDecimals, }); const parameters: SendInvoiceParams = { diff --git a/src/libs/actions/IOU/SendMoney.ts b/src/libs/actions/IOU/SendMoney.ts index f001ad347e94..c485f862ef50 100644 --- a/src/libs/actions/IOU/SendMoney.ts +++ b/src/libs/actions/IOU/SendMoney.ts @@ -1,5 +1,7 @@ import type {PaymentMethodType} from '@components/KYCWall/types'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import * as API from '@libs/API'; import type {SendMoneyParams} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -80,6 +82,7 @@ function getSendMoneyParams({ optimisticChatReportID, currentUserAccountID, delegateAccountID, + getCurrencyDecimals, }: { report: OnyxEntry; quickAction: OnyxEntry; @@ -95,6 +98,7 @@ function getSendMoneyParams({ optimisticChatReportID?: string; currentUserAccountID: number; delegateAccountID: number | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }): SendMoneyParamsData { const recipientEmail = addSMSDomainIfPhoneNumber(recipient.login ?? ''); const recipientAccountID = Number(recipient.accountID); @@ -120,7 +124,7 @@ function getSendMoneyParams({ }); isNewChat = true; } - const optimisticIOUReport = buildOptimisticIOUReport(recipientAccountID, managerID, amount, chatReport.reportID, currency, true); + const optimisticIOUReport = buildOptimisticIOUReport(recipientAccountID, managerID, amount, chatReport.reportID, currency, getCurrencyDecimals, true); const optimisticTransaction = buildOptimisticTransaction({ transactionParams: { @@ -141,6 +145,7 @@ function getSendMoneyParams({ const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, optimisticIOUReportAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: optimisticIOUReport, type: CONST.IOU.REPORT_ACTION_TYPE.PAY, amount, @@ -155,7 +160,7 @@ function getSendMoneyParams({ delegateAccountIDParam: delegateAccountID, }); - const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticIOUReport, undefined, undefined, undefined, undefined, delegateAccountID); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticIOUReport, getCurrencyDecimals, undefined, undefined, undefined, undefined, delegateAccountID); // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page @@ -505,6 +510,7 @@ type SendMoneyActionParams = { shouldStartTracking?: boolean; shouldDeferForSearch?: boolean; delegateAccountID: number | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; function executeSendMoney( @@ -512,7 +518,8 @@ function executeSendMoney( paymentMethodType: typeof CONST.IOU.PAYMENT_TYPE.ELSEWHERE | typeof CONST.IOU.PAYMENT_TYPE.EXPENSIFY, writeCommand: typeof WRITE_COMMANDS.SEND_MONEY_ELSEWHERE | typeof WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, ) { - const {report, quickAction, amount, currency, comment, currentUserAccountID, recipient, created, merchant, receipt, optimisticChatReportID, delegateAccountID} = actionParams; + const {report, quickAction, amount, currency, comment, currentUserAccountID, recipient, created, merchant, receipt, optimisticChatReportID, delegateAccountID, getCurrencyDecimals} = + actionParams; const {shouldStartTracking = true, shouldDeferForSearch = false} = actionParams; const {params, optimisticData, successData, failureData} = getSendMoneyParams({ @@ -530,6 +537,7 @@ function executeSendMoney( optimisticChatReportID, currentUserAccountID, delegateAccountID, + getCurrencyDecimals, }); if (shouldStartTracking) { startTracking( diff --git a/src/libs/actions/IOU/Split.ts b/src/libs/actions/IOU/Split.ts index bba490186c3a..d4c7fe0d78e1 100644 --- a/src/libs/actions/IOU/Split.ts +++ b/src/libs/actions/IOU/Split.ts @@ -150,6 +150,7 @@ type CreateDistanceRequestInformation = { isTrackIntentUser: boolean | undefined; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; /** Optimistic chat reportID to build the new chat report at, so it matches the ID the confirmation screen already subscribed to (brand-new P2P recipient). */ optimisticChatReportID?: string; @@ -179,6 +180,7 @@ type CreateSplitsAndOnyxDataParams = { delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type StartSplitBilActionParams = { @@ -206,6 +208,7 @@ type StartSplitBilActionParams = { participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags; delegateAccountID: number | undefined; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type CompleteSplitBillActionParams = { @@ -222,6 +225,7 @@ type CompleteSplitBillActionParams = { isTrackIntentUser: boolean | undefined; sessionEmail?: string; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type SplitBillActionsParams = { @@ -258,6 +262,7 @@ type SplitBillActionsParams = { participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags; isTrackIntentUser: boolean | undefined; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; /** @@ -297,6 +302,7 @@ function splitBill({ isTrackIntentUser, formatPhoneNumber, participantsPolicyTags, + getCurrencyDecimals, }: SplitBillActionsParams) { const parsedComment = getParsedComment(comment); const {splitData, splits, onyxData} = createSplitsAndOnyxData({ @@ -332,6 +338,7 @@ function splitBill({ delegateAccountID, isTrackIntentUser, formatPhoneNumber, + getCurrencyDecimals, }); const parameters: SplitBillParams = { @@ -413,6 +420,7 @@ function splitBillAndOpenReport({ isTrackIntentUser, formatPhoneNumber, participantsPolicyTags, + getCurrencyDecimals, }: SplitBillActionsParams) { const parsedComment = getParsedComment(comment); const {splitData, splits, onyxData} = createSplitsAndOnyxData({ @@ -448,6 +456,7 @@ function splitBillAndOpenReport({ isTrackIntentUser, formatPhoneNumber, participantsPolicyTags, + getCurrencyDecimals, }); const parameters: SplitBillParams = { @@ -522,6 +531,7 @@ function startSplitBill({ shouldDeferForSearch = false, delegateAccountID, formatPhoneNumber, + getCurrencyDecimals, }: StartSplitBilActionParams) { const currentUserEmailForIOUSplit = addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = participants.map((participant) => Number(participant.accountID)); @@ -564,6 +574,7 @@ function startSplitBill({ isOwnPolicyExpenseChat, iouReportID: splitChatReport.reportID, delegateAccountIDParam: delegateAccountID, + getCurrencyDecimals, }); splitChatReport.lastReadTime = DateUtils.getDBTime(); @@ -714,6 +725,7 @@ function startSplitBill({ participantsPolicyTags, delegateAccountID, formatPhoneNumber, + getCurrencyDecimals, }; if (existingSplitChatReport) { @@ -914,6 +926,7 @@ function completeSplitBill({ delegateAccountID, isTrackIntentUser, sessionEmail, + getCurrencyDecimals, }: CompleteSplitBillActionParams) { if (!reportAction) { return; @@ -1060,8 +1073,16 @@ function completeSplitBill({ optimisticIOUReportID: optimisticExpenseReportID, reportTransactions, betas, + getCurrencyDecimals, }) - : buildOptimisticIOUReport(sessionAccountID, participant.accountID ?? CONST.DEFAULT_NUMBER_ID, splitAmount, oneOnOneChatReport?.reportID, currency ?? ''); + : buildOptimisticIOUReport( + sessionAccountID, + participant.accountID ?? CONST.DEFAULT_NUMBER_ID, + splitAmount, + oneOnOneChatReport?.reportID, + currency ?? '', + getCurrencyDecimals, + ); } else if (isPolicyExpenseChat) { if (oneOnOneIOUReport) { // Capture previous fresh reimbursable totals before mutating, so the diff applies whether or @@ -1108,6 +1129,7 @@ function completeSplitBill({ const [oneOnOneCreatedActionForChat, oneOnOneCreatedActionForIOU, oneOnOneIOUAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: oneOnOneIOUReport, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: splitAmount, @@ -1122,9 +1144,18 @@ function completeSplitBill({ let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport?.reportID, oneOnOneIOUReport?.reportID); if (oneOnOneReportPreviewAction) { - oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction); + oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, getCurrencyDecimals); } else { - oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction, undefined, undefined, delegateAccountID); + oneOnOneReportPreviewAction = buildOptimisticReportPreview( + oneOnOneChatReport, + oneOnOneIOUReport, + getCurrencyDecimals, + '', + oneOnOneTransaction, + undefined, + undefined, + delegateAccountID, + ); } const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations, sessionAccountID, sessionEmail ?? ''); @@ -1162,6 +1193,7 @@ function completeSplitBill({ personalDetails, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); splits.push({ @@ -1453,6 +1485,7 @@ function createSplitsAndOnyxData({ delegateAccountID, isTrackIntentUser, formatPhoneNumber, + getCurrencyDecimals, }: CreateSplitsAndOnyxDataParams): SplitsAndOnyxData { const currentUserEmailForIOUSplit = addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = participants.map((participant) => Number(participant.accountID)); @@ -1505,6 +1538,7 @@ function createSplitsAndOnyxData({ isOwnPolicyExpenseChat, iouReportID: splitChatReport.reportID, delegateAccountIDParam: delegateAccountID, + getCurrencyDecimals, }); splitChatReport.lastReadTime = DateUtils.getDBTime(); @@ -1758,8 +1792,9 @@ function createSplitsAndOnyxData({ optimisticIOUReportID: optimisticExpenseReportID, reportTransactions, betas, + getCurrencyDecimals, }) - : buildOptimisticIOUReport(currentUserAccountID, accountID, splitAmount, oneOnOneChatReport.reportID, currency); + : buildOptimisticIOUReport(currentUserAccountID, accountID, splitAmount, oneOnOneChatReport.reportID, currency, getCurrencyDecimals); } else if (isOwnPolicyExpenseChat) { // Because of the Expense reports are stored as negative values, we subtract the total from the amount if (oneOnOneIOUReport?.currency === currency) { @@ -1816,6 +1851,7 @@ function createSplitsAndOnyxData({ // 5. REPORT_PREVIEW action for the chatReport const [oneOnOneCreatedActionForChat, oneOnOneCreatedActionForIOU, oneOnOneIOUAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: oneOnOneIOUReport, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: splitAmount, @@ -1849,9 +1885,18 @@ function createSplitsAndOnyxData({ let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID); if (oneOnOneReportPreviewAction) { - oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction); + oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, getCurrencyDecimals); } else { - oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction, undefined, undefined, delegateAccountID); + oneOnOneReportPreviewAction = buildOptimisticReportPreview( + oneOnOneChatReport, + oneOnOneIOUReport, + getCurrencyDecimals, + '', + oneOnOneTransaction, + undefined, + undefined, + delegateAccountID, + ); } const optimisticPolicyRecentlyUsedCategories = isPolicyExpenseChat ? mergePolicyRecentlyUsedCategories(category, policyRecentlyUsedCategories) : []; @@ -1907,6 +1952,7 @@ function createSplitsAndOnyxData({ personalDetails, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); const individualSplit = { @@ -1990,6 +2036,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest formatPhoneNumber, participantsPolicyTags, optimisticChatReportID, + getCurrencyDecimals, } = distanceRequestInformation; const {policy, policyCategories, policyTagList, policyRecentlyUsedCategories, policyRecentlyUsedTags} = policyParams; const parsedComment = getParsedComment(transactionParams.comment); @@ -2084,6 +2131,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest delegateAccountID, isTrackIntentUser, formatPhoneNumber, + getCurrencyDecimals, }); onyxData = splitOnyxData; @@ -2181,6 +2229,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest delegateAccountID, isTrackIntentUser, optimisticChatReportID, + getCurrencyDecimals, }); onyxData = moneyRequestOnyxData; diff --git a/src/libs/actions/IOU/SplitTransactionUpdate.ts b/src/libs/actions/IOU/SplitTransactionUpdate.ts index 3aa7f974c149..9e7e70b35a9c 100644 --- a/src/libs/actions/IOU/SplitTransactionUpdate.ts +++ b/src/libs/actions/IOU/SplitTransactionUpdate.ts @@ -1,5 +1,7 @@ import type {SearchActionsContextValue, SearchStateContextValue} from '@components/Search/types'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import {write as apiWrite} from '@libs/API'; import type {RevertSplitTransactionParams, SplitTransactionParams, SplitTransactionSplitsParam} from '@libs/API/parameters'; import {WRITE_COMMANDS} from '@libs/API/types'; @@ -119,6 +121,7 @@ type UpdateSplitTransactionsParams = { isOffline: boolean; delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; /** @@ -200,6 +203,7 @@ function updateSplitTransactions({ isOffline, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }: UpdateSplitTransactionsParams) { const parentTransactionReport = getReportOrDraftReport(transactionReport?.parentReportID); // For selfDM-origin splits the caller can't resolve a real `expenseReport` (the draft/source @@ -662,6 +666,7 @@ function updateSplitTransactions({ personalDetails, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, } as MoneyRequestInformationParams; if (isReverseSplitOperation) { @@ -776,6 +781,7 @@ function updateSplitTransactions({ personalDetails, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); let updateMoneyRequestParamsOnyxData: OnyxData = {}; diff --git a/src/libs/actions/IOU/TrackExpense.ts b/src/libs/actions/IOU/TrackExpense.ts index e363d6c94dca..6a6ff4bcc341 100644 --- a/src/libs/actions/IOU/TrackExpense.ts +++ b/src/libs/actions/IOU/TrackExpense.ts @@ -200,6 +200,7 @@ type GetTrackExpenseInformationParams = { policyType?: CreatableWorkspaceType; // TODO: Remove optional (?) once all callers are updated in follow-up PRs of https://github.com/Expensify/App/issues/66414 isDraftChatReport?: boolean; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; type DeleteTrackExpenseParams = { @@ -866,6 +867,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T isDraftChatReport, currentUserLocalCurrency, policyType, + getCurrencyDecimals, } = params; const {payeeAccountID = currentUserAccountIDParam, payeeEmail = currentUserEmailParam, participant} = participantParams; const {policy} = policyParams; @@ -1056,6 +1058,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T betas, optimisticIOUReportID: optimisticExpenseReportID, reportTransactions, + getCurrencyDecimals, }); } else { iouReport = {...iouReport}; @@ -1131,6 +1134,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T // 3. The transaction thread, which requires the iouAction, and CREATED action for the transaction thread // 4. REPORT_PREVIEW action for the chatReport (if tracking in the Expense chat) const [, optimisticCreatedActionForIOUReport, iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals, iouReport: shouldUseMoneyReport && iouReport ? iouReport : chatReport, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount, @@ -1151,9 +1155,9 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { - reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction); + reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, false, comment, optimisticTransaction); } else { - reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction, undefined, undefined, delegateAccountID); + reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimals, comment, optimisticTransaction, undefined, undefined, delegateAccountID); // Generated ReportPreview action is a parent report action of the iou report. // We are setting the iou report's parentReportActionID to display subtitle correctly in IOU page when offline. iouReport.parentReportActionID = reportPreviewAction.reportActionID; @@ -1662,6 +1666,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation): {iouRep shouldDeferAutoSubmit, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, } = requestMoneyInformation; const {payeeAccountID} = participantParams; const parsedComment = getParsedComment(transactionParams.comment ?? ''); @@ -1772,6 +1777,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation): {iouRep personalDetails, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport.reportID; @@ -1967,6 +1973,7 @@ function convertBulkTrackedExpensesToIOU({ selfDMReportActions, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }: { transactions: OnyxTypes.Transaction[]; iouReport: OnyxEntry; @@ -1983,6 +1990,7 @@ function convertBulkTrackedExpensesToIOU({ selfDMReportActions: OnyxEntry; delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }) { const iouReportID = iouReport?.reportID; @@ -2103,6 +2111,7 @@ function convertBulkTrackedExpensesToIOU({ }, delegateAccountID, isTrackIntentUser, + getCurrencyDecimals, }); const isDistanceRequest = isDistanceRequestTransactionUtils(transaction); @@ -2435,6 +2444,7 @@ function trackExpense(params: CreateTrackExpenseParams) { reportActionsList, isDraftChatReport, currentUserLocalCurrency, + getCurrencyDecimals, } = params; const {accountID: currentUserAccountIDParam, email: currentUserEmailParam = ''} = currentUser; const {participant, payeeAccountID, payeeEmail} = participantParams; @@ -2601,6 +2611,7 @@ function trackExpense(params: CreateTrackExpenseParams) { currentUserLocalCurrency, // Only "Submit to my employer" creates a Submit (submit2026) workspace from a draft; everything else keeps the default (team) type. policyType: action === CONST.IOU.ACTION.SUBMIT && policy?.type === CONST.POLICY.TYPE.SUBMIT ? CONST.POLICY.TYPE.SUBMIT : undefined, + getCurrencyDecimals, }) ?? {}; const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport?.reportID; const onyxData: TrackedExpenseParams['onyxData'] = trackExpenseInformationOnyxData; diff --git a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts index 0ea081547e31..86475e5dcbce 100644 --- a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts +++ b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts @@ -1,5 +1,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; + import type {CurrentUser} from '@userActions/Policy/Policy'; import type {IOUAction} from '@src/CONST'; @@ -50,6 +52,7 @@ type CreateTrackExpenseParams = { reportActionsList: OnyxCollection | undefined; // TODO: Remove optional (?) once all callers are updated in follow-up PRs of https://github.com/Expensify/App/issues/66414 isDraftChatReport?: boolean; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; export type {CreateTrackExpenseParams, TrackExpenseAccountantParams}; diff --git a/src/libs/actions/MergeTransaction.ts b/src/libs/actions/MergeTransaction.ts index d32c9e10747c..52d0fb5f4550 100644 --- a/src/libs/actions/MergeTransaction.ts +++ b/src/libs/actions/MergeTransaction.ts @@ -396,6 +396,7 @@ type MergeTransactionRequestParams = { selfDMReportActions: OnyxEntry; reportPolicyTags: OnyxEntry; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; /** * Merges two transactions by updating the target transaction with selected fields and deleting the source transaction. @@ -426,6 +427,7 @@ function mergeTransactionRequest({ selfDMReportActions, reportPolicyTags, isTrackIntentUser, + getCurrencyDecimals, }: MergeTransactionRequestParams) { // For both unreported expenses and expense reports, negate the display amount when storing // This preserves the user's chosen sign while following the storage convention @@ -691,6 +693,7 @@ function mergeTransactionRequest({ iouReportID: mergeTransaction.reportID, // delegateAccountIDParam: will be threaded in PR 11; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425) delegateAccountIDParam: undefined, + getCurrencyDecimals, }); // IOU action for the surviving expense on its original report (not on mergeTransaction.reportID yet). diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 6224389366f7..6ecef773055c 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -57,6 +57,7 @@ import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs import * as ApiUtils from '@libs/ApiUtils'; import * as Browser from '@libs/Browser'; import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types'; +import {getCurrencyDecimals as getCurrencyDecimalsUtil} from '@libs/CurrencyUtils'; import DateUtils from '@libs/DateUtils'; import * as Environment from '@libs/Environment/Environment'; import {getOldDotURLFromEnvironment} from '@libs/Environment/Environment'; @@ -1730,6 +1731,8 @@ function openReport(params: OpenReportActionParams) { iouReportID: transactionParentReportID, // delegateAccountIDParam: will be threaded in PR 15; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425) delegateAccountIDParam: undefined, + // Non-React call path: pass the standalone util until this file's own threading PR. + getCurrencyDecimals: getCurrencyDecimalsUtil, }); // Override actor fields to show the submitter instead of current user. @@ -7458,6 +7461,7 @@ function buildOptimisticChangePolicyData({ optimisticPolicyExpenseChatReport, reportPreviewAction, isTrackIntentUser, + getCurrencyDecimals, }: { report: Report; parentReport: OnyxEntry; @@ -7472,6 +7476,7 @@ function buildOptimisticChangePolicyData({ optimisticPolicyExpenseChatReport?: Report; reportPreviewAction: OnyxEntry; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }) { const optimisticData: Array< OnyxUpdate< @@ -7703,7 +7708,7 @@ function buildOptimisticChangePolicyData({ // and set it as a parent of the moved report const policyExpenseChat = optimisticPolicyExpenseChatReport ?? getPolicyExpenseChat(report.ownerAccountID, policy.id); // TODO: delegateAccountIDParam will be threaded in PR 15 (https://github.com/Expensify/App/issues/66425) - const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report, '', null, undefined, undefined, undefined); + const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report, getCurrencyDecimals, '', null, undefined, undefined, undefined); const newPolicyExpenseChatReportID = policyExpenseChat?.reportID; @@ -7952,6 +7957,7 @@ function changeReportPolicy({ isReportLastVisibleArchived = false, reportPreviewAction, isTrackIntentUser, + getCurrencyDecimals, reportTransactions, }: { report: Report; @@ -7967,6 +7973,7 @@ function changeReportPolicy({ isReportLastVisibleArchived?: boolean; reportPreviewAction: OnyxEntry; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; reportTransactions: Transaction[]; }) { if (!report || !policy || report.policyID === policy.id || !isExpenseReport(report) || shouldBlockChangeReportPolicyForCommuterExclusion(reportTransactions, policy)) { @@ -7986,6 +7993,7 @@ function changeReportPolicy({ isReportLastVisibleArchived, reportPreviewAction, isTrackIntentUser, + getCurrencyDecimals, }); const params = { @@ -8019,6 +8027,7 @@ function changeReportPolicyAndInviteSubmitter({ reportActionsList, reportPreviewAction, isTrackIntentUser, + getCurrencyDecimals, reportTransactions, }: { report: Report; @@ -8035,6 +8044,7 @@ function changeReportPolicyAndInviteSubmitter({ reportActionsList: OnyxCollection; reportPreviewAction: OnyxEntry; isTrackIntentUser: boolean | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; reportTransactions: Transaction[]; }) { if ( @@ -8097,6 +8107,7 @@ function changeReportPolicyAndInviteSubmitter({ optimisticPolicyExpenseChatReport: membersChats.reportCreationData[submitterLogin], reportPreviewAction, isTrackIntentUser, + getCurrencyDecimals, }); const optimisticData = [...optimisticAddMembersData, ...optimisticChangePolicyData]; diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index fd2e840c8dd6..4f6b670a728a 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -230,6 +230,7 @@ type HandleActionButtonPressParams = { delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; conciergeChat: OnyxEntry; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; function handleActionButtonPress({ @@ -268,6 +269,7 @@ function handleActionButtonPress({ delegateAccountID, isTrackIntentUser, conciergeChat, + getCurrencyDecimals, }: HandleActionButtonPressParams) { // The transactionIDList is needed to handle actions taken on `status:""` where transactions on single expense reports can be approved/paid. // We need the transactionID to display the loading indicator for that list item's action. @@ -320,6 +322,7 @@ function handleActionButtonPress({ delegateAccountID, isTrackIntentUser, conciergeChat, + getCurrencyDecimals, }); return; case CONST.SEARCH.ACTION_TYPES.APPROVE: @@ -352,6 +355,7 @@ function handleActionButtonPress({ delegateAccountID, isTrackIntentUser, ownerLogin: submitterLogin, + getCurrencyDecimals, }); return; case CONST.SEARCH.ACTION_TYPES.SUBMIT: { @@ -527,6 +531,7 @@ type GetPayActionCallbackParams = { delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; conciergeChat: OnyxEntry; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; function getPayActionCallback({ @@ -555,6 +560,7 @@ function getPayActionCallback({ delegateAccountID, isTrackIntentUser, conciergeChat, + getCurrencyDecimals, }: GetPayActionCallbackParams) { const lastPolicyPaymentMethod = getLastPolicyPaymentMethod(item.policyID, personalPolicyID, lastPaymentMethod, getReportType(item.reportID)); @@ -604,6 +610,7 @@ function getPayActionCallback({ delegateAccountID, isTrackIntentUser, conciergeChat, + getCurrencyDecimals, }); } @@ -624,6 +631,7 @@ type GetApproveActionCallbackParams = { delegateAccountID: number | undefined; isTrackIntentUser: boolean | undefined; ownerLogin: string | undefined; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; }; function getApproveActionCallback({ @@ -643,6 +651,7 @@ function getApproveActionCallback({ delegateAccountID, isTrackIntentUser, ownerLogin, + getCurrencyDecimals, }: GetApproveActionCallbackParams) { if (!item.reportID) { return; @@ -670,6 +679,7 @@ function getApproveActionCallback({ full: true, additionalOnyxData: getSearchApproveOnyxData(hash, item.reportID, currentSearchKey), isTrackIntentUser, + getCurrencyDecimals, }); } @@ -1417,6 +1427,7 @@ function rejectMoneyRequestInBulk( currentUserLogin: string, betas: OnyxEntry, delegateAccountID: number | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], hash?: number, ) { const optimisticData: Array> = []; @@ -1436,7 +1447,18 @@ function rejectMoneyRequestInBulk( } > = {}; for (const transactionID of transactionIDs) { - const data = prepareRejectMoneyRequestData(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, undefined, true); + const data = prepareRejectMoneyRequestData({ + transactionID, + reportID, + comment, + policy, + currentUserAccountIDParam, + currentUserLogin, + betas, + delegateAccountID, + getCurrencyDecimals, + shouldUseBulkAction: true, + }); if (data) { optimisticData.push(...data.optimisticData); successData.push(...data.successData); @@ -1474,6 +1496,7 @@ function rejectMoneyRequestsOnSearch( currentUserLogin: string, betas: OnyxEntry, delegateAccountID: number | undefined, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], ) { const transactionIDs = Object.keys(selectedTransactions); @@ -1506,7 +1529,7 @@ function rejectMoneyRequestsOnSearch( const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const isPolicyDelayedSubmissionEnabled = policy ? isDelayedSubmissionEnabled(policy) : false; if (isPolicyDelayedSubmissionEnabled && areAllExpensesSelected) { - rejectMoneyRequestInBulk(reportID, comment, policy, selectedTransactionIDs, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, hash); + rejectMoneyRequestInBulk(reportID, comment, policy, selectedTransactionIDs, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, getCurrencyDecimals, hash); } else { // Share a single destination ID across all rejections from the same source report const sharedRejectedToReportID = generateReportID(); @@ -1515,7 +1538,7 @@ function rejectMoneyRequestsOnSearch( existingRejectedReport = nextRejectedReport; }; for (const transactionID of selectedTransactionIDs) { - rejectMoneyRequest(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, { + rejectMoneyRequest(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, delegateAccountID, getCurrencyDecimals, { sharedRejectedToReportID, existingRejectedReport, setExistingRejectedReport, @@ -2028,7 +2051,12 @@ function getTotalFormattedAmount( * * Note: we don't create anything new, we just optimistically generate the data that we know will be returned by API. */ -function setOptimisticDataForTransactionThreadPreview(item: TransactionListItemType, transactionPreviewData: TransactionPreviewData, IOUTransactionID?: string) { +function setOptimisticDataForTransactionThreadPreview( + item: TransactionListItemType, + transactionPreviewData: TransactionPreviewData, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], + IOUTransactionID?: string, +) { const {reportID, report, amount, currency, transactionID, created, policyID, from} = item; const moneyRequestReportActionID = item?.reportAction?.reportActionID; const {hasParentReport, hasParentReportAction, hasTransaction, hasTransactionThreadReport} = transactionPreviewData; @@ -2060,6 +2088,7 @@ function setOptimisticDataForTransactionThreadPreview(item: TransactionListItemT } as ReportAction, // delegateAccountIDParam: will be threaded in PR 15; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425) delegateAccountIDParam: undefined, + getCurrencyDecimals, }); optimisticIOUAction.pendingAction = undefined; optimisticIOUAction.actorAccountID = from?.accountID; diff --git a/src/pages/DynamicReportChangeWorkspacePage.tsx b/src/pages/DynamicReportChangeWorkspacePage.tsx index 957f5acf0593..c7a44be93414 100644 --- a/src/pages/DynamicReportChangeWorkspacePage.tsx +++ b/src/pages/DynamicReportChangeWorkspacePage.tsx @@ -7,6 +7,7 @@ import type {WorkspaceListItemType} from '@components/SelectionList/ListItem/typ import UserListItem from '@components/SelectionList/ListItem/UserListItem'; import useCommuterExclusionGuard from '@hooks/useCommuterExclusionGuard'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDebouncedState from '@hooks/useDebouncedState'; import useDynamicBackPath from '@hooks/useDynamicBackPath'; @@ -70,6 +71,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace const styles = useThemeStyles(); const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); const {translate, localeCompare} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const reportTransactions = useReportTransactions(reportID); const reportPreviewAction = useParentReportAction(report); @@ -144,6 +146,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace if (isExpenseReport(report) && isPolicyAdmin(policy) && report.ownerAccountID && !isPolicyMember(policy, submitterLogin)) { const employeeList = policy?.employeeList; changeReportPolicyAndInviteSubmitter({ + getCurrencyDecimals, report, parentReport, policy, @@ -169,6 +172,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace } changeReportPolicy({ + getCurrencyDecimals, report, parentReport, policy, diff --git a/src/pages/ReportSubmitToContent.tsx b/src/pages/ReportSubmitToContent.tsx index 8b2ff04cf798..b7abc122af08 100644 --- a/src/pages/ReportSubmitToContent.tsx +++ b/src/pages/ReportSubmitToContent.tsx @@ -6,6 +6,7 @@ import InviteMemberListItem from '@components/SelectionList/ListItem/InviteMembe import type {ListItem} from '@components/SelectionList/types'; import Text from '@components/Text'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDebouncedState from '@hooks/useDebouncedState'; import useIsInLandscapeMode from '@hooks/useIsInLandscapeMode'; @@ -79,6 +80,7 @@ function ReportSubmitToContent({ const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate, localeCompare} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const isInLandscapeMode = useIsInLandscapeMode(); const {keyboardActiveHeight} = useKeyboardState(); @@ -292,6 +294,7 @@ function ReportSubmitToContent({ } submitReport({ + getCurrencyDecimals, expenseReport: report, policy, currentUserAccountIDParam: currentUserDetails.accountID, @@ -350,6 +353,7 @@ function ReportSubmitToContent({ canSubmitRef, shouldDismissRHPAfterSubmit, isTrackIntentUser, + getCurrencyDecimals, ]); const onSelectMember = useCallback( diff --git a/src/pages/Search/SearchRejectReasonPage.tsx b/src/pages/Search/SearchRejectReasonPage.tsx index 63830097c154..cc97433922a3 100644 --- a/src/pages/Search/SearchRejectReasonPage.tsx +++ b/src/pages/Search/SearchRejectReasonPage.tsx @@ -2,6 +2,7 @@ import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/ import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; import {useSearchQueryContext, useSearchSelectionActions, useSearchSelectionContext} from '@components/Search/SearchContext'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLocalize from '@hooks/useLocalize'; @@ -36,6 +37,7 @@ function SearchRejectReasonPage({route}: SearchRejectReasonPageProps) { const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const [betas] = useOnyx(ONYXKEYS.BETAS); const {accountID: currentUserAccountID, login: currentUserLogin} = useCurrentUserPersonalDetails(); @@ -70,6 +72,7 @@ function SearchRejectReasonPage({route}: SearchRejectReasonPageProps) { currentUserLogin ?? '', betas, delegateAccountID, + getCurrencyDecimals, ); if (route.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT_REJECT_TRANSACTIONS) { clearSelectedTransactions(true); @@ -91,6 +94,7 @@ function SearchRejectReasonPage({route}: SearchRejectReasonPageProps) { currentUserLogin, betas, delegateAccountID, + getCurrencyDecimals, route.name, showDelegateNoAccessModal, clearSelectedTransactions, diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index 180f49024fae..a74b6afef2dc 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -4,6 +4,7 @@ import LocationPermissionModal from '@components/LocationPermissionModal'; import MoneyRequestConfirmationList from '@components/MoneyRequestConfirmationList'; import ScreenWrapper from '@components/ScreenWrapper'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLocalize from '@hooks/useLocalize'; @@ -83,6 +84,7 @@ function SubmitDetailsPage({ }: ShareDetailsPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const delegateAccountID = useDelegateAccountID(); const [unknownUserDetails] = useOnyx(ONYXKEYS.SHARE_UNKNOWN_USER_DETAILS); const [personalDetails] = useOnyx(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`); @@ -372,6 +374,7 @@ function SubmitDetailsPage({ const performExpenseCreate = () => { if (isSelfDM(report)) { trackExpense({ + getCurrencyDecimals, report: report ?? {reportID: reportOrAccountID}, isDraftPolicy: false, isDraftChatReport: !!reportDraft, @@ -418,6 +421,7 @@ function SubmitDetailsPage({ const existingTransactionDraft = existingTransactionID ? transactionDrafts?.[existingTransactionID] : undefined; requestMoney({ + getCurrencyDecimals, report: reportToSubmit, participantParams: {payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant}, policyParams: {policy, policyTagList: policyTagsForRequestMoney, policyCategories, policyRecentlyUsedCategories, policyRecentlyUsedTags}, diff --git a/src/pages/TransactionMerge/DynamicConfirmationPage.tsx b/src/pages/TransactionMerge/DynamicConfirmationPage.tsx index 0dfd0e7bfb69..1f230492bf99 100644 --- a/src/pages/TransactionMerge/DynamicConfirmationPage.tsx +++ b/src/pages/TransactionMerge/DynamicConfirmationPage.tsx @@ -8,6 +8,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLocalize from '@hooks/useLocalize'; @@ -44,6 +45,7 @@ type DynamicConfirmationPageProps = PlatformStackScreenProps> | undefined, transactionThreadReport: OnyxTypes.Report | undefined, shouldAddCreatedAction: boolean, + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], ) { const actions = [...(allReportActions ?? [])]; @@ -56,6 +59,7 @@ function getReportActionsToDisplay( created: DateUtils.subtractMillisecondsFromDateTime(actions.at(-1)?.created ?? '', 1), // delegateAccountIDParam: will be threaded in PR 15; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425) delegateAccountIDParam: undefined, + getCurrencyDecimals, }) as OnyxTypes.ReportAction; moneyRequestActions.push(optimisticIOUAction); actions.splice(actions.length - 1, 0, optimisticIOUAction); diff --git a/src/pages/iou/DynamicSplitBillDetailsPage.tsx b/src/pages/iou/DynamicSplitBillDetailsPage.tsx index ac9abe51d85a..5f0dacfe015d 100644 --- a/src/pages/iou/DynamicSplitBillDetailsPage.tsx +++ b/src/pages/iou/DynamicSplitBillDetailsPage.tsx @@ -6,6 +6,7 @@ import MoneyRequestConfirmationList from '@components/MoneyRequestConfirmationLi import MoneyRequestHeaderStatusBar from '@components/MoneyRequestHeaderStatusBar'; import ScreenWrapper from '@components/ScreenWrapper'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useDynamicBackPath from '@hooks/useDynamicBackPath'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; @@ -49,6 +50,7 @@ type SplitBillDetailsPageProps = WithReportAndReportActionOrNotFoundProps & Plat function DynamicSplitBillDetailsPage({report, reportAction}: SplitBillDetailsPageProps) { const styles = useThemeStyles(); const {translate, formatPhoneNumber} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const theme = useTheme(); const {isBetaEnabled} = usePermissions(); const icons = useMemoizedLazyExpensifyIcons(['ReceiptScan']); @@ -107,6 +109,7 @@ function DynamicSplitBillDetailsPage({report, reportAction}: SplitBillDetailsPag const onConfirm = useCallback(() => { setIsConfirmed(true); completeSplitBill({ + getCurrencyDecimals, chatReportID: reportID, reportAction, updatedTransaction: draftTransaction, @@ -135,6 +138,7 @@ function DynamicSplitBillDetailsPage({report, reportAction}: SplitBillDetailsPag delegateAccountID, isTrackIntentUser, formatPhoneNumber, + getCurrencyDecimals, ]); return ( diff --git a/src/pages/iou/RejectReasonPage.tsx b/src/pages/iou/RejectReasonPage.tsx index 4edbd91361c9..58a9839ea674 100644 --- a/src/pages/iou/RejectReasonPage.tsx +++ b/src/pages/iou/RejectReasonPage.tsx @@ -3,6 +3,7 @@ import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; import {useSearchSelectionActions} from '@components/Search/SearchContext'; import {useWideRHPState} from '@components/WideRHPContextProvider'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLocalize from '@hooks/useLocalize'; @@ -34,6 +35,7 @@ type RejectReasonPageProps = function RejectReasonPage({route}: RejectReasonPageProps) { const {translate} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {transactionID, reportID, backTo} = route.params; const {removeTransaction} = useSearchSelectionActions(); @@ -51,7 +53,17 @@ function RejectReasonPage({route}: RejectReasonPageProps) { return; } - const urlToNavigateBack = rejectMoneyRequest(transactionID, reportID, values.comment, policy, currentUserAccountID, currentUserLogin ?? '', betas, delegateAccountID); + const urlToNavigateBack = rejectMoneyRequest( + transactionID, + reportID, + values.comment, + policy, + currentUserAccountID, + currentUserLogin ?? '', + betas, + delegateAccountID, + getCurrencyDecimals, + ); removeTransaction(transactionID); // If the super wide rhp is not opened, dismiss the entire modal. if (superWideRHPRouteKeys.length > 0) { diff --git a/src/pages/iou/SplitExpensePage.tsx b/src/pages/iou/SplitExpensePage.tsx index 4159f264de1a..84f5b8f31611 100644 --- a/src/pages/iou/SplitExpensePage.tsx +++ b/src/pages/iou/SplitExpensePage.tsx @@ -103,7 +103,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) { const {currentSearchHash, currentSearchQueryJSON} = useSearchQueryContext(); const {clearSelectedTransactions} = useSearchSelectionActions(); - const {convertToDisplayString, getCurrencySymbol} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString, getCurrencySymbol} = useCurrencyListActions(); const [selectedTab] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.SPLIT_EXPENSE_TAB_TYPE}`); const [draftTransaction, draftTransactionMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`); @@ -368,6 +368,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) { } updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, diff --git a/src/pages/iou/request/step/DynamicIOURequestStepCompanyInfo.tsx b/src/pages/iou/request/step/DynamicIOURequestStepCompanyInfo.tsx index 7a280ad80b13..808c6576260f 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepCompanyInfo.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepCompanyInfo.tsx @@ -53,7 +53,7 @@ function DynamicIOURequestStepCompanyInfo({route, report, transaction}: DynamicI const styles = useThemeStyles(); const {translate, formatPhoneNumber} = useLocalize(); - const {convertToDisplayString} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const {inputCallbackRef} = useAutoFocusInput(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const delegateAccountID = useDelegateAccountID(); @@ -111,6 +111,7 @@ function DynamicIOURequestStepCompanyInfo({route, report, transaction}: DynamicI reserveSearchChannelIfGlobalCreate(!!isFromGlobalCreate); const invoiceChatReportID = report?.reportID ? undefined : reportID; sendInvoice({ + getCurrencyDecimals, currentUserAccountID: currentUserPersonalDetails.accountID, transaction, policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [], diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 8b4043df52f4..6e6a88c59fbe 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -231,6 +231,7 @@ function IOURequestStepAmount({ } suppressDiscardPrompt(); submitAmount({ + getCurrencyDecimals, translate, report, transaction, diff --git a/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts b/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts index 1a07d87c8e51..e4a1278efee4 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts +++ b/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts @@ -101,6 +101,7 @@ type MoneyRequestStepDistanceNavigationParams = { policyTagList: PolicyTagLists; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol']; + getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; participants: Array; participantsPolicyTags: ParticipantsPolicyTags; }; @@ -202,6 +203,7 @@ function handleMoneyRequestStepDistanceNavigation({ policyTagList, formatPhoneNumber, getCurrencySymbol, + getCurrencyDecimals, participants, participantsPolicyTags, }: MoneyRequestStepDistanceNavigationParams): void { @@ -326,6 +328,7 @@ function handleMoneyRequestStepDistanceNavigation({ currentUserLocalCurrency, delegateAccountID, reportActionsList: undefined, + getCurrencyDecimals, }); cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, { report, @@ -404,6 +407,7 @@ function handleMoneyRequestStepDistanceNavigation({ isTrackIntentUser, delegateAccountID, formatPhoneNumber, + getCurrencyDecimals, participantsPolicyTags, }); cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, { diff --git a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts index 31eeea5f1854..e35edf56b338 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts +++ b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts @@ -153,7 +153,7 @@ function useDistanceNavigation({ const delegateAccountID = useDelegateAccountID(); const {formatPhoneNumber} = useLocalize(); - const {getCurrencySymbol} = useCurrencyListActions(); + const {getCurrencyDecimals, getCurrencySymbol} = useCurrencyListActions(); const policyTagList = useMoneyRequestPolicyTagsForReport({report, currentUserAccountID}); const {participants, participantsPolicyTags} = useMoneyRequestParticipantsPolicyTags({ @@ -173,6 +173,7 @@ function useDistanceNavigation({ const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals, iouType, action, report, diff --git a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts index 4f4d5bd5da99..78c4db708d07 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts +++ b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts @@ -169,13 +169,14 @@ function useOdometerNavigation({ const delegateAccountID = useDelegateAccountID(); const {formatPhoneNumber} = useLocalize(); - const {getCurrencySymbol} = useCurrencyListActions(); + const {getCurrencyDecimals, getCurrencySymbol} = useCurrencyListActions(); return ({odometerStart, odometerEnd, odometerDistance, unit, previousOdometerDraft}: NavigateOptions) => { const optimisticTransactionID = rand64(); const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals, iouType, action, report, diff --git a/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx b/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx index 27e41da76b7f..723549e7dd8b 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx @@ -62,7 +62,7 @@ function IOURequestStepDistanceGPS({ const delegateAccountID = useDelegateAccountID(); const {translate, formatPhoneNumber} = useLocalize(); - const {getCurrencySymbol} = useCurrencyListActions(); + const {getCurrencyDecimals, getCurrencySymbol} = useCurrencyListActions(); const {isBetaEnabled} = usePermissions(); const isInLandscapeMode = useIsInLandscapeMode(); @@ -147,6 +147,7 @@ function IOURequestStepDistanceGPS({ const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals, iouType, action, report, diff --git a/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx b/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx index 52b041a4e818..39a19ec1407d 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx @@ -287,6 +287,7 @@ function IOURequestStepDistanceManual({ const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals, iouType, action, report, diff --git a/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx index f957e0f61931..a95306f59468 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx @@ -2,6 +2,7 @@ import {useFullScreenLoaderActions} from '@components/FullScreenLoaderContext'; import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useFilesValidation from '@hooks/useFilesValidation'; import useLocalize from '@hooks/useLocalize'; @@ -110,6 +111,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID, const [transactions] = useOptimisticDraftTransactions(transaction); const {isMultiScanEnabled} = useMultiScanState(); const {translate, formatPhoneNumber} = useLocalize(); + const {getCurrencyDecimals} = useCurrencyListActions(); const {disableMultiScan} = useMultiScanActions(); const {setIsLoaderVisible} = useFullScreenLoaderActions(); const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false); @@ -235,6 +237,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID, submitWithDismissFirst({ executeWrite: (overrides) => { startSplitBill({ + getCurrencyDecimals, ...splitBaseParams, shouldHandleNavigation: overrides.shouldHandleNavigation, shouldDeferForSearch: false, @@ -276,6 +279,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID, }); const baseParams = { + getCurrencyDecimals, transactions, iouType, report, diff --git a/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts b/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts index bfa9855b498c..d5e394ed3b22 100644 --- a/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts +++ b/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts @@ -198,7 +198,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { // Localization const {translate, toLocaleDigit, formatPhoneNumber} = useLocalize(); - const {getCurrencySymbol} = useCurrencyListActions(); + const {getCurrencyDecimals, getCurrencySymbol} = useCurrencyListActions(); const delegateAccountID = useDelegateAccountID(); // Permissions @@ -467,6 +467,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { } const {iouReport} = requestMoneyIOUActions({ + getCurrencyDecimals, report, existingIOUReport, optimisticChatReportID, @@ -573,6 +574,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { if (isTrackExpense) { const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); submitPerDiemExpenseForSelfDM({ + getCurrencyDecimals, selfDMReport, policy, transactionParams: { @@ -612,6 +614,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { const activeReportID = isExpenseReport ? report?.reportID : chatReportID; const result = submitPerDiemExpenseIOUActions({ + getCurrencyDecimals, report, participantParams: { payeeEmail: currentUserPersonalDetails.login, @@ -714,6 +717,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { const email = currentUserPersonalDetails.email ?? ''; trackExpenseIOUActions({ + getCurrencyDecimals, report: trackReport, isDraftPolicy, isDraftChatReport, @@ -817,6 +821,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { const shouldIncludeCommuterExclusionOverrides = hasAppliedCommuterExclusion(transaction); const {chatReportID: distanceChatReportID, transactionID: distanceTransactionID} = createDistanceRequestIOUActions({ + getCurrencyDecimals, report, participants: selectedParticipantsForRequest, optimisticChatReportID, @@ -926,6 +931,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { // If we have a receipt let's start the split expense by creating only the action, the transaction, and the group DM if needed startSplitBill({ + getCurrencyDecimals, participants: selectedParticipants, currentUserLogin, currentUserAccountID: currentUserPersonalDetails.accountID, @@ -962,6 +968,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { if (iouType === CONST.IOU.TYPE.SPLIT && !transaction?.isFromGlobalCreate) { if (currentUserPersonalDetails.login && !!transaction) { splitBill({ + getCurrencyDecimals, participants: splitParticipants, currentUserLogin: currentUserPersonalDetails.login, currentUserAccountID: currentUserPersonalDetails.accountID, @@ -1004,6 +1011,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { if (iouType === CONST.IOU.TYPE.SPLIT) { if (currentUserPersonalDetails.login && !!transaction) { splitBillAndOpenReport({ + getCurrencyDecimals, participants: splitParticipants, currentUserLogin: currentUserPersonalDetails.login, currentUserAccountID: currentUserPersonalDetails.accountID, @@ -1046,6 +1054,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { const invoiceChatReportID = invoiceChatReport ? undefined : reportID; sendInvoice({ + getCurrencyDecimals, currentUserAccountID: currentUserPersonalDetails.accountID, transaction, policyRecentlyUsedCurrencies, @@ -1156,6 +1165,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { const {optimisticChatReportID, chatReportID} = resolvedReportIDs ?? resolveOptimisticChatReportID([participant.accountID ?? CONST.DEFAULT_NUMBER_ID, currentUserPersonalDetails.accountID], report); const sendMoneyParams = { + getCurrencyDecimals, report, quickAction, amount: transaction.amount, diff --git a/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts b/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts index 9517afe347c5..ea29e47620cb 100644 --- a/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts +++ b/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts @@ -9,6 +9,7 @@ import type {Report, ReportAction, Transaction} from '@src/types/onyx'; import Onyx from 'react-native-onyx'; import {createSelfDM} from '../../utils/collections/reports'; +import {getCurrencyDecimalsLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@src/libs/Navigation/Navigation', () => ({ @@ -177,6 +178,7 @@ describe('buildOnyxDataForMoneyRequest', () => { function buildSelfDMParams(): BuildOnyxDataParams { return { + getCurrencyDecimals: getCurrencyDecimalsLocal, isNewChatReport: false, shouldCreateNewMoneyRequestReport: false, shouldGenerateTransactionThreadReport: true, @@ -320,6 +322,7 @@ describe('buildOnyxDataForMoneyRequest', () => { describe('when isSelfDMSplit=false (standard flow)', () => { function buildStandardParams(): BuildOnyxDataParams { return { + getCurrencyDecimals: getCurrencyDecimalsLocal, isNewChatReport: false, shouldCreateNewMoneyRequestReport: false, shouldGenerateTransactionThreadReport: false, @@ -360,6 +363,7 @@ describe('buildOnyxDataForMoneyRequest', () => { describe('when isSelfDMSplit=true but selfDMReportID is undefined', () => { function buildNoSelfDMReportIDParams(): BuildOnyxDataParams { return { + getCurrencyDecimals: getCurrencyDecimalsLocal, isNewChatReport: false, shouldCreateNewMoneyRequestReport: false, shouldGenerateTransactionThreadReport: false, @@ -399,6 +403,7 @@ describe('buildOnyxDataForMoneyRequest', () => { const optimisticParams = buildBaseOptimisticParams(IOU_REPORT_ID); return { + getCurrencyDecimals: getCurrencyDecimalsLocal, isNewChatReport: false, shouldCreateNewMoneyRequestReport, shouldGenerateTransactionThreadReport: false, diff --git a/tests/actions/IOU/GetMoneyRequestInformationTest.ts b/tests/actions/IOU/GetMoneyRequestInformationTest.ts index b76a4428ede6..27b3dcafcc96 100644 --- a/tests/actions/IOU/GetMoneyRequestInformationTest.ts +++ b/tests/actions/IOU/GetMoneyRequestInformationTest.ts @@ -6,6 +6,7 @@ import type {Beta, PolicyTagLists, Report, Transaction} from '@src/types/onyx'; import Onyx from 'react-native-onyx'; +import {getCurrencyDecimalsLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@src/libs/Navigation/Navigation', () => ({ @@ -86,6 +87,7 @@ describe('getMoneyRequestInformation', () => { describe('optimistic recently used tags', () => { it('should store recently used tags at the correct policy key when policyTagList and tag are provided', () => { const result = getMoneyRequestInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, policyParams: { policyTagList: policyTagListA, @@ -105,6 +107,7 @@ describe('getMoneyRequestInformation', () => { it('should not store recently used tags when tag is not provided', () => { const result = getMoneyRequestInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, policyParams: { policyTagList: policyTagListA, @@ -119,6 +122,7 @@ describe('getMoneyRequestInformation', () => { it('should store tags under empty-string list key when policyTagList has no named tag lists', () => { const result = getMoneyRequestInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, policyParams: { policyTagList: {}, @@ -140,6 +144,7 @@ describe('getMoneyRequestInformation', () => { it('should use parentChatReport.policyID for the recently used tags key', () => { const otherPolicyID = 'policy-other'; const result = getMoneyRequestInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, parentChatReport: { ...parentChatReport, @@ -177,6 +182,7 @@ describe('getMoneyRequestInformation', () => { await waitForBatchedUpdates(); const result = getMoneyRequestInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, moneyRequestReportID, policyParams: { @@ -197,6 +203,7 @@ describe('getMoneyRequestInformation', () => { it('should fall back to parentChatReport.policyID when moneyRequestReportID is empty string', () => { const result = getMoneyRequestInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, moneyRequestReportID: '', policyParams: { @@ -219,7 +226,7 @@ describe('getMoneyRequestInformation', () => { describe('pendingNewTransactionIDs metadata rail', () => { // Only the 0→1 negative is testable here (the resolved report has no existing txs); the >= 1 positive path lives in the useNewTransactions consumer tests. it('does NOT flag the first transaction of a report (no stale flag to re-highlight the original on a later add)', () => { - const result = getMoneyRequestInformation(baseParams); + const result = getMoneyRequestInformation({...baseParams, getCurrencyDecimals: getCurrencyDecimalsLocal}); const expectedKey = `${ONYXKEYS.COLLECTION.REPORT_METADATA}${result.iouReport.reportID}`; const newTxID = result.transaction.transactionID; @@ -257,6 +264,7 @@ describe('getMoneyRequestInformation', () => { }; const result = getMoneyRequestInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, existingTransaction, isSplitExpense: true, diff --git a/tests/actions/IOU/MoneyRequestTest.ts b/tests/actions/IOU/MoneyRequestTest.ts index 7156db768fb8..23ff20276ac5 100644 --- a/tests/actions/IOU/MoneyRequestTest.ts +++ b/tests/actions/IOU/MoneyRequestTest.ts @@ -29,7 +29,7 @@ import createRandomPolicy from '../../utils/collections/policies'; import {createRandomReport, createSelfDM} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {formatPhoneNumber, translateLocal} from '../../utils/TestHelper'; +import {formatPhoneNumber, getCurrencyDecimalsLocal, translateLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@libs/actions/IOU', () => { @@ -169,12 +169,7 @@ describe('MoneyRequest', () => { }); it('should call trackExpense for TRACK iouType', async () => { - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.TRACK, - allTransactionDrafts: {}, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, allTransactionDrafts: {}, delegateAccountID: undefined}); expect(TrackExpense.trackExpense).toHaveBeenCalledTimes(1); expect(TrackExpense.requestMoney).toHaveBeenCalledTimes(0); @@ -211,12 +206,7 @@ describe('MoneyRequest', () => { }); it('should call requestMoney for non-TRACK (SEND) iouType', () => { - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.SEND, - allTransactionDrafts: {}, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.SEND, allTransactionDrafts: {}, delegateAccountID: undefined}); expect(TrackExpense.requestMoney).toHaveBeenCalledTimes(1); expect(TrackExpense.trackExpense).toHaveBeenCalledTimes(0); @@ -256,6 +246,7 @@ describe('MoneyRequest', () => { const policyTagList = {Tag: {name: 'Tag', tags: {}, orderWeight: 0, required: false}} as PolicyTagLists; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.SEND, allTransactionDrafts: {}, @@ -273,6 +264,7 @@ describe('MoneyRequest', () => { const policyTagList = {Tag: {name: 'Tag', tags: {}, orderWeight: 0, required: false}} as PolicyTagLists; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, allTransactionDrafts: {}, @@ -293,13 +285,7 @@ describe('MoneyRequest', () => { {...fakeReceiptFile, transactionID: '333'}, ]; - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.TRACK, - files, - allTransactionDrafts: {}, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, files, allTransactionDrafts: {}, delegateAccountID: undefined}); expect(TrackExpense.trackExpense).toHaveBeenCalledTimes(files.length); const trackExpenseCallsHaveDeferFlag = jest.mocked(TrackExpense.trackExpense).mock.calls.some(([params]) => !!params && 'shouldDeferAPIWrite' in params); @@ -309,12 +295,7 @@ describe('MoneyRequest', () => { it('should default receipt source and state correctly when file is missing', () => { const files = [{...fakeReceiptFile, file: undefined}]; - createTransaction({ - ...baseParams, - files, - allTransactionDrafts: {}, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, files, allTransactionDrafts: {}, delegateAccountID: undefined}); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( expect.objectContaining({ @@ -329,12 +310,7 @@ describe('MoneyRequest', () => { }); it('should default currentUserEmail to empty for requestMoney when not provided', () => { - createTransaction({ - ...baseParams, - currentUserEmail: undefined, - allTransactionDrafts: {}, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, currentUserEmail: undefined, allTransactionDrafts: {}, delegateAccountID: undefined}); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( expect.objectContaining({ @@ -361,6 +337,7 @@ describe('MoneyRequest', () => { }; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, transactions: [transactionWithLinkedAction], allTransactionDrafts: { @@ -378,11 +355,7 @@ describe('MoneyRequest', () => { }); it('should default draftTransactionIDs to empty array when allTransactionDrafts is undefined', () => { - createTransaction({ - ...baseParams, - allTransactionDrafts: undefined, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, allTransactionDrafts: undefined, delegateAccountID: undefined}); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( expect.objectContaining({ @@ -393,6 +366,7 @@ describe('MoneyRequest', () => { it('should pass billable and reimbursable flags to trackExpense', () => { createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, billable: true, @@ -411,11 +385,7 @@ describe('MoneyRequest', () => { }); it('should pass undefined existingTransactionDraft when no matching draft exists', () => { - createTransaction({ - ...baseParams, - allTransactionDrafts: {}, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, allTransactionDrafts: {}, delegateAccountID: undefined}); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( expect.objectContaining({ @@ -427,13 +397,13 @@ describe('MoneyRequest', () => { // getMoneyRequestInformation derives isScanRequest from existingTransaction; dropping it would silently downgrade a scanned receipt to a manual request. it('should pass the receipt transaction as existingTransaction to requestMoney', () => { - createTransaction({...baseParams}); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams}); expect(TrackExpense.requestMoney).toHaveBeenCalledWith(expect.objectContaining({existingTransaction: fakeTransaction})); }); it('should pass the receipt transaction as existingTransaction to trackExpense', () => { - createTransaction({...baseParams, iouType: CONST.IOU.TYPE.TRACK}); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK}); expect(TrackExpense.trackExpense).toHaveBeenCalledWith(expect.objectContaining({existingTransaction: fakeTransaction})); }); @@ -443,6 +413,7 @@ describe('MoneyRequest', () => { const draft2 = createRandomTransaction(102); createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, allTransactionDrafts: { [draft1.transactionID]: draft1, @@ -460,12 +431,7 @@ describe('MoneyRequest', () => { it('should pass gpsPoint to trackExpense when provided', () => { const gpsPoint = {lat: TEST_LATITUDE, long: TEST_LONGITUDE}; - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.TRACK, - gpsPoint, - delegateAccountID: undefined, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, gpsPoint, delegateAccountID: undefined}); expect(TrackExpense.trackExpense).toHaveBeenCalledWith( expect.objectContaining({ @@ -496,6 +462,7 @@ describe('MoneyRequest', () => { }; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, transactions: [transactionWithoutTax], @@ -533,6 +500,7 @@ describe('MoneyRequest', () => { }; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.REQUEST, transactions: [transactionWithoutTax], @@ -570,6 +538,7 @@ describe('MoneyRequest', () => { }; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, transactions: [transactionWithTax], @@ -595,6 +564,7 @@ describe('MoneyRequest', () => { }; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.REQUEST, transactions: [transactionWithoutTax], @@ -619,23 +589,13 @@ describe('MoneyRequest', () => { {...fakeReceiptFile, transactionID: '333'}, ]; - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.SEND, - files, - allTransactionDrafts: {}, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.SEND, files, allTransactionDrafts: {}}); expect(TrackExpense.requestMoney).toHaveBeenCalledTimes(files.length); }); it('should fall back to requestMoney when iouType is TRACK but report is null', () => { - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.TRACK, - report: undefined, - allTransactionDrafts: {}, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, report: undefined, allTransactionDrafts: {}}); expect(TrackExpense.requestMoney).toHaveBeenCalledTimes(1); expect(TrackExpense.trackExpense).not.toHaveBeenCalled(); @@ -644,11 +604,7 @@ describe('MoneyRequest', () => { it('should pass policyRecentlyUsedCurrencies to requestMoney when provided', () => { const policyRecentlyUsedCurrencies = ['USD', 'EUR', 'GBP']; - createTransaction({ - ...baseParams, - policyRecentlyUsedCurrencies, - allTransactionDrafts: {}, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, policyRecentlyUsedCurrencies, allTransactionDrafts: {}}); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( expect.objectContaining({ @@ -658,11 +614,7 @@ describe('MoneyRequest', () => { }); it('should default policyRecentlyUsedCurrencies to empty array for requestMoney when not provided', () => { - createTransaction({ - ...baseParams, - policyRecentlyUsedCurrencies: undefined, - allTransactionDrafts: {}, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, policyRecentlyUsedCurrencies: undefined, allTransactionDrafts: {}}); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( expect.objectContaining({ @@ -674,12 +626,7 @@ describe('MoneyRequest', () => { it('should pass introSelected to trackExpense when provided', () => { const introSelected = {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, inviteType: CONST.ONBOARDING_INVITE_TYPES.IOU}; - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.TRACK, - introSelected, - allTransactionDrafts: {}, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, introSelected, allTransactionDrafts: {}}); expect(TrackExpense.trackExpense).toHaveBeenCalledWith( expect.objectContaining({ @@ -693,6 +640,7 @@ describe('MoneyRequest', () => { const draft2 = createRandomTransaction(202); createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, allTransactionDrafts: { @@ -709,11 +657,7 @@ describe('MoneyRequest', () => { }); it('should default reimbursable to true when not explicitly provided', () => { - createTransaction({ - ...baseParams, - iouType: CONST.IOU.TYPE.TRACK, - allTransactionDrafts: {}, - }); + createTransaction({getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.TRACK, allTransactionDrafts: {}}); expect(TrackExpense.trackExpense).toHaveBeenCalledWith( expect.objectContaining({ @@ -731,6 +675,7 @@ describe('MoneyRequest', () => { const files = [{...fakeReceiptFile, transactionID: transaction2.transactionID}]; createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.SEND, transactions: [transaction1, transaction2], @@ -750,6 +695,7 @@ describe('MoneyRequest', () => { it('should pass each UI-provided optimistic transaction ID to the per-file write (so the UI can target the same id for nav)', () => { createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.REQUEST, optimisticTransactionIDs: ['ui-id-1'], @@ -762,6 +708,7 @@ describe('MoneyRequest', () => { it('should forward the UI-resolved optimisticChatReportID to requestMoney (so the action builds the chat with the same id the UI navigates to)', () => { createTransaction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.REQUEST, report: undefined, @@ -859,6 +806,7 @@ describe('MoneyRequest', () => { it('should go back when backTo is provided', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, backTo, draftTransactionIDs: [baseParams.transactionID], @@ -871,6 +819,7 @@ describe('MoneyRequest', () => { it('should default draftTransactionIDs to empty array when undefined is passed', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, backTo, draftTransactionIDs: undefined, @@ -888,6 +837,7 @@ describe('MoneyRequest', () => { }; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, transaction: splitTransaction, manualDistance: undefined, @@ -903,6 +853,7 @@ describe('MoneyRequest', () => { it('call trackExpense for TRACK iouType when from manual distance step and skipping confirmation', async () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, manualDistance: 20, shouldSkipConfirmation: true, @@ -951,6 +902,7 @@ describe('MoneyRequest', () => { }; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, transaction, manualDistance: 10, @@ -988,6 +940,7 @@ describe('MoneyRequest', () => { }; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, transaction: movedTransaction, manualDistance: 20, @@ -1012,6 +965,7 @@ describe('MoneyRequest', () => { // createDistanceRequest writes under the draft transaction, so cleanup must target that id — not the UI's optimistic one. it('should pass the written transaction id from createDistanceRequest (not the draft or optimistic id) to cleanup for a non-track distance submission', async () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, shouldSkipConfirmation: true, manualDistance: 20, @@ -1058,6 +1012,7 @@ describe('MoneyRequest', () => { }, }; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, policyForMovingExpenses, manualDistance: undefined, @@ -1139,6 +1094,7 @@ describe('MoneyRequest', () => { it('should call createDistanceRequest for non-TRACK iouType when from manual distance step and skipping confirmation', async () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, shouldSkipConfirmation: true, manualDistance: 20, @@ -1183,6 +1139,7 @@ describe('MoneyRequest', () => { it('should call createDistanceRequest for non-TRACK iouType when not from manual distance step and skipping confirmation', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, shouldSkipConfirmation: true, manualDistance: undefined, @@ -1227,6 +1184,7 @@ describe('MoneyRequest', () => { it('should navigate to confirmation page when not skipping confirmation', async () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, shouldSkipConfirmation: false, iouType: CONST.IOU.TYPE.SUBMIT, @@ -1267,6 +1225,7 @@ describe('MoneyRequest', () => { jest.mocked(getPolicyExpenseChat).mockReturnValueOnce(fakeReport); handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, report: undefined, defaultExpensePolicy, @@ -1311,6 +1270,7 @@ describe('MoneyRequest', () => { }; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, report: undefined, defaultExpensePolicy, @@ -1327,6 +1287,7 @@ describe('MoneyRequest', () => { it('should navigate to participants page when the user click create expense option (combined submit/track flow)', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.CREATE, draftTransactionIDs: [baseParams.transactionID], @@ -1339,6 +1300,7 @@ describe('MoneyRequest', () => { it('should pass amountOwed through to shouldUseDefaultExpensePolicy and navigate to participants page when no default policy', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, report: undefined, defaultExpensePolicy: undefined, @@ -1354,6 +1316,7 @@ describe('MoneyRequest', () => { it('should pass ownerBillingGracePeriodEnd through to shouldUseDefaultExpensePolicy', () => { const pastDate = Math.floor(Date.now() / 1000) - 86400 * 30; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, report: undefined, defaultExpensePolicy: undefined, @@ -1369,6 +1332,7 @@ describe('MoneyRequest', () => { it('should pass currentUserAccountID to shouldUseDefaultExpensePolicy so the billing restriction uses the explicit account, not the deprecated session value', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, report: undefined, defaultExpensePolicy: fakePolicy, @@ -1383,6 +1347,7 @@ describe('MoneyRequest', () => { it('should call setDistanceRequestData with the provided participants when report exists', async () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.SUBMIT, shouldSkipConfirmation: false, @@ -1399,6 +1364,7 @@ describe('MoneyRequest', () => { it('should forward a participant marked as disabled to setDistanceRequestData', async () => { let capturedParticipants: Array = []; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.SUBMIT, shouldSkipConfirmation: false, @@ -1421,6 +1387,7 @@ describe('MoneyRequest', () => { it('should forward a participant not marked as disabled to setDistanceRequestData', async () => { let capturedParticipants: Array = []; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, iouType: CONST.IOU.TYPE.SUBMIT, shouldSkipConfirmation: false, @@ -1447,6 +1414,7 @@ describe('MoneyRequest', () => { }; handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, transaction: splitTransaction, odometerDistance: 15, @@ -1462,6 +1430,7 @@ describe('MoneyRequest', () => { it('should call trackExpense with odometerDistance as distance and forward odometerStart and odometerEnd', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, odometerDistance: 25, odometerStart: 1000, @@ -1488,6 +1457,7 @@ describe('MoneyRequest', () => { it('should call trackExpense with gpsDistance as distance and forward gpsCoordinates', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, gpsDistance: 5000, gpsCoordinates: '37.7749,-122.4194', @@ -1511,6 +1481,7 @@ describe('MoneyRequest', () => { it('should call createDistanceRequest with gpsDistance as distance and forward gpsCoordinates for non-TRACK iouType', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, gpsDistance: 3000, gpsCoordinates: '40.7128,-74.0060', @@ -1534,6 +1505,7 @@ describe('MoneyRequest', () => { it('should navigate to participants page when isArchivedExpenseReport is true even when report exists', () => { handleMoneyRequestStepDistanceNavigation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, ...baseParams, report: fakeReport, isArchivedExpenseReport: true, diff --git a/tests/actions/IOU/PerDiemTest.ts b/tests/actions/IOU/PerDiemTest.ts index a175ed714639..1dc8139015e5 100644 --- a/tests/actions/IOU/PerDiemTest.ts +++ b/tests/actions/IOU/PerDiemTest.ts @@ -20,7 +20,7 @@ import createRandomPolicyCategories from '../../utils/collections/policyCategory import createRandomPolicyTags from '../../utils/collections/policyTags'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {formatPhoneNumber, getGlobalFetchMock} from '../../utils/TestHelper'; +import {formatPhoneNumber, getCurrencyDecimalsLocal, getGlobalFetchMock} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@src/libs/Navigation/Navigation', () => ({ @@ -314,6 +314,7 @@ describe('PerDiem', () => { }; const result = getPerDiemExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, parentChatReport: {} as OnyxEntry, transactionParams: mockTransactionParams, participantParams: mockParticipantParams as unknown as RequestMoneyParticipantParams, @@ -405,6 +406,7 @@ describe('PerDiem', () => { // When: Call getPerDiemExpenseInformation const result = getPerDiemExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, parentChatReport: {} as OnyxEntry, transactionParams: mockTransactionParams, participantParams: mockParticipantParams, @@ -498,6 +500,7 @@ describe('PerDiem', () => { }; const result = getPerDiemExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, parentChatReport: undefined, transactionParams: mockTransactionParams, participantParams: mockParticipantParams, @@ -601,6 +604,7 @@ describe('PerDiem', () => { // When: Call getPerDiemExpenseInformation with existing chat report const result = getPerDiemExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, parentChatReport: existingChatReport as OnyxEntry, transactionParams: mockTransactionParams as PerDiemExpenseTransactionParams, participantParams: mockParticipantParams as RequestMoneyParticipantParams, @@ -691,6 +695,7 @@ describe('PerDiem', () => { // When: Call getPerDiemExpenseInformation for policy expense chat const result = getPerDiemExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, parentChatReport: {} as OnyxEntry, transactionParams: mockTransactionParams as PerDiemExpenseTransactionParams, participantParams: mockParticipantParams as RequestMoneyParticipantParams, @@ -749,6 +754,7 @@ describe('PerDiem', () => { // When submitting a per diem expense submitPerDiemExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, currentUserAccountIDParam: currentUserPersonalDetails.accountID, currentUserEmailParam: currentUserPersonalDetails.login ?? '', hasViolations: false, @@ -821,6 +827,7 @@ describe('PerDiem', () => { }); await waitForBatchedUpdates(); submitPerDiemExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, currentUserAccountIDParam: currentUserPersonalDetails.accountID, currentUserEmailParam: currentUserPersonalDetails.login ?? '', hasViolations: false, @@ -909,6 +916,7 @@ describe('PerDiem', () => { // When calling getPerDiemExpenseInformation with personalDetails const result = getPerDiemExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, parentChatReport: {} as OnyxEntry, transactionParams: mockTransactionParams, participantParams: { @@ -964,6 +972,7 @@ describe('PerDiem', () => { // When submitting a per diem expense with personalDetails submitPerDiemExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, currentUserAccountIDParam: currentUserPersonalDetails.accountID, currentUserEmailParam: currentUserPersonalDetails.login ?? '', hasViolations: false, diff --git a/tests/actions/IOU/RequestMoneyTest.ts b/tests/actions/IOU/RequestMoneyTest.ts index d914d34ca9c5..ec00fb0699e1 100644 --- a/tests/actions/IOU/RequestMoneyTest.ts +++ b/tests/actions/IOU/RequestMoneyTest.ts @@ -47,7 +47,16 @@ import createPersonalDetails from '../../utils/collections/personalDetails'; import {createRandomReport} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {expectAPICommandToHaveBeenCalled, formatPhoneNumber, getGlobalFetchMock, getOnyxData, setPersonalDetails, signInWithTestUser, translateLocal} from '../../utils/TestHelper'; +import { + expectAPICommandToHaveBeenCalled, + formatPhoneNumber, + getCurrencyDecimalsLocal, + getGlobalFetchMock, + getOnyxData, + setPersonalDetails, + signInWithTestUser, + translateLocal, +} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; import waitForNetworkPromises from '../../utils/waitForNetworkPromises'; @@ -195,6 +204,7 @@ describe('actions/IOU', () => { let transactionThreadCreatedAction: OnyxEntry; mockFetch?.pause?.(); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -456,6 +466,7 @@ describe('actions/IOU', () => { ) .then(() => { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -688,6 +699,7 @@ describe('actions/IOU', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -855,6 +867,7 @@ describe('actions/IOU', () => { let transactionThreadAction: OnyxEntry; mockFetch?.pause?.(); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -1252,6 +1265,7 @@ describe('actions/IOU', () => { // First create a tracked expense in self DM trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -1312,6 +1326,7 @@ describe('actions/IOU', () => { // Now pause fetch and share the tracked expense with accountant mockFetch?.pause?.(); trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -1374,6 +1389,7 @@ describe('actions/IOU', () => { it('does not trigger notifyNewAction when doing the money request in a money request report', () => { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: '123', type: CONST.REPORT.TYPE.EXPENSE}, participantParams: { @@ -1409,6 +1425,7 @@ describe('actions/IOU', () => { it('trigger notifyNewAction when doing the money request in a chat report', () => { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: '123'}, participantParams: { @@ -1444,6 +1461,7 @@ describe('actions/IOU', () => { it('should pass isSelfTourViewed true to the request when user has viewed the tour', () => { const {iouReport} = requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -1497,6 +1515,7 @@ describe('actions/IOU', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChat.reportID}`, workspaceChat); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: expenseReport, participantParams: { @@ -1544,6 +1563,7 @@ describe('actions/IOU', () => { expect(nonReimbursableTotal).toBe(0); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: expenseReport, participantParams: { @@ -1616,6 +1636,7 @@ describe('actions/IOU', () => { // When requesting money requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: expenseReport, existingIOUReport: expenseReport, @@ -1690,6 +1711,7 @@ describe('actions/IOU', () => { const merchant = 'Test Store'; const {iouReport} = requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -1766,6 +1788,7 @@ describe('actions/IOU', () => { const amount = 10000; const {iouReport} = requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -1813,6 +1836,7 @@ describe('actions/IOU', () => { const amount = 2500; const {iouReport} = requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -1880,6 +1904,7 @@ describe('actions/IOU', () => { // Create a tracked expense trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -1971,6 +1996,7 @@ describe('actions/IOU', () => { // When: submitting the tracked expense to another user const {iouReport} = requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, action: CONST.IOU.ACTION.SUBMIT, report: chatReport, @@ -2052,6 +2078,7 @@ describe('actions/IOU', () => { // Request money from CARLOS, but pass the existing chat report with JULES // This simulates the scenario where submit frequency is disabled and user selects a different participant requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: existingChatReport, participantParams: { @@ -2141,6 +2168,7 @@ describe('actions/IOU', () => { .then(() => { // Request money from CARLOS with matching chat report requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: existingChatReport, participantParams: { @@ -2221,6 +2249,7 @@ describe('actions/IOU', () => { .then(() => { // Request money with isPolicyExpenseChat: true - should skip participant validation requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChatReport, participantParams: { @@ -2296,6 +2325,7 @@ describe('actions/IOU', () => { // Request money from CARLOS but passing a policy expense chat report with different participants (JULES) // Since the chatReport is a policy expense chat, participant validation should be skipped requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChatReport, participantParams: { @@ -2371,6 +2401,7 @@ describe('actions/IOU', () => { // Track expense in self-DM with accountID: 0 (as getMoneyRequestParticipantsFromReport does) // This simulates the scenario where user starts an expense from "Your Space" requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, participantParams: { @@ -2445,6 +2476,7 @@ describe('actions/IOU', () => { mockFetch?.pause?.(); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -2507,6 +2539,7 @@ describe('actions/IOU', () => { mockFetch?.pause?.(); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat, report: {reportID: ''}, participantParams: { @@ -2571,6 +2604,7 @@ describe('actions/IOU', () => { ])('%s', async (expectedCommand: ApiCommand, action: IOUAction) => { // When an expense is created requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, action, report: {reportID: ''}, @@ -2638,6 +2672,7 @@ describe('actions/IOU', () => { // When the expense is submitted requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: ''}, participantParams: { @@ -2701,6 +2736,7 @@ describe('actions/IOU', () => { // When it is moved with a stale local receipt file trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: '123', policyID: 'A'}, isDraftPolicy: false, @@ -2770,6 +2806,7 @@ describe('actions/IOU', () => { // When it is moved before its upload response is processed trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: '123', policyID: 'A'}, isDraftPolicy: false, @@ -2856,6 +2893,7 @@ describe('actions/IOU', () => { // When it is submitted to a workspace with a stale local receipt file requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, action: CONST.IOU.ACTION.SUBMIT, report: { @@ -2934,6 +2972,7 @@ describe('actions/IOU', () => { const getCurrentSearchQueryJSONSpy = jest.spyOn(SearchQueryUtils, 'getCurrentSearchQueryJSON').mockReturnValue(currentSearchQueryJSON); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, action: CONST.IOU.ACTION.CREATE, report: {reportID: ''}, @@ -3013,6 +3052,7 @@ describe('actions/IOU', () => { // When a track expense is created trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: {reportID: '123', policyID: 'A'}, isDraftPolicy: false, @@ -3079,6 +3119,7 @@ describe('actions/IOU', () => { transactionID: 'create-transaction-tx', }; return { + getCurrencyDecimals: getCurrencyDecimalsLocal, transactions: [transaction], iouType, report, diff --git a/tests/actions/IOU/SplitReportTotalsTest.ts b/tests/actions/IOU/SplitReportTotalsTest.ts index 849dbb446894..a04dc38ba953 100644 --- a/tests/actions/IOU/SplitReportTotalsTest.ts +++ b/tests/actions/IOU/SplitReportTotalsTest.ts @@ -24,7 +24,7 @@ import Onyx from 'react-native-onyx'; import currencyList from '../../unit/currencyList.json'; import createMock from '../../utils/createMock'; -import {getGlobalFetchMock, formatPhoneNumber} from '../../utils/TestHelper'; +import {getGlobalFetchMock, formatPhoneNumber, getCurrencyDecimalsLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; const topMostReportID = '23423423'; @@ -489,6 +489,7 @@ describe('actions/IOU', () => { participantsPolicyTags?: Record; } = {}, ) => ({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: overrides.participants ?? [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -745,6 +746,7 @@ describe('actions/IOU', () => { function buildBaseParams(overrides: Record = {}) { return { + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: {}, allReportsList: {}, allReportActionsList: {}, diff --git a/tests/actions/IOUTest/CreateExpenseByTypeTest.ts b/tests/actions/IOUTest/CreateExpenseByTypeTest.ts index c285cd03c118..db6167fe67d5 100644 --- a/tests/actions/IOUTest/CreateExpenseByTypeTest.ts +++ b/tests/actions/IOUTest/CreateExpenseByTypeTest.ts @@ -17,6 +17,7 @@ import Onyx from 'react-native-onyx'; import currencyList from '../../unit/currencyList.json'; import {createRandomReport} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; +import {getCurrencyDecimalsLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@libs/actions/IOU/TrackExpense', () => ({ @@ -132,6 +133,7 @@ describe('actions/IOU/createExpenseByType', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }; return {transaction, transactionDetails, params}; diff --git a/tests/actions/IOUTest/DeleteMoneyRequestTest.ts b/tests/actions/IOUTest/DeleteMoneyRequestTest.ts index 8abc64df6a6c..5bbba69eaa50 100644 --- a/tests/actions/IOUTest/DeleteMoneyRequestTest.ts +++ b/tests/actions/IOUTest/DeleteMoneyRequestTest.ts @@ -183,6 +183,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { comment, }, shouldGenerateTransactionThreadReport: true, + getCurrencyDecimals: getCurrencyDecimalsLocal, isASAPSubmitBetaEnabled: false, currentUserAccountIDParam: 123, currentUserEmailParam: 'existing@example.com', @@ -434,6 +435,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { comment, }, shouldGenerateTransactionThreadReport: true, + getCurrencyDecimals: getCurrencyDecimalsLocal, isASAPSubmitBetaEnabled: false, currentUserAccountIDParam: 123, currentUserEmailParam: 'existing@example.com', @@ -1129,6 +1131,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { comment: comment2, }, shouldGenerateTransactionThreadReport: true, + getCurrencyDecimals: getCurrencyDecimalsLocal, isASAPSubmitBetaEnabled: false, currentUserAccountIDParam: 123, currentUserEmailParam: 'existing@example.com', @@ -1214,6 +1217,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { comment, }, shouldGenerateTransactionThreadReport: true, + getCurrencyDecimals: getCurrencyDecimalsLocal, isASAPSubmitBetaEnabled: false, currentUserAccountIDParam: 123, currentUserEmailParam: 'existing@example.com', @@ -1388,6 +1392,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { comment: comment2, }, shouldGenerateTransactionThreadReport: true, + getCurrencyDecimals: getCurrencyDecimalsLocal, isASAPSubmitBetaEnabled: false, transactionViolations: {}, currentUserAccountIDParam: 123, diff --git a/tests/actions/IOUTest/DuplicateTest.ts b/tests/actions/IOUTest/DuplicateTest.ts index e3d1c30d22e2..9019f1c2a2ac 100644 --- a/tests/actions/IOUTest/DuplicateTest.ts +++ b/tests/actions/IOUTest/DuplicateTest.ts @@ -1604,6 +1604,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -1672,6 +1673,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -1732,6 +1734,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -1785,6 +1788,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -1838,6 +1842,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -1894,6 +1899,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -1960,6 +1966,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2011,6 +2018,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2056,6 +2064,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2104,6 +2113,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2158,6 +2168,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2227,6 +2238,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2297,6 +2309,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2350,6 +2363,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2414,6 +2428,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); @@ -2443,7 +2458,7 @@ describe('actions/Duplicate', () => { describe('resolveDuplicate', () => { test('Resolving duplicates of two transaction by keeping one of them should properly set the other one on hold even if the transaction thread reports do not exist in onyx', () => { // Given two duplicate transactions - const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); + const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal); const transaction1 = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -2472,6 +2487,7 @@ describe('actions/Duplicate', () => { comment: '', participants: [], transactionID: transaction.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }), ); } @@ -3165,6 +3181,7 @@ describe('actions/Duplicate', () => { delegateAccountID: undefined, isTrackIntentUser: false, formatPhoneNumber, + getCurrencyDecimals: getCurrencyDecimalsLocal, participantsPolicyTags: {}, }); diff --git a/tests/actions/IOUTest/HoldTest.ts b/tests/actions/IOUTest/HoldTest.ts index 73a6ac8c683b..4271a73c7277 100644 --- a/tests/actions/IOUTest/HoldTest.ts +++ b/tests/actions/IOUTest/HoldTest.ts @@ -25,7 +25,7 @@ import Onyx from 'react-native-onyx'; import type {MockFetch} from '../../utils/TestHelper'; import createRandomPolicy from '../../utils/collections/policies'; -import {getGlobalFetchMock} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; const topMostReportID = '23423423'; @@ -98,7 +98,7 @@ describe('actions/IOU/Hold', () => { describe('putOnHold', () => { test("should update the transaction thread report's lastVisibleActionCreated to the optimistically added hold comment report action created timestamp", () => { - const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); + const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal); const transaction = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -117,6 +117,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const transactionThread = buildTransactionThread(iouAction, iouReport, RORY_ACCOUNT_ID); @@ -161,7 +162,7 @@ describe('actions/IOU/Hold', () => { }); test('should create transaction thread optimistically when initialReportID is undefined', () => { - const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); + const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal); const transaction = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -179,6 +180,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const actions: OnyxInputValue = {[iouAction.reportActionID]: iouAction}; const reportCollectionDataSet: ReportCollectionDataSet = { @@ -215,7 +217,7 @@ describe('actions/IOU/Hold', () => { describe('putTransactionsOnHold', () => { test('should call putOnHold for each transaction ID', () => { - const iouReport = buildOptimisticIOUReport(1, 2, 300, '1', 'USD'); + const iouReport = buildOptimisticIOUReport(1, 2, 300, '1', 'USD', getCurrencyDecimalsLocal); const transaction1 = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -238,6 +240,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction1.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const iouAction2: ReportAction = buildOptimisticIOUReportAction({ type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, @@ -246,6 +249,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction2.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const transactionThread1 = buildTransactionThread(iouAction1, iouReport, RORY_ACCOUNT_ID); const transactionThread2 = buildTransactionThread(iouAction2, iouReport, RORY_ACCOUNT_ID); @@ -307,7 +311,7 @@ describe('actions/IOU/Hold', () => { }); test('should invoke navigation for each transaction when isOffline is true', () => { - const iouReport = buildOptimisticIOUReport(1, 2, 300, '1', 'USD'); + const iouReport = buildOptimisticIOUReport(1, 2, 300, '1', 'USD', getCurrencyDecimalsLocal); const transaction1 = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -329,6 +333,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction1.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const iouAction2: ReportAction = buildOptimisticIOUReportAction({ type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, @@ -337,6 +342,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction2.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const transactionThread1 = buildTransactionThread(iouAction1, iouReport, RORY_ACCOUNT_ID); const transactionThread2 = buildTransactionThread(iouAction2, iouReport, RORY_ACCOUNT_ID); @@ -376,7 +382,7 @@ describe('actions/IOU/Hold', () => { describe('putOnHold with isOffline', () => { test('should pass isOffline to getDisplayedReportID affecting which reportID is used for navigation', () => { - const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); + const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal); const transaction = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -391,6 +397,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const transactionThread = buildTransactionThread(iouAction, iouReport, RORY_ACCOUNT_ID); @@ -433,7 +440,7 @@ describe('actions/IOU/Hold', () => { ...createRandomPolicy(Number(policyID)), }; const iouReport: Report = { - ...buildOptimisticIOUReport(1, 2, 100, '1', 'USD'), + ...buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal), policyID, }; const transaction = buildOptimisticTransaction({ @@ -454,6 +461,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const transactionThread = buildTransactionThread(iouAction, iouReport, RORY_ACCOUNT_ID); @@ -515,7 +523,7 @@ describe('actions/IOU/Hold', () => { ...createRandomPolicy(Number(policyID)), }; const iouReport: Report = { - ...buildOptimisticIOUReport(1, 2, 100, '1', 'USD'), + ...buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal), policyID, }; const transaction = buildOptimisticTransaction({ @@ -536,6 +544,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: transaction.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const transactionThread = buildTransactionThread(iouAction, iouReport, RORY_ACCOUNT_ID); @@ -608,7 +617,7 @@ describe('actions/IOU/Hold', () => { unheldReimbursableTotal?: number; heldAmount?: number; }) => { - const baseIouReport = buildOptimisticIOUReport(1, 2, overrides.total, '99', 'USD'); + const baseIouReport = buildOptimisticIOUReport(1, 2, overrides.total, '99', 'USD', getCurrencyDecimalsLocal); const iouReport: Report = { ...baseIouReport, total: overrides.total, @@ -634,6 +643,7 @@ describe('actions/IOU/Hold', () => { comment: '', participants: [], transactionID: heldTransaction.transactionID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }) : undefined; @@ -672,6 +682,7 @@ describe('actions/IOU/Hold', () => { policy: undefined, delegateAccountID: undefined, betas: [], + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const totalsUpdate = result.optimisticData.find((entry) => entry.onyxMethod === Onyx.METHOD.MERGE && entry.key === `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`); expect(totalsUpdate).toBeDefined(); @@ -698,6 +709,7 @@ describe('actions/IOU/Hold', () => { policy: undefined, delegateAccountID: undefined, betas: [], + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const restorationEntries = result.failureData.filter( (entry) => entry.onyxMethod === Onyx.METHOD.MERGE && entry.key === `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, @@ -729,6 +741,7 @@ describe('actions/IOU/Hold', () => { policy: undefined, delegateAccountID: undefined, betas: [], + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const totalsUpdates = result.optimisticData.filter((entry) => { const value = entry.value as Partial | undefined; @@ -757,6 +770,7 @@ describe('actions/IOU/Hold', () => { policy: undefined, delegateAccountID: undefined, betas: [], + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const totalsUpdates = result.optimisticData.filter((entry) => { const value = entry.value as Partial | undefined; diff --git a/tests/actions/IOUTest/PayMoneyRequestTest.ts b/tests/actions/IOUTest/PayMoneyRequestTest.ts index e107649f55b1..a030fa24ef8f 100644 --- a/tests/actions/IOUTest/PayMoneyRequestTest.ts +++ b/tests/actions/IOUTest/PayMoneyRequestTest.ts @@ -35,7 +35,7 @@ import createRandomReportAction from '../../utils/collections/reportActions'; import {createRandomReport} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {getGlobalFetchMock, getOnyxData, translateLocal} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock, getOnyxData, translateLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; const topMostReportID = '23423423'; @@ -167,6 +167,7 @@ describe('actions/IOU/PayMoneyRequest', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); return waitForBatchedUpdates() .then( @@ -261,6 +262,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); return waitForBatchedUpdates(); }) @@ -436,6 +438,7 @@ describe('actions/IOU/PayMoneyRequest', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); } return waitForBatchedUpdates(); @@ -474,6 +477,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); return waitForBatchedUpdates(); }) @@ -604,6 +608,7 @@ describe('actions/IOU/PayMoneyRequest', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); } return waitForBatchedUpdates(); @@ -643,6 +648,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); return waitForBatchedUpdates(); }) @@ -699,6 +705,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -785,6 +792,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: DELEGATE_ACCOUNT_ID, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -807,7 +815,7 @@ describe('actions/IOU/PayMoneyRequest', () => { it('calls notifyNewAction for the top most report', () => { // Given two expenses in an iou report where one of them held - const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); + const iouReport = buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal); const transaction1 = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -830,6 +838,7 @@ describe('actions/IOU/PayMoneyRequest', () => { for (const transaction of [transaction1, transaction2]) { iouActions.push( buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: transaction.amount, currency: transaction.currency, @@ -871,6 +880,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); return waitForBatchedUpdates(); }) @@ -971,6 +981,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); const newExpenseReport = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${newExpenseReportID}`); @@ -1011,6 +1022,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1064,6 +1076,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1161,7 +1174,7 @@ describe('actions/IOU/PayMoneyRequest', () => { mockFetch?.pause?.(); - markReportPaymentReceived(chatReport, reimbursedReport, currentUserAccountID, currentUserEmail, mockChatReportActions, false); + markReportPaymentReceived(chatReport, reimbursedReport, currentUserAccountID, currentUserEmail, mockChatReportActions, false, getCurrencyDecimalsLocal); await waitForBatchedUpdates(); const updatedChatReport = await new Promise>((resolve) => { @@ -1233,6 +1246,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1302,6 +1316,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1361,6 +1376,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1400,6 +1416,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1495,6 +1512,7 @@ describe('actions/IOU/PayMoneyRequest', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); } return waitForBatchedUpdates(); @@ -1529,6 +1547,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); return waitForBatchedUpdates(); }) @@ -1624,6 +1643,7 @@ describe('actions/IOU/PayMoneyRequest', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); } await waitForBatchedUpdates(); @@ -1876,6 +1896,7 @@ describe('actions/IOU/PayMoneyRequest', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); } await waitForBatchedUpdates(); @@ -1907,6 +1928,7 @@ describe('actions/IOU/PayMoneyRequest', () => { chatReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); } await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/RejectMoneyRequestTest.ts b/tests/actions/IOUTest/RejectMoneyRequestTest.ts index 523700f0a4b8..7a3774da25b2 100644 --- a/tests/actions/IOUTest/RejectMoneyRequestTest.ts +++ b/tests/actions/IOUTest/RejectMoneyRequestTest.ts @@ -22,7 +22,7 @@ import createRandomPolicy from '../../utils/collections/policies'; import {createRandomReport} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {getGlobalFetchMock, getOnyxData} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock, getOnyxData} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@src/libs/Navigation/Navigation', () => ({ @@ -154,7 +154,17 @@ describe('actions/IOU/RejectMoneyRequest', () => { if (!transaction?.transactionID || !iouReport?.reportID) { throw new Error('Required transaction or report data is missing'); } - const result = rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined); + const result = rejectMoneyRequest( + transaction.transactionID, + iouReport.reportID, + comment, + policy, + TEST_USER_ACCOUNT_ID, + TEST_USER_EMAIL, + [CONST.BETAS.ALL], + undefined, + getCurrencyDecimalsLocal, + ); // Then: Should return navigation route to chat report expect(result).toBe(ROUTES.REPORT_WITH_ID.getRoute(iouReport.reportID)); @@ -170,7 +180,7 @@ describe('actions/IOU/RejectMoneyRequest', () => { if (!transaction?.transactionID || !iouReport?.reportID) { throw new Error('Required transaction or report data is missing'); } - rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined); + rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined, getCurrencyDecimalsLocal); await waitForBatchedUpdates(); // Then: Verify violation is added @@ -226,7 +236,7 @@ describe('actions/IOU/RejectMoneyRequest', () => { if (!transaction?.transactionID || !iouReport?.reportID) { throw new Error('Required transaction or report data is missing'); } - rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined); + rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined, getCurrencyDecimalsLocal); await waitForBatchedUpdates(); // Then: createdIOUReportActionID shouldn't be undefined @@ -265,17 +275,39 @@ describe('actions/IOU/RejectMoneyRequest', () => { throw new Error('Required transaction or report data is missing'); } - rejectMoneyRequest(transaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined, { - sharedRejectedToReportID, - existingRejectedReport, - setExistingRejectedReport, - }); + rejectMoneyRequest( + transaction.transactionID, + iouReport.reportID, + comment, + policy, + TEST_USER_ACCOUNT_ID, + TEST_USER_EMAIL, + [CONST.BETAS.ALL], + undefined, + getCurrencyDecimalsLocal, + { + sharedRejectedToReportID, + existingRejectedReport, + setExistingRejectedReport, + }, + ); - rejectMoneyRequest(secondTransaction.transactionID, iouReport.reportID, comment, policy, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL, [CONST.BETAS.ALL], undefined, { - sharedRejectedToReportID, - existingRejectedReport, - setExistingRejectedReport, - }); + rejectMoneyRequest( + secondTransaction.transactionID, + iouReport.reportID, + comment, + policy, + TEST_USER_ACCOUNT_ID, + TEST_USER_EMAIL, + [CONST.BETAS.ALL], + undefined, + getCurrencyDecimalsLocal, + { + sharedRejectedToReportID, + existingRejectedReport, + setExistingRejectedReport, + }, + ); await waitForBatchedUpdates(); let allReports: OnyxCollection; diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index e7eb16444c69..9c0b37ec4b6e 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -54,7 +54,16 @@ import createRandomReportAction from '../../utils/collections/reportActions'; import {createRandomReport} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {createGlobalFetchMock, formatPhoneNumber, getOnyxData, getRequiredOnyxUpdate, getRequiredOnyxUpdates, getRequiredWriteCall, localeCompare} from '../../utils/TestHelper'; +import { + createGlobalFetchMock, + formatPhoneNumber, + getCurrencyDecimalsLocal, + getOnyxData, + getRequiredOnyxUpdate, + getRequiredOnyxUpdates, + getRequiredWriteCall, + localeCompare, +} from '../../utils/TestHelper'; import {isObject} from '../../utils/typeGuards'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; import waitForBatchedUpdatesWithAct from '../../utils/waitForBatchedUpdatesWithAct'; @@ -200,6 +209,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -269,6 +279,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(async () => { if (expenseReport) { submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy: undefined, @@ -349,6 +360,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -431,6 +443,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -480,6 +493,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -575,6 +589,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(async () => { if (expenseReport) { submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy, @@ -705,6 +720,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -754,6 +770,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -847,6 +864,7 @@ describe('actions/IOU/ReportWorkflow', () => { mockFetch?.fail?.(); if (expenseReport) { submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy: undefined, @@ -948,6 +966,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -1018,6 +1037,7 @@ describe('actions/IOU/ReportWorkflow', () => { .then(() => { if (expenseReport) { submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy, @@ -1090,6 +1110,7 @@ describe('actions/IOU/ReportWorkflow', () => { // Submit with amountOwed > 0 should trigger restriction submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy, @@ -1156,6 +1177,7 @@ describe('actions/IOU/ReportWorkflow', () => { if (chatReport) { requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -1204,6 +1226,7 @@ describe('actions/IOU/ReportWorkflow', () => { const ownerBillingGracePeriodEnd = Math.floor(Date.now() / 1000) - 86400 * 30; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy, @@ -1265,6 +1288,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy, @@ -1329,6 +1353,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy, @@ -1378,6 +1403,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, policy, currentUserAccountIDParam: submitterAccountID, @@ -1431,6 +1457,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, policy, currentUserAccountIDParam: submitterAccountID, @@ -1500,6 +1527,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: submitterEmail, expenseReport, policy, @@ -1590,6 +1618,7 @@ describe('actions/IOU/ReportWorkflow', () => { await waitForBatchedUpdates(); submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, policy, currentUserAccountIDParam: submitterAccountID, @@ -1688,6 +1717,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: submitterEmail, expenseReport, policy, @@ -1761,6 +1791,7 @@ describe('actions/IOU/ReportWorkflow', () => { // Go offline so only the optimistic update is applied mockFetch?.pause?.(); submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: submitterEmail, expenseReport, policy, @@ -1830,6 +1861,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: submitterEmail, expenseReport, policy, @@ -1898,6 +1930,7 @@ describe('actions/IOU/ReportWorkflow', () => { expect(canSubmitReport(report, submitterEmail, policy, [transaction], undefined, false, submitterEmail, submitterAccountID)).toBe(true); submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport: report, policy, @@ -1960,6 +1993,7 @@ describe('actions/IOU/ReportWorkflow', () => { expect(canSubmitReport(report, submitterEmail, policy, [transaction], undefined, false, submitterEmail, submitterAccountID)).toBe(true); submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport: report, policy, @@ -1997,6 +2031,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy: { @@ -2260,6 +2295,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy: undefined, @@ -2296,6 +2332,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; submitReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, submitterLogin: undefined, expenseReport, policy: undefined, @@ -2330,7 +2367,7 @@ describe('actions/IOU/ReportWorkflow', () => { statusNum: CONST.REPORT.STATUS_NUM.APPROVED, }; - unapproveExpenseReport(expenseReport, undefined, CARLOS_ACCOUNT_ID, CARLOS_EMAIL, false, false, DELEGATE_EMAIL, false); + unapproveExpenseReport(expenseReport, undefined, CARLOS_ACCOUNT_ID, CARLOS_EMAIL, false, false, DELEGATE_EMAIL, false, getCurrencyDecimalsLocal); // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure const calls = jest.mocked(API.write).mock.calls; @@ -2384,6 +2421,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, @@ -2426,6 +2464,7 @@ describe('actions/IOU/ReportWorkflow', () => { }; approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, @@ -3147,6 +3186,7 @@ describe('actions/IOU/ReportWorkflow', () => { }); const createApproveMoneyRequestParams = (expenseReport: Report, expenseReportPolicy: OnyxEntry) => ({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, @@ -3335,6 +3375,7 @@ describe('actions/IOU/ReportWorkflow', () => { // Admin approves the report approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy: policy, currentUserAccountIDParam: adminAccountID, @@ -3388,6 +3429,7 @@ describe('actions/IOU/ReportWorkflow', () => { // Manager approves the report approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy: policy, currentUserAccountIDParam: managerAccountID, @@ -3440,6 +3482,7 @@ describe('actions/IOU/ReportWorkflow', () => { // Admin approves the report approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy: policy, currentUserAccountIDParam: adminAccountID, @@ -3567,6 +3610,7 @@ describe('actions/IOU/ReportWorkflow', () => { // Manager approves the report (no take control actions) approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy: policy, currentUserAccountIDParam: managerAccountID, @@ -3599,6 +3643,7 @@ describe('actions/IOU/ReportWorkflow', () => { }); approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy: policy, currentUserAccountIDParam: managerAccountID, @@ -3629,6 +3674,7 @@ describe('actions/IOU/ReportWorkflow', () => { }); approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport: updatedReport, expenseReportPolicy: policy, currentUserAccountIDParam: adminAccountID, @@ -3689,6 +3735,7 @@ describe('actions/IOU/ReportWorkflow', () => { // Manager approves the report approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport: singleApproverReport, expenseReportPolicy: singleApproverPolicy, currentUserAccountIDParam: managerAccountID, @@ -3749,6 +3796,7 @@ describe('actions/IOU/ReportWorkflow', () => { }) .then(() => { approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport: normalReport, expenseReportPolicy: policy, currentUserAccountIDParam: managerAccountID, @@ -3880,6 +3928,7 @@ describe('actions/IOU/ReportWorkflow', () => { }); const newExpenseReportID = approveMoneyRequest({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport, expenseReportPolicy: policy, currentUserAccountIDParam: adminAccountID, diff --git a/tests/actions/IOUTest/SendInvoiceTest.ts b/tests/actions/IOUTest/SendInvoiceTest.ts index b0655ad50399..d3d629e87569 100644 --- a/tests/actions/IOUTest/SendInvoiceTest.ts +++ b/tests/actions/IOUTest/SendInvoiceTest.ts @@ -27,7 +27,7 @@ import createRandomPolicy from '../../utils/collections/policies'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; import initCurrencyListContext from '../../utils/initCurrencyListContext'; -import {formatPhoneNumber, getGlobalFetchMock} from '../../utils/TestHelper'; +import {formatPhoneNumber, getCurrencyDecimalsLocal, getGlobalFetchMock} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; const topMostReportID = '23423423'; @@ -200,6 +200,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then: Verify optimistic data is generated when policyRecentlyUsedCategories are provided @@ -227,6 +228,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); expect(result.onyxData.optimisticData).toBeDefined(); @@ -280,6 +282,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: mockPolicyTagList as PolicyTagLists, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then: Verify the result structure and key values @@ -328,6 +331,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const reportLoadingStateUpdate = result.onyxData.failureData?.find( @@ -368,6 +372,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const reportLoadingStateUpdate = result.onyxData.failureData?.find( @@ -405,6 +410,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: DELEGATE_ACCOUNT_ID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const reportActionsUpdate = result.onyxData.optimisticData?.find((update) => String(update.key) === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${result.invoiceReportID}`); @@ -447,6 +453,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then: Verify the result uses existing chat report @@ -485,6 +492,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then: Verify receipt handling @@ -536,6 +544,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then: Verify function handles missing data gracefully @@ -568,6 +577,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); expect(result.invoiceRoom).toBeDefined(); @@ -622,6 +632,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: baseSenderPolicyTags, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); expect(result.invoiceRoom).toBeDefined(); @@ -677,6 +688,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: senderPolicyTags ?? {}, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then: optimisticData should contain a POLICY_RECENTLY_USED_TAGS update with the transaction tag prepended @@ -726,6 +738,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: senderPolicyTags ?? {}, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then: No POLICY_RECENTLY_USED_TAGS update should be in optimisticData @@ -760,6 +773,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: undefined, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then a new invoice chat is created instead of incorrectly using the invoice chat which has been converted from individual to business @@ -790,6 +804,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: undefined, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); mockFetch?.fail?.(); @@ -831,6 +846,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: undefined, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); // Then onyxData should be passed to API.write @@ -874,6 +890,7 @@ describe('actions/SendInvoice', () => { }, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -911,6 +928,7 @@ describe('actions/SendInvoice', () => { senderPolicyTags: undefined, formatPhoneNumber, delegateAccountID: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); expect(writeSpy).toHaveBeenCalledWith( diff --git a/tests/actions/IOUTest/SendMoneyTest.ts b/tests/actions/IOUTest/SendMoneyTest.ts index d3e559270aaa..c1fc34aea282 100644 --- a/tests/actions/IOUTest/SendMoneyTest.ts +++ b/tests/actions/IOUTest/SendMoneyTest.ts @@ -11,7 +11,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import Onyx from 'react-native-onyx'; -import {getGlobalFetchMock} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; const topMostReportID = '23423423'; @@ -116,6 +116,7 @@ describe('actions/IOU/SendMoney', () => { currentUserAccountID: RORY_ACCOUNT_ID, recipient: {accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}, delegateAccountID: DELEGATE_ACCOUNT_ID, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/SplitSelfDMTest.ts b/tests/actions/IOUTest/SplitSelfDMTest.ts index 87ea4c971123..f8f9346a57cc 100644 --- a/tests/actions/IOUTest/SplitSelfDMTest.ts +++ b/tests/actions/IOUTest/SplitSelfDMTest.ts @@ -20,7 +20,7 @@ import type {MockFetch} from '../../utils/TestHelper'; import createPersonalDetails from '../../utils/collections/personalDetails'; import {createSelfDM} from '../../utils/collections/reports'; import getOnyxValue from '../../utils/getOnyxValue'; -import {getGlobalFetchMock, getOnyxData} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock, getOnyxData} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; import waitForNetworkPromises from '../../utils/waitForNetworkPromises'; @@ -126,6 +126,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => { const trackIouAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 2000, currency: CONST.CURRENCY.USD, @@ -173,6 +174,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => { }); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -259,6 +261,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => { }); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -364,6 +367,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => { }); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -457,6 +461,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => { // Step 1: Create the splits updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -517,6 +522,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => { // Step 3: Edit the splits (change amounts) updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -606,6 +612,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow - selfDM', () => { }); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, diff --git a/tests/actions/IOUTest/SplitTest.ts b/tests/actions/IOUTest/SplitTest.ts index a636b97d61ea..126eae7f0e36 100644 --- a/tests/actions/IOUTest/SplitTest.ts +++ b/tests/actions/IOUTest/SplitTest.ts @@ -57,7 +57,7 @@ import {createRandomReport, createSelfDM} from '../../utils/collections/reports' import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; import initCurrencyListContext from '../../utils/initCurrencyListContext'; -import {formatPhoneNumber, getGlobalFetchMock, getOnyxData, translateLocal} from '../../utils/TestHelper'; +import {formatPhoneNumber, getCurrencyDecimalsLocal, getGlobalFetchMock, getOnyxData, translateLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; import waitForNetworkPromises from '../../utils/waitForNetworkPromises'; @@ -390,6 +390,7 @@ describe('split expense', () => { splitBill( // TODO: Migrate after the backend accepts accountIDs { + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [ [CARLOS_EMAIL, String(CARLOS_ACCOUNT_ID)], [JULES_EMAIL, String(JULES_ACCOUNT_ID)], @@ -727,6 +728,7 @@ describe('split expense', () => { // When the user split bill on the workspace splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{reportID: workspaceReportID}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -780,6 +782,7 @@ describe('split expense', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, {reportID: workspaceReportID, isOwnPolicyExpenseChat: true}); splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{reportID: workspaceReportID}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -807,6 +810,7 @@ describe('split expense', () => { expect(await getOnyxValue(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE)).toHaveProperty('isFirstQuickAction', true); splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{reportID: workspaceReportID}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -841,6 +845,7 @@ describe('split expense', () => { await Onyx.set(ONYXKEYS.RECENTLY_USED_CURRENCIES, initialCurrencies); splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -880,6 +885,7 @@ describe('split expense', () => { // When the user split bill twice on the DM splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -905,6 +911,7 @@ describe('split expense', () => { await waitForBatchedUpdates(); splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -977,6 +984,7 @@ describe('split expense', () => { // When doing a distance split expense splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{reportID: workspaceReportID}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -1027,6 +1035,7 @@ describe('split expense', () => { // When the user split bill on the group chat splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -1088,6 +1097,7 @@ describe('split expense', () => { // When doing a split bill splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{isPolicyExpenseChat: true, policyID}], existingSplitChatReportID: policyExpenseChat.reportID, currentUserLogin: currentUserPersonalDetails.login ?? '', @@ -1156,6 +1166,7 @@ describe('split expense', () => { // Start a scan split bill const {splitTransactionID} = startSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -1196,6 +1207,7 @@ describe('split expense', () => { // Complete this split bill without changing the description completeSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, chatReportID: reportID, reportAction: iouAction, updatedTransaction: updatedSplitTransaction, @@ -1258,6 +1270,7 @@ describe('split expense', () => { const iouAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: Math.abs(originalAmount), currency: 'USD', @@ -1318,6 +1331,7 @@ describe('split expense', () => { // When splitting the expense updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -1399,6 +1413,7 @@ describe('split expense', () => { // When splitting a bill with explicit personalDetails splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -1460,6 +1475,7 @@ describe('split expense', () => { // When splitting a bill among multiple participants with explicit personalDetails splitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants: [ {accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}, {accountID: JULES_ACCOUNT_ID, login: JULES_EMAIL}, @@ -1532,6 +1548,7 @@ describe('split expense', () => { const participantsPolicyTags = await getParticipantsPolicyTags(participants); startSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants, currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -1609,6 +1626,7 @@ describe('split expense', () => { }; completeSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, chatReportID: reportID, reportAction: iouAction, updatedTransaction: updatedSplitTransaction, @@ -1653,6 +1671,7 @@ describe('startSplitBill', () => { // When doing a split bill with a receipt startSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants, currentUserLogin: currentUserPersonalDetails.login ?? '', currentUserAccountID: currentUserPersonalDetails.accountID, @@ -1699,6 +1718,7 @@ describe('startSplitBill', () => { // When starting a split bill const {splitTransactionID} = startSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants, currentUserLogin: currentUserPersonalDetails.login ?? '', currentUserAccountID: currentUserPersonalDetails.accountID, @@ -1748,6 +1768,7 @@ describe('startSplitBill', () => { // When starting a split bill const {splitTransactionID} = startSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants, currentUserLogin: currentUserPersonalDetails.login ?? '', currentUserAccountID: currentUserPersonalDetails.accountID, @@ -1797,6 +1818,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }; const iouAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: transaction.amount, currency: transaction.currency, @@ -1847,6 +1869,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -1913,6 +1936,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }; const iouAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: transaction.amount, currency: transaction.currency, @@ -1966,6 +1990,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -2037,6 +2062,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }; const iouAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: transaction.amount, currency: transaction.currency, @@ -2097,6 +2123,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -2181,6 +2208,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, betas: [CONST.BETAS.ALL], @@ -2263,6 +2291,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { let reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, betas: [CONST.BETAS.ALL], allReportsList: allReports, @@ -2326,6 +2355,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, betas: [CONST.BETAS.ALL], allReportsList: allReports, @@ -2407,6 +2437,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, betas: [CONST.BETAS.ALL], @@ -2518,6 +2549,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { let firstIOU = getIOUActionForReportID(reports.expenseReport?.reportID, originalTransactionID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, betas: [CONST.BETAS.ALL], allReportsList: allReports, @@ -2581,6 +2613,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, betas: [CONST.BETAS.ALL], allReportsList: allReports, @@ -2642,6 +2675,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const splitTransactionID4 = rand64(); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, // Use the search-page-merged view (live data plus any stale snapshot-only ghosts) exactly as // `SplitExpensePage` would pass it via `useAllTransactions()` when opened from Spend > Expenses. allTransactionsList: mergedTransactionsFromSearchPage, @@ -2688,6 +2722,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const unreportedIOUAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: amount / 2, currency: CONST.CURRENCY.USD, @@ -2719,6 +2754,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, betas: [CONST.BETAS.ALL], allReportsList: allReports, @@ -2805,6 +2841,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const workspaceChildIOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 5000, currency: 'USD', @@ -2816,6 +2853,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }; const selfDMChildIOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'USD', @@ -2867,6 +2905,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // leaving the workspace split as the sole remaining split — this triggers a reverse split that merges // the workspace split's data back into the original transaction. updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, @@ -2947,6 +2986,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const child1IOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'USD', @@ -2958,6 +2998,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }; const child2IOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'USD', @@ -3008,6 +3049,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // leaving the other as the sole remaining split — this triggers a reverse split that merges it back // into the original transaction. updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, @@ -3068,6 +3110,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const transactionThread: Report = {...createRandomReport(32, undefined)}; const iouAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: transaction.amount, currency: transaction.currency, @@ -3115,6 +3158,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // When the expense is split in half updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -3194,6 +3238,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const child1IOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'EUR', @@ -3205,6 +3250,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }; const child2IOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'EUR', @@ -3250,6 +3296,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // When one of the two splits is removed, reverting the split back into a single expense updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, @@ -3323,6 +3370,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const child1IOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'EUR', @@ -3334,6 +3382,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }; const child2IOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'EUR', @@ -3378,6 +3427,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // When the amounts of both splits are edited updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, @@ -3461,6 +3511,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const childIOUAction: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.TRACK, amount: 5000, currency: 'EUR', @@ -3501,6 +3552,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { await getOnyxData({key: ONYXKEYS.COLLECTION.SNAPSHOT, callback: (value) => (allSnapshots = value)}); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, @@ -3645,6 +3697,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, betas: [CONST.BETAS.ALL], @@ -3727,6 +3780,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { let reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, betas: [CONST.BETAS.ALL], allReportsList: allReports, @@ -3835,6 +3889,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, betas: [CONST.BETAS.ALL], allReportsList: allReports, @@ -4006,6 +4061,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // When the user reduces splits to 1 (triggering a reverse-split that will delete the expense report) updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -4140,6 +4196,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // When the user reduces splits to 1 (triggering a reverse-split, but the expense report still has another transaction) updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -4221,6 +4278,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }, }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -4325,6 +4383,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -4399,6 +4458,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }, }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -4503,6 +4563,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -4582,6 +4643,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -4695,6 +4757,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // it should use splitExpensesTotal in its calculation updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -4775,6 +4838,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // Create the initial expense requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -4909,6 +4973,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { // When splitting the held expense updateSplitTransactionsFromSplitExpensesFlow({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -5038,6 +5103,7 @@ describe('updateSplitTransactions', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -5094,6 +5160,7 @@ describe('updateSplitTransactions', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -5173,6 +5240,7 @@ describe('updateSplitTransactions', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -5230,6 +5298,7 @@ describe('updateSplitTransactions', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -5310,6 +5379,7 @@ describe('updateSplitTransactions', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -5364,6 +5434,7 @@ describe('updateSplitTransactions', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -5457,6 +5528,7 @@ describe('updateSplitTransactions', () => { }); requestMoney({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: chatReport, participantParams: { @@ -5543,6 +5615,7 @@ describe('updateSplitTransactions', () => { const reports = getTransactionAndExpenseReports(reportID); updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -5611,6 +5684,7 @@ describe('updateSplitTransactions', () => { const writeSpy = jest.spyOn(APIlib, 'write').mockImplementation((...args) => originalWrite(...args)); updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -5874,6 +5948,7 @@ describe('updateSplitTransactions', () => { const splitExpenses: SplitExpense[] = [{transactionID: splitTransactionID1, reportID: remainingSplitTransaction?.reportID, amount, created: DateUtils.getDBTime()}]; updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -5987,6 +6062,7 @@ describe('updateSplitTransactions', () => { const splitExpenses: SplitExpense[] = [{transactionID: splitTransactionID1, reportID: remainingSplitTransaction?.reportID, amount, created: DateUtils.getDBTime()}]; updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports2, allReportActionsList: undefined, @@ -6061,6 +6137,7 @@ describe('updateSplitTransactions', () => { const reports = getTransactionAndExpenseReports(expenseReport.reportID); updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -6131,6 +6208,7 @@ describe('updateSplitTransactions', () => { // The preview action lives in the chat report's actions, supplied via the new allReportActionsList param. updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: allReportActions, @@ -6206,6 +6284,7 @@ describe('updateSplitTransactions', () => { const emptyChatReportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.chatReportID}`]: {}}; updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: emptyChatReportActions, @@ -6275,6 +6354,7 @@ describe('updateSplitTransactions', () => { const splitExpensesTotal = splitAmount * 3; updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -6349,6 +6429,7 @@ describe('updateSplitTransactions', () => { // two prior revert cycles whose cleanup was skipped/incomplete while offline. const staleIOUAction1: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 20000, currency: 'USD', @@ -6360,6 +6441,7 @@ describe('updateSplitTransactions', () => { }; const staleIOUAction2: ReportAction = { ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 20000, currency: 'USD', @@ -6386,6 +6468,7 @@ describe('updateSplitTransactions', () => { // just the first stale action (matching `iouActions.at(0)` in SplitExpensePage.tsx) and the rest via // `extraIOUActions` (matching `iouActions.slice(1)`). updateSplitTransactions({ + getCurrencyDecimals: getCurrencyDecimalsLocal, allTransactionsList: allTransactions, allReportsList: allReports, allReportActionsList: undefined, @@ -8902,6 +8985,7 @@ describe('createDistanceRequest', () => { recentWaypoints: Awaited>> = [], ): Parameters[0] { return { + getCurrencyDecimals: getCurrencyDecimalsLocal, report, participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], currentUserLogin: RORY_EMAIL, @@ -9469,6 +9553,7 @@ describe('startSplitBill delegateAccountID forwarding', () => { const participantsPolicyTags = await getParticipantsPolicyTags(participants); const {splitTransactionID} = startSplitBill({ + getCurrencyDecimals: getCurrencyDecimalsLocal, participants, currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, diff --git a/tests/actions/IOUTest/TrackExpenseTest.ts b/tests/actions/IOUTest/TrackExpenseTest.ts index 3998416ec3cf..cad5927ec025 100644 --- a/tests/actions/IOUTest/TrackExpenseTest.ts +++ b/tests/actions/IOUTest/TrackExpenseTest.ts @@ -183,6 +183,7 @@ describe('actions/IOU/TrackExpense', () => { mockFetch?.pause?.(); trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -307,6 +308,7 @@ describe('actions/IOU/TrackExpense', () => { // When the user submits the transaction to the selfDM report trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -411,6 +413,7 @@ describe('actions/IOU/TrackExpense', () => { // When the user confirms the category for the tracked expense trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -515,6 +518,7 @@ describe('actions/IOU/TrackExpense', () => { // Create a tracked expense trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -562,6 +566,7 @@ describe('actions/IOU/TrackExpense', () => { // Share the tracked expense with an accountant trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -659,6 +664,7 @@ describe('actions/IOU/TrackExpense', () => { // Create a tracked expense trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -706,6 +712,7 @@ describe('actions/IOU/TrackExpense', () => { // Share the tracked expense with an accountant trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -806,6 +813,7 @@ describe('actions/IOU/TrackExpense', () => { const recentWaypoints = (await getOnyxValue(ONYXKEYS.NVP_RECENT_WAYPOINTS)) ?? []; trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -852,6 +860,7 @@ describe('actions/IOU/TrackExpense', () => { mockFetch?.pause?.(); trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -950,6 +959,7 @@ describe('actions/IOU/TrackExpense', () => { const recentWaypoints = (await getOnyxValue(ONYXKEYS.NVP_RECENT_WAYPOINTS)) ?? []; trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -997,6 +1007,7 @@ describe('actions/IOU/TrackExpense', () => { mockFetch?.pause?.(); trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -1115,6 +1126,7 @@ describe('actions/IOU/TrackExpense', () => { // Create the tracked expense first trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -1162,6 +1174,7 @@ describe('actions/IOU/TrackExpense', () => { // When sharing the tracked expense with the accountant, passing the explicit reportActionsList trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: ownPolicyExpenseChat, isDraftPolicy: false, @@ -1238,6 +1251,7 @@ describe('actions/IOU/TrackExpense', () => { transactionOverrides: Partial[0]['transactionParams']> = {}, ): Parameters[0] { return { + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report, isDraftPolicy: false, @@ -1494,6 +1508,7 @@ describe('actions/IOU/TrackExpense', () => { // When the expense is categorized and submitted to workspace trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -1589,6 +1604,7 @@ describe('actions/IOU/TrackExpense', () => { // When trackExpense is called on policy expense chat trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: policyExpenseChat, isDraftPolicy: false, @@ -1960,6 +1976,7 @@ describe('actions/IOU/TrackExpense', () => { // When getTrackExpenseInformation is called with isSelfTourViewed: true const result = getTrackExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, parentChatReport: selfDMReport, participantParams: { @@ -2008,6 +2025,7 @@ describe('actions/IOU/TrackExpense', () => { // When getTrackExpenseInformation is called with isSelfTourViewed: false const result = getTrackExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, parentChatReport: selfDMReport, participantParams: { @@ -2058,6 +2076,7 @@ describe('actions/IOU/TrackExpense', () => { // When getTrackExpenseInformation is called with isSelfTourViewed: true const resultWithTourViewed = getTrackExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, parentChatReport: policyExpenseChat, participantParams: { @@ -2096,6 +2115,7 @@ describe('actions/IOU/TrackExpense', () => { // When getTrackExpenseInformation is called with isSelfTourViewed: false const resultWithoutTourViewed = getTrackExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, parentChatReport: { ...policyExpenseChat, @@ -2167,6 +2187,7 @@ describe('actions/IOU/TrackExpense', () => { // When getTrackExpenseInformation is called with isDraftChatReport: true const result = getTrackExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, parentChatReport: draftSelfDMReport, participantParams: { @@ -2215,6 +2236,7 @@ describe('actions/IOU/TrackExpense', () => { // When getTrackExpenseInformation is called with isDraftChatReport: false const result = getTrackExpenseInformation({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, parentChatReport: liveSelfDMReport, participantParams: { @@ -2307,6 +2329,7 @@ describe('actions/IOU/TrackExpense', () => { // Create a tracked expense trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -2612,6 +2635,7 @@ describe('actions/IOU/TrackExpense', () => { const recentWaypoints = (await getOnyxValue(ONYXKEYS.NVP_RECENT_WAYPOINTS)) ?? []; trackExpense({ + getCurrencyDecimals: getCurrencyDecimalsLocal, conciergeChat: undefined, report: selfDMReport, isDraftPolicy: true, @@ -2812,6 +2836,7 @@ describe('actions/IOU/TrackExpense', () => { // Call should not throw when personalDetails is provided expect(() => { convertBulkTrackedExpensesToIOU({ + getCurrencyDecimals: getCurrencyDecimalsLocal, transactions: [transaction], iouReport, chatReport, @@ -2886,6 +2911,7 @@ describe('actions/IOU/TrackExpense', () => { // Even if no transactions are provided, it should not throw expect(() => { convertBulkTrackedExpensesToIOU({ + getCurrencyDecimals: getCurrencyDecimalsLocal, transactions: [], iouReport, chatReport, @@ -2930,6 +2956,7 @@ describe('actions/IOU/TrackExpense', () => { // Should not throw even with empty personalDetails expect(() => { convertBulkTrackedExpensesToIOU({ + getCurrencyDecimals: getCurrencyDecimalsLocal, transactions: [], iouReport, chatReport, @@ -2974,6 +3001,7 @@ describe('actions/IOU/TrackExpense', () => { // Should not throw even with undefined personalDetails expect(() => { convertBulkTrackedExpensesToIOU({ + getCurrencyDecimals: getCurrencyDecimalsLocal, transactions: [], iouReport, chatReport, diff --git a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts index f17982414351..b7eb17424b82 100644 --- a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts +++ b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts @@ -42,7 +42,7 @@ import createRandomPolicy, {createCategoryTaxExpenseRules} from '../../utils/col import {createRandomReport} from '../../utils/collections/reports'; import createRandomTransaction from '../../utils/collections/transaction'; import getOnyxValue from '../../utils/getOnyxValue'; -import {getGlobalFetchMock} from '../../utils/TestHelper'; +import {getCurrencyDecimalsLocal, getGlobalFetchMock} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; const topMostReportID = '23423423'; @@ -2463,6 +2463,7 @@ describe('actions/IOU/UpdateMoneyRequest', () => { participants: [{accountID: RORY_ACCOUNT_ID, login: RORY_EMAIL}], transactionID, isPersonalTrackingExpense: true, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); const transactionThread: Report = { ...createRandomReport(2, undefined), diff --git a/tests/actions/MergeTransactionTest.ts b/tests/actions/MergeTransactionTest.ts index 7f0c1183ec2e..adbdada939f9 100644 --- a/tests/actions/MergeTransactionTest.ts +++ b/tests/actions/MergeTransactionTest.ts @@ -31,6 +31,7 @@ import {createExpenseReport, createRandomReport} from '../utils/collections/repo import createRandomTransaction, {createRandomDistanceRequestTransaction} from '../utils/collections/transaction'; import getOnyxValue from '../utils/getOnyxValue'; import * as TestHelper from '../utils/TestHelper'; +import {getCurrencyDecimalsLocal} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; // Helper function to create mock violations @@ -205,6 +206,7 @@ function runCrossReportMergeToSourceReportRequest(fixtures: CrossReportMergeToSo selfDMReportActions: undefined, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); } @@ -322,6 +324,7 @@ describe('mergeTransactionRequest', () => { selfDMReport: undefined, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await mockFetch?.resume?.(); @@ -440,6 +443,7 @@ describe('mergeTransactionRequest', () => { selfDMReport: undefined, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await mockFetch?.resume?.(); @@ -543,6 +547,7 @@ describe('mergeTransactionRequest', () => { selfDMReport: undefined, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await mockFetch?.resume?.(); @@ -708,6 +713,7 @@ describe('mergeTransactionRequest', () => { selfDMReport: undefined, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -814,6 +820,7 @@ describe('mergeTransactionRequest', () => { selfDMReport: undefined, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await mockFetch?.resume?.(); @@ -1045,6 +1052,7 @@ describe('mergeTransactionRequest', () => { selfDMReport: undefined, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await mockFetch?.resume?.(); @@ -1247,6 +1255,7 @@ describe('mergeTransactionRequest', () => { selfDMReport: undefined, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1398,6 +1407,7 @@ describe('mergeTransactionRequest', () => { selfDMReport, selfDMReportActions: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index f3d468e9f88e..560bd5d90021 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -3574,6 +3574,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: targetPolicy, currentUserAccountID: 1, @@ -3609,6 +3610,7 @@ describe('actions/Report', () => { // When moving to another workspace Report.changeReportPolicy({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -3670,6 +3672,7 @@ describe('actions/Report', () => { // When moving to another workspace Report.changeReportPolicy({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport, policy: newPolicy, currentUserAccountID: 1, @@ -3741,6 +3744,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -3838,6 +3842,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -3923,6 +3928,7 @@ describe('actions/Report', () => { Report.changeReportPolicy({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: newPolicy, currentUserAccountID: 1, @@ -3976,6 +3982,7 @@ describe('actions/Report', () => { // When moving to another workspace Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4068,6 +4075,7 @@ describe('actions/Report', () => { // Call changeReportPolicyAndInviteSubmitter Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: newPolicy, currentUser: {accountID: 1}, @@ -4113,6 +4121,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4144,6 +4153,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: targetPolicy, currentUser: {accountID: 1}, @@ -4174,6 +4184,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4204,6 +4215,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4236,6 +4248,7 @@ describe('actions/Report', () => { // Do not set personal details for ownerAccountID so getLoginByAccountID returns empty Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: createRandomPolicy(Number(2)), currentUser: {accountID: 1}, @@ -4289,6 +4302,7 @@ describe('actions/Report', () => { Report.changeReportPolicyAndInviteSubmitter({ report: expenseReport, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy: targetPolicy, currentUser: {accountID: 1, email: 'current-user@expensifail.com'}, @@ -4737,6 +4751,7 @@ describe('actions/Report', () => { const policy = createRandomPolicy(Number(1)); Report.buildOptimisticChangePolicyData({ report, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy, currentUserAccountID: 1, @@ -4791,6 +4806,7 @@ describe('actions/Report', () => { const {optimisticData, successData, failureData} = Report.buildOptimisticChangePolicyData({ report, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy, currentUserAccountID: 1, @@ -4855,6 +4871,7 @@ describe('actions/Report', () => { const {optimisticData} = Report.buildOptimisticChangePolicyData({ report, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy, currentUserAccountID: 1, @@ -4903,6 +4920,7 @@ describe('actions/Report', () => { const {optimisticData} = Report.buildOptimisticChangePolicyData({ report, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy, currentUserAccountID: 1, @@ -4964,6 +4982,7 @@ describe('actions/Report', () => { const {optimisticData} = Report.buildOptimisticChangePolicyData({ report, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport: undefined, policy, currentUserAccountID: 1, @@ -5028,6 +5047,7 @@ describe('actions/Report', () => { const {optimisticData, failureData} = Report.buildOptimisticChangePolicyData({ report, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, parentReport, policy, currentUserAccountID: 1, @@ -9396,6 +9416,7 @@ describe('actions/Report', () => { it('sets delegateAccountID when delegateAccountIDParam is provided', () => { const result = ReportUtils.buildOptimisticIOUReportAction({ + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: CONST.CURRENCY.USD, @@ -9409,6 +9430,7 @@ describe('actions/Report', () => { it('does not set delegateAccountID when delegateAccountIDParam is undefined', () => { const result = ReportUtils.buildOptimisticIOUReportAction({ + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: CONST.CURRENCY.USD, @@ -9427,14 +9449,14 @@ describe('actions/Report', () => { it('sets delegateAccountID when delegateAccountIDParam is provided', () => { const chatReport = createMock({reportID: 'chat1'}); const iouReport = createMock({reportID: 'iou1', ownerAccountID: 1, managerID: 2}); - const result = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, '', null, undefined, undefined, DELEGATE_ACCOUNT_ID); + const result = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, TestHelper.getCurrencyDecimalsLocal, '', null, undefined, undefined, DELEGATE_ACCOUNT_ID); expect(result.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('does not set delegateAccountID when delegateAccountIDParam is undefined', () => { const chatReport = createMock({reportID: 'chat2'}); const iouReport = createMock({reportID: 'iou2', ownerAccountID: 1, managerID: 2}); - const result = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, '', null, undefined, undefined, undefined); + const result = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, TestHelper.getCurrencyDecimalsLocal, '', null, undefined, undefined, undefined); expect(result.delegateAccountID).toBeUndefined(); }); }); diff --git a/tests/actions/TransactionTest.ts b/tests/actions/TransactionTest.ts index 35493bb64177..661b1dae411b 100644 --- a/tests/actions/TransactionTest.ts +++ b/tests/actions/TransactionTest.ts @@ -254,6 +254,7 @@ describe('actions/Transaction', () => { currentUserLocalCurrency: undefined, delegateAccountID: undefined, reportActionsList: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await getOnyxData({ key: ONYXKEYS.COLLECTION.TRANSACTION, @@ -631,6 +632,7 @@ describe('actions/Transaction', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); await getOnyxData({ @@ -737,6 +739,7 @@ describe('actions/Transaction', () => { isOffline: false, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -809,6 +812,7 @@ describe('actions/Transaction', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); await getOnyxData({ @@ -915,6 +919,7 @@ describe('actions/Transaction', () => { isOffline: false, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -992,6 +997,7 @@ describe('actions/Transaction', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1107,6 +1113,7 @@ describe('actions/Transaction', () => { isOffline: false, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1185,6 +1192,7 @@ describe('actions/Transaction', () => { personalDetails: {}, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); @@ -1321,6 +1329,7 @@ describe('actions/Transaction', () => { isOffline: false, delegateAccountID: undefined, isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, }); await waitForBatchedUpdates(); diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 29636bfa10e3..6a26ab063086 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -611,6 +611,7 @@ describe('SidebarLinksData', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); const expenseReport = buildOptimisticExpenseReport({ chatReportID: chatReportR14932.reportID, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, policyID: '123', payeeAccountID: 100, total: 122, @@ -625,6 +626,7 @@ describe('SidebarLinksData', () => { }, }); const expenseCreatedAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index 3945e2342b48..9c992d40d3c1 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -788,6 +788,7 @@ describe('Unread Indicators', () => { const participant = {login: USER_A_EMAIL, accountID: USER_A_ACCOUNT_ID}; trackExpense({ conciergeChat: undefined, + getCurrencyDecimals: TestHelper.getCurrencyDecimalsLocal, report: selfDMReport, isDraftPolicy: true, action: CONST.IOU.ACTION.CREATE, diff --git a/tests/unit/GoogleTagManagerTest.tsx b/tests/unit/GoogleTagManagerTest.tsx index 0ce3a97a7aec..38d70c800e5d 100644 --- a/tests/unit/GoogleTagManagerTest.tsx +++ b/tests/unit/GoogleTagManagerTest.tsx @@ -18,6 +18,7 @@ import {NavigationContainer} from '@react-navigation/native'; import Onyx from 'react-native-onyx'; import getOnyxValue from '../utils/getOnyxValue'; +import {getCurrencyDecimalsLocal} from '../utils/TestHelper'; import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; jest.mock('@libs/GoogleTagManager'); @@ -267,6 +268,7 @@ describe('GoogleTagManagerTest', () => { trackExpense({ conciergeChat: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, report: {reportID: '123'}, isDraftPolicy: true, action: CONST.IOU.ACTION.CATEGORIZE, diff --git a/tests/unit/IOUAmountSubmissionTest.ts b/tests/unit/IOUAmountSubmissionTest.ts index 7cddfcf710da..880f0d513f95 100644 --- a/tests/unit/IOUAmountSubmissionTest.ts +++ b/tests/unit/IOUAmountSubmissionTest.ts @@ -12,7 +12,7 @@ import Onyx from 'react-native-onyx'; import createRandomPolicy from '../utils/collections/policies'; import {createRandomReport} from '../utils/collections/reports'; -import {translateLocal} from '../utils/TestHelper'; +import {getCurrencyDecimalsLocal, translateLocal} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; const CURRENT_USER_ACCOUNT_ID = 5; @@ -170,6 +170,7 @@ describe('AmountSubmission', () => { return { report: baseReport, translate: translateLocal, + getCurrencyDecimals: getCurrencyDecimalsLocal, transaction: undefined, splitDraftTransaction: undefined, policy: undefined, diff --git a/tests/unit/IOUUtilsTest.ts b/tests/unit/IOUUtilsTest.ts index a764d84e4c5b..21f48d8232fa 100644 --- a/tests/unit/IOUUtilsTest.ts +++ b/tests/unit/IOUUtilsTest.ts @@ -25,6 +25,7 @@ import createRandomPolicy from '../utils/collections/policies'; import {createRandomReport} from '../utils/collections/reports'; import createRandomTransaction from '../utils/collections/transaction'; import initCurrencyListContext from '../utils/initCurrencyListContext'; +import {getCurrencyDecimalsLocal} from '../utils/TestHelper'; const testDate = DateUtils.getDBTime(); const currentUserAccountID = 5; @@ -614,7 +615,7 @@ describe('canSubmitReport', () => { describe('Check valid amount for IOU/Expense request', () => { test('IOU amount should be positive', () => { - const iouReport = ReportUtils.buildOptimisticIOUReport(1, 2, 100, '1', 'USD'); + const iouReport = ReportUtils.buildOptimisticIOUReport(1, 2, 100, '1', 'USD', getCurrencyDecimalsLocal); const iouTransaction = TransactionUtils.buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -627,7 +628,15 @@ describe('Check valid amount for IOU/Expense request', () => { }); test('Expense amount should be negative', () => { - const expenseReport = ReportUtils.buildOptimisticExpenseReport({chatReportID: '212', policyID: '123', payeeAccountID: 100, total: 122, currency: 'USD', betas: [CONST.BETAS.ALL]}); + const expenseReport = ReportUtils.buildOptimisticExpenseReport({ + getCurrencyDecimals: getCurrencyDecimalsLocal, + chatReportID: '212', + policyID: '123', + payeeAccountID: 100, + total: 122, + currency: 'USD', + betas: [CONST.BETAS.ALL], + }); const expenseTransaction = TransactionUtils.buildOptimisticTransaction({ transactionParams: { amount: 100, diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 50f121ad024b..d371c05eedce 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -21,7 +21,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {format} from 'date-fns'; import Onyx from 'react-native-onyx'; -import {formatPhoneNumber, translateLocal} from '../utils/TestHelper'; +import {formatPhoneNumber, getCurrencyDecimalsLocal, translateLocal} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; Onyx.init({keys: ONYXKEYS}); @@ -52,6 +52,7 @@ describe('libs/NextStepUtils', () => { }; const report = buildOptimisticExpenseReport({ chatReportID: 'fake-chat-report-id-1', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID, payeeAccountID: 1, total: -500, @@ -849,6 +850,7 @@ describe('libs/NextStepUtils', () => { const report: Report = { ...buildOptimisticExpenseReport({ chatReportID: 'chat-1', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID, payeeAccountID: 1, total: -500, @@ -878,6 +880,7 @@ describe('libs/NextStepUtils', () => { const report: Report = { ...buildOptimisticExpenseReport({ chatReportID: 'chat-2', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID, payeeAccountID: 1, total: -500, @@ -949,6 +952,7 @@ describe('libs/NextStepUtils', () => { const report: Report = { ...buildOptimisticExpenseReport({ chatReportID: 'chat-3', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID, payeeAccountID: 1, total: -500, @@ -1002,6 +1006,7 @@ describe('libs/NextStepUtils', () => { const report: Report = { ...buildOptimisticExpenseReport({ chatReportID: 'chat-4', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID, payeeAccountID: 1, total: -500, @@ -1153,6 +1158,7 @@ describe('libs/NextStepUtils', () => { ({ ...buildOptimisticExpenseReport({ chatReportID: 'chat-track-intent', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID, payeeAccountID: currentUserAccountID, total: -500, diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index c61b639b3df5..1582eae3eaf4 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -15,6 +15,7 @@ import type PaymentMethod from '@src/types/onyx/PaymentMethod'; import createMockPaymentMethod from '../utils/collections/paymentMethods'; import createRandomPolicy from '../utils/collections/policies'; +import {getCurrencyDecimalsLocal} from '../utils/TestHelper'; jest.mock('@libs/Navigation/Navigation', () => ({ navigate: jest.fn(), @@ -135,6 +136,7 @@ describe('PaymentUtils', () => { const baseParams: SelectPaymentTypeParams = { event: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, iouPaymentType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, triggerKYCFlow: mockTriggerKYCFlow, expenseReportPolicy: testPolicy, @@ -241,6 +243,7 @@ describe('PaymentUtils', () => { selectPaymentType(params); expect(approveMoneyRequest).toHaveBeenCalledWith({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport: params.iouReport, expenseReportPolicy: params.expenseReportPolicy, currentUserAccountIDParam: params.currentAccountID, @@ -270,6 +273,7 @@ describe('PaymentUtils', () => { selectPaymentType(params); expect(approveMoneyRequest).toHaveBeenCalledWith({ + getCurrencyDecimals: getCurrencyDecimalsLocal, expenseReport: params.iouReport, expenseReportPolicy: params.expenseReportPolicy, currentUserAccountIDParam: params.currentAccountID, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 1d6952a2008c..779e6f91da5f 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -4801,6 +4801,7 @@ describe('ReportUtils', () => { it('should disable thread on split expense actions', () => { const reportAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.SPLIT, amount: 50000, currency: CONST.CURRENCY.USD, @@ -5162,6 +5163,7 @@ describe('ReportUtils', () => { const reportPreviewReportActionID = '8'; const expenseReport = buildOptimisticExpenseReport({ chatReportID: chatReport.reportID, + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID: '123', payeeAccountID: currentUserAccountID, total: 122, @@ -5176,8 +5178,17 @@ describe('ReportUtils', () => { reportID: expenseReport.reportID, }, }); - const reportPreview = buildOptimisticReportPreview(chatReport, expenseReport, '', expenseTransaction, expenseReport.reportID, reportPreviewReportActionID); + const reportPreview = buildOptimisticReportPreview( + chatReport, + expenseReport, + getCurrencyDecimalsLocal, + '', + expenseTransaction, + expenseReport.reportID, + reportPreviewReportActionID, + ); const expenseCreatedAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', @@ -5283,6 +5294,7 @@ describe('ReportUtils', () => { }, }); const expenseCreatedAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: 'USD', @@ -5319,6 +5331,7 @@ describe('ReportUtils', () => { }, }); const expenseCreatedAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: 'USD', @@ -5350,6 +5363,7 @@ describe('ReportUtils', () => { }, }); const expenseCreatedAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: 'USD', @@ -5427,6 +5441,7 @@ describe('ReportUtils', () => { policyID, }); const reportAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 123, currency: 'USD', @@ -5485,6 +5500,7 @@ describe('ReportUtils', () => { }); const reportAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 123, currency: 'USD', @@ -5532,6 +5548,7 @@ describe('ReportUtils', () => { }); const reportAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: 'USD', @@ -5547,6 +5564,7 @@ describe('ReportUtils', () => { it('should return undefined when no matching transaction exists', () => { const reportAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: 'USD', @@ -7225,7 +7243,15 @@ describe('ReportUtils', () => { }); it('should return true when the report has outstanding violations', async () => { - const expenseReport = buildOptimisticExpenseReport({chatReportID: '212', policyID: '123', payeeAccountID: 100, total: 122, currency: 'USD', betas: [CONST.BETAS.ALL]}); + const expenseReport = buildOptimisticExpenseReport({ + chatReportID: '212', + policyID: '123', + payeeAccountID: 100, + total: 122, + currency: 'USD', + betas: [CONST.BETAS.ALL], + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); const expenseTransaction = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -7234,6 +7260,7 @@ describe('ReportUtils', () => { }, }); const expenseCreatedAction1 = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', @@ -7244,6 +7271,7 @@ describe('ReportUtils', () => { iouReportID: expenseReport.reportID, }); const expenseCreatedAction2 = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', @@ -7551,7 +7579,15 @@ describe('ReportUtils', () => { }); it('should return false when the report is the single transaction thread', async () => { - const expenseReport = buildOptimisticExpenseReport({chatReportID: '212', policyID: '123', payeeAccountID: 100, total: 122, currency: 'USD', betas: [CONST.BETAS.ALL]}); + const expenseReport = buildOptimisticExpenseReport({ + chatReportID: '212', + policyID: '123', + payeeAccountID: 100, + total: 122, + currency: 'USD', + betas: [CONST.BETAS.ALL], + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); const expenseTransaction = buildOptimisticTransaction({ transactionParams: { amount: 100, @@ -7560,6 +7596,7 @@ describe('ReportUtils', () => { }, }); const expenseCreatedAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', @@ -8166,7 +8203,15 @@ describe('ReportUtils', () => { it('should not return HAS_IOU_VIOLATIONS for a settled (reimbursed) expense request with violations', async () => { const expenseReport: Report = { - ...buildOptimisticExpenseReport({chatReportID: '212', policyID: '123', payeeAccountID: 100, total: 122, currency: 'USD', betas: [CONST.BETAS.ALL]}), + ...buildOptimisticExpenseReport({ + chatReportID: '212', + policyID: '123', + payeeAccountID: 100, + total: 122, + currency: 'USD', + betas: [CONST.BETAS.ALL], + getCurrencyDecimals: getCurrencyDecimalsLocal, + }), statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, }; const expenseTransaction = buildOptimisticTransaction({ @@ -8177,6 +8222,7 @@ describe('ReportUtils', () => { }, }); const expenseCreatedAction1 = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', @@ -8186,6 +8232,7 @@ describe('ReportUtils', () => { iouReportID: expenseReport.reportID, }); const expenseCreatedAction2 = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', @@ -8547,6 +8594,7 @@ describe('ReportUtils', () => { describe('buildOptimisticIOUReportAction', () => { it('should set the action reportID to the provided iouReportID when tracking a personal expense', () => { const iouAction = buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'track', amount: 1200, currency: 'INR', @@ -12842,7 +12890,7 @@ describe('ReportUtils', () => { managerID: 2, }; - const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimalsLocal); expect(reportPreviewAction.childOwnerAccountID).toBe(iouReport.ownerAccountID); expect(reportPreviewAction.childManagerAccountID).toBe(iouReport.managerID); @@ -12864,10 +12912,11 @@ describe('ReportUtils', () => { managerID: 2, }; - const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimalsLocal); const updatedPreviewAction = updateReportPreview( iouReport, reportPreviewAction, + getCurrencyDecimalsLocal, false, '', createMock({ @@ -14569,7 +14618,15 @@ describe('ReportUtils', () => { const total = 100; const currency = CONST.CURRENCY.USD; - const expenseReport = buildOptimisticExpenseReport({chatReportID, policyID: undefined, payeeAccountID: 1, total, currency, betas: [CONST.BETAS.ALL]}); + const expenseReport = buildOptimisticExpenseReport({ + chatReportID, + policyID: undefined, + payeeAccountID: 1, + total, + currency, + betas: [CONST.BETAS.ALL], + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); expect(expenseReport.reportName).toBe(`${fakePolicy.name} owes ${convertToDisplayString(-total, currency)}`); }); @@ -14596,7 +14653,15 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${chatReportID}`, reportDraft); const total = 100; const currency = CONST.CURRENCY.USD; - const expenseReport = buildOptimisticExpenseReport({chatReportID, policyID, payeeAccountID: 1, total, currency, betas: [CONST.BETAS.ALL]}); + const expenseReport = buildOptimisticExpenseReport({ + chatReportID, + policyID, + payeeAccountID: 1, + total, + currency, + betas: [CONST.BETAS.ALL], + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); // Then the report name should be "New Report" instead of the default name expect(expenseReport.reportName).toBe(CONST.REPORT.DEFAULT_EXPENSE_REPORT_NAME); @@ -14625,7 +14690,15 @@ describe('ReportUtils', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${chatReportID}`, reportDraft); const total = 100; const currency = CONST.CURRENCY.USD; - const expenseReport = buildOptimisticExpenseReport({chatReportID, policyID, payeeAccountID: 1, total, currency, betas: [CONST.BETAS.ALL]}); + const expenseReport = buildOptimisticExpenseReport({ + chatReportID, + policyID, + payeeAccountID: 1, + total, + currency, + betas: [CONST.BETAS.ALL], + getCurrencyDecimals: getCurrencyDecimalsLocal, + }); // Then the report name should be the default expense report name expect(expenseReport.reportName).toBe(CONST.REPORT.DEFAULT_EXPENSE_REPORT_NAME); @@ -16019,7 +16092,15 @@ describe('ReportUtils', () => { const mockReceiverName = 'John Doe'; const mockTotal = 100; const mockCurrency = 'USD'; - const optimisticInvoiceReport = buildOptimisticInvoiceReport(mockChatReportID, mockPolicyID, mockReceiverAccountID, mockReceiverName, mockTotal, mockCurrency); + const optimisticInvoiceReport = buildOptimisticInvoiceReport( + mockChatReportID, + mockPolicyID, + mockReceiverAccountID, + mockReceiverName, + mockTotal, + mockCurrency, + getCurrencyDecimalsLocal, + ); expect(optimisticInvoiceReport.statusNum).toBe(CONST.REPORT.STATUS_NUM.SUBMITTED); expect(optimisticInvoiceReport.stateNum).toBe(CONST.REPORT.STATE_NUM.SUBMITTED); @@ -20200,13 +20281,13 @@ describe('ReportUtils', () => { describe('buildOptimisticApprovedReportAction', () => { it('should set actorAccountID to the provided currentUserAccountID', () => { const customAccountID = 99; - const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', customAccountID, undefined); + const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', customAccountID, undefined, getCurrencyDecimalsLocal); expect(action.actorAccountID).toBe(customAccountID); }); it('should set actionName to APPROVED', () => { - const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', currentUserAccountID, undefined); + const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', currentUserAccountID, undefined, getCurrencyDecimalsLocal); expect(action.actionName).toBe(CONST.REPORT.ACTIONS.TYPE.APPROVED); }); @@ -20215,19 +20296,19 @@ describe('ReportUtils', () => { const amount = 1200; const currency = 'EUR'; const expenseReportID = 'report42'; - const action = buildOptimisticApprovedReportAction(amount, currency, expenseReportID, currentUserAccountID, undefined); + const action = buildOptimisticApprovedReportAction(amount, currency, expenseReportID, currentUserAccountID, undefined, getCurrencyDecimalsLocal); expect(getOriginalMessage(action as ReportAction)).toMatchObject({amount, currency, expenseReportID}); }); it('should set pendingAction to ADD', () => { - const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', currentUserAccountID, undefined); + const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', currentUserAccountID, undefined, getCurrencyDecimalsLocal); expect(action.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); }); it('should generate a non-empty reportActionID', () => { - const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', currentUserAccountID, undefined); + const action = buildOptimisticApprovedReportAction(500, 'USD', 'expenseReport1', currentUserAccountID, undefined, getCurrencyDecimalsLocal); expect(action.reportActionID).toBeTruthy(); }); @@ -20544,7 +20625,7 @@ describe('ReportUtils', () => { }; // REPORT_PREVIEW action that sits in the chat report and links to the expense report - const reportPreviewAction = buildOptimisticReportPreview(chatReport, expenseReport, '', transaction); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, expenseReport, getCurrencyDecimalsLocal, '', transaction); beforeAll(async () => { await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID}); @@ -20758,6 +20839,7 @@ describe('ReportUtils', () => { const buildIOUAction = (overrides?: Partial) => createMock({ ...buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD', @@ -20773,6 +20855,7 @@ describe('ReportUtils', () => { const buildExpenseReport = () => buildOptimisticExpenseReport({ chatReportID, + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID: '123', payeeAccountID: actorAccountID, total: 100, @@ -20844,6 +20927,7 @@ describe('ReportUtils', () => { const chatReport: Report = {reportID: '8001'}; const expenseReport = buildOptimisticExpenseReport({ chatReportID: chatReport.reportID, + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID: '123', payeeAccountID: currentUserAccountID, total: 200, @@ -20853,6 +20937,7 @@ describe('ReportUtils', () => { const otherActorAccountID = 99; const [, , iouAction, transactionThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals: getCurrencyDecimalsLocal, iouReport: expenseReport, type: 'create', amount: 200, @@ -20879,6 +20964,7 @@ describe('ReportUtils', () => { const chatReport: Report = {reportID: '8002'}; const expenseReport = buildOptimisticExpenseReport({ chatReportID: chatReport.reportID, + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID: '123', payeeAccountID: currentUserAccountID, total: 50, @@ -20887,6 +20973,7 @@ describe('ReportUtils', () => { }); const [, , , transactionThread, createdActionForThread] = buildOptimisticMoneyRequestEntities({ + getCurrencyDecimals: getCurrencyDecimalsLocal, iouReport: expenseReport, type: 'create', amount: 50, @@ -21324,6 +21411,7 @@ describe('ReportUtils', () => { const buildExpenseReportForAutoReimbursement = () => buildOptimisticExpenseReport({ chatReportID: '1', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID: '1', payeeAccountID: 100, total: 100, @@ -21358,6 +21446,7 @@ describe('ReportUtils', () => { it('returns true when report is an expense report and policy type is a group type', () => { const expenseReport = buildOptimisticExpenseReport({ chatReportID: '1', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID: '1', payeeAccountID: 100, total: 100, @@ -21372,6 +21461,7 @@ describe('ReportUtils', () => { it('returns false when report is an expense report but policy type is not a group type', () => { const expenseReport = buildOptimisticExpenseReport({ chatReportID: '1', + getCurrencyDecimals: getCurrencyDecimalsLocal, policyID: '1', payeeAccountID: 100, total: 100, diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 100b5cb12afa..d3a276094dc3 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -48,7 +48,7 @@ import Onyx from 'react-native-onyx'; import createRandomPolicy from '../../utils/collections/policies'; import createMock from '../../utils/createMock'; import getOnyxValue from '../../utils/getOnyxValue'; -import {convertToDisplayString, formatPhoneNumber, localeCompare, translateLocal} from '../../utils/TestHelper'; +import {convertToDisplayString, formatPhoneNumber, getCurrencyDecimalsLocal, localeCompare, translateLocal} from '../../utils/TestHelper'; import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; jest.mock('@src/components/ConfirmedRoute.tsx'); @@ -11092,6 +11092,7 @@ describe('SearchUIUtils', () => { const baseParams = { item: transactionListItem, introSelected: introSelectedData, + getCurrencyDecimals: getCurrencyDecimalsLocal, backTo, currentUserLogin, currentUserAccountID, @@ -11203,7 +11204,7 @@ describe('SearchUIUtils', () => { it('Should create an optimistic parent report if the hasParentReport is false', async () => { const transactionListItem = getTransactionListItem(0); - setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasParentReport: false}); + setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasParentReport: false}, getCurrencyDecimalsLocal); await waitForBatchedUpdates(); @@ -11215,7 +11216,7 @@ describe('SearchUIUtils', () => { it('Should create an optimistic parent report action if the hasParentReportAction is false', async () => { const transactionListItem = getTransactionListItem(0); - setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasParentReportAction: false}); + setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasParentReportAction: false}, getCurrencyDecimalsLocal); await waitForBatchedUpdates(); @@ -11227,7 +11228,7 @@ describe('SearchUIUtils', () => { it('Should create an optimistic transaction if the hasTransaction is false', async () => { const transactionListItem = getTransactionListItem(0); - setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasTransaction: false}); + setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasTransaction: false}, getCurrencyDecimalsLocal); await waitForBatchedUpdates(); @@ -11238,7 +11239,7 @@ describe('SearchUIUtils', () => { it('Should create an optimistic transaction thread if the hasTransactionThreadReport is false', async () => { const transactionListItem = getTransactionListItem(0); - setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasTransactionThreadReport: false}, '456'); + setOptimisticDataForTransactionThreadPreview(transactionListItem, {...transactionPreviewData, hasTransactionThreadReport: false}, getCurrencyDecimalsLocal, '456'); await waitForBatchedUpdates(); diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index a33efe31aa1a..acadcdd80a16 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -14,6 +14,7 @@ import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import createRandomPolicy from '../../utils/collections/policies'; +import {getCurrencyDecimalsLocal} from '../../utils/TestHelper'; jest.mock('@src/components/ConfirmedRoute.tsx'); jest.mock('@libs/deferModalPresentationAfterPopoverDismiss', () => ({ @@ -340,6 +341,7 @@ describe('handleActionButtonPress', () => { const goToItem = jest.fn(() => {}); handleActionButtonPress({ conciergeChat: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, hash: searchHash, item: mockReportItemWithHold, goToItem, @@ -365,6 +367,7 @@ describe('handleActionButtonPress', () => { const onHoldMenuOpen = jest.fn(); handleActionButtonPress({ conciergeChat: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, hash: searchHash, item: mockReportItemWithHold, goToItem: jest.fn(), @@ -391,6 +394,7 @@ describe('handleActionButtonPress', () => { const goToItem = jest.fn(() => {}); handleActionButtonPress({ conciergeChat: undefined, + getCurrencyDecimals: getCurrencyDecimalsLocal, hash: searchHash, item: updatedMockReportItem, goToItem, diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index f22aa002f392..1d37c145cec3 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -926,7 +926,7 @@ describe('SidebarUtils', () => { participantAccountIDs: [actorAccountID], }, }; - const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, '', transaction); + const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimalsLocal, '', transaction); await act(async () => { await Onyx.set(ONYXKEYS.SESSION, {accountID: 55555}); diff --git a/tests/unit/TransactionPreviewUtils.test.ts b/tests/unit/TransactionPreviewUtils.test.ts index 52c6bf8fba94..b80f1d1f3fac 100644 --- a/tests/unit/TransactionPreviewUtils.test.ts +++ b/tests/unit/TransactionPreviewUtils.test.ts @@ -18,11 +18,11 @@ import type {ReportActions, Transaction} from '@src/types/onyx'; import Onyx from 'react-native-onyx'; import createRandomPolicy from '../utils/collections/policies'; -import {convertToDisplayString} from '../utils/TestHelper'; +import {convertToDisplayString, getCurrencyDecimalsLocal} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; const basicProps = { - iouReport: buildOptimisticIOUReport(123, 234, 1000, '1', 'USD'), + iouReport: buildOptimisticIOUReport(123, 234, 1000, '1', 'USD', getCurrencyDecimalsLocal), iouReportOwnerLogin: undefined, policy: undefined, transaction: buildOptimisticTransaction({ @@ -38,6 +38,7 @@ const basicProps = { }), translate: jest.fn().mockImplementation((key: string) => key), action: buildOptimisticIOUReportAction({ + getCurrencyDecimals: getCurrencyDecimalsLocal, type: 'create', amount: 100, currency: 'USD',