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:path="/signup"
/>
<data
android:scheme="https"
android:host="ecency.com"
android:path="/purchase"
/>
</intent-filter>
<intent-filter android:label="Ecency" >
<action android:name="android.intent.action.VIEW" />

View File

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

View File

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

View File

@ -585,7 +585,8 @@
},
"deep_link": {
"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": {
"posts": "Posts",

View File

@ -28,21 +28,8 @@ class InAppPurchaseContainer extends Component {
}
// Component Life Cycle Functions
async componentDidMount() {
try {
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();
componentDidMount() {
this._initContainer();
}
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
//that are set to be consumed yet
_consumeAvailablePurchases = async () => {
@ -152,7 +168,7 @@ class InAppPurchaseContainer extends Component {
const products = await RNIap.getProducts(skus);
console.log(products);
products.sort((a, b) => parseFloat(a.price) - parseFloat(b.price)).reverse();
await this.setState({ productList: products });
this.setState({ productList: products });
} catch (err) {
bugsnagInstance.notify(err);
Alert.alert(
@ -163,7 +179,7 @@ class InAppPurchaseContainer extends Component {
);
}
await this.setState({ isLoading: false });
this.setState({ isLoading: false });
};
_buyItem = async (sku) => {

View File

@ -91,6 +91,7 @@ import parseAuthUrl from '../../../utils/parseAuthUrl';
import { purgeExpiredCache } from '../../../redux/actions/cacheActions';
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
import MigrationHelpers from '../../../utils/migrationHelpers';
import { deepLinkParser } from '../../../utils/deepLinkParser';
// Workaround
let previousAppState = 'background';
@ -236,93 +237,25 @@ class ApplicationContainer extends Component {
};
_handleDeepLink = async (url = '') => {
if (!url || url.indexOf('ShareMedia://') >= 0) return;
let routeName;
let params;
let content;
let profile;
let keey;
const { currentAccount } = this.props;
const postUrl = postUrlParser(url);
const { author, permlink, feedType, tag } = postUrl || {};
const { currentAccount, intl } = this.props;
try{
if (author) {
if (
!permlink ||
permlink === 'wallet' ||
permlink === 'points' ||
permlink === 'comments' ||
permlink === 'replies' ||
permlink === 'posts'
) {
let deepLinkFilter;
if (permlink) {
deepLinkFilter = permlink === 'points' ? 'wallet' : permlink;
}
const deepLinkData = await deepLinkParser(url, currentAccount);
const { routeName, params, key } = deepLinkData || {};
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) {
if (routeName && key) {
navigate({
routeName,
params,
key: keey,
key: key,
});
} else {
throw new Error(intl.formatMessage({id:'deep_link.invalid_link'}))
}
} catch(err){
this._handleAlert(err.message)
}
};
_compareAndPromptForUpdate = async () => {