144 lines
6.9 KiB
TypeScript
144 lines
6.9 KiB
TypeScript
// Metro module 5848 (f5849).
|
|
import { useState, useEffect } from "react";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import SubscriptionStore from "../../../stores/billing/SubscriptionStore";
|
|
import EntitlementStore from "../../../stores/game_store/EntitlementStore";
|
|
import { EntitlementSourceTypes, EntitlementTypes, SubscriptionStatusTypes } from "../../../Constants";
|
|
import { FractionalPremiumStates, PREMIUM_SUBSCRIPTION_APPLICATION } from "../../premium/PremiumConstants";
|
|
import Module3771 from "../../../_bundle/Module3771";
|
|
import Module38 from "../../../_bundle/Module38";
|
|
import { captureBillingMessage } from "../../../utils/BillingUtils";
|
|
import { extendDateWithUnconsumedFractionalPremium } from "../../../utils/PremiumUtils";
|
|
import { useStateFromStores, useStateFromStoresArray } from "../../../_bundle/Module589";
|
|
import useMountEffect from "../../../hooks/useMountEffect";
|
|
import { fetchUserEntitlements, fetchUserEntitlementsForApplication } from "../../../actions/EntitlementActionCreators";
|
|
import { isEqual } from "../../../_bundle/Module12";
|
|
const calculateFractionalPremiumInfo = function calculateFractionalPremiumInfo(a0) {
|
|
let r42;
|
|
const { isFetching = false, entitlements, unactivatedFractionalPremiumUnits, currentUser, premiumSubscription, fetchedAllEntitlements } = a0;
|
|
let excludeReverseTrialFromCountdown2 = a0.excludeReverseTrialFromCountdown;
|
|
const r24 = {
|
|
isFractionalPremiumActive: false,
|
|
fractionalState: FractionalPremiumStates.NONE,
|
|
startsAt: Module3771(0),
|
|
endsAt: Module3771(0),
|
|
currentEntitlementId: "",
|
|
currentEntitlementEndsAt: Module3771(0),
|
|
unactivatedUnits: [],
|
|
fetched: fetchedAllEntitlements
|
|
};
|
|
if (isFetching) {
|
|
return {
|
|
...r24,
|
|
fetched: false
|
|
};
|
|
}
|
|
L35: {
|
|
if (currentUser != null) {
|
|
if (entitlements.length === 0 && unactivatedFractionalPremiumUnits.length === 0) {
|
|
break L35;
|
|
}
|
|
L10: {
|
|
r42 = entitlements.filter((entitlement) => entitlement.endsAt != null && entitlement.startsAt != null).sort((a, b) => {
|
|
Module38(a.endsAt != null && b.endsAt != null, "endsAt should not be null");
|
|
return a.endsAt < b.endsAt ? -1 : a.endsAt > b.endsAt ? 1 : 0;
|
|
});
|
|
r42.reverse();
|
|
if (r42.length > 0) {
|
|
if (r42.length === entitlements.length && r42[0].startsAt != null && r42[0].endsAt != null) {
|
|
break L10;
|
|
}
|
|
const r99 = {
|
|
extra: {
|
|
entitlementIds: Array.from(entitlements.values()).map((item) => item.id)
|
|
}
|
|
};
|
|
const r100 = "fractional redemption entitlements should have startsAt/endsAt";
|
|
captureBillingMessage(r100, r99);
|
|
throw new Error(r100);
|
|
}
|
|
}
|
|
let r52 = r42[0];
|
|
if (r52 == null) {
|
|
r52 = null;
|
|
}
|
|
let NONE = FractionalPremiumStates.NONE;
|
|
if (r52 != null) {
|
|
NONE = premiumSubscription != null && premiumSubscription.status === SubscriptionStatusTypes.PAUSED ? FractionalPremiumStates.FP_SUB_PAUSED : FractionalPremiumStates.FP_ONLY;
|
|
}
|
|
if (excludeReverseTrialFromCountdown2) {
|
|
excludeReverseTrialFromCountdown2 = r52?.sourceType === EntitlementSourceTypes.REVERSE_TRIAL;
|
|
}
|
|
return {
|
|
isFractionalPremiumActive: r52 != null,
|
|
fractionalState: NONE,
|
|
startsAt: r52 != null ? Module3771(r52.startsAt) : Module3771(0),
|
|
endsAt: r52 != null ? Module3771(extendDateWithUnconsumedFractionalPremium(r52.endsAt, unactivatedFractionalPremiumUnits, void 0, excludeReverseTrialFromCountdown2)) : Module3771(0),
|
|
currentEntitlementId: r52 != null ? r52.id : "",
|
|
currentEntitlementEndsAt: r52 != null ? Module3771(r52.endsAt) : Module3771(0),
|
|
unactivatedUnits: unactivatedFractionalPremiumUnits,
|
|
fetched: fetchedAllEntitlements
|
|
};
|
|
}
|
|
}
|
|
return r24;
|
|
};
|
|
export default function useFractionalPremiumInfo(r4 = {
|
|
forceFetch: false,
|
|
excludeReverseTrial: false,
|
|
excludeReverseTrialFromCountdown: false
|
|
}) {
|
|
let stateFromStoresArray, stateFromStores2, stateFromStoresArray2, stateFromStores3, setState;
|
|
const { forceFetch, excludeReverseTrial, excludeReverseTrialFromCountdown } = r4;
|
|
stateFromStoresArray = void 0;
|
|
stateFromStores2 = void 0;
|
|
stateFromStoresArray2 = void 0;
|
|
stateFromStores3 = void 0;
|
|
setState = void 0;
|
|
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
|
|
stateFromStoresArray = useStateFromStoresArray([EntitlementStore], () => EntitlementStore.getFractionalPremium({
|
|
excludeReverseTrial
|
|
}));
|
|
stateFromStores2 = useStateFromStores([EntitlementStore], () => EntitlementStore.fetchedAllEntitlements);
|
|
stateFromStoresArray2 = useStateFromStoresArray([EntitlementStore], () => EntitlementStore.getUnactivatedFractionalPremiumUnits());
|
|
stateFromStores3 = useStateFromStores([SubscriptionStore], () => SubscriptionStore.getPremiumTypeSubscription());
|
|
let state;
|
|
[state, setState] = useState(calculateFractionalPremiumInfo({
|
|
isFetching: stateFromStores != null && !EntitlementStore.fetchingAllEntitlements && (EntitlementStore.fetchedAllEntitlements ? forceFetch : !EntitlementStore.fetchedAllEntitlements) || EntitlementStore.fetchingAllEntitlements || stateFromStores != null && !EntitlementStore.applicationIdsFetching.has(PREMIUM_SUBSCRIPTION_APPLICATION) && !EntitlementStore.applicationIdsFetched.has(PREMIUM_SUBSCRIPTION_APPLICATION) || EntitlementStore.applicationIdsFetching.has(PREMIUM_SUBSCRIPTION_APPLICATION),
|
|
entitlements: stateFromStoresArray,
|
|
unactivatedFractionalPremiumUnits: stateFromStoresArray2,
|
|
currentUser: stateFromStores,
|
|
premiumSubscription: stateFromStores3,
|
|
fetchedAllEntitlements: stateFromStores2,
|
|
excludeReverseTrialFromCountdown
|
|
}));
|
|
useMountEffect(() => {
|
|
if (stateFromStores != null && !EntitlementStore.fetchingAllEntitlements && (EntitlementStore.fetchedAllEntitlements ? forceFetch : !EntitlementStore.fetchedAllEntitlements)) {
|
|
fetchUserEntitlements({
|
|
entitlementType: EntitlementTypes.FRACTIONAL_REDEMPTION
|
|
});
|
|
}
|
|
if (stateFromStores != null && !EntitlementStore.applicationIdsFetching.has(PREMIUM_SUBSCRIPTION_APPLICATION) && !EntitlementStore.applicationIdsFetched.has(PREMIUM_SUBSCRIPTION_APPLICATION)) {
|
|
fetchUserEntitlementsForApplication(PREMIUM_SUBSCRIPTION_APPLICATION);
|
|
}
|
|
});
|
|
useEffect(() => {
|
|
let c25630_0 = calculateFractionalPremiumInfo({
|
|
entitlements: stateFromStoresArray,
|
|
unactivatedFractionalPremiumUnits: stateFromStoresArray2,
|
|
currentUser: stateFromStores,
|
|
premiumSubscription: stateFromStores3,
|
|
fetchedAllEntitlements: stateFromStores2,
|
|
excludeReverseTrialFromCountdown
|
|
});
|
|
setState((prevState) => {
|
|
let r9 = c25630_0;
|
|
if (isEqual(prevState, r9)) {
|
|
r9 = prevState;
|
|
}
|
|
return r9;
|
|
});
|
|
}, [stateFromStores, stateFromStoresArray, stateFromStores3, stateFromStoresArray2, stateFromStores2, excludeReverseTrialFromCountdown]);
|
|
return state;
|
|
};
|