Skip to content

Commit

Permalink
(PC-33967) feat(creditV3): use FF enable credit V3 backend in useDepo…
Browse files Browse the repository at this point in the history
…sitAmountsByAge (#7544)
  • Loading branch information
lbeneston-pass authored Jan 17, 2025
1 parent a292324 commit 5f9b460
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useAuthContext } from 'features/auth/context/AuthContext'
import { CreditProgressBar } from 'features/profile/components/CreditInfo/CreditProgressBar'
import { isUserBeneficiary18 } from 'features/profile/helpers/isUserBeneficiary18'
import { BlockDescriptionItem } from 'features/tutorial/components/profileTutorial/BlockDescriptionItem'
import { DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT } from 'shared/credits/defaultCredits'
import { DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT_V2 } from 'shared/credits/defaultCredits'
import { formatCurrencyFromCents } from 'shared/currency/formatCurrencyFromCents'
import { useGetCurrencyToDisplay } from 'shared/currency/useGetCurrencyToDisplay'
import { useGetPacificFrancToEuroRate } from 'shared/exchangeRates/useGetPacificFrancToEuroRate'
Expand All @@ -25,7 +25,7 @@ export const EighteenBlockDescription: FunctionComponent<Props> = ({ ongoingCred
const euroToPacificFrancRate = useGetPacificFrancToEuroRate()

const digitalCredit = formatCurrencyFromCents(
DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT,
DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT_V2,
currency,
euroToPacificFrancRate
)
Expand Down
18 changes: 13 additions & 5 deletions src/shared/credits/defaultCredits.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
export const DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT = 20_00
export const DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT = 30_00
export const DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT = 30_00
export const DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT = 300_00
export const DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT = 100_00
export const DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V2 = 20_00
export const DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V3 = 0

export const DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V2 = 30_00
export const DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V3 = 0

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_AMOUNT_V2 = 300_00
export const DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V3 = 150_00

export const DEFAULT_EIGHTEEN_YEARS_OLD_DIGITAL_AMOUNT_V2 = 100_00
58 changes: 41 additions & 17 deletions src/shared/user/useDepositAmountsByAge.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,73 @@
import { DepositAmountsByAge } from 'api/gen'
import { useSettingsContext } from 'features/auth/context/SettingsContext'
import {
DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT,
DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT,
DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT,
DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT,
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 { formatCurrencyFromCents } from 'shared/currency/formatCurrencyFromCents'
import { useGetCurrencyToDisplay } from 'shared/currency/useGetCurrencyToDisplay'
import { useGetPacificFrancToEuroRate } from 'shared/exchangeRates/useGetPacificFrancToEuroRate'

export function useDepositAmountsByAge() {
const { data: settings } = useSettingsContext()
const enableCreditV3 = settings?.wipEnableCreditV3
const deposit = settings?.depositAmountsByAge

const currency = useGetCurrencyToDisplay()
const euroToPacificFrancRate = useGetPacificFrancToEuroRate()

const fifteenYearsOldAmount =
settings?.depositAmountsByAge?.age_15 ?? DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT
const sixteenYearsOldAmount =
settings?.depositAmountsByAge?.age_16 ?? DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT
const seventeenYearsOldAmount =
settings?.depositAmountsByAge?.age_17 ?? DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT
const eighteenYearsOldAmount =
settings?.depositAmountsByAge?.age_18 ?? DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT
const getDefaultAmountByAge = (
ageKey: keyof DepositAmountsByAge,
defaultV2: number,
defaultV3: number
): number => {
return deposit?.[ageKey] ?? (enableCreditV3 ? defaultV3 : defaultV2)
}

const amountsByAge = {
fifteenYearsOldDeposit: formatCurrencyFromCents(
fifteenYearsOldAmount,
getDefaultAmountByAge(
'age_15',
DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V2,
DEFAULT_FIFTEEN_YEARS_OLD_AMOUNT_V3
),
currency,
euroToPacificFrancRate
),
sixteenYearsOldDeposit: formatCurrencyFromCents(
sixteenYearsOldAmount,
getDefaultAmountByAge(
'age_16',
DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V2,
DEFAULT_SIXTEEN_YEARS_OLD_AMOUNT_V3
),
currency,
euroToPacificFrancRate
),
seventeenYearsOldDeposit: formatCurrencyFromCents(
seventeenYearsOldAmount,
getDefaultAmountByAge(
'age_17',
DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V2,
DEFAULT_SEVENTEEN_YEARS_OLD_AMOUNT_V3
),
currency,
euroToPacificFrancRate
),
eighteenYearsOldDeposit: formatCurrencyFromCents(
eighteenYearsOldAmount,
getDefaultAmountByAge(
'age_18',
DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V2,
DEFAULT_EIGHTEEN_YEARS_OLD_AMOUNT_V3
),
currency,
euroToPacificFrancRate
),
}
return { ...amountsByAge }

return amountsByAge
}

0 comments on commit 5f9b460

Please sign in to comment.