146 lines
5.0 KiB
TypeScript
146 lines
5.0 KiB
TypeScript
// Metro module 11909 (f11910).
|
|
import { useState, useCallback } from "react";
|
|
import { Routes } from "../../../Constants";
|
|
import Logger from "../../debug/Logger";
|
|
import useMobileCollectiblesPurchaseSKU_android from "./hooks/useMobileCollectiblesPurchaseSKU.android";
|
|
import { fetchCollectiblesPurchases } from "../CollectiblesActionCreators";
|
|
import ActionSheetActionCreators from "../../action_sheet/native/ActionSheetActionCreators";
|
|
import ProductPurchaseSuccessActionCreators from "./ProductPurchaseSuccessActionCreators";
|
|
import { isMetaQuest } from "../../device/MetaQuestUtils.android";
|
|
import MobileWebHandoffLinking from "../../mobile_web_handoff/native/MobileWebHandoffLinking";
|
|
import { captureBillingException } from "../../../utils/BillingUtils";
|
|
import ToastActionCreators from "../../toast/native/ToastActionCreators";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
let c8163_7;
|
|
export function useHandleBuyNow({ product, analyticsLocations, onBuy, orderId }) {
|
|
let state, setState, c19265_4;
|
|
state = void 0;
|
|
setState = void 0;
|
|
c19265_4 = void 0;
|
|
let _onPurchaseComplete2 = function _onPurchaseComplete() {
|
|
const r9 = async () => {
|
|
let c30473_0;
|
|
c30473_0 = void 0;
|
|
await fetchCollectiblesPurchases();
|
|
(0, setState)(false);
|
|
ActionSheetActionCreators.hideActionSheet();
|
|
ProductPurchaseSuccessActionCreators.open({
|
|
product,
|
|
useCategoryImage: true
|
|
});
|
|
};
|
|
_onPurchaseComplete2 = r9;
|
|
return r9.apply(this, arguments);
|
|
};
|
|
[state, setState] = useState(false);
|
|
const mobileCollectiblesPurchaseSKU_android = useMobileCollectiblesPurchaseSKU_android({
|
|
product,
|
|
analyticsLocations,
|
|
onPurchaseComplete: function onPurchaseComplete() {
|
|
return _onPurchaseComplete2.apply(this, arguments);
|
|
},
|
|
onPurchaseError: function onPurchaseError() {
|
|
setState(false);
|
|
},
|
|
onPurchasePending: function onPurchasePending() {},
|
|
orderId
|
|
});
|
|
c19265_4 = mobileCollectiblesPurchaseSKU_android;
|
|
return {
|
|
handleBuyNow: useCallback(async () => {
|
|
let c27207_2;
|
|
let c27207_3 = 0;
|
|
let c30474_0, c30474_1;
|
|
L16: {
|
|
L18: {
|
|
try {
|
|
if (isMetaQuest()) {
|
|
c27207_3 = 1;
|
|
await MobileWebHandoffLinking.redirectWithHandoffToken(`${Routes.COLLECTIBLES_SHOP}#itemSkuId=${product.skuId}`, {
|
|
forceExternalBrowser: true
|
|
});
|
|
ActionSheetActionCreators.hideActionSheet();
|
|
c27207_3 = 0;
|
|
break L16;
|
|
}
|
|
c27207_3 = 2;
|
|
if (state) {
|
|
c27207_3 = 0;
|
|
break L18;
|
|
}
|
|
setState(true);
|
|
await c19265_4();
|
|
if (onBuy != null) {
|
|
(0, onBuy)();
|
|
}
|
|
c27207_3 = 0;
|
|
break L16;
|
|
} catch ($e) {
|
|
const r40 = $e;
|
|
let r7 = r40;
|
|
c27207_2 = r40;
|
|
let r41 = c27207_3;
|
|
if (r41 !== 0) {
|
|
while (true) {
|
|
if (r41 === 1) {
|
|
try {
|
|
const r164 = c27207_2;
|
|
c27207_3 = 0;
|
|
c30474_0 = r164;
|
|
c8163_7.error(`Error performing web handoff: ${JSON.stringify(c30474_0)}`);
|
|
captureBillingException(c30474_0, {
|
|
tags: {
|
|
source: "useHandleBuyNow",
|
|
skuId: product.skuId
|
|
}
|
|
});
|
|
ToastActionCreators.open({
|
|
key: "SHOP_ITEM_HANDOFF_ERROR",
|
|
content: intl.string(t["rTU7/z"])
|
|
});
|
|
break L16;
|
|
} catch (r161) {
|
|
r7 = r161;
|
|
c27207_2 = r161;
|
|
r41 = c27207_3;
|
|
if (r41 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
try {
|
|
const r135 = c27207_2;
|
|
c27207_3 = 0;
|
|
c30474_1 = r135;
|
|
(0, setState)(false);
|
|
c8163_7.error(`Error running purchase: ${JSON.stringify(c30474_1)}`);
|
|
captureBillingException(c30474_1, {
|
|
tags: {
|
|
source: "useHandleBuyNow",
|
|
skuId: product.skuId
|
|
}
|
|
});
|
|
break L16;
|
|
} catch (r133) {
|
|
r7 = r133;
|
|
c27207_2 = r133;
|
|
r41 = c27207_3;
|
|
if (r41 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
}, [mobileCollectiblesPurchaseSKU_android, state, onBuy, product.skuId]),
|
|
isBuying: state
|
|
};
|
|
}
|
|
c8163_7 = new Logger("useHandleBuyNow");
|
|
export default useHandleBuyNow;
|