|
|
|
@ -7,8 +7,10 @@ import { GfFireCalculatorComponent } from '@ghostfolio/ui/fire-calculator'; |
|
|
|
import { GfPremiumIndicatorComponent } from '@ghostfolio/ui/premium-indicator'; |
|
|
|
import { GfValueComponent } from '@ghostfolio/ui/value'; |
|
|
|
|
|
|
|
import { NgStyle } from '@angular/common'; |
|
|
|
import { CommonModule, NgStyle } from '@angular/common'; |
|
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
|
|
|
import { FormControl } from '@angular/forms'; |
|
|
|
import { Big } from 'big.js'; |
|
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
|
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|
|
|
@ -17,11 +19,14 @@ import { takeUntil } from 'rxjs/operators'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
imports: [ |
|
|
|
CommonModule, |
|
|
|
FormsModule, |
|
|
|
GfFireCalculatorComponent, |
|
|
|
GfPremiumIndicatorComponent, |
|
|
|
GfValueComponent, |
|
|
|
NgStyle, |
|
|
|
NgxSkeletonLoaderModule |
|
|
|
NgxSkeletonLoaderModule, |
|
|
|
ReactiveFormsModule |
|
|
|
], |
|
|
|
selector: 'gf-fire-page', |
|
|
|
styleUrls: ['./fire-page.scss'], |
|
|
|
@ -33,6 +38,8 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
public hasImpersonationId: boolean; |
|
|
|
public hasPermissionToUpdateUserSettings: boolean; |
|
|
|
public isLoading = false; |
|
|
|
public safeWithdrawalRateControl = new FormControl<number>(undefined); |
|
|
|
public safeWithdrawalRateOptions = [0.025, 0.03, 0.035, 0.04, 0.045]; |
|
|
|
public user: User; |
|
|
|
public withdrawalRatePerMonth: Big; |
|
|
|
public withdrawalRatePerYear: Big; |
|
|
|
@ -70,11 +77,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
this.withdrawalRatePerYear = Big( |
|
|
|
this.fireWealth.today.valueInBaseCurrency |
|
|
|
).mul(this.user.settings.safeWithdrawalRate); |
|
|
|
|
|
|
|
this.withdrawalRatePerMonth = this.withdrawalRatePerYear.div(12); |
|
|
|
this.calculateWithdrawalRates(); |
|
|
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
|
|
@ -88,6 +91,12 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
this.hasImpersonationId = !!impersonationId; |
|
|
|
}); |
|
|
|
|
|
|
|
this.safeWithdrawalRateControl.valueChanges |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe((value) => { |
|
|
|
this.onSafeWithdrawalRateChange(Number(value)); |
|
|
|
}); |
|
|
|
|
|
|
|
this.userService.stateChanged |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe((state) => { |
|
|
|
@ -102,6 +111,13 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
permissions.updateUserSettings |
|
|
|
); |
|
|
|
|
|
|
|
this.safeWithdrawalRateControl.setValue( |
|
|
|
this.user.settings.safeWithdrawalRate, |
|
|
|
{ emitEvent: false } |
|
|
|
); |
|
|
|
|
|
|
|
this.calculateWithdrawalRates(); |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
} |
|
|
|
}); |
|
|
|
@ -141,6 +157,25 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public onSafeWithdrawalRateChange(safeWithdrawalRate: number) { |
|
|
|
this.dataService |
|
|
|
.putUserSetting({ safeWithdrawalRate }) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe(() => { |
|
|
|
this.userService |
|
|
|
.get(true) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe((user) => { |
|
|
|
this.user = user; |
|
|
|
|
|
|
|
this.calculateWithdrawalRates(); |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public onSavingsRateChange(savingsRate: number) { |
|
|
|
this.dataService |
|
|
|
.putUserSetting({ savingsRate }) |
|
|
|
@ -180,4 +215,14 @@ export class GfFirePageComponent implements OnDestroy, OnInit { |
|
|
|
this.unsubscribeSubject.next(); |
|
|
|
this.unsubscribeSubject.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
private calculateWithdrawalRates() { |
|
|
|
if (this.fireWealth && this.user?.settings?.safeWithdrawalRate) { |
|
|
|
this.withdrawalRatePerYear = new Big( |
|
|
|
this.fireWealth.today.valueInBaseCurrency |
|
|
|
).mul(this.user.settings.safeWithdrawalRate); |
|
|
|
|
|
|
|
this.withdrawalRatePerMonth = this.withdrawalRatePerYear.div(12); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|