Merge pull request #2418 from ecency/nt/iap

rearranged iap initializer
This commit is contained in:
Feruz M 2022-08-12 10:21:12 +03:00 committed by GitHub
commit a9c08de51e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 104 deletions

View File

@ -92,6 +92,11 @@
android:host="ecency.com" android:host="ecency.com"
android:path="/signup" android:path="/signup"
/> />
<data
android:scheme="https"
android:host="ecency.com"
android:path="/purchase"
/>
</intent-filter> </intent-filter>
<intent-filter android:label="Ecency" > <intent-filter android:label="Ecency" >
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />

View File

@ -827,4 +827,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311 PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311
COCOAPODS: 1.11.2 COCOAPODS: 1.11.3

View File

@ -21,7 +21,6 @@ import { Modal } from '../modal';
// Styles // Styles
import styles from './postBoostStyles'; import styles from './postBoostStyles';
import { OptionsModal } from '../atoms'; import { OptionsModal } from '../atoms';
import { deepLinkParser } from '../../utils/deepLinkParser';
import postUrlParser from '../../utils/postUrlParser'; import postUrlParser from '../../utils/postUrlParser';
class BoostPostScreen extends PureComponent { class BoostPostScreen extends PureComponent {

View File

@ -585,7 +585,8 @@
}, },
"deep_link": { "deep_link": {
"no_existing_user": "No existing user", "no_existing_user": "No existing user",
"no_existing_post": "No existing post" "no_existing_post": "No existing post",
"invalid_link":"Url is invalid, you may try again with valid url or try opening it in web browser"
}, },
"search": { "search": {
"posts": "Posts", "posts": "Posts",

View File

@ -28,21 +28,8 @@ class InAppPurchaseContainer extends Component {
} }
// Component Life Cycle Functions // Component Life Cycle Functions
async componentDidMount() { componentDidMount() {
try { this._initContainer();
await RNIap.initConnection();
if (Platform.OS === 'android') {
await RNIap.flushFailedPurchasesCachedAsPendingAndroid();
}
this._consumeAvailablePurchases()
} catch (err) {
bugsnagInstance.notify(err);
console.warn(err.code, err.message);
}
this._getItems();
this._purchaseUpdatedListener();
} }
componentWillUnmount() { componentWillUnmount() {
@ -59,6 +46,35 @@ class InAppPurchaseContainer extends Component {
} }
_initContainer = async () => {
const {
intl,
} = this.props;
try {
await RNIap.initConnection();
if (Platform.OS === 'android') {
await RNIap.flushFailedPurchasesCachedAsPendingAndroid();
}
await this._consumeAvailablePurchases()
this._getItems();
this._purchaseUpdatedListener();
} catch (err) {
bugsnagInstance.notify(err);
console.warn(err.code, err.message);
Alert.alert(
intl.formatMessage({
id: 'alert.connection_issues',
}),
err.message
);
}
}
//this snippet consumes all previously bought purchases //this snippet consumes all previously bought purchases
//that are set to be consumed yet //that are set to be consumed yet
_consumeAvailablePurchases = async () => { _consumeAvailablePurchases = async () => {
@ -152,7 +168,7 @@ class InAppPurchaseContainer extends Component {
const products = await RNIap.getProducts(skus); const products = await RNIap.getProducts(skus);
console.log(products); console.log(products);
products.sort((a, b) => parseFloat(a.price) - parseFloat(b.price)).reverse(); products.sort((a, b) => parseFloat(a.price) - parseFloat(b.price)).reverse();
await this.setState({ productList: products }); this.setState({ productList: products });
} catch (err) { } catch (err) {
bugsnagInstance.notify(err); bugsnagInstance.notify(err);
Alert.alert( Alert.alert(
@ -163,7 +179,7 @@ class InAppPurchaseContainer extends Component {
); );
} }
await this.setState({ isLoading: false }); this.setState({ isLoading: false });
}; };
_buyItem = async (sku) => { _buyItem = async (sku) => {

View File

@ -91,6 +91,7 @@ import parseAuthUrl from '../../../utils/parseAuthUrl';
import { purgeExpiredCache } from '../../../redux/actions/cacheActions'; import { purgeExpiredCache } from '../../../redux/actions/cacheActions';
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction'; import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
import MigrationHelpers from '../../../utils/migrationHelpers'; import MigrationHelpers from '../../../utils/migrationHelpers';
import { deepLinkParser } from '../../../utils/deepLinkParser';
// Workaround // Workaround
let previousAppState = 'background'; let previousAppState = 'background';
@ -236,93 +237,25 @@ class ApplicationContainer extends Component {
}; };
_handleDeepLink = async (url = '') => { _handleDeepLink = async (url = '') => {
if (!url || url.indexOf('ShareMedia://') >= 0) return; const { currentAccount, intl } = this.props;
let routeName; try{
let params; const deepLinkData = await deepLinkParser(url, currentAccount);
let content; const { routeName, params, key } = deepLinkData || {};
let profile;
let keey;
const { currentAccount } = this.props;
const postUrl = postUrlParser(url); if (routeName && key) {
const { author, permlink, feedType, tag } = postUrl || {};
try {
if (author) {
if (
!permlink ||
permlink === 'wallet' ||
permlink === 'points' ||
permlink === 'comments' ||
permlink === 'replies' ||
permlink === 'posts'
) {
let deepLinkFilter;
if (permlink) {
deepLinkFilter = permlink === 'points' ? 'wallet' : permlink;
}
profile = await getUser(author);
routeName = ROUTES.SCREENS.PROFILE;
params = {
username: get(profile, 'name'),
reputation: get(profile, 'reputation'),
deepLinkFilter, //TODO: process this in profile screen
};
keey = get(profile, 'name');
} else if (permlink === 'communities') {
routeName = ROUTES.SCREENS.WEB_BROWSER;
params = {
url: url,
};
keey = 'WebBrowser';
} else if (permlink) {
content = await getPost(author, permlink, currentAccount.name);
routeName = ROUTES.SCREENS.POST;
params = {
content,
};
keey = `${author}/${permlink}`;
}
}
if (feedType === 'hot' || feedType === 'trending' || feedType === 'created') {
if (!tag) {
routeName = ROUTES.SCREENS.TAG_RESULT;
} else if (/hive-[1-3]\d{4,6}$/.test(tag)) {
routeName = ROUTES.SCREENS.COMMUNITY;
} else {
routeName = ROUTES.SCREENS.TAG_RESULT;
}
params = {
tag,
filter: feedType,
};
keey = `${feedType}/${tag || ''}`;
}
} catch (error) {
this._handleAlert('deep_link.no_existing_user');
}
if (!routeName) {
const { mode, referredUser } = parseAuthUrl(url);
if (mode === 'SIGNUP') {
routeName = ROUTES.SCREENS.REGISTER;
params = {
referredUser,
};
keey = `${mode}/${referredUser || ''}`;
}
}
if (routeName && keey) {
navigate({ navigate({
routeName, routeName,
params, params,
key: keey, key: key,
}); });
} else {
throw new Error(intl.formatMessage({id:'deep_link.invalid_link'}))
} }
} catch(err){
this._handleAlert(err.message)
}
}; };
_compareAndPromptForUpdate = async () => { _compareAndPromptForUpdate = async () => {