Files
discord-decomp/modules/premium/roadblocks/native/hooks/usePremiumFeatureUpsellGetNitro.tsx
T
2026-11-01 12:12:55 +02:00

59 lines
2.7 KiB
TypeScript

// Metro module 6210 (f6211).
import { useState, useRef, useCallback } from "react";
import SubscriptionStore from "../../../../../stores/billing/SubscriptionStore";
import UserOfferStore from "../../../../../stores/billing/UserOfferStore";
import { PremiumTypes } from "../../../PremiumConstants";
import { AnalyticsObjectTypes } from "../../../../../Constants";
import useAnalyticsLocations from "../../../../app_analytics/useAnalyticsLocations";
import openPremiumPlanSelectionActionSheet from "../../../native/openPremiumPlanSelectionActionSheet";
import { fetchSubscriptions } from "../../../../billing/actions/BillingActionCreators";
import { fetchUserOffer } from "../../../UserOfferActionCreators";
import { presentFailedToast } from "../../../../toast/native/ToastUtils";
import { intl, t } from "../../../../../intl/index.native";
import { getBestActiveInput } from "../../../../../utils/native/ChatInputUtils";
export default function usePremiumFeatureUpsellGetNitro(a0, a1, a2, a3) {
const page = a2;
const [loading, setState] = useState(false);
const analyticsLocations = useAnalyticsLocations().analyticsLocations;
const ref = useRef(0);
const callback = useCallback(() => {
const premiumTypeSubscription = SubscriptionStore.getPremiumTypeSubscription(false);
const hasFetchedSubscriptions = SubscriptionStore.hasFetchedSubscriptions();
const r1 = premiumTypeSubscription == null || Object.keys(premiumTypeSubscription).length === 0;
const r21 = UserOfferStore.hasFetchedOffer() && !UserOfferStore.hasAnyUnexpiredOffer();
L23: {
const isFetchingOffer = UserOfferStore.isFetchingOffer();
if (hasFetchedSubscriptions && (r1 && r21)) {
openPremiumPlanSelectionActionSheet({
analyticsLocation: {
page,
objectType: AnalyticsObjectTypes.BUY
},
analyticsLocations,
premiumType: a0 ? PremiumTypes.TIER_0 : PremiumTypes.TIER_2
}, a3);
} else {
if (!(hasFetchedSubscriptions && isFetchingOffer) && ref.current < 5) {
setState(true);
Promise.all([hasFetchedSubscriptions ? Promise.resolve() : fetchSubscriptions(), isFetchingOffer ? Promise.resolve() : fetchUserOffer("usePremiumFeatureUpsellGetNitro")]).then(() => {
ref.current = ref.current + 1;
callback();
}).catch(() => {
presentFailedToast(intl.string(t.R0RpRX));
}).finally(() => setState(false));
break L23;
}
a1();
const bestActiveInput = getBestActiveInput();
if (bestActiveInput != null) {
bestActiveInput.closeCustomKeyboard();
}
}
}
}, [a2, analyticsLocations, a1, a0, a3]);
return {
loading,
onPress: callback
};
};