94 lines
3.6 KiB
TypeScript
94 lines
3.6 KiB
TypeScript
// Metro module 16323 (f16324).
|
|
import UserStore from "../../stores/UserStore";
|
|
import BillingInfoStore from "../../stores/billing/BillingInfoStore";
|
|
import SubscriptionStore from "../../stores/billing/SubscriptionStore";
|
|
import EntitlementStore from "../../stores/game_store/EntitlementStore";
|
|
import { PREMIUM_SUBSCRIPTION_APPLICATION, PremiumTypes } from "./PremiumConstants";
|
|
import AutomaticLifecycleManager from "../../lib/AutomaticLifecycleManager";
|
|
import * as _PremiumTypeUtils from "../../utils/PremiumTypeUtils";
|
|
import { isPremium } from "../../utils/PremiumTypeUtils";
|
|
import { fetchSubscriptions, fetchMostRecentSubscription, fetchIpCountryCode, fetchPaymentSources } from "../billing/actions/BillingActionCreators";
|
|
import { fetchUserEntitlementsForApplication } from "../../actions/EntitlementActionCreators";
|
|
class SubscriptionManager extends AutomaticLifecycleManager {
|
|
constructor() {
|
|
let c22969_0;
|
|
super(...arguments);
|
|
const _this = this;
|
|
this.actions = {
|
|
POST_CONNECTION_OPEN: () => {
|
|
_this.maybeFetchSubscriptions();
|
|
_this.maybeFetchCountryCode();
|
|
_this.maybeFetchMostRecentSubscription();
|
|
}
|
|
};
|
|
this.maybeFetchSubscriptions = async () => {
|
|
let c31028_1;
|
|
let c31813_0;
|
|
L30: {
|
|
L22: {
|
|
L23: {
|
|
c31028_1 = void 0;
|
|
c31813_0 = void 0;
|
|
if (!isPremium(UserStore.getCurrentUser())) {
|
|
break L30;
|
|
}
|
|
if (SubscriptionStore.hasFetchedSubscriptions() || BillingInfoStore.isSubscriptionFetching) {
|
|
c31813_0 = SubscriptionStore.getPremiumSubscription();
|
|
if (c31813_0?.paymentSourceId != null || EntitlementStore.applicationIdsFetched.has(PREMIUM_SUBSCRIPTION_APPLICATION)) {
|
|
break L30;
|
|
}
|
|
await fetchUserEntitlementsForApplication(PREMIUM_SUBSCRIPTION_APPLICATION);
|
|
break L22;
|
|
}
|
|
await fetchSubscriptions();
|
|
c31813_0 = SubscriptionStore.getPremiumSubscription();
|
|
if (c31813_0?.paymentSourceId != null || EntitlementStore.applicationIdsFetched.has(PREMIUM_SUBSCRIPTION_APPLICATION)) {
|
|
break L23;
|
|
}
|
|
await fetchUserEntitlementsForApplication(PREMIUM_SUBSCRIPTION_APPLICATION);
|
|
break L22;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
this.maybeFetchMostRecentSubscription = () => {
|
|
const currentUser = UserStore.getCurrentUser();
|
|
let r7 = currentUser?.premiumType;
|
|
if (r7 == null) {
|
|
r7 = null;
|
|
}
|
|
const isPremiumAtMost = _PremiumTypeUtils.isPremiumAtMost(r7, PremiumTypes.TIER_1);
|
|
const isFetchingMostRecentSubscription = SubscriptionStore.getIsFetchingMostRecentSubscription();
|
|
if (currentUser != null && isPremiumAtMost && currentUser.hasHadPremium() && !isFetchingMostRecentSubscription) {
|
|
fetchMostRecentSubscription();
|
|
}
|
|
};
|
|
c22969_0 = this;
|
|
this.maybeFetchCountryCode = async () => {
|
|
L13: {
|
|
if (isPremium(UserStore.getCurrentUser()) && !BillingInfoStore.ipCountryCodeLoaded) {
|
|
await c22969_0.fetchCountryCode();
|
|
break L13;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
this.fetchCountryCode = async () => {
|
|
let c31030_0;
|
|
L13: {
|
|
c31030_0 = void 0;
|
|
await fetchIpCountryCode();
|
|
if (BillingInfoStore.ipCountryCode != null) {
|
|
await fetchPaymentSources();
|
|
break L13;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
const subscriptionManager = new SubscriptionManager();
|
|
export default subscriptionManager;
|