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';
8 type GetPreferredCurrencyParams,
9 getPlansMap as getPlansMapInner,
10 } from '@proton/payments';
12 import { useCurrencies } from '../payments/client-extensions/useCurrencies';
14 type PreferredPlansMapHook = {
15 plansMapLoading: boolean;
16 plansMap: FullPlansMap;
17 getPlansMap: (overrides?: GetPreferredCurrencyParams) => {
18 plansMap: FullPlansMap;
19 preferredCurrency: Currency;
21 preferredCurrency: Currency;
24 export const usePreferredPlansMap = (currencyFallback?: boolean): PreferredPlansMapHook => {
25 const [plans, plansLoading] = usePlans();
26 const [status, statusLoading] = usePaymentStatus();
27 const [subscription, subscriptionLoading] = useSubscription();
28 const [user] = useUser();
29 const { getPreferredCurrency } = useCurrencies();
31 const getPlansMap = (overrides: GetPreferredCurrencyParams = {}) => {
32 const preferredCurrency = getPreferredCurrency({
42 plansMap: getPlansMapInner(plans?.plans ?? [], preferredCurrency, currencyFallback),
49 plansMapLoading: plansLoading || statusLoading || subscriptionLoading,