Browse Source

refactor: extract calculation into a function, recall on onSafeWithdrawalRateChange

pull/6034/head
Johnson Towoju 4 days ago
parent
commit
1b6b8f82f9
  1. 30
      apps/client/src/app/pages/portfolio/fire/fire-page.component.ts

30
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.user = user;
this.calculateWithdrawalRates(); this.calculateWithdrawalRates();
this.calculateProjectedWithdrawalRates();
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}); });
@ -221,19 +222,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit {
public onCalculationComplete(calculation: FireCalculation) { public onCalculationComplete(calculation: FireCalculation) {
this.fireCalculation = calculation; this.fireCalculation = calculation;
this.calculateProjectedWithdrawalRates();
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);
}
} }
public ngOnDestroy() { public ngOnDestroy() {
@ -250,4 +239,19 @@ export class GfFirePageComponent implements OnDestroy, OnInit {
this.withdrawalRatePerMonth = this.withdrawalRatePerYear.div(12); 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);
}
}
} }

Loading…
Cancel
Save