90 lines
4.6 KiB
TypeScript
90 lines
4.6 KiB
TypeScript
// Metro module 11625 (f11626).
|
|
import { useCallback } from "react";
|
|
import GuildStore from "../../../../../stores/GuildStore";
|
|
import GuildBoostSlotStore from "../../../../../stores/billing/GuildBoostSlotStore";
|
|
import { BoostPurchaseIntent, GuildPowerupType } from "../../constants/GuildPowerupsConstants";
|
|
import useGuildPowerupOnToggle from "../../hooks/useGuildPowerupOnToggle";
|
|
import { useStateFromStores } from "../../../../../_bundle/Module589";
|
|
import useAvailableBoostCountForPowerup from "../../hooks/useAvailableBoostCountForPowerup";
|
|
import useAnalyticsLocations from "../../../../app_analytics/useAnalyticsLocations";
|
|
import useGuildBoostPurchaseHandler from "../../../../guild_boosting/native/hooks/useGuildBoostPurchaseHandler";
|
|
import { getAvailableGuildBoostSlots } from "../../../../../utils/GuildBoostingUtils";
|
|
import ActionSheetActionCreators from "../../../../action_sheet/native/ActionSheetActionCreators";
|
|
import { GUILD_POWERUPS_BOTTOM_SHEET_KEY } from "../utils/openGuildPowerupsBottomSheet";
|
|
import { openTransferModal } from "../../../../../actions/native/BoostingActionCreators";
|
|
import { launchGuildBoostFlowOrAlert } from "../../../../guild_boosting/native/GuildBoostPurchasingUtils";
|
|
import ModalActionCreators from "../../../../../actions/ModalActionCreators";
|
|
import { PREMIUM_KEY } from "../../../../../components_native/premium/PremiumModal";
|
|
export default function useGuildPowerupOnActivate(a0, a1) {
|
|
let c19036_4, analyticsLocations, shouldUseMobileWebRedirectCheckout, handleMobileWebRedirectCheckout;
|
|
let c19036_0 = a0;
|
|
const guildPowerupOnToggle = useGuildPowerupOnToggle(a0, a1);
|
|
const { onToggle, isLoading, error } = guildPowerupOnToggle;
|
|
const stateFromStores = useStateFromStores([GuildStore], () => GuildStore.getGuild(c19036_0));
|
|
const availableBoostCountForPowerup = useAvailableBoostCountForPowerup(a0, a1);
|
|
c19036_4 = availableBoostCountForPowerup;
|
|
analyticsLocations = useAnalyticsLocations().analyticsLocations;
|
|
const guildBoostPurchaseHandler = useGuildBoostPurchaseHandler("guild_powerup_activation");
|
|
shouldUseMobileWebRedirectCheckout = guildBoostPurchaseHandler.shouldUseMobileWebRedirectCheckout;
|
|
handleMobileWebRedirectCheckout = guildBoostPurchaseHandler.handleMobileWebRedirectCheckout;
|
|
return {
|
|
onActivate: useCallback(() => {
|
|
if (stateFromStores != null) {
|
|
if (a1 != null) {
|
|
if (c19036_4 >= a1.cost) {
|
|
onToggle(true);
|
|
} else {
|
|
const r11 = a1.cost - c19036_4;
|
|
let c27121_0 = r11;
|
|
const availableGuildBoostSlots = getAvailableGuildBoostSlots(GuildBoostSlotStore.boostSlots);
|
|
const LEVEL = a1.type === GuildPowerupType.LEVEL ? BoostPurchaseIntent.LEVEL : BoostPurchaseIntent.PERK;
|
|
ActionSheetActionCreators.hideActionSheet(GUILD_POWERUPS_BOTTOM_SHEET_KEY);
|
|
if (availableGuildBoostSlots.length > 0) {
|
|
openTransferModal({
|
|
guildBoostSlots: availableGuildBoostSlots.slice(0, r11),
|
|
guildId: stateFromStores.id,
|
|
intent: LEVEL,
|
|
onResult: (a0) => {
|
|
if (a0) {
|
|
onToggle(true);
|
|
}
|
|
}
|
|
});
|
|
} else if (shouldUseMobileWebRedirectCheckout) {
|
|
handleMobileWebRedirectCheckout(analyticsLocations, stateFromStores.id);
|
|
} else {
|
|
launchGuildBoostFlowOrAlert({
|
|
source: {
|
|
page: "Guild Powerups",
|
|
section: "Powerup Activation"
|
|
},
|
|
analyticsLocations,
|
|
guildId: stateFromStores.id,
|
|
onBack: () => ModalActionCreators.popWithKey(PREMIUM_KEY),
|
|
onPaymentSuccess: () => {
|
|
const availableGuildBoostSlots = getAvailableGuildBoostSlots(GuildBoostSlotStore.boostSlots);
|
|
if (availableGuildBoostSlots.length >= c27121_0) {
|
|
openTransferModal({
|
|
guildBoostSlots: availableGuildBoostSlots.slice(0, a1.cost),
|
|
guildId: stateFromStores.id,
|
|
intent: LEVEL,
|
|
onResult: (a0) => {
|
|
if (a0) {
|
|
onToggle(true);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
onPaymentDismiss: () => ModalActionCreators.popWithKey(PREMIUM_KEY)
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}, [onToggle, a1, availableBoostCountForPowerup, stateFromStores, analyticsLocations, shouldUseMobileWebRedirectCheckout, handleMobileWebRedirectCheckout]),
|
|
isLoading,
|
|
error
|
|
};
|
|
};
|