Files
discord-decomp/modules/collectibles/hooks/useProductPurchaseState.tsx
T
2026-11-01 12:12:55 +02:00

52 lines
1.9 KiB
TypeScript

// Metro module 8710 (f8711).
import CollectiblesPurchaseStore from "../CollectiblesPurchaseStore";
import compact from "../../../_bundle/compact";
import { CollectiblesItemType } from "../../../_bundle/Module1901";
import { useStateFromStoresObject } from "../../../_bundle/Module589";
const getProductPurchaseState = function getProductPurchaseState(a0, a1) {
let isPurchased = a0.getPurchase(a1.skuId) != null;
let items = a1.items;
if (items == null) {
items = [];
}
const r20 = compact(items.map((item) => a0.getPurchase(item.skuId)));
const type = a1?.type;
if (CollectiblesItemType.BUNDLE === type) {
if (!isPurchased) {
isPurchased = items.length > 0 && r20.length === items.length;
}
return {
isPurchased,
isPartiallyOwnedBundle: r20.length > 0 && r20.length < items.length,
isPartiallyOwnedVariantsGroup: false
};
}
if (CollectiblesItemType.VARIANTS_GROUP === type) {
const variants = a1.variants;
const r34 = variants == null ? void 0 : variants.every((variant) => a0.getPurchase(variant.skuId) != null);
let isPurchased2 = r34;
if (isPurchased2 == null) {
isPurchased2 = false;
}
const variants2 = a1.variants;
let isPartiallyOwnedVariantsGroup = (variants2 == null ? void 0 : variants2.some((item) => a0.getPurchase(item.skuId) != null)) && !r34;
if (isPartiallyOwnedVariantsGroup == null) {
isPartiallyOwnedVariantsGroup = false;
}
return {
isPurchased: isPurchased2,
isPartiallyOwnedBundle: false,
isPartiallyOwnedVariantsGroup
};
}
return {
isPurchased,
isPartiallyOwnedBundle: false,
isPartiallyOwnedVariantsGroup: false
};
};
export { getProductPurchaseState };
export function useProductPurchaseState(c16739_0) {
return useStateFromStoresObject([CollectiblesPurchaseStore], () => getProductPurchaseState(CollectiblesPurchaseStore, c16739_0));
}