write jest tests import type { BaseIndicator, RatePeriod, RatePeriodValue,…
- User
write jest tests import type { BaseIndicator, RatePeriod, RatePeriodValue, RateSettingsDto, SpecialValueIA, SpecialValueIV, SpecialValueIV2, } from '$interest-rates/entities/rates';
import { DEFAULT_VALUES_TABLE_LOAN_DEBT, SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, } from '../../../consts';
type GenerateEscrowPeriodProps = { rateSettings: RateSettingsDto; complexLoan: boolean; withoutPeriods: boolean; periods: RatePeriod[] | undefined; };
export const generateEscrowPeriod = ({ rateSettings, complexLoan, withoutPeriods, periods, }: GenerateEscrowPeriodProps) => { const absoluteRate = rateSettings.settingsRateType.ESCROW.absoluteRates.defaultValue; const periodRateSubType = rateSettings.settingsRateType.ESCROW.periodRateSubTypes.defaultValue;
codeconst value = { absoluteRate, grossMargin: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, eva: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, netMargin: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, lgd: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, } as RatePeriodValue; let baseIndicator: BaseIndicator = { cap: null, capChecked: false, floor: null, floorChecked: false, lookback: null, kind: null, replacementRate: null, termIndex: null, id: null, }; const specialValueIV: Nullable<SpecialValueIV> = { value, periodRateSubType, differentiatedIV: periods?.[0].specialValueIV?.differentiatedIV ?? true, table: periods?.[0].specialValueIV?.differentiatedIV || complexLoan ? DEFAULT_VALUES_TABLE_LOAN_DEBT : [], } as SpecialValueIV; let specialValueIA: Nullable<SpecialValueIA> = null; let specialValueIV2: Nullable<SpecialValueIV2> = null; if (periods) { baseIndicator = { ...baseIndicator, cap: periods[0].baseIndicator.cap, capChecked: periods[0].baseIndicator.capChecked, floor: periods[0].baseIndicator.floor, floorChecked: periods[0].baseIndicator.floorChecked, }; } if (rateSettings.visibleSpecialValueIA) { specialValueIA = { value, periodRateSubType, } as SpecialValueIA; } if (complexLoan) { specialValueIV2 = { value } as SpecialValueIV2; } return { baseIndicator, value, periodRateSubType, specialValueIV, specialValueIV2, specialValueIA, endInvestmentPhase: withoutPeriods ? false : undefined, } as RatePeriod; - Assistant
- User
import type { RatePeriod, RateSettingsDto } from '$interest-rates/entities/rates';
import { SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE } from '../../../consts';
type GenerateFixedPeriodProps = { rateSettings: RateSettingsDto; };
export const generateFixedPeriod = ({ rateSettings }: GenerateFixedPeriodProps) => { const absoluteRate = rateSettings.settingsRateType.FIXED.absoluteRates.defaultValue; const maxRequired = rateSettings.settingsRateType.FIXED.max?.required;
codereturn { value: { absoluteRate, maxValue: maxRequired ? null : undefined, grossMargin: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, eva: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, netMargin: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, lgd: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, }, } as RatePeriod;};
- Assistant
- User
import type { RatePeriod, RateSettingsDto } from '$interest-rates/entities/rates';
import { SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE } from '../../../consts';
type GenerateFloatingPeriodProps = { rateSettings: RateSettingsDto; };
export const generateFloatingPeriod = ({ rateSettings }: GenerateFloatingPeriodProps) => { const absoluteRate = rateSettings.settingsRateType.FLOATING.absoluteRates.defaultValue; const baseIndicator = rateSettings.settingsRateType.FLOATING.baseIndicatorKind.disabled ? rateSettings.settingsRateType.FLOATING.baseIndicatorKind.defaultValue : undefined; const periodRateSubType = rateSettings.settingsRateType.FLOATING.periodRateSubTypes.defaultValue; const { maxValue } = rateSettings.settingsRateType.FLOATING;
codereturn { periodRateSubType, baseIndicator: { kind: baseIndicator, }, value: { absoluteRate, maxValue: maxValue ? null : undefined, grossMargin: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, eva: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, netMargin: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, lgd: SIZE_SPECIAL_INTEREST_RATE_DEFAULT_VALUE, }, increasedValue: { absoluteRate, }, } as unknown as RatePeriod; - Assistant
- User
import { useCallback } from 'react'; import { useFormContext } from 'react-hook-form';
import type { CommonParamsFormState } from '../types';
export const useParamsMaxMinBaseIndicator = () => { const { setValue, getValues } = useFormContext();
codeconst { periods } = getValues(); console.log(getValues()); const handleChangeCapCheckbox = useCallback( (value: boolean) => { periods?.forEach((_, index) => { setValue(`periods.${index}.baseIndicator.capChecked`, value); }); }, [periods, setValue], ); const handleChangeCapInput = useCallback( (value: number) => { periods?.forEach((_, index) => { setValue(`periods.${index}.baseIndicator.cap`, value); }); }, [periods, setValue], ); const handleChangeFloorCheckbox = useCallback( (value: boolean) => { periods?.forEach((_, index) => { setValue(`periods.${index}.baseIndicator.floorChecked`, value); }); }, [periods, setValue], ); const handleChangeFloorInput = useCallback( (value: number) => { periods?.forEach((_, index) => { setValue(`periods.${index}.baseIndicator.floor`, value); }); }, [periods, setValue], ); return { handleChangeCapCheckbox, handleChangeCapInput, handleChangeFloorCheckbox, handleChangeFloorInput, }; - Assistant