decord/source/modules/storefront/StorefrontUtils.tsx

389 lines
14 KiB
TypeScript
Raw Normal View History

// Module ID: 7334
// Function ID: 7335
// Name: StorefrontUtils
// Dependencies: [19, 2025, 1371, 7335, 1074, 1373, 12, 7336, 1151, 1384, 504, 7329, 7337, 4294, 7344, 2]
2026-07-29 08:29:29 +00:00
// Exports: isSlayerSkuAvailableOnThisPlatform, transformPriceSetAssignmentToStorefrontPurchaseType, transformStorefrontPricesServer, useFormatSKUPrice, useFormattedSKUPrice, useSKUOrbPrice
2026-07-20 16:05:17 +00:00
// Module 7334 (StorefrontUtils)
import _modDef12 from "module_12" /* 12 */;
import PremiumUtilsDefault from "PremiumUtils" /* 4294 */;
import SlayerStorefrontUtils from "SlayerStorefrontUtils" /* 7329 */;
import StorefrontTypes from "StorefrontTypes" /* 7336 */;
import PriceUtils from "PriceUtils" /* 7337 */;
import OrbCheckoutUtils from "OrbCheckoutUtils" /* 7344 */;
import noop from "module_19" /* 19 */;
import LocaleStore from "LocaleStore" /* 2025 */;
import UserStore from "UserStore" /* 1371 */;
import SKUPricesStore from "SKUPricesStore" /* 7335 */;
2026-07-23 10:11:24 +00:00
const require = globalThis.__r;
require = fn;
2026-07-29 08:29:29 +00:00
function useSKUPrice(sku) {
2026-07-20 16:05:17 +00:00
sku = sku.sku;
2026-07-29 08:29:29 +00:00
let DEFAULT = sku.priceSetAssignmentPurchaseType;
if (DEFAULT === undefined) {
DEFAULT = constants.DEFAULT;
}
let userPrice;
let pricesForPurchaseType;
let stateFromStoresArray;
closure_129_0 = sku;
closure_129_1 = DEFAULT;
closure_129_2 = false;
2026-07-29 08:29:29 +00:00
const items = [stateFromStoresArray];
const stateFromStores = sku(userPrice[10]).useStateFromStores(items, () => {
2026-07-20 16:05:17 +00:00
let id;
2026-07-29 08:29:29 +00:00
if (sku != null) {
2026-07-20 16:05:17 +00:00
id = sku.id;
}
2026-07-29 08:29:29 +00:00
if (id == null) {
id = null;
2026-07-20 16:05:17 +00:00
}
return SKUPricesStore.getPricesForSkuId(id);
2026-07-20 16:05:17 +00:00
});
closure_129_3 = stateFromStores;
2026-07-29 08:29:29 +00:00
const items1 = [sku, stateFromStores, DEFAULT, false];
const memo = pricesForPurchaseType.useMemo(() => {
if (null == userPrice) {
let SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
let tmp4 = require;
} else if (constants.DEFAULT === tmp) {
SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
tmp4 = require;
2026-07-29 08:29:29 +00:00
} else if (tmp14.GIFT === tmp) {
SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.GIFT;
tmp4 = require;
2026-07-29 08:29:29 +00:00
} else {
SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
tmp4 = require;
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
if (null != sku) {
2026-07-29 08:29:29 +00:00
if (null != stateFromStores1) {
let tmp12 = tmp11[SELF_PURCHASE];
if (tmp12 == null) {
tmp12 = tmp11[tmp4(undefined, 7336).StorefrontPurchaseType.SELF_PURCHASE];
2026-07-20 16:05:17 +00:00
}
let found;
2026-07-29 08:29:29 +00:00
if (tmp12 != null) {
userPrice = tmp12.userPrice;
if (userPrice != null) {
2026-07-20 16:05:17 +00:00
found = userPrice.find((currency) => {
currency = currency.currency;
const DISCORD_ORB = constants.DISCORD_ORB;
return storeHasPrice ? currency === DISCORD_ORB : currency !== DISCORD_ORB;
2026-07-20 16:05:17 +00:00
});
}
}
const obj = { userPrice: found, pricesForPurchaseType: tmp12, purchaseType: SELF_PURCHASE, storeHasPrice: true };
2026-07-20 16:05:17 +00:00
return obj;
}
}
const obj2 = { userPrice: "r", pricesForPurchaseType: "ip", purchaseType: SELF_PURCHASE, storeHasPrice: null != stateFromStores1 };
return obj2;
2026-07-20 16:05:17 +00:00
}, items1);
2026-07-29 08:29:29 +00:00
userPrice = memo.userPrice;
pricesForPurchaseType = memo.pricesForPurchaseType;
const purchaseType = memo.purchaseType;
const storeHasPrice = memo.storeHasPrice;
const obj = sku(userPrice[10]);
2026-07-29 08:29:29 +00:00
const items2 = [stateFromStoresArray];
stateFromStoresArray = sku(userPrice[10]).useStateFromStoresArray(items2, () => {
2026-07-20 16:05:17 +00:00
let id;
2026-07-29 08:29:29 +00:00
if (sku != null) {
2026-07-20 16:05:17 +00:00
id = sku.id;
}
let rewardsForSkuId = SKUPricesStore.getRewardsForSkuId(id);
2026-07-29 08:29:29 +00:00
if (rewardsForSkuId == null) {
2026-07-20 16:05:17 +00:00
rewardsForSkuId = [];
}
return rewardsForSkuId;
});
2026-07-29 08:29:29 +00:00
let obj2 = sku(userPrice[10]);
const items3 = [storeHasPrice];
const stateFromStores1 = sku(userPrice[10]).useStateFromStores(items3, () => storeHasPrice.getCurrentUser());
2026-07-29 08:29:29 +00:00
const items4 = [sku, DEFAULT, , , , , , ];
2026-07-20 16:05:17 +00:00
let premiumType;
2026-07-29 08:29:29 +00:00
if (stateFromStores1 != null) {
premiumType = stateFromStores1.premiumType;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
items4[2] = premiumType;
items4[3] = storeHasPrice;
items4[4] = userPrice;
items4[5] = pricesForPurchaseType;
items4[6] = purchaseType;
items4[7] = stateFromStoresArray;
2026-07-23 10:11:24 +00:00
return pricesForPurchaseType.useMemo(() => {
2026-07-20 16:05:17 +00:00
if (null == sku) {
2026-07-23 10:11:24 +00:00
return { normalPrice: null, discountedPrice: null, discountPercent: null, userPrice: null };
2026-07-20 16:05:17 +00:00
} else if (storeHasPrice) {
const found = stateFromStoresArray.find((item) => {
if (null == item[purchaseType]) {
2026-07-20 16:05:17 +00:00
return false;
} else {
2026-07-29 08:29:29 +00:00
const type = tmp.type;
if (sku(userPrice[7]).StorefrontPromotionRewardType.DISCOUNT === type) {
2026-07-20 16:05:17 +00:00
return true;
} else {
2026-07-29 08:29:29 +00:00
if (tmp2(tmp3[7]).StorefrontPromotionRewardType.FIXED_PRICE !== type) {
if (tmp2(tmp3[7]).StorefrontPromotionRewardType.ACTION !== type) {
const type2 = tmp.type;
2026-07-20 16:05:17 +00:00
return false;
}
}
return false;
}
}
});
2026-07-29 08:29:29 +00:00
let tmp9 = null;
2026-07-20 16:05:17 +00:00
if (null != found) {
2026-07-29 08:29:29 +00:00
tmp9 = found[purchaseType];
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let tmp11 = null;
if (null != tmp9) {
tmp11 = null;
2026-07-20 16:05:17 +00:00
if (null != userPrice) {
2026-07-29 08:29:29 +00:00
tmp11 = userPrice;
2026-07-20 16:05:17 +00:00
}
}
let amount = null;
2026-07-29 08:29:29 +00:00
if (null != tmp9) {
2026-07-20 16:05:17 +00:00
amount = null;
2026-07-29 08:29:29 +00:00
if (tmp9.amount > 0) {
amount = tmp9.amount;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
if (null != tmp9) {
2026-07-20 16:05:17 +00:00
let found1;
2026-07-29 08:29:29 +00:00
if (pricesForPurchaseType != null) {
if (pricesForPurchaseType.prices[constants2.BASE] != null) {
const arr = tmp16[StorefrontTypes.StorefrontPriceVariant.NORMAL];
2026-07-29 08:29:29 +00:00
if (arr != null) {
found1 = arr.find((currency) => currency.currency !== constants.DISCORD_ORB);
2026-07-20 16:05:17 +00:00
}
}
}
2026-07-29 08:29:29 +00:00
let tmp13 = found1;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
tmp13 = userPrice;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (tmp13 == null) {
tmp13 = null;
2026-07-20 16:05:17 +00:00
}
const obj3 = { normalPrice: tmp13, discountedPrice: tmp11, discountPercent: amount, userPrice: null };
2026-07-29 08:29:29 +00:00
let tmp19 = userPrice;
if (userPrice == null) {
tmp19 = null;
2026-07-20 16:05:17 +00:00
}
obj3.userPrice = tmp19;
return obj3;
2026-07-20 16:05:17 +00:00
} else {
if (obj.productLine === constants4.SOCIAL_LAYER_GAME_ITEM) {
let price = SlayerStorefrontUtils.getPrice(obj, DEFAULT);
2026-07-20 16:05:17 +00:00
} else {
let premiumType;
2026-07-29 08:29:29 +00:00
if (stateFromStores1 != null) {
premiumType = stateFromStores1.premiumType;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
price = obj.getPrice(premiumType);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (price == null) {
price = null;
2026-07-20 16:05:17 +00:00
}
const obj4 = { normalPrice: price, discountedPrice: null, discountPercent: null, userPrice: price };
return obj4;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
}, items4);
2026-07-23 10:11:24 +00:00
}
function formatSKUPrice(arg0, stateFromStores) {
2026-07-20 16:05:17 +00:00
({ normalPrice, discountedPrice, discountPercent, userPrice } = arg0);
let formatPriceResult = null;
if (null != normalPrice) {
formatPriceResult = PriceUtils.formatPrice(normalPrice.amount, normalPrice.currency);
2026-07-20 16:05:17 +00:00
}
const obj2 = { normalPrice: formatPriceResult, discountedPrice: null, discountPercent: null, userPrice: null };
2026-07-20 16:05:17 +00:00
let formatPriceResult1 = null;
if (null != discountedPrice) {
formatPriceResult1 = PriceUtils.formatPrice(discountedPrice.amount, discountedPrice.currency);
2026-07-20 16:05:17 +00:00
}
obj2.discountedPrice = formatPriceResult1;
2026-07-20 16:05:17 +00:00
let formatPercentResult = null;
if (null != discountPercent) {
formatPercentResult = PriceUtils.formatPercent(stateFromStores, -discountPercent / 100);
2026-07-20 16:05:17 +00:00
}
obj2.discountPercent = formatPercentResult;
2026-07-20 16:05:17 +00:00
let formatPriceResult2 = null;
if (null != userPrice) {
formatPriceResult2 = PriceUtils.formatPrice(userPrice.amount, userPrice.currency);
2026-07-20 16:05:17 +00:00
}
obj2.userPrice = formatPriceResult2;
return obj2;
2026-07-20 16:05:17 +00:00
}
const Constants = fn(1074);
({ CurrencyCodes: closure_7, PriceSetAssignmentPurchaseTypes: closure_8, PriceTypes: closure_9, SKUFlags: c10, SKUProductLines: closure_11 } = Constants);
const PremiumTypes = fn(1373).PremiumTypes;
const size = fn(2);
const result = size.fileFinishedImporting("modules/storefront/StorefrontUtils.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export const transformStorefrontPricesServer = function transformStorefrontPricesServer(storefront_pricing) {
let obj = { skuPriceMap: _modDef12.mapValues(storefront_pricing.sku_price_map, (pricingResultId) => ({ pricingResultId: pricingResultId.pricing_result_id, storefrontPromotionIds: pricingResultId.storefront_promotion_ids, rewardResultIds: pricingResultId.reward_result_ids })), pricingResultIdMap: null, rewardResultIdMap: null };
obj.pricingResultIdMap = _modDef12.mapValues(storefront_pricing.pricing_result_id_map, (arg0) => _modDef12.mapValues(arg0, (user_price) => {
const obj = { userPrice: null, prices: closure_1_1(dependencyMap[6]).mapValues(user_price.prices, (arg0) => closure_1_1(closure_1_2[6]).mapValues(arg0, (arr) => arr.map(() => { ... }))) };
2026-07-29 08:29:29 +00:00
user_price = user_price.user_price;
obj.userPrice = user_price.map((currency) => ({ currency: currency.currency, amount: currency.amount }));
2026-07-29 08:29:29 +00:00
return obj;
}));
obj.rewardResultIdMap = _modDef12.mapValues(storefront_pricing.reward_result_id_map, (arg0) => _modDef12.mapValues(arg0, (type) => ({ type: type.type, amount: type.amount })));
2026-07-20 16:05:17 +00:00
return obj;
};
2026-07-29 08:29:29 +00:00
export const transformPriceSetAssignmentToStorefrontPurchaseType = function transformPriceSetAssignmentToStorefrontPurchaseType(arg0) {
if (null == arg0) {
return StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
2026-07-29 08:29:29 +00:00
} else if (constants.DEFAULT === arg0) {
return StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
2026-07-29 08:29:29 +00:00
} else if (tmp9.GIFT === arg0) {
return StorefrontTypes.StorefrontPurchaseType.GIFT;
2026-07-29 08:29:29 +00:00
} else {
return StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
2026-07-29 08:29:29 +00:00
}
};
2026-07-20 16:05:17 +00:00
export const isSlayerSkuAvailableOnThisPlatform = function isSlayerSkuAvailableOnThisPlatform(sku) {
if (null != sku) {
if (sku.productLine === constants4.SOCIAL_LAYER_GAME_ITEM) {
2026-07-29 08:29:29 +00:00
let num;
if (sku != null) {
num = sku.flags;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (num == null) {
num = 0;
2026-07-20 16:05:17 +00:00
}
if (obj.isIOS()) {
let hasFlagResult = tmp(1384).hasFlag(num, constants3.AVAILABLE_ON_IOS);
const tmpResult = tmp(1384);
2026-07-20 16:05:17 +00:00
} else {
const isAndroidResult = tmp(1151).isAndroid();
2026-07-29 08:29:29 +00:00
hasFlagResult = !isAndroidResult;
if (isAndroidResult) {
hasFlagResult = tmp(1384).hasFlag(num, constants3.AVAILABLE_ON_ANDROID);
const tmpResult4 = tmp(1384);
2026-07-20 16:05:17 +00:00
}
const tmpResult3 = tmp(1151);
2026-07-20 16:05:17 +00:00
}
return hasFlagResult;
}
}
return false;
};
export { useSKUPrice };
2026-07-29 08:29:29 +00:00
export const useFormattedSKUPrice = function useFormattedSKUPrice(sku) {
let DEFAULT = sku.priceSetAssignmentPurchaseType;
2026-07-20 16:05:17 +00:00
if (DEFAULT === undefined) {
DEFAULT = constants.DEFAULT;
}
2026-07-29 08:29:29 +00:00
const tmp2 = useSKUPrice({ sku: sku.sku, priceSetAssignmentPurchaseType: DEFAULT });
_require = tmp2;
const items = [LocaleStore];
const stateFromStores = require("initialize").useStateFromStores(items, () => locale.locale);
2026-07-29 08:29:29 +00:00
const items1 = [tmp2, stateFromStores];
return noop.useMemo(() => formatSKUPrice(closure_0, stateFromStores), items1);
2026-07-29 08:29:29 +00:00
};
export const useFormatSKUPrice = function useFormatSKUPrice(arg0) {
_require = arg0;
const items = [LocaleStore];
const stateFromStores = require("initialize").useStateFromStores(items, () => locale.locale);
2026-07-29 08:29:29 +00:00
const items1 = [arg0, stateFromStores];
return noop.useMemo(() => formatSKUPrice(closure_0, stateFromStores), items1);
2026-07-20 16:05:17 +00:00
};
export { formatSKUPrice };
export const useSKUOrbPrice = function useSKUOrbPrice(sku) {
sku = sku.sku;
let DEFAULT = sku.priceSetAssignmentPurchaseType;
if (DEFAULT === undefined) {
DEFAULT = constants.DEFAULT;
}
2026-07-23 10:11:24 +00:00
let storeHasPrice;
2026-07-29 08:29:29 +00:00
let stateFromStores1;
closure_129_0 = sku;
closure_129_1 = DEFAULT;
closure_129_2 = true;
const items = [SKUPricesStore];
2026-07-29 08:29:29 +00:00
const stateFromStores = sku(storeHasPrice[10]).useStateFromStores(items, () => {
let id;
if (sku != null) {
id = sku.id;
}
if (id == null) {
id = null;
}
return SKUPricesStore.getPricesForSkuId(id);
2026-07-29 08:29:29 +00:00
});
closure_129_3 = stateFromStores;
2026-07-29 08:29:29 +00:00
const items1 = [sku, stateFromStores, DEFAULT, true];
const memo = stateFromStores1.useMemo(() => {
if (null == userPrice) {
let SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
let tmp4 = require;
} else if (constants.DEFAULT === tmp) {
SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
tmp4 = require;
2026-07-29 08:29:29 +00:00
} else if (tmp14.GIFT === tmp) {
SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.GIFT;
tmp4 = require;
2026-07-29 08:29:29 +00:00
} else {
SELF_PURCHASE = StorefrontTypes.StorefrontPurchaseType.SELF_PURCHASE;
tmp4 = require;
2026-07-29 08:29:29 +00:00
}
if (null != sku) {
if (null != stateFromStores1) {
let tmp12 = tmp11[SELF_PURCHASE];
if (tmp12 == null) {
tmp12 = tmp11[tmp4(undefined, 7336).StorefrontPurchaseType.SELF_PURCHASE];
2026-07-29 08:29:29 +00:00
}
let found;
if (tmp12 != null) {
userPrice = tmp12.userPrice;
if (userPrice != null) {
found = userPrice.find((currency) => {
currency = currency.currency;
const DISCORD_ORB = constants.DISCORD_ORB;
return storeHasPrice ? currency === DISCORD_ORB : currency !== DISCORD_ORB;
2026-07-29 08:29:29 +00:00
});
}
}
const obj = { userPrice: found, pricesForPurchaseType: tmp12, purchaseType: SELF_PURCHASE, storeHasPrice: true };
2026-07-29 08:29:29 +00:00
return obj;
}
}
const obj2 = { userPrice: "r", pricesForPurchaseType: "ip", purchaseType: SELF_PURCHASE, storeHasPrice: null != stateFromStores1 };
return obj2;
2026-07-29 08:29:29 +00:00
}, items1);
let userPrice = memo.userPrice;
2026-07-29 08:29:29 +00:00
storeHasPrice = memo.storeHasPrice;
let obj = sku(storeHasPrice[10]);
const items2 = [UserStore];
2026-07-29 08:29:29 +00:00
stateFromStores1 = sku(storeHasPrice[10]).useStateFromStores(items2, () => currentUser.getCurrentUser());
const items3 = [stateFromStores1];
const memo1 = stateFromStores1.useMemo(() => PremiumUtilsDefault.isPremium(stateFromStores1, PremiumTypes.TIER_2), items3);
2026-07-29 08:29:29 +00:00
const items4 = [sku, memo1, storeHasPrice, userPrice];
return stateFromStores1.useMemo(() => {
2026-07-20 16:05:17 +00:00
if (null == sku) {
return null;
} else if (storeHasPrice) {
2026-07-29 08:29:29 +00:00
let tmp8 = userPrice;
if (userPrice == null) {
tmp8 = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp8;
2026-07-20 16:05:17 +00:00
} else {
const orbPriceFromPrices = OrbCheckoutUtils.getOrbPriceFromPrices(tmp.prices, memo1);
2026-07-20 16:05:17 +00:00
let tmp7 = null;
if (null != orbPriceFromPrices) {
({ amount: obj2.amount, currency: obj2.currency } = orbPriceFromPrices);
tmp7 = { amount: null, currency: null };
const obj3 = { amount: null, currency: null };
2026-07-20 16:05:17 +00:00
}
return tmp7;
}
2026-07-29 08:29:29 +00:00
}, items4);
2026-07-20 16:05:17 +00:00
};