|
|
@ -12,14 +12,18 @@ import { DataService } from '@ghostfolio/ui/services'; |
|
|
import { GfValueComponent } from '@ghostfolio/ui/value'; |
|
|
import { GfValueComponent } from '@ghostfolio/ui/value'; |
|
|
|
|
|
|
|
|
import { CommonModule, NgStyle } from '@angular/common'; |
|
|
import { CommonModule, NgStyle } from '@angular/common'; |
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
import { |
|
|
|
|
|
ChangeDetectorRef, |
|
|
|
|
|
Component, |
|
|
|
|
|
DestroyRef, |
|
|
|
|
|
OnInit |
|
|
|
|
|
} from '@angular/core'; |
|
|
|
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
|
|
import { FormControl } from '@angular/forms'; |
|
|
import { FormControl } from '@angular/forms'; |
|
|
import { Big } from 'big.js'; |
|
|
import { Big } from 'big.js'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|
|
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|
|
import { Subject } from 'rxjs'; |
|
|
|
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
imports: [ |
|
|
imports: [ |
|
|
@ -36,7 +40,7 @@ import { takeUntil } from 'rxjs/operators'; |
|
|
styleUrls: ['./fire-page.scss'], |
|
|
styleUrls: ['./fire-page.scss'], |
|
|
templateUrl: './fire-page.html' |
|
|
templateUrl: './fire-page.html' |
|
|
}) |
|
|
}) |
|
|
export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
export class GfFirePageComponent implements OnInit { |
|
|
public deviceType: string; |
|
|
public deviceType: string; |
|
|
public fireWealth: FireWealth; |
|
|
public fireWealth: FireWealth; |
|
|
public hasImpersonationId: boolean; |
|
|
public hasImpersonationId: boolean; |
|
|
@ -52,11 +56,10 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
public withdrawalRatePerYear: Big; |
|
|
public withdrawalRatePerYear: Big; |
|
|
public withdrawalRatePerYearProjected: Big; |
|
|
public withdrawalRatePerYearProjected: Big; |
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
|
|
|
|
|
|
|
|
|
public constructor( |
|
|
public constructor( |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
private dataService: DataService, |
|
|
private dataService: DataService, |
|
|
|
|
|
private destroyRef: DestroyRef, |
|
|
private deviceService: DeviceDetectorService, |
|
|
private deviceService: DeviceDetectorService, |
|
|
private impersonationStorageService: ImpersonationStorageService, |
|
|
private impersonationStorageService: ImpersonationStorageService, |
|
|
private userService: UserService |
|
|
private userService: UserService |
|
|
@ -68,7 +71,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
this.dataService |
|
|
this.dataService |
|
|
.fetchPortfolioDetails() |
|
|
.fetchPortfolioDetails() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(({ summary }) => { |
|
|
.subscribe(({ summary }) => { |
|
|
this.fireWealth = { |
|
|
this.fireWealth = { |
|
|
today: { |
|
|
today: { |
|
|
@ -92,19 +95,19 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
this.impersonationStorageService |
|
|
this.impersonationStorageService |
|
|
.onChangeHasImpersonation() |
|
|
.onChangeHasImpersonation() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((impersonationId) => { |
|
|
.subscribe((impersonationId) => { |
|
|
this.hasImpersonationId = !!impersonationId; |
|
|
this.hasImpersonationId = !!impersonationId; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.safeWithdrawalRateControl.valueChanges |
|
|
this.safeWithdrawalRateControl.valueChanges |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((value) => { |
|
|
.subscribe((value) => { |
|
|
this.onSafeWithdrawalRateChange(Number(value)); |
|
|
this.onSafeWithdrawalRateChange(Number(value)); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.userService.stateChanged |
|
|
this.userService.stateChanged |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((state) => { |
|
|
.subscribe((state) => { |
|
|
if (state?.user) { |
|
|
if (state?.user) { |
|
|
this.user = state.user; |
|
|
this.user = state.user; |
|
|
@ -132,11 +135,11 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
public onAnnualInterestRateChange(annualInterestRate: number) { |
|
|
public onAnnualInterestRateChange(annualInterestRate: number) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.putUserSetting({ annualInterestRate }) |
|
|
.putUserSetting({ annualInterestRate }) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((user) => { |
|
|
.subscribe((user) => { |
|
|
this.user = user; |
|
|
this.user = user; |
|
|
|
|
|
|
|
|
@ -163,11 +166,11 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
retirementDate: retirementDate.toISOString(), |
|
|
retirementDate: retirementDate.toISOString(), |
|
|
projectedTotalAmount: null |
|
|
projectedTotalAmount: null |
|
|
}) |
|
|
}) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((user) => { |
|
|
.subscribe((user) => { |
|
|
this.user = user; |
|
|
this.user = user; |
|
|
|
|
|
|
|
|
@ -179,11 +182,11 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
public onSafeWithdrawalRateChange(safeWithdrawalRate: number) { |
|
|
public onSafeWithdrawalRateChange(safeWithdrawalRate: number) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.putUserSetting({ safeWithdrawalRate }) |
|
|
.putUserSetting({ safeWithdrawalRate }) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((user) => { |
|
|
.subscribe((user) => { |
|
|
this.user = user; |
|
|
this.user = user; |
|
|
|
|
|
|
|
|
@ -198,11 +201,11 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
public onSavingsRateChange(savingsRate: number) { |
|
|
public onSavingsRateChange(savingsRate: number) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.putUserSetting({ savingsRate }) |
|
|
.putUserSetting({ savingsRate }) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((user) => { |
|
|
.subscribe((user) => { |
|
|
this.user = user; |
|
|
this.user = user; |
|
|
|
|
|
|
|
|
@ -217,11 +220,11 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
projectedTotalAmount, |
|
|
projectedTotalAmount, |
|
|
retirementDate: null |
|
|
retirementDate: null |
|
|
}) |
|
|
}) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((user) => { |
|
|
.subscribe((user) => { |
|
|
this.user = user; |
|
|
this.user = user; |
|
|
|
|
|
|
|
|
@ -230,11 +233,6 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
|
|
this.unsubscribeSubject.next(); |
|
|
|
|
|
this.unsubscribeSubject.complete(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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( |
|
|
|