Skip to content

Commit

Permalink
(PC-33967) feat(creditV3): refactor after review
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeneston-pass committed Jan 17, 2025
1 parent 5f9b460 commit 2b08764
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
27 changes: 18 additions & 9 deletions src/shared/credits/defaultCredits.ts
Original file line number Diff line number Diff line change
@@ -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<Record<Version, DepositAmountsByAge>>
44 changes: 8 additions & 36 deletions src/shared/user/useDepositAmountsByAge.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
),
Expand Down

0 comments on commit 2b08764

Please sign in to comment.