197 lines
9.0 KiB
TypeScript
197 lines
9.0 KiB
TypeScript
// Metro module 11887 (f11888).
|
|
import { useState, useEffect, useCallback } from "react";
|
|
import { View } from "react-native";
|
|
import BadgeDirectoryStore from "../../badges/BadgeDirectoryStore";
|
|
import { useNativeCheckoutStore } from "../../checkout/native/NativeCheckoutStore";
|
|
import { AnalyticEvents, MarketingURLs } from "../../../Constants";
|
|
import { GiftingOrigin, PremiumGiftStyles } from "../../premium/PremiumConstants";
|
|
import { PaymentGateways } from "../../../_bundle/Module505";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import useSafeAreaInsetsKeyboardAware_native from "../../safe_area/useSafeAreaInsetsKeyboardAware.native";
|
|
import { GiftingBadgeExperiment } from "../../premium/gifting/experiments/GiftingBadgeExperiment";
|
|
import { useStateFromStoresObject } from "../../../_bundle/Module589";
|
|
import { BadgeId } from "../../../_bundle/Module8106";
|
|
import useAnalyticsLocations from "../../app_analytics/useAnalyticsLocations";
|
|
import useSyncGiftOptionsToOrder from "../../checkout/native/useSyncGiftOptionsToOrder";
|
|
import useMobileCollectiblesPurchaseSKU_android from "./hooks/useMobileCollectiblesPurchaseSKU.android";
|
|
import Dispatcher from "../../../Dispatcher";
|
|
import ModalActionCreators from "../../../actions/ModalActionCreators";
|
|
import AlertActionCreators from "../../../actions/native/AlertActionCreators";
|
|
import { isIOS } from "../../../utils/PlatformUtils";
|
|
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
|
|
import GiftingBadgeProgressBanner from "../../premium/gifting/native/views/GiftingBadgeProgressBanner";
|
|
import { Text } from "../../../design/components/Text/native/Text";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { Button } from "../../../design/components/Button/native/Button.native";
|
|
import { GiftACOMOrderExperiment } from "../../billing/native/ACOMExperiments";
|
|
import { useAndroidShopOrdersEnabled } from "../../billing/experiments/AndroidShopOrdersExperiment";
|
|
import { isGooglePlayBillingSupported } from "../../device/BillingPlatformUtils";
|
|
import useCollectiblesExternalGatewayFacet_android from "./hooks/useCollectiblesExternalGatewayFacet.android";
|
|
import { closeShopGiftModal } from "./openGiftModal";
|
|
import { NativePaymentContextProvider } from "../../payments/native/NativePaymentContext";
|
|
import NativeCheckoutStoreProvider from "../../checkout/native/stores/NativeCheckoutStoreProvider";
|
|
let useStyles, c8152_17;
|
|
const CollectiblesShopGiftPurchaseSection = function CollectiblesShopGiftPurchaseSection(props) {
|
|
let badgeProgress, state, setState, awaitSync, c19253_8;
|
|
const { product, isPurchaseDisabled, giftOptions, baseAnalyticsFields, giftingOrigin } = props;
|
|
badgeProgress = void 0;
|
|
state = void 0;
|
|
setState = void 0;
|
|
awaitSync = void 0;
|
|
c19253_8 = void 0;
|
|
const styles = useStyles(useSafeAreaInsetsKeyboardAware_native().insets.bottom);
|
|
const enabled = GiftingBadgeExperiment.useConfig({
|
|
location: "CollectiblesShopGiftPurchaseSection"
|
|
}).enabled;
|
|
const stateFromStoresObject = useStateFromStoresObject([BadgeDirectoryStore], () => ({
|
|
nextTier: BadgeDirectoryStore.getNextTier(BadgeId.GIFTING),
|
|
giftsToNextTier: BadgeDirectoryStore.getRemainingToNextTier(BadgeId.GIFTING),
|
|
badgeProgress: BadgeDirectoryStore.getSingleRequirementProgress(BadgeId.GIFTING)?.current
|
|
}));
|
|
const { nextTier, giftsToNextTier } = stateFromStoresObject;
|
|
badgeProgress = stateFromStoresObject.badgeProgress;
|
|
[state, setState] = useState(c8152_17.NOT_STARTED);
|
|
const analyticsLocations = useAnalyticsLocations().analyticsLocations;
|
|
const nativeCheckoutStore = useNativeCheckoutStore((a0) => a0.orderRecord);
|
|
awaitSync = useSyncGiftOptionsToOrder(nativeCheckoutStore, giftOptions).awaitSync;
|
|
c19253_8 = useMobileCollectiblesPurchaseSKU_android({
|
|
product,
|
|
analyticsLocations,
|
|
orderId: nativeCheckoutStore?.id,
|
|
analyticsData: baseAnalyticsFields,
|
|
onPurchaseComplete: () => {
|
|
if (!(giftOptions.recipient_id == null || giftingOrigin !== GiftingOrigin.USER_PROFILE_WISHLIST && giftingOrigin !== GiftingOrigin.DM_CHANNEL_WISHLIST)) {
|
|
Dispatcher.dispatch({
|
|
type: "WISHLIST_GIFT_SENT",
|
|
skuId: product.skuId,
|
|
recipientId: giftOptions.recipient_id
|
|
});
|
|
}
|
|
setState(c8152_17.SUCCEEDED);
|
|
ModalActionCreators.pop();
|
|
AlertActionCreators.openLazy({
|
|
importer: () => import("../../checkout/native/gifting/UnifiedGiftModalSuccessScreen").then(({ default: Component }) => (a0) => {
|
|
let gift_style = giftOptions.gift_style;
|
|
if (gift_style == null) {
|
|
gift_style = PremiumGiftStyles.STANDARD_BOX;
|
|
}
|
|
return <Component giftStyle={gift_style} giftBadgeProgress={badgeProgress} {...a0} />;
|
|
})
|
|
});
|
|
if (isIOS()) {
|
|
AnalyticsUtils.track(AnalyticEvents.PAYMENT_FLOW_SUCCEEDED, baseAnalyticsFields);
|
|
}
|
|
},
|
|
onPurchaseError: () => {
|
|
setState(c8152_17.FAILED);
|
|
AnalyticsUtils.track(AnalyticEvents.PAYMENT_FLOW_FAILED, baseAnalyticsFields);
|
|
},
|
|
onPurchasePending: () => {},
|
|
giftParams: {
|
|
isGift: true,
|
|
options: giftOptions
|
|
}
|
|
});
|
|
useEffect(() => () => {
|
|
if (state !== c8152_17.SUCCEEDED) {
|
|
AnalyticsUtils.track(AnalyticEvents.PAYMENT_FLOW_CANCELED, baseAnalyticsFields);
|
|
}
|
|
}, []);
|
|
let r77 = null;
|
|
if (enabled) {
|
|
const r78 = nextTier != null;
|
|
r77 = null;
|
|
if (r78) {
|
|
let name = nextTier.name;
|
|
if (name == null) {
|
|
name = "";
|
|
}
|
|
r77 = <GiftingBadgeProgressBanner giftsToNextTier={giftsToNextTier} nextTierName={name} nextTierIcon={nextTier.simple_icon_url} />;
|
|
}
|
|
}
|
|
return <View style={styles.container}>
|
|
{r77}
|
|
<Text variant="text-xs/normal" style={styles.disclaimer}>
|
|
{intl.format(t.rsEdd2, {
|
|
buyButtonLabel: intl.string(t.ouo4FK),
|
|
paidServiceTermURL: MarketingURLs.PAID_TERMS,
|
|
virtualGoodsURL: MarketingURLs.PAID_TERMS_VIRTUAL_GOODS
|
|
})}
|
|
</Text>
|
|
<Button disabled={isPurchaseDisabled} loading={state === c8152_17.PURCHASING} variant="active" text={intl.string(t.ouo4FK)} onPress={async () => {
|
|
let c27204_2 = 0;
|
|
L15: {
|
|
try {
|
|
setState(c8152_17.PURCHASING);
|
|
if (await awaitSync()) {
|
|
c27204_2 = 1;
|
|
await (0, c19253_8)();
|
|
c27204_2 = 0;
|
|
break L15;
|
|
}
|
|
setState(c8152_17.FAILED);
|
|
AnalyticsUtils.track(AnalyticEvents.PAYMENT_FLOW_FAILED, baseAnalyticsFields);
|
|
} catch ($e) {
|
|
let r26 = $e;
|
|
if (c27204_2 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c27204_2 = 0;
|
|
(0, setState)(c8152_17.FAILED);
|
|
break L15;
|
|
} catch ($e) {
|
|
r26 = $e;
|
|
if (c27204_2 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r26;
|
|
}
|
|
return void 0;
|
|
}
|
|
}} />
|
|
</View>;
|
|
};
|
|
useStyles = createStyles((a0) => ({
|
|
container: {
|
|
paddingBottom: Module712.space.PX_12 + a0,
|
|
paddingTop: Module712.space.PX_12,
|
|
paddingHorizontal: Module712.space.PX_16,
|
|
gap: Module712.space.PX_8,
|
|
backgroundColor: Module712.colors.BACKGROUND_BASE_LOW,
|
|
...Module712.shadows.SHADOW_TOP_HIGH
|
|
},
|
|
disclaimer: {
|
|
includeFontPadding: true
|
|
}
|
|
}));
|
|
c8152_17 = {
|
|
NOT_STARTED: "not_started",
|
|
PURCHASING: "purchasing",
|
|
SUCCEEDED: "succeeded",
|
|
FAILED: "failed"
|
|
};
|
|
export default function WrappedCollectiblesShopGiftPurchaseSection(props) {
|
|
const { product: product2, isPurchaseDisabled, giftOptions: giftOptions2, baseAnalyticsFields: baseAnalyticsFields2, giftingOrigin: giftingOrigin2, onGiftModalDismiss } = props;
|
|
const enabled = GiftACOMOrderExperiment.useConfig({
|
|
location: "WrappedCollectiblesShopGiftPurchaseSection"
|
|
}).enabled;
|
|
const androidShopOrdersEnabled = useAndroidShopOrdersEnabled({
|
|
location: "WrappedCollectiblesShopGiftPurchaseSection"
|
|
});
|
|
const paymentGateway = isIOS() ? PaymentGateways.APPLE_ADVANCED_COMMERCE : PaymentGateways.GOOGLE;
|
|
return <NativePaymentContextProvider skuIDs={[]} activeSubscription={null}>
|
|
<NativeCheckoutStoreProvider key={product2.skuId} paymentGateway={paymentGateway} orderRequired={paymentGateway === PaymentGateways.APPLE_ADVANCED_COMMERCE && enabled || paymentGateway === PaymentGateways.GOOGLE && isGooglePlayBillingSupported() && androidShopOrdersEnabled} skuIds={[product2.skuId]} isGift activeSubscription={null} initialExternalGatewayFacet={useCollectiblesExternalGatewayFacet_android(product2)} onOrderRetryCancellation={useCallback(() => {
|
|
closeShopGiftModal();
|
|
if (onGiftModalDismiss != null) {
|
|
onGiftModalDismiss();
|
|
}
|
|
}, [onGiftModalDismiss])}>
|
|
<CollectiblesShopGiftPurchaseSection product={product2} isPurchaseDisabled={isPurchaseDisabled} giftOptions={giftOptions2} baseAnalyticsFields={baseAnalyticsFields2} giftingOrigin={giftingOrigin2} />
|
|
</NativeCheckoutStoreProvider>
|
|
</NativePaymentContextProvider>;
|
|
};
|