({
shouldShowPlusHeader,
showModalSection,
}: PlusIOSProps)
| 35 | }; |
| 36 | |
| 37 | export 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 |
nothing calls this directly
no test coverage detected