({
children,
successCallback,
}: PaymentContextProviderProps)
| 28 | >; |
| 29 | |
| 30 | export const StoreKitSubProvider = ({ |
| 31 | children, |
| 32 | successCallback, |
| 33 | }: PaymentContextProviderProps): ReactElement => { |
| 34 | const { user, isValidRegion: isPlusAvailable } = useAuthContext(); |
| 35 | |
| 36 | const { data: metadata } = useQuery<ProductPricingMetadata[]>({ |
| 37 | queryKey: generateQueryKey( |
| 38 | RequestKey.PriceMetadata, |
| 39 | user, |
| 40 | PurchaseType.Plus, |
| 41 | ), |
| 42 | queryFn: () => fetchPricingMetadata(PurchaseType.Plus), |
| 43 | enabled: !!user && iOSSupportsPlusPurchase(), |
| 44 | staleTime: StaleTime.Default, |
| 45 | }); |
| 46 | |
| 47 | const { data: products } = useQuery({ |
| 48 | queryKey: generateQueryKey( |
| 49 | RequestKey.PricePreview, |
| 50 | user, |
| 51 | PurchaseType.Plus, |
| 52 | ), |
| 53 | enabled: !!metadata?.length && iOSSupportsPlusPurchase(), |
| 54 | staleTime: StaleTime.Default, |
| 55 | queryFn: async () => getApplePricing(metadata), |
| 56 | }); |
| 57 | const { openCheckout } = useStoreKitPayment({ |
| 58 | type: PurchaseType.Plus, |
| 59 | products, |
| 60 | successCallback, |
| 61 | }); |
| 62 | |
| 63 | const contextData = useMemo<PaymentContextData>( |
| 64 | () => ({ |
| 65 | openCheckout, |
| 66 | productOptions: products, |
| 67 | isPlusAvailable: isPlusAvailable ?? false, |
| 68 | giftOneYear: undefined, |
| 69 | isPricesPending: false, |
| 70 | }), |
| 71 | [isPlusAvailable, openCheckout, products], |
| 72 | ); |
| 73 | |
| 74 | return ( |
| 75 | <PaymentContext.Provider value={contextData}> |
| 76 | {children} |
| 77 | </PaymentContext.Provider> |
| 78 | ); |
| 79 | }; |
nothing calls this directly
no test coverage detected