diff --git a/App.js b/App.js index b703c017..89f34811 100644 --- a/App.js +++ b/App.js @@ -3,8 +3,9 @@ import { ActivityIndicator } from 'react-native'; import LoginOverlayScreen from './components/LoginOverlayScreen'; import ApplicationRoot from './ApplicationRoot'; import Storage from './libs/Storage'; +import { withIAPContext } from 'react-native-iap'; -export default function App() { +const App = () => { const [isLoading, setIsLoading] = React.useState(false); const [isLoginOverlayStepDone, setIsLoginOverlayStepDone] = React.useState(true); React.useEffect(() => { @@ -29,4 +30,6 @@ export default function App() { ) : ( ); -} +}; + +export default withIAPContext(App); diff --git a/ApplicationRoot.js b/ApplicationRoot.js index af4bc50d..b0cb60d8 100644 --- a/ApplicationRoot.js +++ b/ApplicationRoot.js @@ -22,11 +22,10 @@ import HamburgerMenu from './components/HamburgerMenu'; import SideMenu from 'react-native-side-menu'; import { HEADER_HEIGHT } from './constants/Layout'; import Entypo from 'react-native-vector-icons/Entypo'; -import { notifyMessage } from './libs/Helpers'; -import RNIap from 'react-native-iap'; import { t } from 'i18next'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; const Stack = createNativeStackNavigator(); + /*import { LogBox } from 'react-native'; // enabled for recording demos LogBox.ignoreAllLogs();//Ignore all log notifications*/ export default function App() { @@ -36,17 +35,9 @@ export default function App() { const navigationRef = useNavigationContainerRef(); useEffect(() => { (async () => { - try { - await RNIap.initConnection(); - } catch (e) { - notifyMessage(t('Error initializing purchase: ') + e); - } await applicationState.loadInitPaletteFromStore(); setIsPalettesLoaded(true); })(); - return () => { - RNIap.endConnection(); - }; }, []); const spinner = ( diff --git a/libs/Helpers.js b/libs/Helpers.js index 903d4f6b..4f591027 100644 --- a/libs/Helpers.js +++ b/libs/Helpers.js @@ -1,5 +1,7 @@ import { NativeModules, Platform, Alert, ToastAndroid } from 'react-native'; -import RNIap from 'react-native-iap'; +import * as RNIap from 'react-native-iap'; +import { requestPurchase, getProducts } from 'react-native-iap'; + const productSku = function () { return Platform.OS === 'android' ? 'croma_pro' : 'app_croma'; }; @@ -24,8 +26,11 @@ const purchase = async function (setPurchase, productSKU) { productSKU = productSku(); } try { - await RNIap.getProducts([productSKU]); - const details = await RNIap.requestPurchase(productSKU, false); + await getProducts({ skus: [productSKU] }); + const details = await requestPurchase({ + skus: [productSKU], + andDangerouslyFinishTransactionAutomatically: true + }); await setPurchase(details); logEvent('purchase_successful'); notifyMessage('Congrats, You are now a pro user!'); @@ -37,7 +42,6 @@ const purchase = async function (setPurchase, productSKU) { }; const initPurchase = async function (setPurchase) { const productSKU = productSku(); - notifyMessage('Congrats, You are a pro user. Huehive pro version is now free for limited time!'); try { let products = await getAvailablePurchases(); if (products.find((product) => product.productId === productSKU)) {