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

Function StoreKitSubProvider

packages/shared/src/contexts/payment/StoreKit.tsx:30–79  ·  view source on GitHub ↗
({
  children,
  successCallback,
}: PaymentContextProviderProps)

Source from the content-addressed store, hash-verified

28>;
29
30export 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};

Callers

nothing calls this directly

Calls 6

useAuthContextFunction · 0.90
generateQueryKeyFunction · 0.90
fetchPricingMetadataFunction · 0.90
iOSSupportsPlusPurchaseFunction · 0.90
getApplePricingFunction · 0.90
useStoreKitPaymentFunction · 0.90

Tested by

no test coverage detected