107 lines
3.6 KiB
React
107 lines
3.6 KiB
React
// Metro module 6349 (f6350).
|
|
import Module19, { useContext, useEffect, useMemo, useState } from "react";
|
|
import { initConnection, IapIos } from "./addSubscriptionPlatform";
|
|
import { purchaseUpdatedListener, transactionListener, purchaseErrorListener, promotedProductListener } from "./Module6346";
|
|
function $mk118767($env) {
|
|
return (a0) => {
|
|
const r4 = $env[0];
|
|
return [...a0, ...r4 ? [r4] : []];
|
|
};
|
|
}
|
|
const context = Module19.createContext(null);
|
|
export function useIAPContext() {
|
|
const context2 = useContext(context);
|
|
if (context2) {
|
|
return context2;
|
|
}
|
|
throw new Error("You need wrap your app with withIAPContext HOC");
|
|
}
|
|
export function withIAPContext(Component) {
|
|
return function WrapperComponent(props) {
|
|
const [state, setState] = useState(false);
|
|
const [state2, setState2] = useState([]);
|
|
const [state3, setState3] = useState([]);
|
|
const [state4, setState4] = useState([]);
|
|
const [state5, setState5] = useState([]);
|
|
const [state6, setState6] = useState([]);
|
|
const [state7, setState7] = useState();
|
|
const [state8, setState8] = useState();
|
|
const [state9, setState9] = useState();
|
|
const [state10, setState10] = useState();
|
|
const memo = useMemo(() => ({
|
|
connected: state,
|
|
products: state2,
|
|
subscriptions: state4,
|
|
promotedProductsIOS: state3,
|
|
purchaseHistory: state5,
|
|
availablePurchases: state6,
|
|
currentPurchase: state7,
|
|
currentTransaction: state8,
|
|
currentPurchaseError: state9,
|
|
initConnectionError: state10,
|
|
setConnected: setState,
|
|
setProducts: setState2,
|
|
setSubscriptions: setState4,
|
|
setPurchaseHistory: setState5,
|
|
setAvailablePurchases: setState6,
|
|
setCurrentPurchase: setState7,
|
|
setCurrentPurchaseError: setState9
|
|
}), [state, state2, state4, state3, state5, state6, state7, state8, state9, state10, setState, setState2, setState4, setState5, setState6, setState7, setState9]);
|
|
useEffect(() => {
|
|
initConnection().then((result) => {
|
|
setState10(void 0);
|
|
setState(result);
|
|
}).catch(setState10);
|
|
}, []);
|
|
useEffect(() => {
|
|
if (state) {
|
|
let c29756_0, c29756_1, c29756_2, c29756_3;
|
|
let c29758_0;
|
|
let c29757_0 = async (c31958_0) => {
|
|
setState9(void 0);
|
|
setState7(c31958_0);
|
|
};
|
|
c29756_0 = purchaseUpdatedListener(function(a0) {
|
|
return c29757_0.apply(this, arguments);
|
|
});
|
|
c29758_0 = void 0;
|
|
c29758_0 = async (c31959_0) => {
|
|
setState9(c31959_0?.error);
|
|
setState8(c31959_0?.transaction);
|
|
};
|
|
c29756_1 = transactionListener(function(a0) {
|
|
return c29758_0.apply(this, arguments);
|
|
});
|
|
c29756_2 = purchaseErrorListener((a0) => {
|
|
setState7(void 0);
|
|
setState9(a0);
|
|
});
|
|
c29756_3 = promotedProductListener(async () => {
|
|
let c31418_1;
|
|
let env31960;
|
|
c31418_1 = void 0;
|
|
const r9 = env31960 = {};
|
|
let c31418_0 = r9;
|
|
env31960[0] = void 0;
|
|
const promotedProductIOS = await IapIos.getPromotedProductIOS();
|
|
env31960[0] = promotedProductIOS;
|
|
(0, setState3)($mk118767(c31418_0));
|
|
});
|
|
return () => {
|
|
c29756_0.remove();
|
|
c29756_2.remove();
|
|
if (c29756_3 != null) {
|
|
c29756_3.remove();
|
|
}
|
|
if (c29756_1 != null) {
|
|
c29756_1.remove();
|
|
}
|
|
};
|
|
}
|
|
}, [state]);
|
|
return <context.Provider value={memo}>
|
|
<Component {...props} />
|
|
</context.Provider>;
|
|
};
|
|
}
|