mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 12:51:42 +03:00
commit
2e3679517c
6
App.js
6
App.js
@ -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;
|
||||
|
@ -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
5
src/config/bugsnag.js
Normal 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;
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
// Component Functions
|
||||
async componentDidMount() {
|
||||
componentDidMount() {
|
||||
this._getItems();
|
||||
this._purchaseUpdatedListener();
|
||||
}
|
||||
|
||||
_getAvailablePurchases = async () => {
|
||||
try {
|
||||
const purchases = await RNIap.getAvailablePurchases();
|
||||
console.info('Available purchases :: ', purchases);
|
||||
if (purchases && purchases.length > 0) {
|
||||
this.setState({
|
||||
receipt: purchases[0].transactionReceipt,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(err.code, err.message);
|
||||
Alert.alert(err.message);
|
||||
componentWillUnmount() {
|
||||
if (this.purchaseUpdateSubscription) {
|
||||
this.purchaseUpdateSubscription.remove();
|
||||
this.purchaseUpdateSubscription = null;
|
||||
}
|
||||
if (this.purchaseErrorSubscription) {
|
||||
this.purchaseErrorSubscription.remove();
|
||||
this.purchaseErrorSubscription = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Component Functions
|
||||
|
||||
_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);
|
||||
});
|
||||
};
|
||||
|
||||
_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' };
|
||||
|
@ -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"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user