-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-33967) feat(creditV3): use FF enable credit V3 backend in useDepo…
…sitAmountsByAge (#7544)
- Loading branch information
1 parent
a292324
commit 5f9b460
Showing
3 changed files
with
56 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |