Skip to content

Commit

Permalink
upgraded iap library to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalkishor1991 committed Mar 13, 2024
1 parent 92bddc5 commit a64521a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
7 changes: 5 additions & 2 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -29,4 +30,6 @@ export default function App() {
) : (
<ActivityIndicator />
);
}
};

export default withIAPContext(App);
11 changes: 1 addition & 10 deletions ApplicationRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 = (
Expand Down
12 changes: 8 additions & 4 deletions libs/Helpers.js
Original file line number Diff line number Diff line change
@@ -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';
};
Expand All @@ -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!');
Expand All @@ -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)) {
Expand Down

0 comments on commit a64521a

Please sign in to comment.