400 lines
15 KiB
TypeScript
400 lines
15 KiB
TypeScript
// Metro module 5662 (f5663).
|
|
import ApplicationStore from "../applications/ApplicationStore";
|
|
import { WishlistRecommendationReason } from "../wishlists/records/WishlistRecommendationRecord";
|
|
import ApplicationRecord from "../../records/ApplicationRecord";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import SocialLayerStorefrontStore from "./SocialLayerStorefrontStore";
|
|
import { STOREFRONT_MARKETING_GUILD_ID, STOREFRONT_MARKETING_GUILD_ID_TEST, getChannelsGameShopPrefix } from "./SocialLayerStorefrontConstants";
|
|
import { GuildFeatures, PriceSetAssignmentPurchaseTypes, Routes, SKUProductLines } from "../../Constants";
|
|
import { CollectibleShopTab } from "../collectibles/CollectiblesShopConstants";
|
|
import { CurrencyCodes } from "../../_bundle/Module505";
|
|
import { SUPPORTS_WEBP, getAssetURL } from "../../utils/StoreUtils";
|
|
import Module12 from "../../_bundle/Module12";
|
|
import { transformStorefrontPricesServer } from "../storefront/StorefrontUtils";
|
|
import URLUtils from "../../utils/URLUtils";
|
|
import { parse } from "../../_bundle/keysSorter";
|
|
import { useStateFromStores } from "../../_bundle/Module589";
|
|
import { useGetOrFetchApplication } from "../applications/useGetOrFetchApplications";
|
|
let c3500_17, hasSocialLayerStorefront, transformSlayerStorefrontPromotionServer, getSKUShareURL;
|
|
const getPrice = function getPrice(sku, a1) {
|
|
const r18 = sku.prices[a1] != null && sku.prices[a1].countryPrices.prices.length > 0 ? sku.prices[a1].countryPrices : sku.prices[PriceSetAssignmentPurchaseTypes.DEFAULT] != null ? sku.prices[PriceSetAssignmentPurchaseTypes.DEFAULT].countryPrices.prices.length > 0 ? sku.prices[PriceSetAssignmentPurchaseTypes.DEFAULT].countryPrices : null : null;
|
|
return r18 != null ? r18.prices[0] : sku.price != null ? sku.price : null;
|
|
};
|
|
hasSocialLayerStorefront = function hasSocialLayerStorefront(guild) {
|
|
if (SocialLayerStorefrontStore.getStorefrontGuildIds().has(guild.id)) {
|
|
return true;
|
|
}
|
|
if ("type" in guild) {
|
|
return false;
|
|
}
|
|
let r16 = SocialLayerStorefrontStore.getApplicationIdFromGuildId(guild.id);
|
|
if (r16 == null) {
|
|
r16 = (guild == null ? void 0 : guild.gameApplicationIds?.length) === 1 ? guild.gameApplicationIds[0] : void 0;
|
|
}
|
|
const storefrontApplicationIds = SocialLayerStorefrontStore.getStorefrontApplicationIds();
|
|
const r24 = r16 == null || !storefrontApplicationIds.has(r16);
|
|
let r27 = !r24;
|
|
if (r24) {
|
|
const features = guild.features;
|
|
let r30 = features == null ? void 0 : features.has(GuildFeatures.SOCIAL_LAYER_STOREFRONT);
|
|
if (r30 == null) {
|
|
r30 = false;
|
|
}
|
|
r27 = r30;
|
|
}
|
|
return r27;
|
|
};
|
|
transformSlayerStorefrontPromotionServer = function transformSlayerStorefrontPromotionServer(a0) {
|
|
let ends_at = a0.ends_at;
|
|
if (ends_at == null) {
|
|
ends_at = null;
|
|
}
|
|
let flavor = a0.flavor;
|
|
if (flavor == null) {
|
|
flavor = "default";
|
|
}
|
|
const pdp = a0.pdp;
|
|
const pdp2 = pdp == null ? null : {
|
|
label: pdp.label,
|
|
tooltip: pdp.tooltip,
|
|
icon: pdp.icon
|
|
};
|
|
const storefront = a0.storefront != null ? {
|
|
headerText: a0.storefront.header_text
|
|
} : null;
|
|
const checkout = a0.checkout;
|
|
const checkout2 = checkout == null ? null : {
|
|
label: checkout.label,
|
|
tooltip: checkout.tooltip,
|
|
icon: checkout.icon
|
|
};
|
|
const vc_stream = a0.vc_stream;
|
|
return {
|
|
id: a0.id,
|
|
endsAt: ends_at,
|
|
flavor,
|
|
pdp: pdp2,
|
|
storefront,
|
|
checkout: checkout2,
|
|
vcStream: vc_stream == null ? null : {
|
|
label: vc_stream.label,
|
|
tooltip: vc_stream.tooltip,
|
|
icon: vc_stream.icon
|
|
}
|
|
};
|
|
};
|
|
getSKUShareURL = function getSKUShareURL(a0, a1) {
|
|
let r47;
|
|
if (a0 != null) {
|
|
const { pathname, search } = location;
|
|
const applicationId = a1.applicationId;
|
|
const r26 = parse(search);
|
|
const { tab, applicationId: applicationId2 } = r26;
|
|
r26.skuId;
|
|
r47 = pathname.indexOf(Routes.COLLECTIBLES_SHOP) >= 0 && (tab === CollectibleShopTab.GAME_SHOPS && applicationId2 === applicationId && true) ? `${location.protocol}${window.GLOBAL_ENV.WEBAPP_ENDPOINT}${Routes.COLLECTIBLES_SHOP_GAME_SHOP(a1.applicationId, void 0, a1.id, a1.slug)}` : `${location.protocol}${window.GLOBAL_ENV.WEBAPP_ENDPOINT}${Routes.GAME_SHOP(a0, a1.id, a1.slug)}`;
|
|
} else {
|
|
r47 = `${location.protocol}${window.GLOBAL_ENV.WEBAPP_ENDPOINT}${Routes.COLLECTIBLES_SHOP_GAME_SHOP(a1.applicationId, void 0, a1.id, a1.slug)}`;
|
|
}
|
|
return r47;
|
|
};
|
|
const r47 = SUPPORTS_WEBP ? "webp" : "jpg";
|
|
export function getCountryPrices(a0, a1) {
|
|
return a0.prices[a1] != null && a0.prices[a1].countryPrices.prices.length > 0 ? a0.prices[a1].countryPrices : a0.prices[PriceSetAssignmentPurchaseTypes.DEFAULT] != null ? a0.prices[PriceSetAssignmentPurchaseTypes.DEFAULT].countryPrices.prices.length > 0 ? a0.prices[PriceSetAssignmentPurchaseTypes.DEFAULT].countryPrices : null : null;
|
|
}
|
|
export function isOnCollectiblesShopGameShopPage(a0, a1, a2, a3) {
|
|
const r15 = parse(a1);
|
|
const { tab, applicationId, skuId } = r15;
|
|
return a0.indexOf(Routes.COLLECTIBLES_SHOP) >= 0 && (tab === CollectibleShopTab.GAME_SHOPS && applicationId === a2 && (a3 == null || skuId === a3));
|
|
}
|
|
c3500_17 = r47;
|
|
export { c3500_17 as LARGE_ASSET_FORMAT };
|
|
export function hasPrice(a0) {
|
|
return a0.price != null || a0.prices[PriceSetAssignmentPurchaseTypes.DEFAULT] != null;
|
|
}
|
|
export { getPrice };
|
|
export function isGiftPriceDifferent(a0) {
|
|
let r9 = getPrice(a0, PriceSetAssignmentPurchaseTypes.DEFAULT);
|
|
if (r9 == null) {
|
|
r9 = {
|
|
amount: 0,
|
|
currency: CurrencyCodes.USD
|
|
};
|
|
}
|
|
let r12 = getPrice(a0, PriceSetAssignmentPurchaseTypes.GIFT);
|
|
if (r12 == null) {
|
|
r12 = {
|
|
amount: 0,
|
|
currency: CurrencyCodes.USD
|
|
};
|
|
}
|
|
return r9.currency !== r12.currency || r9.amount !== r12.amount;
|
|
}
|
|
export function getOrderedStorefrontSkuIds(a0) {
|
|
const set = new Set();
|
|
const r31 = [];
|
|
loop1: for (const r36 of a0.pages) {
|
|
const r37 = r36;
|
|
for (const skuId of r36.skuIds) {
|
|
if (!set.has(skuId)) {
|
|
set.add(skuId);
|
|
r31.push(skuId);
|
|
}
|
|
}
|
|
let sections = r37.sections;
|
|
if (sections == null) {
|
|
sections = [];
|
|
}
|
|
for (const item of sections) {
|
|
for (const skuId2 of item.skuIds) {
|
|
if (!set.has(skuId2)) {
|
|
set.add(skuId2);
|
|
r31.push(skuId2);
|
|
}
|
|
}
|
|
}
|
|
continue loop1;
|
|
}
|
|
return r31;
|
|
}
|
|
export function isGameItemSKU(a0) {
|
|
return a0 != null && a0.productLine === SKUProductLines.SOCIAL_LAYER_GAME_ITEM;
|
|
}
|
|
export function getMarketingGuildId() {
|
|
const guild = GuildStore.getGuild(STOREFRONT_MARKETING_GUILD_ID_TEST);
|
|
return guild != null && guild.features.has(GuildFeatures.SOCIAL_LAYER_STOREFRONT) ? guild.id : STOREFRONT_MARKETING_GUILD_ID;
|
|
}
|
|
export { hasSocialLayerStorefront };
|
|
export function transformStorefrontMetadataServer(a0) {
|
|
let logo_asset_id = a0.logo_asset_id;
|
|
if (logo_asset_id == null) {
|
|
logo_asset_id = null;
|
|
}
|
|
let light_theme_logo_asset_id = a0.light_theme_logo_asset_id;
|
|
if (light_theme_logo_asset_id == null) {
|
|
light_theme_logo_asset_id = null;
|
|
}
|
|
return {
|
|
logoAssetId: logo_asset_id,
|
|
lightThemeLogoAssetId: light_theme_logo_asset_id
|
|
};
|
|
}
|
|
export function transformSlayerApplicationStorefrontSummaryServer(a0) {
|
|
const published_at = a0.published_at;
|
|
const r1 = published_at == null;
|
|
let publishedAt = null;
|
|
if (!r1) {
|
|
const date = new Date(published_at);
|
|
publishedAt = Number.isNaN(date.getTime()) ? null : date;
|
|
}
|
|
let logo_asset_id = a0.logo_asset_id;
|
|
if (logo_asset_id == null) {
|
|
logo_asset_id = null;
|
|
}
|
|
let light_theme_logo_asset_id = a0.light_theme_logo_asset_id;
|
|
if (light_theme_logo_asset_id == null) {
|
|
light_theme_logo_asset_id = null;
|
|
}
|
|
return {
|
|
id: a0.id,
|
|
publishedAt,
|
|
title: a0.title,
|
|
logoAssetId: logo_asset_id,
|
|
lightThemeLogoAssetId: light_theme_logo_asset_id
|
|
};
|
|
}
|
|
export function transformSlayerApplicationStorefrontServer(a0) {
|
|
const published_at = a0.published_at;
|
|
const r0 = published_at == null;
|
|
let publishedAt = null;
|
|
if (!r0) {
|
|
const date = new Date(published_at);
|
|
publishedAt = Number.isNaN(date.getTime()) ? null : date;
|
|
}
|
|
const r3 = {
|
|
id: a0.id,
|
|
publishedAt,
|
|
applicationId: a0.application_id,
|
|
title: a0.title,
|
|
logoAssetId: a0.logo_asset_id,
|
|
lightThemeLogoAssetId: a0.light_theme_logo_asset_id,
|
|
pages: a0.pages.map((page) => ({
|
|
title: page.title,
|
|
leaderboard: page.leaderboard != null ? {
|
|
title: page.leaderboard.title,
|
|
description: page.leaderboard.description,
|
|
backgroundImageAssetId: page.leaderboard.background_image_asset_id
|
|
} : void 0,
|
|
skuIds: page.sku_ids,
|
|
sections: page.sections != null ? page.sections.map((section) => ({
|
|
title: section.title,
|
|
skuIds: section.sku_ids
|
|
})) : void 0
|
|
})),
|
|
assets: Module12.keyBy(a0.assets, "id"),
|
|
application: a0.application != null ? ApplicationRecord.createFromServer(a0.application) : void 0,
|
|
storefrontPricing: a0.storefront_pricing != null ? transformStorefrontPricesServer(a0.storefront_pricing) : void 0,
|
|
promotions: null
|
|
};
|
|
let promotions = a0.promotions;
|
|
if (promotions == null) {
|
|
promotions = {};
|
|
}
|
|
r3.promotions = Module12.mapValues(promotions, transformSlayerStorefrontPromotionServer);
|
|
return r3;
|
|
}
|
|
export function getPrimaryCarouselItemInfo(a0, a1, r4 = {}) {
|
|
let r41;
|
|
const size = r4.size;
|
|
const r12 = size !== void 0 ? size : 512;
|
|
if (a1 != null) {
|
|
const r3 = a0 == null;
|
|
let r5 = void 0;
|
|
if (!r3) {
|
|
const tenantMetadata = a0.tenantMetadata;
|
|
r5 = tenantMetadata == null ? void 0 : tenantMetadata.socialLayer?.carouselItems;
|
|
}
|
|
if (r5 != null && a0.tenantMetadata.socialLayer.carouselItems.length !== 0) {
|
|
const r30 = a0.tenantMetadata.socialLayer.carouselItems[0];
|
|
if (r30.labelIconAssetId == null) {
|
|
r41 = {
|
|
primaryIconAsset: void 0,
|
|
primaryIconLabel: void 0
|
|
};
|
|
} else {
|
|
let primaryIconAsset = URLUtils.toURLSafe(getAssetURL(a1, r30.labelIconAssetId, r12, "webp"));
|
|
if (primaryIconAsset == null) {
|
|
primaryIconAsset = void 0;
|
|
}
|
|
r41 = {
|
|
primaryIconAsset,
|
|
primaryIconLabel: r30.label
|
|
};
|
|
}
|
|
return r41;
|
|
}
|
|
}
|
|
return {
|
|
primaryIconAsset: void 0,
|
|
primaryIconLabel: void 0
|
|
};
|
|
}
|
|
export function getGameItemThumbnailUrl(a0, r2 = {}) {
|
|
const size = r2.size;
|
|
const r9 = size !== void 0 ? size : 512;
|
|
if (a0 != null && a0.thumbnailAssetId != null) {
|
|
return URLUtils.toURLSafe(getAssetURL(a0.applicationId, a0.thumbnailAssetId, r9, "webp"));
|
|
}
|
|
}
|
|
export function getCardImageURL(a0, r3 = {}) {
|
|
const size = r3.size;
|
|
const r10 = size !== void 0 ? size : 512;
|
|
const applicationId = a0?.applicationId;
|
|
const r17 = a0 == null;
|
|
let r8 = void 0;
|
|
if (!r17) {
|
|
const tenantMetadata = a0.tenantMetadata;
|
|
r8 = tenantMetadata == null ? void 0 : tenantMetadata.socialLayer?.cardImageAssetId;
|
|
}
|
|
if (r8 == null) {
|
|
r8 = a0?.thumbnailAssetId;
|
|
}
|
|
if (r8 != null && applicationId != null) {
|
|
return URLUtils.toURLSafe(getAssetURL(applicationId, r8, r10, "webp"));
|
|
}
|
|
}
|
|
export function getCardBackgroundImageURL(a0, r3 = {}) {
|
|
const size = r3.size;
|
|
const r10 = size !== void 0 ? size : 1024;
|
|
const r2 = a0 == null;
|
|
let r17 = void 0;
|
|
if (!r2) {
|
|
const tenantMetadata = a0.tenantMetadata;
|
|
r17 = tenantMetadata == null ? void 0 : tenantMetadata.socialLayer?.cardBackgroundImageAssetId;
|
|
}
|
|
if (r17 != null && a0?.applicationId != null) {
|
|
return URLUtils.toURLSafe(getAssetURL(a0.applicationId, a0.tenantMetadata.socialLayer.cardBackgroundImageAssetId, r10, c3500_17));
|
|
}
|
|
}
|
|
export { getSKUShareURL };
|
|
export function getForwardedSKUShareURL(a0, a1) {
|
|
return `${getSKUShareURL(a0, a1)}
|
|
|
|
`;
|
|
}
|
|
export function canSeeGameShop(a0) {
|
|
const guild = GuildStore.getGuild(a0);
|
|
return guild != null && hasSocialLayerStorefront(guild);
|
|
}
|
|
export function getHasWishlistOrPopularRecommendations(a0, c14985_0, c14985_1) {
|
|
return a0.length === 0 ? {
|
|
hasWishlist: false,
|
|
hasPopular: false
|
|
} : {
|
|
hasWishlist: a0.some((a0) => {
|
|
let r4 = c14985_0[a0.id];
|
|
if (r4 == null) {
|
|
r4 = {};
|
|
}
|
|
return Object.entries(r4).some((item) => {
|
|
const [r22, r23] = item;
|
|
return r23 === WishlistRecommendationReason.WISHLIST && c14985_1.has(r22);
|
|
});
|
|
}),
|
|
hasPopular: a0.some((item) => {
|
|
const r5 = c14985_0[item.id];
|
|
return r5 == null || Object.entries(r5).every((item) => {
|
|
const [r22, r23] = item;
|
|
return r23 === WishlistRecommendationReason.RECOMMENDATION && c14985_1.has(r22) || !c14985_1.has(r22);
|
|
});
|
|
})
|
|
};
|
|
}
|
|
export function isOnSocialLayerStorefrontPage(a0, a1, a2, a3) {
|
|
const r14 = parse(a1);
|
|
const { tab, applicationId } = r14;
|
|
r14.skuId;
|
|
return a0.indexOf(Routes.COLLECTIBLES_SHOP) >= 0 && (tab === CollectibleShopTab.GAME_SHOPS && applicationId === a2 && true) || a3 != null && a0.indexOf(getChannelsGameShopPrefix(a3)) >= 0;
|
|
}
|
|
export function isOnSocialLayerStorefrontSkuPage({ pathname, search, pageIndex = 0, applicationId, guildId, skuId }) {
|
|
const r20 = parse(search);
|
|
const { tab, applicationId: applicationId2, skuId: skuId2 } = r20;
|
|
return pathname.indexOf(Routes.COLLECTIBLES_SHOP) >= 0 && (tab === CollectibleShopTab.GAME_SHOPS && applicationId2 === applicationId && (skuId == null || skuId2 === skuId)) || guildId != null && pathname.includes(Routes.CHANNELS_GAME_SHOP(guildId, pageIndex, skuId));
|
|
}
|
|
export function useGetSocialLayerStorefrontGuildIdAndApplication(a0) {
|
|
const stateFromStores = useStateFromStores([SocialLayerStorefrontStore], () => SocialLayerStorefrontStore.getGuildIdFromApplicationId(a0));
|
|
const getOrFetchApplication = useGetOrFetchApplication(a0);
|
|
let guildId = stateFromStores;
|
|
if (guildId == null) {
|
|
guildId = getOrFetchApplication?.guildId;
|
|
}
|
|
return {
|
|
guildId,
|
|
application: getOrFetchApplication
|
|
};
|
|
}
|
|
export function getSocialLayerStorefrontApplicationId(a0) {
|
|
let r8 = SocialLayerStorefrontStore.getApplicationIdFromGuildId(a0);
|
|
const guild = GuildStore.getGuild(a0);
|
|
if (r8 == null) {
|
|
r8 = (guild == null ? void 0 : guild.gameApplicationIds?.length) === 1 ? guild.gameApplicationIds[0] : void 0;
|
|
}
|
|
return r8;
|
|
}
|
|
export function useGetSocialLayerStorefrontApplicationId(a0) {
|
|
let r15 = useStateFromStores([SocialLayerStorefrontStore], () => SocialLayerStorefrontStore.getApplicationIdFromGuildId(a0));
|
|
const stateFromStores = useStateFromStores([GuildStore], () => GuildStore.getGuild(a0), [a0]);
|
|
if (r15 == null) {
|
|
r15 = (stateFromStores == null ? void 0 : stateFromStores.gameApplicationIds?.length) === 1 ? stateFromStores.gameApplicationIds[0] : void 0;
|
|
}
|
|
return r15;
|
|
}
|
|
export function getSocialLayerStorefrontGuildId(a0) {
|
|
if (a0 != null) {
|
|
let r6 = SocialLayerStorefrontStore.getGuildIdFromApplicationId(a0);
|
|
if (r6 == null) {
|
|
r6 = ApplicationStore.getApplication(a0)?.guildId;
|
|
}
|
|
return r6;
|
|
}
|
|
}
|