|
|
@ -88,7 +88,7 @@ export class ExchangeRateDataService { |
|
|
); |
|
|
); |
|
|
const lastDateString = dateStrings.reduce((a, b) => { |
|
|
const lastDateString = dateStrings.reduce((a, b) => { |
|
|
return a > b ? a : b; |
|
|
return a > b ? a : b; |
|
|
}, undefined); |
|
|
}, ''); |
|
|
|
|
|
|
|
|
let previousExchangeRate = |
|
|
let previousExchangeRate = |
|
|
exchangeRatesByCurrency[`${currency}${targetCurrency}`]?.[ |
|
|
exchangeRatesByCurrency[`${currency}${targetCurrency}`]?.[ |
|
|
@ -214,7 +214,7 @@ export class ExchangeRateDataService { |
|
|
const resultExtended = result; |
|
|
const resultExtended = result; |
|
|
|
|
|
|
|
|
for (const symbol of Object.keys(result)) { |
|
|
for (const symbol of Object.keys(result)) { |
|
|
const [currency1, currency2] = symbol.match(/.{1,3}/g); |
|
|
const [currency1, currency2] = symbol.match(/.{1,3}/g) ?? []; |
|
|
const [date] = Object.keys(result[symbol]); |
|
|
const [date] = Object.keys(result[symbol]); |
|
|
|
|
|
|
|
|
// Calculate the opposite direction
|
|
|
// Calculate the opposite direction
|
|
|
@ -226,7 +226,7 @@ export class ExchangeRateDataService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (const symbol of Object.keys(resultExtended)) { |
|
|
for (const symbol of Object.keys(resultExtended)) { |
|
|
const [currency1, currency2] = symbol.match(/.{1,3}/g); |
|
|
const [currency1, currency2] = symbol.match(/.{1,3}/g) ?? []; |
|
|
|
|
|
|
|
|
this.exchangeRates[symbol] = |
|
|
this.exchangeRates[symbol] = |
|
|
resultExtended[symbol]?.[dateStringOfYesterday]?.marketPrice; |
|
|
resultExtended[symbol]?.[dateStringOfYesterday]?.marketPrice; |
|
|
@ -302,7 +302,7 @@ export class ExchangeRateDataService { |
|
|
|
|
|
|
|
|
const derivedCurrencyFactor = |
|
|
const derivedCurrencyFactor = |
|
|
this.derivedCurrencyFactors[`${aFromCurrency}${aToCurrency}`]; |
|
|
this.derivedCurrencyFactors[`${aFromCurrency}${aToCurrency}`]; |
|
|
let factor: number; |
|
|
let factor: number | undefined; |
|
|
|
|
|
|
|
|
if (aFromCurrency === aToCurrency) { |
|
|
if (aFromCurrency === aToCurrency) { |
|
|
factor = 1; |
|
|
factor = 1; |
|
|
@ -324,8 +324,8 @@ export class ExchangeRateDataService { |
|
|
} else { |
|
|
} else { |
|
|
// Calculate indirectly via base currency
|
|
|
// Calculate indirectly via base currency
|
|
|
|
|
|
|
|
|
let marketPriceBaseCurrencyFromCurrency: number; |
|
|
let marketPriceBaseCurrencyFromCurrency: number | undefined; |
|
|
let marketPriceBaseCurrencyToCurrency: number; |
|
|
let marketPriceBaseCurrencyToCurrency: number | undefined; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
if (aFromCurrency === DEFAULT_CURRENCY) { |
|
|
if (aFromCurrency === DEFAULT_CURRENCY) { |
|
|
@ -337,7 +337,7 @@ export class ExchangeRateDataService { |
|
|
date: aDate, |
|
|
date: aDate, |
|
|
symbol: `${DEFAULT_CURRENCY}${aFromCurrency}` |
|
|
symbol: `${DEFAULT_CURRENCY}${aFromCurrency}` |
|
|
}) |
|
|
}) |
|
|
)?.marketPrice as number; |
|
|
)?.marketPrice; |
|
|
} |
|
|
} |
|
|
} catch {} |
|
|
} catch {} |
|
|
|
|
|
|
|
|
@ -351,14 +351,19 @@ export class ExchangeRateDataService { |
|
|
date: aDate, |
|
|
date: aDate, |
|
|
symbol: `${DEFAULT_CURRENCY}${aToCurrency}` |
|
|
symbol: `${DEFAULT_CURRENCY}${aToCurrency}` |
|
|
}) |
|
|
}) |
|
|
)?.marketPrice as number; |
|
|
)?.marketPrice; |
|
|
} |
|
|
} |
|
|
} catch {} |
|
|
} catch {} |
|
|
|
|
|
|
|
|
// Calculate the opposite direction
|
|
|
if ( |
|
|
factor = |
|
|
isNumber(marketPriceBaseCurrencyFromCurrency) && |
|
|
(1 / marketPriceBaseCurrencyFromCurrency) * |
|
|
isNumber(marketPriceBaseCurrencyToCurrency) |
|
|
marketPriceBaseCurrencyToCurrency; |
|
|
) { |
|
|
|
|
|
// Calculate the opposite direction
|
|
|
|
|
|
factor = |
|
|
|
|
|
(1 / marketPriceBaseCurrencyFromCurrency) * |
|
|
|
|
|
marketPriceBaseCurrencyToCurrency; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -530,7 +535,9 @@ export class ExchangeRateDataService { |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
).forEach(({ currency }) => { |
|
|
).forEach(({ currency }) => { |
|
|
currencies.push(currency); |
|
|
if (currency) { |
|
|
|
|
|
currencies.push(currency); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
( |
|
|
( |
|
|
|