diff --git a/src/shared/credits/defaultCredits.ts b/src/shared/credits/defaultCredits.ts index 5daf2d139a7..4642d1cb515 100644 --- a/src/shared/credits/defaultCredits.ts +++ b/src/shared/credits/defaultCredits.ts @@ -1,13 +1,22 @@ -export const DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V2 = 20_00 -export const DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V3 = 0 +import type { ReadonlyDeep } from 'type-fest' -export const DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V2 = 30_00 -export const DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V3 = 0 +import { DepositAmountsByAge } from 'api/gen' -export const DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V2 = 30_00 -export const DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V3 = 50_00 +export const DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT_V2 = 100_00 -export const DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V2 = 300_00 -export const DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V3 = 150_00 +type Version = 'v2' | 'v3' -export const DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT_V2 = 100_00 +export const defaultCreditByAge = { + v2: { + age_15: 20_00, + age_16: 30_00, + age_17: 30_00, + age_18: 300_0, + }, + v3: { + age_15: 0, + age_16: 0, + age_17: 50_00, + age_18: 150_0, + }, +} as const satisfies ReadonlyDeep> diff --git a/src/shared/user/useDepositAmountsByAge.ts b/src/shared/user/useDepositAmountsByAge.ts index 9e0157ed2db..15c9c84bf27 100644 --- a/src/shared/user/useDepositAmountsByAge.ts +++ b/src/shared/user/useDepositAmountsByAge.ts @@ -1,15 +1,6 @@ import { DepositAmountsByAge } from 'api/gen' import { useSettingsContext } from 'features/auth/context/SettingsContext' -import { - DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V3, - DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V3, - DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V3, - DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V3, -} from 'shared/credits/defaultCredits' +import { defaultCreditByAge } from 'shared/credits/defaultCredits' import { formatCurrencyFromCents } from 'shared/currency/formatCurrencyFromCents' import { useGetCurrencyToDisplay } from 'shared/currency/useGetCurrencyToDisplay' import { useGetPacificFrancToEuroRate } from 'shared/exchangeRates/useGetPacificFrancToEuroRate' @@ -22,48 +13,29 @@ export function useDepositAmountsByAge() { const currency = useGetCurrencyToDisplay() const euroToPacificFrancRate = useGetPacificFrancToEuroRate() - const getDefaultAmountByAge = ( - ageKey: keyof DepositAmountsByAge, - defaultV2: number, - defaultV3: number - ): number => { - return deposit?.[ageKey] ?? (enableCreditV3 ? defaultV3 : defaultV2) + const getDefaultAmountByAge = (ageKey: keyof DepositAmountsByAge): number => { + const version = enableCreditV3 ? 'v3' : 'v2' + return deposit?.[ageKey] ?? defaultCreditByAge[version][ageKey] } const amountsByAge = { fifteenYearsOldDeposit: formatCurrencyFromCents( - getDefaultAmountByAge( - 'age_15', - DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V3 - ), + getDefaultAmountByAge('age_15'), currency, euroToPacificFrancRate ), sixteenYearsOldDeposit: formatCurrencyFromCents( - getDefaultAmountByAge( - 'age_16', - DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V3 - ), + getDefaultAmountByAge('age_16'), currency, euroToPacificFrancRate ), seventeenYearsOldDeposit: formatCurrencyFromCents( - getDefaultAmountByAge( - 'age_17', - DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V3 - ), + getDefaultAmountByAge('age_17'), currency, euroToPacificFrancRate ), eighteenYearsOldDeposit: formatCurrencyFromCents( - getDefaultAmountByAge( - 'age_18', - DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V2, - DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V3 - ), + getDefaultAmountByAge('age_18'), currency, euroToPacificFrancRate ),