Merge pull request #1014 from esteemapp/feature/boost

Feature/boost
This commit is contained in:
uğur erdal 2019-08-05 17:39:13 +03:00 committed by GitHub
commit 2e3679517c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 62 deletions

6
App.js
View File

@ -1,7 +1,5 @@
import { Client } from 'bugsnag-react-native';
import Config from 'react-native-config';
// eslint-disable-next-line
import bugsnag from './src/config/bugsnag';
import App from './src/index';
const bugsnag = new Client(Config.BUGSNAG_API_KEY);
export default App;

View File

@ -52,7 +52,7 @@
"react-native-datepicker": "^1.7.2",
"react-native-extended-stylesheet": "^0.10.0",
"react-native-fast-image": "^4.0.14",
"react-native-iap": "^3.3.0",
"react-native-iap": "^3.3.8",
"react-native-image-crop-picker": "^0.24.1",
"react-native-keyboard-aware-scroll-view": "^0.8.0",
"react-native-linear-gradient": "^2.4.2",

5
src/config/bugsnag.js Normal file
View File

@ -0,0 +1,5 @@
import { Client } from 'bugsnag-react-native';
import Config from 'react-native-config';
const client = new Client(Config.BUGSNAG_API_KEY);
export default client;

View File

@ -311,3 +311,5 @@ export const getSCAccessToken = code =>
});
export const getPromotePosts = () => api.get(`/promoted-posts`).then(resp => resp.data);
export const purchaseOrder = data => api.post('/purchase-order', data).then(resp => resp.data);

View File

@ -2,29 +2,19 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Platform, Alert } from 'react-native';
import { withNavigation } from 'react-navigation';
import RNIap, {
purchaseErrorListener,
purchaseUpdatedListener,
ProductPurchase,
PurchaseError,
} from 'react-native-iap';
// import { Alert } from 'react-native';
import RNIap, { purchaseErrorListener, purchaseUpdatedListener } from 'react-native-iap';
import { injectIntl } from 'react-intl';
// import { toastNotification } from '../../../redux/actions/uiAction';
// Services
import { purchaseOrder } from '../../../providers/esteem/esteem';
import bugsnag from '../../../config/bugsnag';
// Constants
// Utilities
import { default as ROUTES } from '../../../constants/routeNames';
// Component
import BoostScreen from '../screen/boostScreen';
/*
* Props Name Description Value
*@props --> props name here description here Value Type Here
*
*/
const ITEM_SKUS = Platform.select({
ios: ['099points', '199points', '499points', '999points', '4999points', '9999points'],
android: ['099points', '199points', '499points', '999points', '4999points', '9999points'],
@ -34,7 +24,6 @@ class BoostContainer extends Component {
constructor(props) {
super(props);
this.state = {
receipt: '',
productList: [],
isLoading: true,
isProccesing: false,
@ -42,34 +31,70 @@ class BoostContainer extends Component {
}
// Component Life Cycle Functions
componentDidMount() {
this._getItems();
this._purchaseUpdatedListener();
}
componentWillUnmount() {
if (this.purchaseUpdateSubscription) {
this.purchaseUpdateSubscription.remove();
this.purchaseUpdateSubscription = null;
}
if (this.purchaseErrorSubscription) {
this.purchaseErrorSubscription.remove();
this.purchaseErrorSubscription = null;
}
}
// Component Functions
async componentDidMount() {
this._getItems();
}
_getAvailablePurchases = async () => {
try {
const purchases = await RNIap.getAvailablePurchases();
console.info('Available purchases :: ', purchases);
if (purchases && purchases.length > 0) {
this.setState({
receipt: purchases[0].transactionReceipt,
_purchaseUpdatedListener = () => {
const {
currentAccount: { name },
} = this.props;
this.purchaseUpdateSubscription = purchaseUpdatedListener(purchase => {
const receipt = purchase.transactionReceipt;
if (receipt) {
const data = {
platform: Platform.OS === 'android' ? 'play_store' : 'app_store',
product: purchase.productId,
receipt: Platform.OS === 'android' ? purchase.purchaseToken : purchase.transactionReceipt,
user: name,
};
purchaseOrder(data)
.then(() => {
if (Platform.OS === 'ios') {
RNIap.finishTransactionIOS(purchase.transactionId);
} else if (Platform.OS === 'android') {
RNIap.consumePurchaseAndroid(purchase.purchaseToken);
}
})
.catch(err =>
bugsnag.notify(err, report => {
report.metadata = {
data,
};
}),
);
}
});
this.purchaseErrorSubscription = purchaseErrorListener(error => {
Alert.alert('Warning', error);
bugsnag.notify(error);
});
}
} catch (err) {
console.warn(err.code, err.message);
Alert.alert(err.message);
}
};
_getItems = async () => {
try {
const products = await RNIap.getProducts(ITEM_SKUS);
products.sort((a, b) => parseFloat(a.price) - parseFloat(b.price)).reverse();
await this.setState({ productList: products });
} catch (err) {
bugsnag.notify(err);
Alert.alert(
`Fetching data from server failed, please try again or notify us at info@esteem.app \n${err.message.substr(
0,
@ -88,9 +113,13 @@ class BoostContainer extends Component {
if (sku !== 'freePoints') {
try {
await RNIap.requestPurchase(sku);
await RNIap.requestPurchase(sku, false);
} catch (err) {
console.warn(err.code, err.message);
bugsnag.notify(err, report => {
report.metadata = {
sku,
};
});
}
} else {
navigation.navigate({
@ -101,25 +130,6 @@ class BoostContainer extends Component {
this.setState({ isProccesing: false });
};
// _buyItem = async sku => {
// console.info('buyItem', sku);
// // const purchase = await RNIap.buyProduct(sku);
// // const products = await RNIap.buySubscription(sku);
// // const purchase = await RNIap.buyProductWithoutFinishTransaction(sku);
// try {
// const purchase = await RNIap.buyProduct(sku);
// // console.log('purchase', purchase);
// // await RNIap.consumePurchaseAndroid(purchase.purchaseToken);
// this.setState({ receipt: purchase.transactionReceipt }, () => this.goNext());
// } catch (err) {
// console.warn(err.code, err.message);
// const subscription = RNIap.addAdditionalSuccessPurchaseListenerIOS(async purchase => {
// this.setState({ receipt: purchase.transactionReceipt }, () => this.goNext());
// subscription.remove();
// });
// }
// };
render() {
const { productList, isLoading, isProccesing } = this.state;
// const FREE_ESTM = { productId: 'freePoints', title: 'free estm' };

View File

@ -7670,10 +7670,10 @@ react-native-fast-image@^4.0.14:
dependencies:
prop-types "^15.5.10"
react-native-iap@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/react-native-iap/-/react-native-iap-3.3.0.tgz#e8aae960072dffb926dad52cb2215e1edbb00caf"
integrity sha512-C/e/LjiYKgWJuPr1LTr3Tt5Bl4nwcb4WLbUF5QbMAXqsWKpyHd8qocqdww0bsBd3gCqtWoexFKPeKQ9ZqQVHYg==
react-native-iap@^3.3.8:
version "3.3.8"
resolved "https://registry.yarnpkg.com/react-native-iap/-/react-native-iap-3.3.8.tgz#4db012e60f4fd8473122fb48d79adb498befc7fa"
integrity sha512-AP+8VqXcAs48GUmqJPgRWcVpuCT2dWJMm6LQQPNw8B3jYV8BOTgpOQ4Q0Um92u04z2C9nAubyvjR+3tPbxSZag==
dependencies:
dooboolab-welcome "^1.1.0"