127 lines
4.4 KiB
TypeScript
127 lines
4.4 KiB
TypeScript
// Metro module 11903 (f11904).
|
|
import { useCallback, useContext, useMemo, createContext } from "react";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import SKUStore from "../../../stores/game_store/SKUStore";
|
|
import { v4 } from "../../../_bundle/Module514";
|
|
import { useStateFromStores } from "../../../_bundle/Module589";
|
|
import PremiumUtils from "../../../utils/PremiumUtils";
|
|
import { get1PShopApplicationIdForSKU } from "../VirtualCurrencyUtils";
|
|
import { useSKUOrbPrice } from "../../storefront/StorefrontUtils";
|
|
import { useFetchCollectiblesProduct } from "../../collectibles/hooks/useFetchCollectiblesProduct";
|
|
import { getProductOrbPrice } from "../../collectibles/utils/CollectiblesProductUtils";
|
|
import { captureBillingMessage } from "../../../utils/BillingUtils";
|
|
import { useRedeemVirtualCurrency } from "../hooks/useRedeemVirtualCurrency";
|
|
let context;
|
|
const useOrbCheckoutModalContextProvider = function useOrbCheckoutModalContextProvider({ skuId, loadId, onCheckoutSuccess, onSignFailure, order }) {
|
|
let sKUOrbPrice, product, redeemVirtualCurrency;
|
|
sKUOrbPrice = void 0;
|
|
product = void 0;
|
|
redeemVirtualCurrency = void 0;
|
|
const stateFromStores = useStateFromStores([UserStore], () => PremiumUtils.canUseShopDiscounts(UserStore.getCurrentUser()));
|
|
const stateFromStores2 = useStateFromStores([SKUStore], () => SKUStore.get(skuId), [skuId]);
|
|
const skuProductLine = stateFromStores2 != null ? stateFromStores2.productLine : null;
|
|
let skuApplicationId = stateFromStores2?.applicationId;
|
|
if (skuApplicationId == null) {
|
|
skuApplicationId = get1PShopApplicationIdForSKU(skuId);
|
|
}
|
|
sKUOrbPrice = useSKUOrbPrice({
|
|
sku: stateFromStores2
|
|
});
|
|
product = useFetchCollectiblesProduct(skuId).product;
|
|
const memo = useMemo(() => {
|
|
if (sKUOrbPrice != null) {
|
|
return {
|
|
orbPriceAmount: sKUOrbPrice.amount
|
|
};
|
|
}
|
|
if (product != null) {
|
|
const productOrbPrice = getProductOrbPrice({
|
|
product,
|
|
hasShopDiscount: stateFromStores
|
|
});
|
|
return {
|
|
orbPriceAmount: productOrbPrice !== null ? productOrbPrice.amount : null
|
|
};
|
|
}
|
|
return null;
|
|
}, [sKUOrbPrice, product, stateFromStores]);
|
|
if (memo?.orbPriceAmount == null) {
|
|
captureBillingMessage("Orb price not found for product", {
|
|
tags: {
|
|
sku_id: skuId
|
|
}
|
|
});
|
|
}
|
|
const redeemVirtualCurrency2 = useRedeemVirtualCurrency({
|
|
skuId,
|
|
loadId,
|
|
order,
|
|
onSignFailure
|
|
});
|
|
redeemVirtualCurrency = redeemVirtualCurrency2.redeemVirtualCurrency;
|
|
const { isSubmitting, error } = redeemVirtualCurrency2;
|
|
return {
|
|
skuId,
|
|
skuProductLine,
|
|
skuApplicationId,
|
|
loadId,
|
|
orbProductContext: memo,
|
|
onRedeemVirtualCurrency: useCallback((c27205_0) => {
|
|
redeemVirtualCurrency(skuId, loadId, (a0) => {
|
|
if (onCheckoutSuccess != null) {
|
|
onCheckoutSuccess({
|
|
entitlements: a0,
|
|
skuId
|
|
});
|
|
}
|
|
c27205_0(a0);
|
|
});
|
|
}, [skuId, loadId, redeemVirtualCurrency, onCheckoutSuccess]),
|
|
isRedeeming: isSubmitting,
|
|
orbRedemptionError: error
|
|
};
|
|
};
|
|
context = createContext({
|
|
skuId: "123",
|
|
skuProductLine: null,
|
|
skuApplicationId: void 0,
|
|
loadId: v4(),
|
|
analyticsLocations: [],
|
|
analyticsSourceLocation: void 0,
|
|
isRedeeming: false,
|
|
orbRedemptionError: null,
|
|
orbProductContext: null,
|
|
onRedeemVirtualCurrency: () => {}
|
|
});
|
|
export { useOrbCheckoutModalContextProvider };
|
|
export function OrbCheckoutModalContextProvider(a0) {
|
|
const { skuId: skuId2, loadId: loadId2, analyticsSourceLocation } = a0;
|
|
let analyticsLocations = a0.analyticsLocations;
|
|
const { onCheckoutSuccess: onCheckoutSuccess2, children } = a0;
|
|
const orbCheckoutModalContextProvider = useOrbCheckoutModalContextProvider({
|
|
skuId: skuId2,
|
|
loadId: loadId2,
|
|
onCheckoutSuccess: onCheckoutSuccess2
|
|
});
|
|
const { orbProductContext, onRedeemVirtualCurrency: onRedeemVirtualCurrency2, isRedeeming, orbRedemptionError, skuProductLine, skuApplicationId } = orbCheckoutModalContextProvider;
|
|
const Provider = context.Provider;
|
|
if (analyticsLocations == null) {
|
|
analyticsLocations = [];
|
|
}
|
|
return <Provider value={{
|
|
skuId: skuId2,
|
|
skuProductLine,
|
|
skuApplicationId,
|
|
loadId: loadId2,
|
|
analyticsLocations,
|
|
analyticsSourceLocation,
|
|
orbProductContext,
|
|
onRedeemVirtualCurrency: onRedeemVirtualCurrency2,
|
|
isRedeeming,
|
|
orbRedemptionError
|
|
}}>{children}</Provider>;
|
|
}
|
|
export function useOrbCheckoutModalContext() {
|
|
return useContext(context);
|
|
}
|