MCPcopy Create free account
hub / github.com/dailydotdev/apps / usePlusSubscription

Function usePlusSubscription

packages/shared/src/hooks/usePlusSubscription.ts:17–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15};
16
17export const usePlusSubscription = (): {
18 isPlus: boolean;
19 plusProvider?: SubscriptionProvider;
20 logSubscriptionEvent: (event: LogSubscriptionEvent) => void;
21 plusHref: string | undefined;
22 status?: SubscriptionStatus;
23} => {
24 const { user } = useAuthContext();
25 const { logEvent } = useLogContext();
26 const isPlus = user?.isPlus || false;
27 const { status, provider: plusProvider } = user?.subscriptionFlags || {};
28
29 const logSubscriptionEvent = useCallback(
30 ({ event_name, target_id, extra }: LogSubscriptionEvent) => {
31 logEvent({
32 event_name,
33 target_type: TargetType.Plus,
34 target_id,
35 extra: JSON.stringify(extra) || undefined,
36 });
37 },
38 [logEvent],
39 );
40
41 const plusHref = useMemo(() => {
42 if (!isPlus) {
43 return plusUrl;
44 }
45
46 // Plus users with Apple StoreKit on iOS get no URL (handled by onClick)
47 if (isIOSNative() && plusProvider === SubscriptionProvider.AppleStoreKit) {
48 return undefined;
49 }
50
51 // External subscription management for Paddle users
52 if (plusProvider === SubscriptionProvider.Paddle) {
53 return managePlusUrl;
54 }
55
56 // Internal subscription management for other cases
57 return `${webappUrl}account/subscription`;
58 }, [isPlus, plusProvider]);
59
60 return {
61 isPlus,
62 plusProvider,
63 logSubscriptionEvent,
64 plusHref,
65 status,
66 };
67};

Callers 15

UpgradeToPlusFunction · 0.90
PlusUserBadgeFunction · 0.90
PlusDesktopFunction · 0.90
PlusProductToggleFunction · 0.90
PlusInfoFunction · 0.90
PlusAdjustQuantityFunction · 0.90
PlusProductListFunction · 0.90
PlusIOSFunction · 0.90
PlusCheckoutContainerFunction · 0.90
PostUpgradeToPlusFunction · 0.90
ToggleClickbaitShieldFunction · 0.90
PersonalizedDigestFunction · 0.90

Calls 4

useAuthContextFunction · 0.90
useLogContextFunction · 0.90
isIOSNativeFunction · 0.90
logEventFunction · 0.85

Tested by

no test coverage detected