Files
discord-decomp/sources/modules/storefront/StorefrontUtils.tsx
T
2026-07-27 16:20:00 +03:00

334 lines
18 KiB
TypeScript

/* Metro module 6833; source: modules/storefront/StorefrontUtils.tsx; dependencies: [31, 1949, 1878, 6834, 661, 1880, 22, 6835, 478, 1391, 566, 6829, 5137, 3802, 6836, 2] */
function _fun53784(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#53784, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:6, offset: 0x01355809, size: 354 bytes, params: 8, frame: 21
const env0_0 = require;
const transformStorefrontSKUPricesServer = function(a0) {
return a0.map(_fun53786);
};
const closure = useSKUPrice;
const closure2 = formatSKUPrice;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importAll(31) /* metro dependency 31 */;
const localeStore = importDefault(1949) /* metro dependency 1949: LocaleStore */;
const userStore = importDefault(1878) /* metro dependency 1878: UserStore */;
const skuPricesStore = importDefault(6834) /* metro dependency 6834: SKUPricesStore */;
const constantsModule = require(661) /* metro dependency 661: Constants */;
const env0_7 = constantsModule.CurrencyCodes;
const env0_8 = constantsModule.PriceSetAssignmentPurchaseTypes;
const env0_9 = constantsModule.PriceTypes;
const env0_10 = constantsModule.SKUFlags;
const env0_11 = constantsModule.SKUProductLines;
const env0_12 = (require(1880) /* metro dependency 1880: PremiumConstants */).PremiumTypes;
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/storefront/StorefrontUtils.tsx');
exports.transformStorefrontPricesServer = function(a0) {
var object = {};
object.skuPriceMap = importDefault(dependencyMap[6]).mapValues(a0.sku_price_map, _fun53807);
object.pricingResultIdMap = transformStorefrontPricesResultMapServer(a0.pricing_result_id_map);
object.rewardResultIdMap = transformStorefrontRewardsResultMapServer(a0.reward_result_id_map);
return object;
};
exports.isSlayerSkuAvailableOnThisPlatform = isSlayerSkuAvailableOnThisPlatform;
exports.useSKUPrice = closure;
exports.useFormattedSKUPrice = useFormattedSKUPrice;
exports.formatSKUPrice = closure2;
exports.useSKUOrbPrice = useSKUOrbPrice;
}
function transformStorefrontSKUPricesServer(a0) { // fn#53785, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:271, offset: 0x0135596b, size: 22 bytes, params: 2, frame: 11
return a0.map(function(a0) {
return {currency: a0.currency, amount: a0.amount};
});
}
function transformStorefrontPricesResultMapServer(a0) { // fn#53787, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:377, offset: 0x0135599e, size: 49 bytes, params: 2, frame: 13
return (importDefault(22) /* metro dependency 22 */).mapValues(a0, _fun53788);
}
function transformStorefrontRewardsResultMapServer(a0) { // fn#53792, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:656, offset: 0x01355a98, size: 49 bytes, params: 2, frame: 13
return (importDefault(22) /* metro dependency 22 */).mapValues(a0, _fun53793);
}
function useResolvedUserPrice({sku, priceSetAssignmentPurchaseType, isOrbPrice}) { // fn#53795, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:867, offset: 0x01355b15, size: 134 bytes, params: 2, frame: 18
const pricesForSkuId = (require(566) /* metro dependency 566: flux */).useStateFromStores([SKUPricesStore],
function() {
var r3;
var getPricesForSkuId = SKUPricesStore.getPricesForSkuId;
var skuBinding = sku;
var value2 = null;
r3 = value2 == skuBinding ? undefined : sku.id;
return Reflect.apply(getPricesForSkuId, SKUPricesStore, [value2 != r3 ? r3 : value2]);
});
return pricesForSkuId.useMemo(_fun53797, [sku, pricesForSkuId, priceSetAssignmentPurchaseType, isOrbPrice]);
}
function useSKUPrice({sku, priceSetAssignmentPurchaseType = PriceSetAssignmentPurchaseTypes.DEFAULT}) { // fn#53799, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:1745, offset: 0x01355d79, size: 308 bytes, params: 2, frame: 25
const value4 = useResolvedUserPrice({sku: sku, priceSetAssignmentPurchaseType: priceSetAssignmentPurchaseType,
isOrbPrice: false});
const userPrice = value4.userPrice;
const pricesForPurchaseType = value4.pricesForPurchaseType;
const env0_3 = pricesForPurchaseType;
const purchaseType = value4.purchaseType;
const storeHasPrice = value4.storeHasPrice;
const value5 = (require(566) /* metro dependency 566: flux */).useStateFromStoresArray([SKUPricesStore], _fun53800);
const currentUser = (require(566) /* metro dependency 566: flux */).useStateFromStores([UserStore], function() {
return UserStore.getCurrentUser();
});
return env0_3.useMemo(_fun53802, [sku, priceSetAssignmentPurchaseType, currentUser?.premiumType, storeHasPrice,
userPrice, pricesForPurchaseType, purchaseType, value5]);
}
function formatSKUPrice({normalPrice, discountedPrice, discountPercent, userPrice}, a1) { // fn#53805, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:2997, offset: 0x0135613e, size: 337 bytes, params: 3, frame: 19
var r1;
var moduleValue;
var moduleValue2;
const object2 = {};
let value = null;
if (value != normalPrice) {
if (normalPrice.amount > 0) {
moduleValue = require(5137) /* metro dependency 5137: PriceUtils */;
r1 = moduleValue.formatPrice(normalPrice.amount, normalPrice.currency);
} else {
r1 = value;
}
} else {
r1 = value;
}
object2.normalPrice = r1;
if (value != discountedPrice) {
if (discountedPrice.amount > 0) {
moduleValue2 = require(5137) /* metro dependency 5137: PriceUtils */;
r1 = moduleValue2.formatPrice(discountedPrice.amount, discountedPrice.currency);
} else {
r1 = value;
}
} else {
r1 = value;
}
object2.discountedPrice = r1;
object2.discountPercent = value != discountPercent ? (require(5137) /* metro dependency 5137: PriceUtils */).formatPercent(a1,
-discountPercent / 100) : value;
if (value != userPrice) {
if (userPrice.amount > 0) {
value = require(5137) /* metro dependency 5137: PriceUtils */;
value = value.formatPrice(userPrice.amount, userPrice.currency);
r1 = value;
} else {
r1 = value;
}
} else {
r1 = value;
}
object2.userPrice = r1;
return object2;
}
function transformStorefrontPricesServer({sku_price_map, pricing_result_id_map, reward_result_id_map}) { // fn#53806, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:3516, offset: 0x0135628f, size: 108 bytes, params: 2, frame: 17
const object2 = {};
object2.skuPriceMap = (importDefault(22) /* metro dependency 22 */).mapValues(sku_price_map, function(a0) {
return {pricingResultId: a0.pricing_result_id, rewardResultIds: a0.reward_result_ids};
});
object2.pricingResultIdMap = transformStorefrontPricesResultMapServer(pricing_result_id_map);
object2.rewardResultIdMap = transformStorefrontRewardsResultMapServer(reward_result_id_map);
return object2;
}
function isSlayerSkuAvailableOnThisPlatform(a0) { // fn#53808, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:3964, offset: 0x0135631c, size: 216 bytes, params: 2, frame: 18
var r0;
var isAndroid2;
var moduleValue3;
var moduleValue4;
if (a0 == null) {
return false;
}
const productLine = a0.productLine;
const SOCIAL_LAYER_GAME_ITEM = SKUProductLines.SOCIAL_LAYER_GAME_ITEM;
if (productLine !== SOCIAL_LAYER_GAME_ITEM) {
return false;
}
const r4 = a0?.flags ?? 0;
if ((require(478) /* metro dependency 478: PlatformUtils */).isIOS()) {
moduleValue4 = require(1391) /* metro dependency 1391: FlagUtils */;
r0 = moduleValue4.hasFlag(r4, SKUFlags.AVAILABLE_ON_IOS);
} else {
isAndroid2 = (require(478) /* metro dependency 478: PlatformUtils */).isAndroid();
if (isAndroid2) {
moduleValue3 = require(1391) /* metro dependency 1391: FlagUtils */;
r0 = moduleValue3.hasFlag(r4, SKUFlags.AVAILABLE_ON_ANDROID);
} else {
r0 = !isAndroid2;
}
}
return r0;
}
function useFormattedSKUPrice({sku, priceSetAssignmentPurchaseType = PriceSetAssignmentPurchaseTypes.DEFAULT}) { // fn#53809, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:4297, offset: 0x013563f4, size: 158 bytes, params: 2, frame: 16
return env0_3.useMemo(_fun53811, [useSKUPrice({sku: sku,
priceSetAssignmentPurchaseType: priceSetAssignmentPurchaseType}),
(require(566) /* metro dependency 566: flux */).useStateFromStores([LocaleStore], function() {
return LocaleStore.locale;
})]);
}
function useSKUOrbPrice({sku, priceSetAssignmentPurchaseType = PriceSetAssignmentPurchaseTypes.DEFAULT}) { // fn#53812, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:4589, offset: 0x013564a1, size: 233 bytes, params: 2, frame: 18
const {userPrice, storeHasPrice} = useResolvedUserPrice({sku: sku,
priceSetAssignmentPurchaseType: priceSetAssignmentPurchaseType, isOrbPrice: true});
const currentUser = (require(566) /* metro dependency 566: flux */).useStateFromStores([UserStore], function() {
return UserStore.getCurrentUser();
});
const env0_3 = currentUser;
return env0_3.useMemo(_fun53815, [sku, env0_3.useMemo(function() {
return importDefault(dependencyMap[13]).isPremium(currentUser, PremiumTypes.TIER_2);
}, [currentUser]), storeHasPrice, userPrice]);
}
function _fun53788(a0) { // fn#53788, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:458, offset: 0x013559cf, size: 49 bytes, params: 2, frame: 13
var environment;
const value = environment.__proto__;
return (importDefault(22) /* metro dependency 22 */).mapValues(a0, _fun53789);
}
function _fun53793(a0) { // fn#53793, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:738, offset: 0x01355ac9, size: 49 bytes, params: 2, frame: 13
var environment;
const value = environment.__proto__;
return (importDefault(22) /* metro dependency 22 */).mapValues(a0, function(a0) {
return {type: a0.type, amount: a0.amount};
});
}
function _fun53797() { // fn#53797, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:1088, offset: 0x01355bd8, size: 373 bytes, params: 1, frame: 17
const StorefrontPurchaseType = (require(6835) /* metro dependency 6835: StorefrontTypes */).StorefrontPurchaseType;
const priceSetAssignmentPurchaseTypeBinding = priceSetAssignmentPurchaseType;
const r3 = priceSetAssignmentPurchaseTypeBinding == null || PriceSetAssignmentPurchaseTypes.DEFAULT === priceSetAssignmentPurchaseTypeBinding ? StorefrontPurchaseType.SELF_PURCHASE : PriceSetAssignmentPurchaseTypes.GIFT === priceSetAssignmentPurchaseTypeBinding ? StorefrontPurchaseType.GIFT : StorefrontPurchaseType.SELF_PURCHASE;
if (sku == null) {
return {userPrice: undefined, pricesForPurchaseType: undefined, purchaseType: r3,
storeHasPrice: pricesForSkuId != null};
}
if (pricesForSkuId == null) {
return {userPrice: undefined, pricesForPurchaseType: undefined, purchaseType: r3,
storeHasPrice: pricesForSkuId != null};
}
const r4 = pricesForSkuId[r3] ?? pricesForSkuId[StorefrontPurchaseType.SELF_PURCHASE];
return {userPrice: r4 == null || r4.userPrice == null ? undefined : r4.userPrice.find(_fun53798),
pricesForPurchaseType: r4, purchaseType: r3, storeHasPrice: true};
}
function _fun53800() { // fn#53800, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:2016, offset: 0x01355ead, size: 57 bytes, params: 1, frame: 14
const value = environment.__proto__;
return SKUPricesStore.getRewardsForSkuId(sku?.id) ?? [];
}
function _fun53802() { // fn#53802, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:2172, offset: 0x01355ee6, size: 499 bytes, params: 1, frame: 21
var environment;
var r0;
var userPrice2;
var amount;
var r6;
var moduleValue;
var value5;
var property;
var pricesForPurchaseTypeBinding;
var value6;
var prices;
var value7;
let skuBinding = sku;
const value2 = null;
if (value2 == skuBinding) {
return {'normalPrice': null, 'discountedPrice': null, 'discountPercent': null, 'userPrice': null};
}
if (storeHasPrice) {
value5 = env0_6.find(_fun53803);
r0 = value2 != value5 ? value5[purchaseType] : value2;
userPrice2 = value2 != r0 && value2 != userPrice ? userPrice : value2;
if (value2 != r0) {
amount = r0.amount;
amount = amount > 0 ? r0.amount : value2;
} else {
amount = value2;
}
if (value2 != r0) {
pricesForPurchaseTypeBinding = pricesForPurchaseType;
value6 = undefined;
if (value2 == pricesForPurchaseTypeBinding) {
r0 = value6;
} else {
prices = pricesForPurchaseType.prices;
value7 = environment.__proto__;
property = prices[PriceTypes.BASE];
if (value2 == property) {
r0 = value6;
} else {
property = property[(require(6835) /* metro dependency 6835: StorefrontTypes */).StorefrontPriceVariant.NORMAL];
r0 = value2 == property ? value6 : property.find(function({currency}) {
return currency !== CurrencyCodes.DISCORD_ORB;
});
}
}
r6 = r0;
} else {
r6 = userPrice;
}
return {normalPrice: value2 != r6 && r6.amount > 0 ? r6 : value2, discountedPrice: userPrice2,
discountPercent: amount, userPrice: value2 != userPrice ? userPrice : value2};
}
const productLine = sku.productLine;
const SOCIAL_LAYER_GAME_ITEM = SKUProductLines.SOCIAL_LAYER_GAME_ITEM;
if (productLine === SOCIAL_LAYER_GAME_ITEM) {
moduleValue = require(6829) /* metro dependency 6829: SlayerStorefrontUtils */;
r0 = moduleValue.getPrice(sku, env0_1);
} else {
skuBinding = sku;
r0 = skuBinding.getPrice(value2 == currentUser ? undefined : currentUser.premiumType);
}
const r3 = value2 != r0 && r0.amount > 0 ? r0 : value2;
return {'normalPrice': null, 'discountedPrice': null, 'discountPercent': null, normalPrice: r3, userPrice: r3};
}
function _fun53815() { // fn#53815, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:4912, offset: 0x013565c2, size: 130 bytes, params: 1, frame: 15
const skuBinding = sku;
const value2 = null;
if (value2 == skuBinding) {
return value2;
}
if (storeHasPrice) {
return value2 != userPrice ? userPrice : value2;
}
const orbPriceFromPrices = (require(6836) /* metro dependency 6836: OrbCheckoutUtils */).getOrbPriceFromPrices(sku.prices,
env0_4);
return value2 != orbPriceFromPrices ? {amount: orbPriceFromPrices.amount,
currency: orbPriceFromPrices.currency} : value2;
}
function _fun53789({user_price, prices}) { // fn#53789, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:482, offset: 0x01355a00, size: 84 bytes, params: 2, frame: 15
var environment;
const object2 = {};
const value = environment.__proto__.__proto__;
object2.userPrice = transformStorefrontSKUPricesServer(user_price);
object2.prices = (importDefault(22) /* metro dependency 22 */).mapValues(prices, _fun53790);
return object2;
}
function _fun53798({currency}) { // fn#53798, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:1614, offset: 0x01355d4d, size: 44 bytes, params: 2, frame: 4
let value = environment.__proto__;
const isOrbPriceBinding = isOrbPrice;
value = environment.__proto__.__proto__;
const DISCORD_ORB = CurrencyCodes.DISCORD_ORB;
return isOrbPriceBinding ? currency === DISCORD_ORB : currency !== DISCORD_ORB;
}
function _fun53803(a0) { // fn#53803, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:2513, offset: 0x013560d9, size: 73 bytes, params: 2, frame: 13
const value = environment.__proto__;
const type = a0[purchaseType]?.type;
const StorefrontPromotionRewardType = (require(6835) /* metro dependency 6835: StorefrontTypes */).StorefrontPromotionRewardType;
const DISCOUNT = StorefrontPromotionRewardType.DISCOUNT;
return type === DISCOUNT;
}
function _fun53790(a0) { // fn#53790, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7011:581, offset: 0x01355a54, size: 49 bytes, params: 2, frame: 13
var environment;
const value = environment.__proto__.__proto__.__proto__;
return (importDefault(22) /* metro dependency 22 */).mapValues(a0, function(a0) {
return transformStorefrontSKUPricesServer(a0);
});
}