@@ -2,8 +2,7 @@ import { whoamiQueryKey } from "@follow/store/user/hooks"
22import { userSyncService } from "@follow/store/user/store"
33import { requireNativeModule } from "expo"
44import type { ProductPurchase , SubscriptionProduct } from "expo-iap"
5- import { getTransactionJws , showManageSubscriptions , useIAP } from "expo-iap"
6- import { openURL } from "expo-linking"
5+ import { getTransactionJws , useIAP } from "expo-iap"
76import type { PropsWithChildren } from "react"
87import { createContext , use , useCallback , useEffect , useMemo , useRef , useState } from "react"
98import { useTranslation } from "react-i18next"
@@ -15,7 +14,6 @@ import { proxyEnv } from "@/src/lib/proxy-env"
1514import { queryClient } from "@/src/lib/query-client"
1615import { toast } from "@/src/lib/toast"
1716
18- const APPLE_SUBSCRIPTION_MANAGEMENT_URL = "https://apps.apple.com/account/subscriptions"
1917const billingSubscriptionQueryKey = [ "billingSubscription" ]
2018
2119type BillingSubscriptionResponse = {
@@ -40,12 +38,17 @@ type AppleIAPContextValue = {
4038 appAccountToken ?: string | null
4139 } ) => Promise < void >
4240 restoreSubscriptionPurchases : ( ) => Promise < void >
43- openSubscriptionManagement : ( ) => Promise < void >
4441}
4542
4643const AppleIAPContext = createContext < AppleIAPContextValue | null > ( null )
4744
48- const noopAsync = async ( ) => { }
45+ const refreshBillingState = async ( ) => {
46+ await Promise . allSettled ( [
47+ userSyncService . whoami ( ) ,
48+ queryClient . invalidateQueries ( { queryKey : whoamiQueryKey } ) ,
49+ queryClient . invalidateQueries ( { queryKey : billingSubscriptionQueryKey } ) ,
50+ ] )
51+ }
4952
5053export const AppleIAPProvider = ( { children } : PropsWithChildren ) => {
5154 const { t } = useTranslation ( "settings" )
@@ -107,14 +110,6 @@ export const AppleIAPProvider = ({ children }: PropsWithChildren) => {
107110 availablePurchasesRef . current = availablePurchases
108111 } , [ availablePurchases ] )
109112
110- const refreshBillingState = useCallback ( async ( ) => {
111- await Promise . allSettled ( [
112- userSyncService . whoami ( ) ,
113- queryClient . invalidateQueries ( { queryKey : whoamiQueryKey } ) ,
114- queryClient . invalidateQueries ( { queryKey : billingSubscriptionQueryKey } ) ,
115- ] )
116- } , [ ] )
117-
118113 const verifyPurchase = useCallback (
119114 async ( purchase : ProductPurchase ) => {
120115 const productId = purchase . id
@@ -186,14 +181,7 @@ export const AppleIAPProvider = ({ children }: PropsWithChildren) => {
186181 setIsProcessingPurchase ( false )
187182 }
188183 } ) ( )
189- } , [
190- currentPurchase ,
191- finishTransaction ,
192- knownSubscriptionIds ,
193- refreshBillingState ,
194- t ,
195- verifyPurchase ,
196- ] )
184+ } , [ currentPurchase , finishTransaction , knownSubscriptionIds , t , verifyPurchase ] )
197185
198186 useEffect ( ( ) => {
199187 if ( ! currentPurchaseError ) {
@@ -267,7 +255,7 @@ export const AppleIAPProvider = ({ children }: PropsWithChildren) => {
267255 throw error
268256 }
269257 } ,
270- [ refreshBillingState , requestPurchase , storeKitTestHelper ] ,
258+ [ requestPurchase , storeKitTestHelper ] ,
271259 )
272260
273261 const restoreSubscriptionPurchases = useCallback ( async ( ) => {
@@ -322,20 +310,7 @@ export const AppleIAPProvider = ({ children }: PropsWithChildren) => {
322310 } finally {
323311 setIsRestoring ( false )
324312 }
325- } , [ knownSubscriptionIds , refreshBillingState , restorePurchases , t , verifyPurchase ] )
326-
327- const openSubscriptionManagement = useCallback ( async ( ) => {
328- if ( Platform . OS !== "ios" ) {
329- await noopAsync ( )
330- return
331- }
332-
333- try {
334- await showManageSubscriptions ( )
335- } catch {
336- await openURL ( APPLE_SUBSCRIPTION_MANAGEMENT_URL )
337- }
338- } , [ ] )
313+ } , [ knownSubscriptionIds , restorePurchases , t , verifyPurchase ] )
339314
340315 const contextValue = useMemo < AppleIAPContextValue > (
341316 ( ) => ( {
@@ -347,7 +322,6 @@ export const AppleIAPProvider = ({ children }: PropsWithChildren) => {
347322 loadSubscriptions,
348323 requestSubscriptionPurchase,
349324 restoreSubscriptionPurchases,
350- openSubscriptionManagement,
351325 } ) ,
352326 [
353327 connected ,
@@ -358,7 +332,6 @@ export const AppleIAPProvider = ({ children }: PropsWithChildren) => {
358332 loadSubscriptions ,
359333 requestSubscriptionPurchase ,
360334 restoreSubscriptionPurchases ,
361- openSubscriptionManagement ,
362335 ] ,
363336 )
364337
0 commit comments