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

Function PlusIOS

packages/shared/src/components/plus/PlusIOS.tsx:37–197  ·  view source on GitHub ↗
({
  shouldShowPlusHeader,
  showModalSection,
}: PlusIOSProps)

Source from the content-addressed store, hash-verified

35};
36
37export const PlusIOS = ({
38 shouldShowPlusHeader,
39 showModalSection,
40}: PlusIOSProps): ReactElement => {
41 const router = useRouter();
42 const { displayToast } = useToastNotification();
43 const [selectedOption, setSelectedOption] = useState<string | null>(null);
44 const { productOptions, openCheckout, isPlusAvailable } = usePaymentContext();
45 const { isPlus, logSubscriptionEvent } = usePlusSubscription();
46 const [isLoading, setIsLoading] = useState(false);
47 const [listenForSuccess, setListenForSuccess] = useState(false);
48
49 const { getMarketingCta } = useBoot();
50
51 const { title, description, ctaText } = useMemo<
52 Partial<MarketingCtaFlags>
53 >(() => {
54 if (!showModalSection) {
55 return {};
56 }
57 const marketingCta = getMarketingCta(MarketingCtaVariant.Plus);
58 const { flags } = marketingCta || {};
59 return flags;
60 }, [getMarketingCta, showModalSection]);
61
62 const canContinue = useMemo(
63 () =>
64 iOSSupportsPlusPurchase() &&
65 !!selectedOption &&
66 !isPlus &&
67 isPlusAvailable,
68 [isPlus, isPlusAvailable, selectedOption],
69 );
70
71 const selectionChange: OpenCheckoutFn = useCallback(({ priceId }) => {
72 setSelectedOption(priceId);
73 }, []);
74
75 const onContinue = useCallback(() => {
76 // @DEPRECATED: Remove setListenForSuccess once usage of App v1.8 is low
77 setListenForSuccess(true);
78 logSubscriptionEvent({
79 event_name: LogEvent.InitiateCheckout,
80 });
81 openCheckout({ priceId: selectedOption });
82 }, [logSubscriptionEvent, openCheckout, selectedOption]);
83
84 useEffect(() => {
85 // @DEPRECATED: Remove event listener once usage of App v1.8 is low
86 promisifyEventListener('iap-error', ({ detail }) => {
87 if (detail === 'userCancelled') {
88 setListenForSuccess(false);
89 return;
90 }
91
92 displayToast(DEFAULT_ERROR);
93 });
94

Callers

nothing calls this directly

Calls 12

useToastNotificationFunction · 0.90
usePaymentContextFunction · 0.90
usePlusSubscriptionFunction · 0.90
useBootFunction · 0.90
iOSSupportsPlusPurchaseFunction · 0.90
promisifyEventListenerFunction · 0.90
stringToBooleanFunction · 0.90
getMarketingCtaFunction · 0.85
openCheckoutFunction · 0.85
displayToastFunction · 0.85
pushMethod · 0.80
useRouterFunction · 0.50

Tested by

no test coverage detected