Browse Source

Task/widen input types in fire calculator component

pull/8015/head
KenTandrian 2 weeks ago
parent
commit
896000ea98
  1. 41
      libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

41
libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

@ -2,7 +2,7 @@ import {
getTooltipOptions, getTooltipOptions,
transformTickToAbbreviation transformTickToAbbreviation
} from '@ghostfolio/common/chart-helper'; } from '@ghostfolio/common/chart-helper';
import { primaryColorRgb } from '@ghostfolio/common/config'; import { DEFAULT_CURRENCY, primaryColorRgb } from '@ghostfolio/common/config';
import { formatMonthAndYear, getLocale } from '@ghostfolio/common/helper'; import { formatMonthAndYear, getLocale } from '@ghostfolio/common/helper';
import { FireCalculationCompleteEvent } from '@ghostfolio/common/interfaces'; import { FireCalculationCompleteEvent } from '@ghostfolio/common/interfaces';
import { ColorScheme } from '@ghostfolio/common/types'; import { ColorScheme } from '@ghostfolio/common/types';
@ -86,16 +86,16 @@ import { FireCalculatorService } from './fire-calculator.service';
templateUrl: './fire-calculator.component.html' templateUrl: './fire-calculator.component.html'
}) })
export class GfFireCalculatorComponent implements OnChanges, OnDestroy { export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
@Input() annualInterestRate = 0; @Input() public annualInterestRate?: number = 0;
@Input() colorScheme?: ColorScheme; @Input() public colorScheme?: ColorScheme;
@Input() currency: string; @Input() public currency?: string = DEFAULT_CURRENCY;
@Input() deviceType: string; @Input() public deviceType: string;
@Input() fireWealth = 0; @Input() public fireWealth = 0;
@Input() hasPermissionToUpdateUserSettings: boolean; @Input() public hasPermissionToUpdateUserSettings: boolean;
@Input() locale = getLocale(); @Input() public locale?: string = getLocale();
@Input() projectedTotalAmount = 0; @Input() public projectedTotalAmount?: number;
@Input() retirementDate: Date; @Input() public retirementDate?: Date | string;
@Input() savingsRate = 0; @Input() public savingsRate?: number = 0;
public calculatorForm = this.formBuilder.group({ public calculatorForm = this.formBuilder.group({
annualInterestRate: new FormControl<number | null>(null), annualInterestRate: new FormControl<number | null>(null),
@ -243,11 +243,13 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
if (isNumber(this.fireWealth) && this.fireWealth >= 0) { if (isNumber(this.fireWealth) && this.fireWealth >= 0) {
this.calculatorForm.setValue( this.calculatorForm.setValue(
{ {
annualInterestRate: this.annualInterestRate, annualInterestRate: this.annualInterestRate ?? 0,
paymentPerPeriod: this.savingsRate, paymentPerPeriod: this.savingsRate ?? 0,
principalInvestmentAmount: this.fireWealth, principalInvestmentAmount: this.fireWealth,
projectedTotalAmount: this.projectedTotalAmount, projectedTotalAmount: this.projectedTotalAmount ?? null,
retirementDate: this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE retirementDate: this.retirementDate
? new Date(this.retirementDate)
: this.DEFAULT_RETIREMENT_DATE
}, },
{ {
emitEvent: false emitEvent: false
@ -353,7 +355,7 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
); );
return `Total: ${new Intl.NumberFormat(this.locale, { return `Total: ${new Intl.NumberFormat(this.locale, {
currency: this.currency, currency: this.currency ?? DEFAULT_CURRENCY,
currencyDisplay: 'code', currencyDisplay: 'code',
style: 'currency' style: 'currency'
}).format(totalAmount)}`; }).format(totalAmount)}`;
@ -367,7 +369,7 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
if (context.parsed.y !== null) { if (context.parsed.y !== null) {
label += new Intl.NumberFormat(this.locale, { label += new Intl.NumberFormat(this.locale, {
currency: this.currency, currency: this.currency ?? DEFAULT_CURRENCY,
currencyDisplay: 'code', currencyDisplay: 'code',
style: 'currency' style: 'currency'
}).format(context.parsed.y); }).format(context.parsed.y);
@ -509,8 +511,9 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
return periods; return periods;
} else { } else {
const today = new Date(); const today = new Date();
const retirementDate = const retirementDate = this.retirementDate
this.retirementDate ?? this.DEFAULT_RETIREMENT_DATE; ? new Date(this.retirementDate)
: this.DEFAULT_RETIREMENT_DATE;
return ( return (
12 * (retirementDate.getFullYear() - today.getFullYear()) + 12 * (retirementDate.getFullYear() - today.getFullYear()) +

Loading…
Cancel
Save