decord/source/modules/billing/hooks/useFractionalPremiumInfo.tsx
2026-08-05 07:35:12 +00:00

237 lines
9.8 KiB
TypeScript

// Module ID: 6754
// Function ID: 6755
// Name: calculateFractionalPremiumInfo
// Dependencies: [32, 19, 1874, 3907, 6755, 676, 1876, 3837, 38, 3916, 3901, 589, 4681, 6756, 12, 2]
// Exports: default
// Module 6754 (calculateFractionalPremiumInfo)
import _slicedToArray from "_slicedToArray";
import noop from "noop";
import mergeGuildAvatar from "mergeGuildAvatar";
import reset from "reset";
import addEntitlement from "addEntitlement";
import ME from "ME";
import GuildFeatures from "GuildFeatures";
let c10;
let c9;
let closure_12;
let metroImportAll;
let unpackModuleId;
const require = arg1;
function calculateFractionalPremiumInfo(isFetching) {
let entitlements;
let excludeReverseTrialFromCountdown;
let fetchedAllEntitlements;
let premiumSubscription;
let unactivatedFractionalPremiumUnits;
let flag = isFetching.isFetching;
if (flag === undefined) {
flag = false;
}
({ entitlements, unactivatedFractionalPremiumUnits, premiumSubscription, fetchedAllEntitlements, excludeReverseTrialFromCountdown } = isFetching);
let obj = { isFractionalPremiumActive: false, fractionalState: constants3.NONE, startsAt: importDefault(3837)(0), endsAt: importDefault(3837)(0), currentEntitlementId: "", currentEntitlementEndsAt: importDefault(3837)(0), unactivatedUnits: [], fetched: fetchedAllEntitlements };
if (flag) {
obj = {};
const merged = Object.assign(obj);
obj.fetched = false;
return obj;
} else {
if (null != isFetching.currentUser) {
const found = entitlements.filter((endsAt) => null != endsAt.endsAt && null != endsAt.startsAt);
const sorted = found.sort((endsAt, endsAt2) => {
let tmp2 = null != endsAt.endsAt;
if (tmp2) {
tmp2 = null != endsAt2.endsAt;
}
callback(table[8])(tmp2, "endsAt should not be null");
let num = -1;
if (endsAt.endsAt >= endsAt2.endsAt) {
let num2 = 0;
if (endsAt.endsAt > endsAt2.endsAt) {
num2 = 1;
}
num = num2;
}
return num;
});
const reversed = sorted.reverse();
if (sorted.length > 0) {
const _Array = Array;
const mapped = Array.from(entitlements.values()).map((id) => id.id);
const arr = Array.from(entitlements.values());
obj = { extra: null };
const obj1 = { entitlementIds: null };
obj1[0] = mapped;
obj[0] = obj1;
const result = require(3916) /* _createGatewayCheckoutContext */.captureBillingMessage("fractional redemption entitlements should have startsAt/endsAt", obj);
const _Error = Error;
const error = new Error("fractional redemption entitlements should have startsAt/endsAt");
throw error;
}
let first = sorted[0];
if (first == null) {
first = null;
}
if (null == first) {
if (excludeReverseTrialFromCountdown) {
let sourceType;
if (first != null) {
sourceType = first.sourceType;
}
excludeReverseTrialFromCountdown = sourceType === constants.REVERSE_TRIAL;
}
const obj2 = { isFractionalPremiumActive: null, fractionalState: null, startsAt: null, endsAt: null, currentEntitlementId: null, currentEntitlementEndsAt: null, unactivatedUnits: null, fetched: null };
obj2[0] = null != first;
obj2[1] = tmp7;
if (null != first) {
let tmp11 = tmp2(3837)(first.startsAt);
} else {
tmp11 = tmp2(3837)(0);
}
obj2[2] = tmp11;
if (null != first) {
const obj4 = require(3901) /* getPremiumPlanItem */;
let tmp2ResultResult = tmp2(3837)(obj4.extendDateWithUnconsumedFractionalPremium(first.endsAt, unactivatedFractionalPremiumUnits, undefined, excludeReverseTrialFromCountdown));
const tmp2Result = tmp2(3837);
} else {
tmp2ResultResult = tmp2(3837)(0);
}
obj2[3] = tmp2ResultResult;
let str = "";
if (null != first) {
str = first.id;
}
obj2[4] = str;
if (null != first) {
let tmp18 = tmp2(3837)(first.endsAt);
} else {
tmp18 = tmp2(3837)(0);
}
obj2[5] = tmp18;
obj2[6] = unactivatedFractionalPremiumUnits;
obj2[7] = fetchedAllEntitlements;
return obj2;
} else {
if (null == premiumSubscription) {
const FP_ONLY = tmp.FP_ONLY;
}
const FP_SUB_PAUSED = tmp.FP_SUB_PAUSED;
}
}
return obj;
}
}
({ EntitlementSourceTypes: metroImportAll, EntitlementTypes: c9, SubscriptionStatusTypes: c10 } = ME);
({ FractionalPremiumStates: unpackModuleId, PREMIUM_SUBSCRIPTION_APPLICATION: closure_12 } = GuildFeatures);
let result = require("mergeGuildAvatar").fileFinishedImporting("modules/billing/hooks/useFractionalPremiumInfo.tsx");
export default function useFractionalPremiumInfo() {
let excludeReverseTrialFromCountdown;
let importDefault;
let obj = arg0;
if (arg0 === undefined) {
obj = { forceFetch: false, excludeReverseTrial: false, excludeReverseTrialFromCountdown: false };
}
const forceFetch = obj.forceFetch;
({ excludeReverseTrial: importDefault, excludeReverseTrialFromCountdown } = obj);
let stateFromStores;
let stateFromStoresArray;
let stateFromStores1;
let stateFromStoresArray1;
let stateFromStores2;
let closure_8;
const items = [stateFromStores1];
stateFromStores = forceFetch(excludeReverseTrialFromCountdown[11]).useStateFromStores(items, () => stateFromStores1.getCurrentUser());
const obj2 = forceFetch(excludeReverseTrialFromCountdown[11]);
let tmp = excludeReverseTrialFromCountdown;
const items1 = [stateFromStores2];
stateFromStoresArray = forceFetch(excludeReverseTrialFromCountdown[11]).useStateFromStoresArray(items1, () => stateFromStores2.getFractionalPremium({ excludeReverseTrial: closure_1 }));
let obj3 = forceFetch(excludeReverseTrialFromCountdown[11]);
const items2 = [stateFromStores2];
stateFromStores1 = forceFetch(excludeReverseTrialFromCountdown[11]).useStateFromStores(items2, () => stateFromStores2.fetchedAllEntitlements);
const obj4 = forceFetch(excludeReverseTrialFromCountdown[11]);
const items3 = [stateFromStores2];
stateFromStoresArray1 = forceFetch(excludeReverseTrialFromCountdown[11]).useStateFromStoresArray(items3, () => stateFromStores2.getUnactivatedFractionalPremiumUnits());
const obj5 = forceFetch(excludeReverseTrialFromCountdown[11]);
const items4 = [stateFromStoresArray1];
stateFromStores2 = forceFetch(excludeReverseTrialFromCountdown[11]).useStateFromStores(items4, () => stateFromStoresArray1.getPremiumTypeSubscription());
let fetchingAllEntitlements = null != stateFromStores;
if (fetchingAllEntitlements) {
fetchingAllEntitlements = !tmp3.fetchingAllEntitlements;
}
if (fetchingAllEntitlements) {
let fetchedAllEntitlements = tmp3.fetchedAllEntitlements;
let tmp9 = !fetchedAllEntitlements;
if (fetchedAllEntitlements) {
tmp9 = forceFetch;
}
fetchingAllEntitlements = tmp9;
}
if (!fetchingAllEntitlements) {
fetchingAllEntitlements = tmp3.fetchingAllEntitlements;
}
if (!fetchingAllEntitlements) {
let tmp10 = null != stateFromStores;
if (tmp10) {
let applicationIdsFetching = tmp3.applicationIdsFetching;
tmp10 = !applicationIdsFetching.has(closure_12);
}
if (tmp10) {
let applicationIdsFetched = tmp3.applicationIdsFetched;
tmp10 = !applicationIdsFetched.has(closure_12);
}
fetchingAllEntitlements = tmp10;
}
if (!fetchingAllEntitlements) {
const applicationIdsFetching2 = tmp3.applicationIdsFetching;
fetchingAllEntitlements = applicationIdsFetching2.has(closure_12);
}
const tmp14 = stateFromStores(stateFromStoresArray.useState(calculateFractionalPremiumInfo({ isFetching: fetchingAllEntitlements, entitlements: stateFromStoresArray, unactivatedFractionalPremiumUnits: stateFromStoresArray1, currentUser: stateFromStores, premiumSubscription: stateFromStores2, fetchedAllEntitlements: stateFromStores1, excludeReverseTrialFromCountdown })), 2);
closure_8 = tmp14[1];
importDefault(tmp[12])(() => {
let tmp3 = null != stateFromStores;
if (tmp3) {
tmp3 = !stateFromStores2.fetchingAllEntitlements;
}
if (tmp3) {
const fetchedAllEntitlements = stateFromStores2.fetchedAllEntitlements;
let tmp6 = !fetchedAllEntitlements;
if (fetchedAllEntitlements) {
tmp6 = forceFetch;
}
tmp3 = tmp6;
}
if (tmp3) {
let obj = forceFetch(excludeReverseTrialFromCountdown[13]);
obj = { entitlementType: null };
obj[0] = outer1_9.FRACTIONAL_REDEMPTION;
const userEntitlements = obj.fetchUserEntitlements(obj);
}
let tmp11 = null != stateFromStores;
if (tmp11) {
const applicationIdsFetching = stateFromStores2.applicationIdsFetching;
tmp11 = !applicationIdsFetching.has(outer1_12);
}
if (tmp11) {
const applicationIdsFetched = stateFromStores2.applicationIdsFetched;
tmp11 = !applicationIdsFetched.has(outer1_12);
}
if (tmp11) {
const userEntitlementsForApplication = forceFetch(excludeReverseTrialFromCountdown[13]).fetchUserEntitlementsForApplication(outer1_12);
const obj3 = forceFetch(excludeReverseTrialFromCountdown[13]);
}
});
const items5 = [stateFromStores, stateFromStoresArray, stateFromStores2, stateFromStoresArray1, stateFromStores1, excludeReverseTrialFromCountdown];
const effect = stateFromStoresArray.useEffect(() => {
let closure_0 = outer1_13({ entitlements: stateFromStoresArray, unactivatedFractionalPremiumUnits: stateFromStoresArray1, currentUser: stateFromStores, premiumSubscription: stateFromStores2, fetchedAllEntitlements: stateFromStores1, excludeReverseTrialFromCountdown });
callback((arg0) => {
let tmp = callback;
if (obj.isEqual(arg0, callback)) {
tmp = arg0;
}
return tmp;
});
}, items5);
return tmp14[0];
};