79 lines
3.1 KiB
TypeScript
79 lines
3.1 KiB
TypeScript
// Metro module 11598 (f11599).
|
|
import { useMemo } from "react";
|
|
import GameServerStore from "../../game_server/GameServerStore";
|
|
import GuildPowerupsStore from "../GuildPowerupsStore";
|
|
import { useStateFromStores } from "../../../../_bundle/Module589";
|
|
import { useExpiringPowerupCoachmarkEnabled } from "../experiments/ExpiringPowerupCoachmarkExperiment";
|
|
import { getDaysRemaining } from "../../../collectibles/CollectiblesUtils";
|
|
import { HermesBuiltin } from "../../../../_hermes/prelude";
|
|
export default function useFeaturedExpiringPowerup(c19020_0) {
|
|
let stateFromStores2, expiringPowerupCoachmarkEnabled;
|
|
const stateFromStores = useStateFromStores([GuildPowerupsStore], () => GuildPowerupsStore.getStateForGuild(c19020_0));
|
|
stateFromStores2 = useStateFromStores([GameServerStore], () => GameServerStore.getStateForGuild(c19020_0));
|
|
expiringPowerupCoachmarkEnabled = useExpiringPowerupCoachmarkEnabled("useFeaturedExpiringPowerup");
|
|
return useMemo(() => {
|
|
L21: {
|
|
if (expiringPowerupCoachmarkEnabled) {
|
|
const r11 = Object;
|
|
let r9 = stateFromStores?.unlockedPowerups;
|
|
if (r9 == null) {
|
|
r9 = {};
|
|
}
|
|
const r16 = r11.values(r9);
|
|
const r20 = [];
|
|
const r1 = HermesBuiltin.arraySpread(r20, r16, 0);
|
|
const r21 = Object;
|
|
let r24 = stateFromStores2?.entitlements;
|
|
if (r24 == null) {
|
|
r24 = {};
|
|
}
|
|
HermesBuiltin.arraySpread(r20, r21.values(r24), r1);
|
|
const r31 = r20.filter((item) => {
|
|
let r1 = item.ends_at != null;
|
|
if (r1) {
|
|
let r7 = item.metadata?.num_expiring_boosts;
|
|
if (r7 == null) {
|
|
r7 = 0;
|
|
}
|
|
r1 = r7 > 0;
|
|
}
|
|
return r1;
|
|
});
|
|
if (r31.length !== 0) {
|
|
const r35 = r31.reduce((acc, item) => item.ends_at > acc.ends_at ? item : acc);
|
|
let name = stateFromStores == null ? void 0 : stateFromStores.allPowerups[r35.sku_id]?.title;
|
|
if (name == null) {
|
|
name = null;
|
|
}
|
|
const sku = r35.sku;
|
|
const r43 = sku == null;
|
|
let r44 = void 0;
|
|
if (!r43) {
|
|
const tenant_metadata = sku.tenant_metadata;
|
|
r44 = tenant_metadata == null ? void 0 : tenant_metadata.guild_monetization?.game_server;
|
|
}
|
|
const isGameServer = r44 != null;
|
|
if (name === null && !isGameServer) {
|
|
break L21;
|
|
}
|
|
const r50 = {
|
|
name,
|
|
daysUntilExpiry: Math.max(0, getDaysRemaining(new Date(r35.ends_at))),
|
|
numExpiringBoosts: null,
|
|
isGameServer: null,
|
|
skuId: null
|
|
};
|
|
let numExpiringBoosts = r35.metadata?.num_expiring_boosts;
|
|
if (numExpiringBoosts == null) {
|
|
numExpiringBoosts = 0;
|
|
}
|
|
r50.numExpiringBoosts = numExpiringBoosts;
|
|
r50.isGameServer = isGameServer;
|
|
r50.skuId = r35.sku_id;
|
|
return r50;
|
|
}
|
|
}
|
|
}
|
|
}, [stateFromStores, stateFromStores2, expiringPowerupCoachmarkEnabled]);
|
|
};
|