@@ -2,7 +2,7 @@ import {endOfDay, endOfMonth, endOfWeek, getDay, lastDayOfMonth, set, startOfMon
22import type { OnyxEntry } from 'react-native-onyx' ;
33import type { ValueOf } from 'type-fest' ;
44import CONST from '@src/CONST' ;
5- import type { PersonalDetails , Policy , PolicyReportField , Report , Transaction } from '@src/types/onyx' ;
5+ import type { CurrencyList , PersonalDetails , Policy , PolicyReportField , Report , Transaction } from '@src/types/onyx' ;
66import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
77import { convertToDisplayString , convertToDisplayStringWithoutCurrency , isValidCurrencyCode } from './CurrencyUtils' ;
88import { formatDate } from './FormulaDatetime' ;
@@ -31,6 +31,7 @@ type MinimalTransaction = Pick<Transaction, 'transactionID' | 'reportID' | 'crea
3131type FormulaContext = {
3232 report : Report ;
3333 policy : OnyxEntry < Policy > ;
34+ currencyList ?: CurrencyList ;
3435 transaction ?: Transaction ;
3536 submitterPersonalDetails ?: PersonalDetails ;
3637 managerPersonalDetails ?: PersonalDetails ;
@@ -370,12 +371,12 @@ function computeReportPart(part: FormulaPart, context: FormulaContext): string {
370371 case 'enddate' :
371372 return formatDate ( getNewestTransactionDate ( report . reportID , context ) , format ) ;
372373 case 'total' : {
373- const formattedAmount = formatAmount ( report . total , report . currency , format ) ;
374+ const formattedAmount = formatAmount ( report . total , report . currency , format , context . currencyList ) ;
374375 // Return empty string when conversion needed (formatAmount returns null for unavailable conversions)
375376 return formattedAmount ?? '' ;
376377 }
377378 case 'reimbursable' : {
378- const formattedAmount = formatAmount ( getMoneyRequestSpendBreakdown ( report ) . reimbursableSpend , report . currency , format ) ;
379+ const formattedAmount = formatAmount ( getMoneyRequestSpendBreakdown ( report ) . reimbursableSpend , report . currency , format , context . currencyList ) ;
379380 return formattedAmount ?? '' ;
380381 }
381382 case 'currency' :
@@ -559,7 +560,7 @@ function getSubstring(value: string, args: string[]): string {
559560 * Format an amount value
560561 * @returns The formatted amount string, or null if currency conversion is needed (unavailable on frontend)
561562 */
562- function formatAmount ( amount : number | undefined , currency : string | undefined , displayCurrency ?: string ) : string | null {
563+ function formatAmount ( amount : number | undefined , currency : string | undefined , displayCurrency ?: string , currencyList ?: CurrencyList ) : string | null {
563564 if ( amount === undefined ) {
564565 return '' ;
565566 }
@@ -570,11 +571,11 @@ function formatAmount(amount: number | undefined, currency: string | undefined,
570571 const trimmedDisplayCurrency = displayCurrency ?. trim ( ) . toUpperCase ( ) ;
571572 if ( trimmedDisplayCurrency ) {
572573 if ( trimmedDisplayCurrency === 'NOSYMBOL' ) {
573- return convertToDisplayStringWithoutCurrency ( absoluteAmount , currency ) ;
574+ return convertToDisplayStringWithoutCurrency ( absoluteAmount , currency , currencyList ) ;
574575 }
575576
576577 // Check if format is a valid currency code (e.g., USD, EUR, eur)
577- if ( ! isValidCurrencyCode ( trimmedDisplayCurrency ) ) {
578+ if ( ! isValidCurrencyCode ( trimmedDisplayCurrency , currencyList ) ) {
578579 return '' ;
579580 }
580581
@@ -585,14 +586,14 @@ function formatAmount(amount: number | undefined, currency: string | undefined,
585586 return null ;
586587 }
587588
588- return convertToDisplayString ( absoluteAmount , trimmedDisplayCurrency ) ;
589+ return convertToDisplayString ( absoluteAmount , trimmedDisplayCurrency , false , currencyList ) ;
589590 }
590591
591- if ( currency && isValidCurrencyCode ( currency ) ) {
592- return convertToDisplayString ( absoluteAmount , currency , true ) ;
592+ if ( currency && isValidCurrencyCode ( currency , currencyList ) ) {
593+ return convertToDisplayString ( absoluteAmount , currency , true , currencyList ) ;
593594 }
594595
595- return convertToDisplayStringWithoutCurrency ( absoluteAmount , currency ) ;
596+ return convertToDisplayStringWithoutCurrency ( absoluteAmount , currency , currencyList ) ;
596597 } catch ( error ) {
597598 Log . hmmm ( '[Formula] formatAmount failed' , { error, amount, currency, displayCurrency} ) ;
598599 return '' ;
0 commit comments