Browse Source

fix(portfolio): tolerate unconvertible fees in the calculator

`toCurrencyAtDate()` resolves to undefined when no exchange rate exists for an
activity's date, so `feeInAssetProfileCurrency` and `feeInBaseCurrency` can
reach the calculator unset. Passing those straight into `new Big()` threw
"[big.js] Invalid number" and failed the whole portfolio request, so the
Overview, Portfolio and Holdings pages rendered "Oops! Something went wrong".

Fees are only ever accumulated, so 0 is the identity here and the snapshot
stays computable while the exchange rate data is still being gathered.

Refs ghostfolio/ghostfolio#6482
pull/7384/head
Arham Amin 4 weeks ago
parent
commit
d83578e223
  1. 9
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

9
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -145,8 +145,13 @@ export abstract class PortfolioCalculator {
tags, tags,
type, type,
date: format(date, DATE_FORMAT), date: format(date, DATE_FORMAT),
fee: new Big(feeInAssetProfileCurrency), // Fees are converted via the exchange rate data service, which
feeInBaseCurrency: new Big(feeInBaseCurrency), // yields undefined when no rate is available for the activity’s
// date. Fees are only ever accumulated, so falling back to 0 keeps
// the portfolio computable instead of failing the whole request
// with “[big.js] Invalid number”.
fee: new Big(feeInAssetProfileCurrency ?? 0),
feeInBaseCurrency: new Big(feeInBaseCurrency ?? 0),
quantity: new Big(quantity), quantity: new Big(quantity),
unitPrice: new Big(unitPriceInAssetProfileCurrency) unitPrice: new Big(unitPriceInAssetProfileCurrency)
}; };

Loading…
Cancel
Save