1 import { usePaymentStatus } from '@proton/account/paymentStatus/hooks';
2 import { usePlans } from '@proton/account/plans/hooks';
3 import { useSubscription } from '@proton/account/subscription/hooks';
4 import { useUser } from '@proton/account/user/hooks';
5 import { type Currency, type FullPlansMap, getPlansMap as getPlansMapInner } from '@proton/payments';
7 import { type GetPreferredCurrencyParamsHook, useCurrencies } from '../payments/client-extensions/useCurrencies';
9 type PreferredPlansMapHook = {
10 plansMapLoading: boolean;
11 plansMap: FullPlansMap;
12 getPlansMap: (overrides?: GetPreferredCurrencyParamsHook) => {
13 plansMap: FullPlansMap;
14 preferredCurrency: Currency;
16 preferredCurrency: Currency;
19 export const usePreferredPlansMap = (currencyFallback?: boolean): PreferredPlansMapHook => {
20 const [plans, plansLoading] = usePlans();
21 const [status, statusLoading] = usePaymentStatus();
22 const [subscription, subscriptionLoading] = useSubscription();
23 const [user] = useUser();
24 const { getPreferredCurrency } = useCurrencies();
26 const getPlansMap = (overrides: GetPreferredCurrencyParamsHook = {}) => {
27 const preferredCurrency = getPreferredCurrency({
37 plansMap: getPlansMapInner(plans?.plans ?? [], preferredCurrency, currencyFallback),
44 plansMapLoading: plansLoading || statusLoading || subscriptionLoading,