From 1b6b8f82f94ac5ad240319012e4382e29c1fa0c8 Mon Sep 17 00:00:00 2001 From: Johnson Towoju Date: Thu, 4 Dec 2025 23:33:06 +0100 Subject: [PATCH] refactor: extract calculation into a function, recall on onSafeWithdrawalRateChange --- .../portfolio/fire/fire-page.component.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) 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 ec038139b..61ee39027 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 @@ -178,6 +178,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit { this.user = user; this.calculateWithdrawalRates(); + this.calculateProjectedWithdrawalRates(); this.changeDetectorRef.markForCheck(); }); @@ -221,19 +222,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit { public onCalculationComplete(calculation: FireCalculation) { this.fireCalculation = calculation; - - if ( - this.fireWealth && - this.user?.settings?.safeWithdrawalRate && - calculation.projectedTotalAmount - ) { - this.projectedWithdrawalRatePerYear = new Big( - calculation.projectedTotalAmount - ).mul(this.user.settings.safeWithdrawalRate); - - this.projectedWithdrawalRatePerMonth = - this.projectedWithdrawalRatePerYear.div(12); - } + this.calculateProjectedWithdrawalRates(); } public ngOnDestroy() { @@ -250,4 +239,19 @@ export class GfFirePageComponent implements OnDestroy, OnInit { this.withdrawalRatePerMonth = this.withdrawalRatePerYear.div(12); } } + + private calculateProjectedWithdrawalRates() { + if ( + this.fireWealth && + this.user?.settings?.safeWithdrawalRate && + this.fireCalculation.projectedTotalAmount + ) { + this.projectedWithdrawalRatePerYear = new Big( + this.fireCalculation.projectedTotalAmount + ).mul(this.user.settings.safeWithdrawalRate); + + this.projectedWithdrawalRatePerMonth = + this.projectedWithdrawalRatePerYear.div(12); + } + } }