223 lines
8.6 KiB
TypeScript
223 lines
8.6 KiB
TypeScript
// Metro module 12497 (f12498).
|
|
import UserStore from "../../stores/UserStore";
|
|
import SubscriptionStore from "../../stores/billing/SubscriptionStore";
|
|
import UserOfferStore from "../../stores/billing/UserOfferStore";
|
|
import EntitlementStore from "../../stores/game_store/EntitlementStore";
|
|
import PromotionsStore from "./promotions/PromotionsStore";
|
|
import { PremiumTypes, PurchasedFlags } from "./PremiumConstants";
|
|
import { PaymentGateways, SubscriptionStatusTypes } from "../../Constants";
|
|
import Module3771 from "../../_bundle/Module3771";
|
|
import PremiumUtils from "../../utils/PremiumUtils";
|
|
import { isAndroid } from "../../utils/PlatformUtils";
|
|
import { isMobile } from "../../_bundle/Module4426";
|
|
import { getIsPaymentsBlocked, useIsPaymentsBlocked } from "../billing/experiments/BlockedPaymentsCountryExperiment";
|
|
import { useBogoPromotion } from "./promotions/PromotionsHooks";
|
|
import { getBogoPromotionGateEnabled, useBogoPromotionGateEnabled } from "./experiments/BogoPromotionExperiment";
|
|
import { useStateFromStoresObject } from "../../_bundle/defaultAreStatesEqual";
|
|
import { usePremiumTrialOffer } from "./hooks/usePremiumTrialOffer.android";
|
|
import { usePremiumDiscountOffer } from "./hooks/usePremiumDiscountOffer.android";
|
|
import useScheduledForcedUpdate from "./hooks/useScheduledForcedUpdate";
|
|
import { getBogoMarketingMaterialsEnabled, useBogoMarketingMaterialsEnabled } from "./experiments/BOGOPromotionMarketingMaterialsExperiments";
|
|
import { fetchMostRecentSubscription, fetchSubscriptions } from "../billing/actions/BillingActionCreators";
|
|
import { fetchActiveBogoPromotion } from "./promotions/PromotionsActionCreators";
|
|
let isEligibleForBOGOPromotion;
|
|
const isUserEligibleBasedOnCurrentOrPreviousSubs = function isUserEligibleBasedOnCurrentOrPreviousSubs({ experimentEnabled, premiumSubscription, mostRecentSubscription, previousPremiumSubscription }) {
|
|
if (experimentEnabled) {
|
|
if (mostRecentSubscription != null && mostRecentSubscription.status === SubscriptionStatusTypes.ENDED) {
|
|
const endedAt = mostRecentSubscription.endedAt;
|
|
const hasPremiumAtLeast = mostRecentSubscription.hasPremiumAtLeast(PremiumTypes.TIER_2);
|
|
if (endedAt != null && hasPremiumAtLeast && Module3771().subtract(10, "days").isBefore(endedAt)) {
|
|
return false;
|
|
}
|
|
}
|
|
if (previousPremiumSubscription != null && previousPremiumSubscription.status === SubscriptionStatusTypes.ENDED) {
|
|
const endedAt2 = previousPremiumSubscription.endedAt;
|
|
const hasPremiumAtLeast2 = previousPremiumSubscription.hasPremiumAtLeast(PremiumTypes.TIER_2);
|
|
if (endedAt2 != null && hasPremiumAtLeast2 && Module3771().subtract(10, "days").isBefore(endedAt2)) {
|
|
return false;
|
|
}
|
|
}
|
|
L22: {
|
|
if (premiumSubscription != null) {
|
|
const hasPremiumAtLeast3 = premiumSubscription.hasPremiumAtLeast(PremiumTypes.TIER_2);
|
|
const currentUser = UserStore.getCurrentUser();
|
|
const r59 = !!premiumSubscription?.hasActiveTrial && PremiumUtils.isPremiumExactly(currentUser, PremiumTypes.TIER_0);
|
|
const r71 = isAndroid() && premiumSubscription.paymentGateway !== PaymentGateways.GOOGLE;
|
|
if (!hasPremiumAtLeast3 && !r59 && !r71) {
|
|
break L22;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
return isMobile ? !EntitlementStore.isFractionalPremiumActive() : !isMobile;
|
|
}
|
|
return false;
|
|
};
|
|
isEligibleForBOGOPromotion = async function isEligibleForBOGOPromotion(c27297_0) {
|
|
let r152;
|
|
let c27297_2;
|
|
let c30524_0, c30524_1, c30524_2, c30524_3, c30524_4, c30524_5, c30524_6, c30524_7;
|
|
L39: {
|
|
L37: {
|
|
L27: {
|
|
c27297_2 = void 0;
|
|
c30524_0 = void 0;
|
|
if (c27297_0 !== void 0) {
|
|
c30524_0 = c27297_0;
|
|
c30524_1 = void 0;
|
|
c30524_2 = void 0;
|
|
c30524_3 = void 0;
|
|
c30524_4 = void 0;
|
|
c30524_5 = void 0;
|
|
c30524_6 = void 0;
|
|
c30524_7 = void 0;
|
|
} else {
|
|
c30524_0 = true;
|
|
c30524_1 = void 0;
|
|
c30524_2 = void 0;
|
|
c30524_3 = void 0;
|
|
c30524_4 = void 0;
|
|
c30524_5 = void 0;
|
|
c30524_6 = void 0;
|
|
c30524_7 = void 0;
|
|
}
|
|
await void 0;
|
|
c30524_1 = UserStore.getCurrentUser();
|
|
const r13 = c30524_1;
|
|
c30524_2 = !(r13 == null ? void 0 : r13.isClaimed());
|
|
c30524_3 = getIsPaymentsBlocked();
|
|
c30524_4 = getBogoPromotionGateEnabled("bogo eligibility async check");
|
|
c30524_5 = getBogoMarketingMaterialsEnabled("bogo marketing eligibility async check");
|
|
let r80 = !isMobile;
|
|
if (isMobile) {
|
|
r80 = isAndroid();
|
|
}
|
|
c30524_6 = r80;
|
|
if (c30524_2) {
|
|
break L39;
|
|
}
|
|
if (c30524_3) {
|
|
break L39;
|
|
}
|
|
if (!c30524_4) {
|
|
break L39;
|
|
}
|
|
if (c30524_0 && !c30524_5) {
|
|
break L39;
|
|
}
|
|
if (!c30524_6) {
|
|
break L39;
|
|
}
|
|
if (UserOfferStore.hasFetchedOffer()) {
|
|
if (UserOfferStore.hasAnyUnexpiredOffer()) {
|
|
break L27;
|
|
}
|
|
if (UserOfferStore.hasAnyUnexpiredDiscountOffer()) {
|
|
break L27;
|
|
}
|
|
}
|
|
const hasFetchedMostRecentPremiumTypeSubscription = SubscriptionStore.hasFetchedMostRecentPremiumTypeSubscription();
|
|
let r104 = !hasFetchedMostRecentPremiumTypeSubscription;
|
|
if (!hasFetchedMostRecentPremiumTypeSubscription) {
|
|
const currentUser = UserStore.getCurrentUser();
|
|
r104 = currentUser == null ? void 0 : currentUser.hasPurchasedFlag(PurchasedFlags.PREMIUM_TIER_2);
|
|
}
|
|
if (r104) {
|
|
await fetchMostRecentSubscription();
|
|
}
|
|
if (!SubscriptionStore.hasFetchedSubscriptions()) {
|
|
await fetchSubscriptions();
|
|
}
|
|
c30524_7 = SubscriptionStore.getMostRecentPremiumTypeSubscription();
|
|
r152 = (0, isUserEligibleBasedOnCurrentOrPreviousSubs)({
|
|
experimentEnabled: c30524_4,
|
|
premiumSubscription: SubscriptionStore.getPremiumTypeSubscription(),
|
|
mostRecentSubscription: c30524_7,
|
|
previousPremiumSubscription: SubscriptionStore.getPreviousPremiumTypeSubscription()
|
|
});
|
|
break L37;
|
|
}
|
|
return false;
|
|
}
|
|
return r152;
|
|
}
|
|
return false;
|
|
};
|
|
export { isUserEligibleBasedOnCurrentOrPreviousSubs };
|
|
export function useIsEligibleForBogoPromotion(r12 = true) {
|
|
const isPaymentsBlocked = useIsPaymentsBlocked();
|
|
const promotion = useBogoPromotion().promotion;
|
|
const bogoPromotionGateEnabled = useBogoPromotionGateEnabled("bogo eligibility hook");
|
|
const stateFromStoresObject = useStateFromStoresObject([SubscriptionStore], () => ({
|
|
mostRecentSubscription: SubscriptionStore.getMostRecentPremiumTypeSubscription(),
|
|
premiumSubscription: SubscriptionStore.getPremiumTypeSubscription(),
|
|
previousPremiumSubscription: SubscriptionStore.getPreviousPremiumTypeSubscription()
|
|
}));
|
|
const { mostRecentSubscription, premiumSubscription, previousPremiumSubscription } = stateFromStoresObject;
|
|
const premiumTrialOffer = usePremiumTrialOffer();
|
|
const premiumDiscountOffer = usePremiumDiscountOffer();
|
|
const r20 = Date;
|
|
let r47 = promotion?.endDate;
|
|
if (r47 == null) {
|
|
r47 = 0;
|
|
}
|
|
const r51 = new r20(r47).valueOf();
|
|
const r54 = Date.now();
|
|
const r4 = r54 > r51;
|
|
useScheduledForcedUpdate({
|
|
delay: r4 ? -1 : r51 - r54
|
|
});
|
|
let r64 = isMobile ? isAndroid() : !isMobile;
|
|
const isUserEligibleBasedOnCurrentOrPreviousSubs2 = isUserEligibleBasedOnCurrentOrPreviousSubs({
|
|
experimentEnabled: bogoPromotionGateEnabled,
|
|
premiumSubscription,
|
|
mostRecentSubscription,
|
|
previousPremiumSubscription
|
|
});
|
|
let r75 = useBogoMarketingMaterialsEnabled("bogo marketing eligibility hook");
|
|
let r76 = !r4;
|
|
if (!r4) {
|
|
if (!r12) {
|
|
if (r64) {
|
|
r64 = isUserEligibleBasedOnCurrentOrPreviousSubs2;
|
|
}
|
|
if (r64) {
|
|
r64 = premiumTrialOffer == null;
|
|
}
|
|
if (r64) {
|
|
r64 = promotion != null;
|
|
}
|
|
if (r64) {
|
|
r64 = !isPaymentsBlocked;
|
|
}
|
|
if (r64) {
|
|
r64 = premiumDiscountOffer == null;
|
|
}
|
|
r75 = r64;
|
|
}
|
|
r76 = r75;
|
|
}
|
|
return r76;
|
|
}
|
|
export { isEligibleForBOGOPromotion };
|
|
export async function maybeFetchActiveBogoPromotion() {
|
|
let c27298_1;
|
|
let c30525_0;
|
|
L17: {
|
|
L15: {
|
|
c27298_1 = void 0;
|
|
c30525_0 = void 0;
|
|
if (await isEligibleForBOGOPromotion(false)) {
|
|
c30525_0 = PromotionsStore.bogoPromotion;
|
|
if (c30525_0 != null && new Date(c30525_0.endDate).valueOf() >= Date.now()) {
|
|
break L15;
|
|
}
|
|
await fetchActiveBogoPromotion();
|
|
break L17;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|