@ -270,6 +270,14 @@ export class ExchangeRateDataService {
if ( aFromCurrency === aToCurrency ) {
factor = 1 ;
} else {
const derivedCurrencyFactor = this . getDerivedCurrencyFactor (
aFromCurrency ,
aToCurrency
) ;
if ( derivedCurrencyFactor !== null ) {
factor = derivedCurrencyFactor ;
} else {
const dataSource =
this . dataProviderService . getDataSourceForExchangeRates ( ) ;
@ -323,6 +331,7 @@ export class ExchangeRateDataService {
marketPriceBaseCurrencyToCurrency ;
}
}
}
if ( isNumber ( factor ) && ! isNaN ( factor ) ) {
return factor * aValue ;
@ -357,7 +366,25 @@ export class ExchangeRateDataService {
for ( const date of dates ) {
factors [ format ( date , DATE_FORMAT ) ] = 1 ;
}
} else {
return factors ;
}
// Check if this is a conversion between a derived currency and its root currency
const derivedCurrencyFactor = this . getDerivedCurrencyFactor (
currencyFrom ,
currencyTo
) ;
if ( derivedCurrencyFactor !== null ) {
// Use the fixed mathematical factor for derived currencies
for ( const date of dates ) {
factors [ format ( date , DATE_FORMAT ) ] = derivedCurrencyFactor ;
}
return factors ;
}
// Continue with standard exchange rate logic
{
const dataSource =
this . dataProviderService . getDataSourceForExchangeRates ( ) ;
const symbol = ` ${ currencyFrom } ${ currencyTo } ` ;
@ -469,6 +496,35 @@ export class ExchangeRateDataService {
return factors ;
}
private getDerivedCurrencyFactor (
currencyFrom : string ,
currencyTo : string
) : number | null {
// Check if currencyFrom is a derived currency of currencyTo
const derivedFrom = DERIVED_CURRENCIES . find (
( { currency , rootCurrency } ) = >
currency === currencyFrom && rootCurrency === currencyTo
) ;
if ( derivedFrom ) {
// e.g., GBp → GBP: factor = 1/100 = 0.01
return 1 / derivedFrom . factor ;
}
// Check if currencyTo is a derived currency of currencyFrom
const derivedTo = DERIVED_CURRENCIES . find (
( { currency , rootCurrency } ) = >
currency === currencyTo && rootCurrency === currencyFrom
) ;
if ( derivedTo ) {
// e.g., GBP → GBp: factor = 100
return derivedTo . factor ;
}
return null ;
}
private async prepareCurrencies ( ) : Promise < string [ ] > {
let currencies : string [ ] = [ DEFAULT_CURRENCY ] ;