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

99 lines
4.0 KiB
TypeScript

// Metro module 6571 (f6572).
import { useEffect } from "react";
import SubscriptionPlanStore from "../../../../stores/billing/SubscriptionPlanStore";
import SubscriptionStore from "../../../../stores/billing/SubscriptionStore";
import IAPStore_android from "../../../../stores/native/IAPStore.android";
import { PaymentGateways } from "../../../../_bundle/Module505";
import { useStateFromStores } from "../../../../_bundle/Module589";
import { NitroACOMSubscriptionExperiment } from "../../../billing/native/ACOMExperiments";
import NativePaymentHooks_android from "../../../payments/native/hooks/NativePaymentHooks.android";
import useStoreFrontPrice, { PriceStates } from "../../../billing/native/subscription/useStoreFrontPrice";
import { BasePlanIdToProductId } from "../ProductIds.android";
import { isIOS } from "../../../../utils/PlatformUtils";
import useInitialValue from "../../../../hooks/useInitialValue";
import Backoff from "../../../../_bundle/Backoff";
import { fetchPremiumSubscriptionPlans } from "../../../../actions/SubscriptionPlanActionCreators";
import { formatPrice } from "../../../../utils/PriceUtils";
export default function usePremiumPlanPrice(a0) {
let r72;
let storeFront, priceState, c15807_3, c15807_4, c15807_5;
const stateFromStores = useStateFromStores([SubscriptionStore], () => SubscriptionStore.getPremiumTypeSubscription());
let enabled = NitroACOMSubscriptionExperiment.useConfig({
location: "usePremiumPlanPrice"
}).enabled;
storeFront = NativePaymentHooks_android.useNativeIAPPayments().storeFront;
const storeFrontPrice = useStoreFrontPrice(useStateFromStores([SubscriptionPlanStore], () => a0 != null ? SubscriptionPlanStore.get(a0) : null, [a0]), storeFront);
const price = storeFrontPrice.price;
priceState = storeFrontPrice.priceState;
const r43 = a0 != null ? BasePlanIdToProductId[a0] : null;
c15807_3 = r43;
const stateFromStores2 = useStateFromStores([IAPStore_android], () => c15807_3 != null ? IAPStore_android.getProduct(c15807_3) : null, [r43]);
let r56 = isIOS();
if (r56) {
if (!enabled) {
enabled = stateFromStores?.isACOM === true;
}
r56 = enabled;
}
c15807_4 = r56;
const initialValue = useInitialValue(() => new Backoff(500, 10000));
c15807_5 = initialValue;
useEffect(() => {
L12: {
if (c15807_4) {
if (priceState !== PriceStates.PRICE_AVAILABLE) {
if (priceState !== PriceStates.MISMATCHING_COUNTRIES && priceState !== PriceStates.COUNTRY_PRICE_UNAVAILABLE) {
break L12;
}
if (storeFront?.country != null) {
if (!c15807_5.pending && !SubscriptionPlanStore.isFetchingForPremiumSKUs() && !(c15807_5.fails >= 3)) {
const country = storeFront.country;
c15807_5.fail(() => {
if (!SubscriptionPlanStore.isFetchingForPremiumSKUs()) {
fetchPremiumSubscriptionPlans(country, void 0, void 0, PaymentGateways.APPLE_ADVANCED_COMMERCE).catch(() => {});
}
});
return () => {
c15807_5.cancel();
};
}
}
} else {
c15807_5.succeed();
}
}
}
}, [r56, priceState, storeFront, initialValue]);
const r69 = a0 == null;
let r70 = null;
if (!r69) {
if (r56) {
r72 = priceState === PriceStates.PRICE_AVAILABLE ? price != null ? {
price: price.amount,
currency: price.currency,
countryCode: storeFront?.country,
priceString: formatPrice(price.amount, price.currency),
source: "API"
} : null : null;
} else {
const r71 = stateFromStores2 != null;
r72 = null;
if (r71) {
let countryCode = storeFront?.country;
if (countryCode == null) {
countryCode = stateFromStores2.countryCode;
}
r72 = {
price: stateFromStores2.price,
currency: stateFromStores2.currencyCode,
countryCode,
priceString: stateFromStores2.priceString,
source: "IAP"
};
}
}
r70 = r72;
}
return r70;
};