From c17399867790cd2b978a788010560b8ce8f993b3 Mon Sep 17 00:00:00 2001 From: Flavien Lankai-Mills Date: Thu, 2 Oct 2025 17:42:27 +0200 Subject: [PATCH] Task/refactor fire wealth from number to object in portfolio summary interface (#5644) * Refactor fire wealth from number to object in portfolio summary interface * Update changelog --- CHANGELOG.md | 1 + .../src/app/portfolio/portfolio.controller.ts | 1 - .../src/app/portfolio/portfolio.service.ts | 10 ++++--- .../portfolio/fire/fire-page.component.ts | 27 ++++++++++++------- .../app/pages/portfolio/fire/fire-page.html | 4 +-- .../lib/interfaces/fire-wealth.interface.ts | 3 +++ libs/common/src/lib/interfaces/index.ts | 2 ++ .../interfaces/portfolio-summary.interface.ts | 3 ++- 8 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 libs/common/src/lib/interfaces/fire-wealth.interface.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 0af604cac..7d5425fc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Improved the usability of the _Cancel_ / _Close_ buttons in the create watchlist item dialog +- Refactored the `fireWealth` from `number` type to a structured object in the summary of the portfolio details endpoint - Refactored the symbol pipe to standalone ### Fixed diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index d703cf604..5659818a8 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -195,7 +195,6 @@ export class PortfolioController { 'excludedAccountsAndActivities', 'fees', 'filteredValueInBaseCurrency', - 'fireWealth', 'grossPerformance', 'grossPerformanceWithCurrencyEffect', 'interest', diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index f5b4ab1c6..e73f79784 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -2092,9 +2092,13 @@ export class PortfolioService { filteredValueInPercentage: netWorth ? filteredValueInBaseCurrency.div(netWorth).toNumber() : undefined, - fireWealth: new Big(currentValueInBaseCurrency) - .minus(emergencyFundHoldingsValueInBaseCurrency) - .toNumber(), + fireWealth: { + today: { + valueInBaseCurrency: new Big(currentValueInBaseCurrency) + .minus(emergencyFundHoldingsValueInBaseCurrency) + .toNumber() + } + }, grossPerformance: new Big(netPerformance).plus(fees).toNumber(), grossPerformanceWithCurrencyEffect: new Big( netPerformanceWithCurrencyEffect diff --git a/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts b/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts index ab0fbc787..c80b55c45 100644 --- a/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts +++ b/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts @@ -1,7 +1,7 @@ import { DataService } from '@ghostfolio/client/services/data.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; -import { User } from '@ghostfolio/common/interfaces'; +import { FireWealth, User } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { GfFireCalculatorComponent } from '@ghostfolio/ui/fire-calculator'; import { GfPremiumIndicatorComponent } from '@ghostfolio/ui/premium-indicator'; @@ -29,7 +29,7 @@ import { takeUntil } from 'rxjs/operators'; }) export class GfFirePageComponent implements OnDestroy, OnInit { public deviceType: string; - public fireWealth: Big; + public fireWealth: FireWealth; public hasImpersonationId: boolean; public hasPermissionToUpdateUserSettings: boolean; public isLoading = false; @@ -55,17 +55,24 @@ export class GfFirePageComponent implements OnDestroy, OnInit { .fetchPortfolioDetails() .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(({ summary }) => { - this.fireWealth = summary.fireWealth - ? new Big(summary.fireWealth) - : new Big(0); - + this.fireWealth = { + today: { + valueInBaseCurrency: summary.fireWealth + ? summary.fireWealth.today.valueInBaseCurrency + : 0 + } + }; if (this.user.subscription?.type === 'Basic') { - this.fireWealth = new Big(10000); + this.fireWealth = { + today: { + valueInBaseCurrency: 10000 + } + }; } - this.withdrawalRatePerYear = this.fireWealth.mul( - this.user.settings.safeWithdrawalRate - ); + this.withdrawalRatePerYear = Big( + this.fireWealth.today.valueInBaseCurrency + ).mul(this.user.settings.safeWithdrawalRate); this.withdrawalRatePerMonth = this.withdrawalRatePerYear.div(12); diff --git a/apps/client/src/app/pages/portfolio/fire/fire-page.html b/apps/client/src/app/pages/portfolio/fire/fire-page.html index df81991c3..d6548f761 100644 --- a/apps/client/src/app/pages/portfolio/fire/fire-page.html +++ b/apps/client/src/app/pages/portfolio/fire/fire-page.html @@ -14,7 +14,7 @@ [colorScheme]="user?.settings?.colorScheme" [currency]="user?.settings?.baseCurrency" [deviceType]="deviceType" - [fireWealth]="fireWealth?.toNumber()" + [fireWealth]="fireWealth?.today.valueInBaseCurrency" [hasPermissionToUpdateUserSettings]=" !hasImpersonationId && hasPermissionToUpdateUserSettings " @@ -100,7 +100,7 @@ [isCurrency]="true" [locale]="user?.settings?.locale" [unit]="user?.settings?.baseCurrency" - [value]="fireWealth?.toNumber()" + [value]="fireWealth?.today.valueInBaseCurrency" />   diff --git a/libs/common/src/lib/interfaces/fire-wealth.interface.ts b/libs/common/src/lib/interfaces/fire-wealth.interface.ts new file mode 100644 index 000000000..42fbeabd4 --- /dev/null +++ b/libs/common/src/lib/interfaces/fire-wealth.interface.ts @@ -0,0 +1,3 @@ +export interface FireWealth { + today: { valueInBaseCurrency: number }; +} diff --git a/libs/common/src/lib/interfaces/index.ts b/libs/common/src/lib/interfaces/index.ts index 6529fa3ef..1da2236e8 100644 --- a/libs/common/src/lib/interfaces/index.ts +++ b/libs/common/src/lib/interfaces/index.ts @@ -19,6 +19,7 @@ import type { EnhancedSymbolProfile } from './enhanced-symbol-profile.interface' import type { Export } from './export.interface'; import type { FilterGroup } from './filter-group.interface'; import type { Filter } from './filter.interface'; +import type { FireWealth } from './fire-wealth.interface'; import type { HistoricalDataItem } from './historical-data-item.interface'; import type { HoldingWithParents } from './holding-with-parents.interface'; import type { Holding } from './holding.interface'; @@ -104,6 +105,7 @@ export { Export, Filter, FilterGroup, + FireWealth, HistoricalDataItem, HistoricalResponse, Holding, diff --git a/libs/common/src/lib/interfaces/portfolio-summary.interface.ts b/libs/common/src/lib/interfaces/portfolio-summary.interface.ts index 419915a79..05fac0ba0 100644 --- a/libs/common/src/lib/interfaces/portfolio-summary.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-summary.interface.ts @@ -1,3 +1,4 @@ +import { FireWealth } from './fire-wealth.interface'; import { PortfolioPerformance } from './portfolio-performance.interface'; export interface PortfolioSummary extends PortfolioPerformance { @@ -16,7 +17,7 @@ export interface PortfolioSummary extends PortfolioPerformance { fees: number; filteredValueInBaseCurrency?: number; filteredValueInPercentage?: number; - fireWealth: number; + fireWealth: FireWealth; grossPerformance: number; grossPerformanceWithCurrencyEffect: number; interest: number;