Browse Source

feat(client): enforce encapsulation

pull/6807/head
KenTandrian 4 weeks ago
parent
commit
d63e796856
  1. 89
      apps/client/src/app/pages/portfolio/fire/fire-page.component.ts

89
apps/client/src/app/pages/portfolio/fire/fire-page.component.ts

@ -42,24 +42,25 @@ import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
templateUrl: './fire-page.html' templateUrl: './fire-page.html'
}) })
export class GfFirePageComponent implements OnInit { export class GfFirePageComponent implements OnInit {
public deviceType: string; protected deviceType: string;
public fireWealth: FireWealth; protected fireWealth: FireWealth;
public hasImpersonationId: boolean; protected hasImpersonationId: boolean;
public hasPermissionToUpdateUserSettings: boolean; protected hasPermissionToUpdateUserSettings: boolean;
public isLoading = false; protected isLoading = false;
public projectedTotalAmount: number; protected retirementDate: Date;
public retirementDate: Date; protected readonly safeWithdrawalRateControl = new FormControl<
public readonly safeWithdrawalRateControl = new FormControl<
number | undefined number | undefined
>(undefined); >(undefined);
public readonly safeWithdrawalRateOptions = [ protected readonly safeWithdrawalRateOptions = [
0.025, 0.03, 0.035, 0.04, 0.045 0.025, 0.03, 0.035, 0.04, 0.045
] as const; ] as const;
public user: User; protected user: User;
public withdrawalRatePerMonth: Big; protected withdrawalRatePerMonth: Big;
public withdrawalRatePerMonthProjected: Big; protected withdrawalRatePerMonthProjected: Big;
public withdrawalRatePerYear: Big; protected withdrawalRatePerYear: Big;
public withdrawalRatePerYearProjected: Big; protected withdrawalRatePerYearProjected: Big;
private projectedTotalAmount: number;
public constructor( public constructor(
private readonly changeDetectorRef: ChangeDetectorRef, private readonly changeDetectorRef: ChangeDetectorRef,
@ -137,7 +138,7 @@ export class GfFirePageComponent implements OnInit {
}); });
} }
public onAnnualInterestRateChange(annualInterestRate: number) { protected onAnnualInterestRateChange(annualInterestRate: number) {
this.dataService this.dataService
.putUserSetting({ annualInterestRate }) .putUserSetting({ annualInterestRate })
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
@ -153,7 +154,7 @@ export class GfFirePageComponent implements OnInit {
}); });
} }
public onCalculationComplete({ protected onCalculationComplete({
projectedTotalAmount, projectedTotalAmount,
retirementDate retirementDate
}: FireCalculationCompleteEvent) { }: FireCalculationCompleteEvent) {
@ -165,11 +166,11 @@ export class GfFirePageComponent implements OnInit {
this.isLoading = false; this.isLoading = false;
} }
public onRetirementDateChange(retirementDate: Date) { protected onProjectedTotalAmountChange(projectedTotalAmount: number) {
this.dataService this.dataService
.putUserSetting({ .putUserSetting({
retirementDate: retirementDate.toISOString(), projectedTotalAmount,
projectedTotalAmount: undefined retirementDate: undefined
}) })
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => { .subscribe(() => {
@ -184,9 +185,12 @@ export class GfFirePageComponent implements OnInit {
}); });
} }
public onSafeWithdrawalRateChange(safeWithdrawalRate: number) { protected onRetirementDateChange(retirementDate: Date) {
this.dataService this.dataService
.putUserSetting({ safeWithdrawalRate }) .putUserSetting({
retirementDate: retirementDate.toISOString(),
projectedTotalAmount: undefined
})
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => { .subscribe(() => {
this.userService this.userService
@ -195,15 +199,12 @@ export class GfFirePageComponent implements OnInit {
.subscribe((user) => { .subscribe((user) => {
this.user = user; this.user = user;
this.calculateWithdrawalRates();
this.calculateWithdrawalRatesProjected();
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}); });
}); });
} }
public onSavingsRateChange(savingsRate: number) { protected onSavingsRateChange(savingsRate: number) {
this.dataService this.dataService
.putUserSetting({ savingsRate }) .putUserSetting({ savingsRate })
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
@ -219,25 +220,6 @@ export class GfFirePageComponent implements OnInit {
}); });
} }
public onProjectedTotalAmountChange(projectedTotalAmount: number) {
this.dataService
.putUserSetting({
projectedTotalAmount,
retirementDate: undefined
})
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.userService
.get(true)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((user) => {
this.user = user;
this.changeDetectorRef.markForCheck();
});
});
}
private calculateWithdrawalRates() { private calculateWithdrawalRates() {
if (this.fireWealth && this.user?.settings?.safeWithdrawalRate) { if (this.fireWealth && this.user?.settings?.safeWithdrawalRate) {
this.withdrawalRatePerYear = new Big( this.withdrawalRatePerYear = new Big(
@ -262,4 +244,23 @@ export class GfFirePageComponent implements OnInit {
this.withdrawalRatePerYearProjected.div(12); this.withdrawalRatePerYearProjected.div(12);
} }
} }
private onSafeWithdrawalRateChange(safeWithdrawalRate: number) {
this.dataService
.putUserSetting({ safeWithdrawalRate })
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.userService
.get(true)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((user) => {
this.user = user;
this.calculateWithdrawalRates();
this.calculateWithdrawalRatesProjected();
this.changeDetectorRef.markForCheck();
});
});
}
} }

Loading…
Cancel
Save