286 lines
11 KiB
TypeScript
286 lines
11 KiB
TypeScript
// Metro module 14794 (f14795).
|
|
import { useState, useRef, useEffect, useMemo } from "react";
|
|
import { View } from "react-native";
|
|
import UserStore from "../../../../stores/UserStore";
|
|
import SKUStore from "../../../../stores/game_store/SKUStore";
|
|
import { PriceSetAssignmentPurchaseTypes } from "../../../../Constants";
|
|
import { PremiumTypes } from "../../../premium/PremiumConstants";
|
|
import Logger from "../../../debug/Logger";
|
|
import useSafeAreaInsets_native from "../../../safe_area/useSafeAreaInsets.native";
|
|
import { useNativeGiftContext, NativeGiftContextProvider } from "../../../payments/native/NativeGiftContext";
|
|
import { useStateFromStores } from "../../../../_bundle/Module589";
|
|
import { useFetchCollectiblesProduct } from "../../../collectibles/hooks/useFetchCollectiblesProduct";
|
|
import * as _CollectiblesActionCreators from "../../../collectibles/CollectiblesActionCreators";
|
|
import * as _PremiumTypeUtils from "../../../../utils/PremiumTypeUtils";
|
|
import { loadInAppSkus } from "../../../../actions/native/GPlayActionCreators";
|
|
import useMobileCollectiblesPurchaseSKU_android from "../../../collectibles/native/hooks/useMobileCollectiblesPurchaseSKU.android";
|
|
import ActionSheetActionCreators from "../../../action_sheet/native/ActionSheetActionCreators";
|
|
import AlertActionCreators from "../../../../actions/native/AlertActionCreators";
|
|
import { getFormattedPriceForCollectiblesProduct } from "../../../collectibles/CollectiblesUtils";
|
|
import { Stack } from "../../../../design/components/Stack/native/Stack.native";
|
|
import { Text } from "../../../../design/components/Text/native/Text";
|
|
import { Card } from "../../../../design/components/Card/native/Card.native";
|
|
import { Button } from "../../../../design/components/Button/native/Button.native";
|
|
import PremiumGiftBackgroundSelect from "../../../premium/native/gifting/PremiumGiftBackgroundSelect";
|
|
import { v4 } from "../../../../_bundle/Module514";
|
|
import { getBasePurchaseFlowAnalyticsFields } from "../../../premium/native/PremiumAnalyticsUtils";
|
|
import { BottomSheet } from "../../../../design/components/Sheet/native/BottomSheet.native";
|
|
import { NativePaymentContextProvider } from "../../../payments/native/NativePaymentContext";
|
|
let c10439_13, SimpleRequestOTPActionSheet;
|
|
const GiftPurchaseSKUView = function GiftPurchaseSKUView(props) {
|
|
let state, setState, currentUser, ref, product, memo, memo2, c21348_8;
|
|
const { selectedSkuId, giftRecipientId, giftMessage } = props;
|
|
state = void 0;
|
|
setState = void 0;
|
|
currentUser = void 0;
|
|
ref = void 0;
|
|
product = void 0;
|
|
memo = void 0;
|
|
memo2 = void 0;
|
|
c21348_8 = void 0;
|
|
let _submitGiftPurchase2 = function _submitGiftPurchase() {
|
|
const r9 = async () => {
|
|
let c30781_2;
|
|
let c30781_3 = 0;
|
|
let c31740_0;
|
|
const r16 = "Cannot proceed with purchase: collectibleProduct is undefined";
|
|
L17: {
|
|
L15: {
|
|
try {
|
|
c30781_3 = 1;
|
|
if (product == null) {
|
|
c10439_13.error(r16);
|
|
AlertActionCreators.show({
|
|
title: "Product Not Found",
|
|
body: "The product information could not be loaded. Please try again."
|
|
});
|
|
c30781_3 = 0;
|
|
break L17;
|
|
}
|
|
if (product.googleSkuIds != null && memo.length !== 0) {
|
|
await c21348_8();
|
|
c30781_3 = 0;
|
|
break L15;
|
|
}
|
|
c10439_13.error(`No Google SKU IDs available for product ${product.skuId}`);
|
|
AlertActionCreators.show({
|
|
title: "Product Not Available",
|
|
body: "This product is not available for purchase on Google Play."
|
|
});
|
|
c30781_3 = 0;
|
|
} catch ($e) {
|
|
const r31 = $e;
|
|
let r7 = r31;
|
|
c30781_2 = r31;
|
|
if (c30781_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r95 = c30781_2;
|
|
c30781_3 = 0;
|
|
c31740_0 = r95;
|
|
c10439_13.warn("Error creating gift purchase:", c31740_0);
|
|
AlertActionCreators.show({
|
|
title: "Gift Purchase Failed",
|
|
body: `Error: ${c31740_0?.message || JSON.stringify(c31740_0)}`
|
|
});
|
|
break L15;
|
|
} catch (r91) {
|
|
r7 = r91;
|
|
c30781_2 = r91;
|
|
if (c30781_3 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
_submitGiftPurchase2 = r9;
|
|
return r9.apply(this, arguments);
|
|
};
|
|
const safeAreaInsets_native = useSafeAreaInsets_native();
|
|
[state, setState] = useState(false);
|
|
currentUser = UserStore.getCurrentUser();
|
|
ref = useRef({});
|
|
const giftStyle = useNativeGiftContext().giftStyle;
|
|
const stateFromStores = useStateFromStores([SKUStore], () => SKUStore.get(selectedSkuId));
|
|
const fetchCollectiblesProduct = useFetchCollectiblesProduct(selectedSkuId);
|
|
product = fetchCollectiblesProduct.product;
|
|
let isFetching = fetchCollectiblesProduct.isFetching;
|
|
useEffect(() => {
|
|
if (selectedSkuId != null) {
|
|
_CollectiblesActionCreators.fetchCollectiblesProduct(selectedSkuId);
|
|
}
|
|
}, [selectedSkuId]);
|
|
memo = useMemo(() => {
|
|
if (product != null && product.googleSkuIds != null) {
|
|
const isPremium = _PremiumTypeUtils.isPremium(currentUser, PremiumTypes.TIER_2);
|
|
const googleSkuIds = product.googleSkuIds;
|
|
const r18 = isPremium ? googleSkuIds[PriceSetAssignmentPurchaseTypes.MOBILE_PREMIUM_TIER_2] : googleSkuIds[PriceSetAssignmentPurchaseTypes.MOBILE];
|
|
return r18 == null ? [r18] : Object.values(product.googleSkuIds);
|
|
}
|
|
c10439_13.warn(`No googleSkuIds available for product: ${selectedSkuId}`);
|
|
return [];
|
|
}, [product, currentUser, selectedSkuId]);
|
|
memo2 = useMemo(() => memo.sort().join(","), [memo]);
|
|
useEffect(() => {
|
|
let _loadGoogleSkus2 = function _loadGoogleSkus() {
|
|
const r9 = async () => {
|
|
let c31741_2;
|
|
let c31741_3 = 0;
|
|
let c32061_0;
|
|
let r10 = "Unable to fetch product IDs from Google Play store:";
|
|
L10: {
|
|
L18: {
|
|
try {
|
|
if (memo2 != null && ref.current[memo2]) {
|
|
break L10;
|
|
}
|
|
if (memo.length === 0) {
|
|
break L10;
|
|
}
|
|
if (state) {
|
|
break L10;
|
|
}
|
|
setState(true);
|
|
c31741_3 = 1;
|
|
await loadInAppSkus(memo);
|
|
r10 = "Unable to fetch product IDs from Google Play store:";
|
|
if (memo2 != null) {
|
|
ref.current[memo2] = true;
|
|
}
|
|
(0, setState)(false);
|
|
c31741_3 = 0;
|
|
} catch ($e) {
|
|
const r28 = $e;
|
|
let r7 = r28;
|
|
c31741_2 = r28;
|
|
if (c31741_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r86 = c31741_2;
|
|
c31741_3 = 0;
|
|
c32061_0 = r86;
|
|
c10439_13.error(r10, c32061_0);
|
|
(0, setState)(false);
|
|
break L18;
|
|
} catch (r82) {
|
|
r7 = r82;
|
|
c31741_2 = r82;
|
|
if (c31741_3 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
_loadGoogleSkus2 = r9;
|
|
return r9.apply(this, arguments);
|
|
};
|
|
(function loadGoogleSkus() {
|
|
return _loadGoogleSkus2.apply(this, arguments);
|
|
})();
|
|
}, [memo, state, memo2]);
|
|
c21348_8 = useMobileCollectiblesPurchaseSKU_android({
|
|
product: product == null ? {
|
|
skuId: selectedSkuId,
|
|
googleSkuIds: {}
|
|
} : product,
|
|
onPurchaseComplete: function onPurchaseComplete() {
|
|
ActionSheetActionCreators.hideActionSheet();
|
|
},
|
|
onPurchaseError: () => {
|
|
c10439_13.error("Purchase error occurred");
|
|
},
|
|
onPurchasePending: () => {
|
|
c10439_13.info("Purchase is pending");
|
|
},
|
|
giftParams: {
|
|
isGift: true,
|
|
options: {
|
|
recipient_id: giftRecipientId,
|
|
custom_message: giftMessage,
|
|
gift_style: giftStyle
|
|
}
|
|
}
|
|
});
|
|
const [r82, r83] = useMemo(() => product == null ? ["Loading...", "Loading..."] : [getFormattedPriceForCollectiblesProduct(product, true, true), getFormattedPriceForCollectiblesProduct(product, false, true)], [product]);
|
|
if (!isFetching) {
|
|
isFetching = state;
|
|
}
|
|
if (!isFetching) {
|
|
isFetching = product == null;
|
|
}
|
|
return <Stack spacing={24} style={{
|
|
paddingTop: safeAreaInsets_native.top,
|
|
paddingBottom: safeAreaInsets_native.bottom,
|
|
paddingHorizontal: 12
|
|
}}>
|
|
<Text variant="text-md/medium" color="text-overlay-light">
|
|
{"Gifting "}
|
|
{stateFromStores?.name}
|
|
{" to "}
|
|
{giftRecipientId}
|
|
{" "}
|
|
{"\n"}
|
|
{"Regular price: "}
|
|
{r83}
|
|
{" "}
|
|
{"\n"}
|
|
{"Premium price: "}
|
|
{r82}
|
|
{" "}
|
|
{"\n"}
|
|
{giftMessage != null ? giftMessage !== "" ? `Message: ${giftMessage}` : "No message" : "No message"}
|
|
</Text>
|
|
<Card>
|
|
<Button variant="primary" text={isFetching ? "Loading..." : "Send Gift"} onPress={function submitGiftPurchase() {
|
|
return _submitGiftPurchase2.apply(this, arguments);
|
|
}} disabled={isFetching} />
|
|
</Card>
|
|
<Card>
|
|
<Text variant="text-md/medium" color="text-overlay-light">
|
|
{"Select style: "}
|
|
{giftStyle}
|
|
</Text>
|
|
<PremiumGiftBackgroundSelect />
|
|
</Card>
|
|
</Stack>;
|
|
};
|
|
SimpleRequestOTPActionSheet = function SimpleRequestOTPActionSheet(props) {
|
|
const { selectedSkuId: selectedSkuId2, requestType, giftRecipientId, giftMessage } = props;
|
|
const analyticsLoadId = v4();
|
|
const memo3 = useMemo(() => getBasePurchaseFlowAnalyticsFields({
|
|
isGift: true,
|
|
analyticsLoadId,
|
|
analyticsLocations: []
|
|
}), [analyticsLoadId]);
|
|
return <BottomSheet>
|
|
{requestType === "giftSku" && (selectedSkuId2 != null && giftRecipientId != null) ? <NativeGiftContextProvider basePurchaseAnalytics={memo3} onClose={() => {}} setCurrentAnalyticsStep={() => {}}>
|
|
<GiftPurchaseSKUView selectedSkuId={selectedSkuId2} giftRecipientId={giftRecipientId} giftMessage={giftMessage} />
|
|
</NativeGiftContextProvider> : <View>
|
|
<Text variant="text-lg/bold" color="text-feedback-warning">Gift purchasing is the only supported feature on Android in this version.</Text>
|
|
<Text variant="text-md/normal" color="text-feedback-warning">
|
|
{"Request type: "}
|
|
{requestType ?? "none"}
|
|
</Text>
|
|
</View>}
|
|
</BottomSheet>;
|
|
};
|
|
c10439_13 = new Logger("PaymentFlowTest.android");
|
|
export default function SimpleCreateOTPActionSheetWrapper(props) {
|
|
return <NativePaymentContextProvider skuIDs={[]} activeSubscription={null}>
|
|
<SimpleRequestOTPActionSheet {...props} />
|
|
</NativePaymentContextProvider>;
|
|
};
|