128 lines
3.8 KiB
TypeScript
128 lines
3.8 KiB
TypeScript
// Metro module 9769 (f9770).
|
|
import { useRef, useState, useCallback, useEffect, useMemo } from "react";
|
|
import Logger from "../../debug/Logger";
|
|
import { updateOrder } from "../../payments/native/OrderActionCreators";
|
|
import { captureBillingException } from "../../../utils/BillingUtils";
|
|
let c6476_4 = new Logger("useSyncGiftOptionsToOrder");
|
|
export default function useSyncGiftOptionsToOrder(a0, a1) {
|
|
let callback2;
|
|
let c17473_0 = a0;
|
|
const current = a1;
|
|
const ref = useRef(null);
|
|
const ref2 = useRef(null);
|
|
const ref3 = useRef(false);
|
|
const ref4 = useRef(void 0);
|
|
const ref5 = useRef(null);
|
|
const ref6 = useRef(0);
|
|
const ref7 = useRef(null);
|
|
const ref8 = useRef(null);
|
|
const ref9 = useRef([]);
|
|
const [state, setState] = useState(0);
|
|
const callback = useCallback((a0) => {
|
|
const current2 = ref9.current;
|
|
ref9.current = [];
|
|
for (const item of current2) {
|
|
item(a0);
|
|
}
|
|
}, []);
|
|
useEffect(() => () => {
|
|
if (ref8.current != null) {
|
|
clearTimeout(ref8.current);
|
|
}
|
|
callback(false);
|
|
}, [callback]);
|
|
useEffect(() => {
|
|
if (c17473_0 != null) {
|
|
const id = c17473_0.id;
|
|
ref2.current = current;
|
|
if (ref5.current !== id) {
|
|
ref5.current = id;
|
|
ref4.current = c17473_0.revision;
|
|
ref.current = null;
|
|
ref6.current = 0;
|
|
}
|
|
if (ref7.current !== current) {
|
|
ref6.current = 0;
|
|
}
|
|
if (!ref3.current) {
|
|
if (ref.current !== current) {
|
|
if (ref8.current != null) {
|
|
clearTimeout(ref8.current);
|
|
ref8.current = null;
|
|
}
|
|
ref3.current = true;
|
|
ref7.current = current;
|
|
updateOrder({
|
|
orderId: id,
|
|
giftInfo: {
|
|
recipient_id: current.recipient_id,
|
|
gift_style: current.gift_style,
|
|
emoji_id: current.emoji_id,
|
|
emoji_name: current.emoji_name,
|
|
sound_id: current.sound_id,
|
|
reward_sku_ids: current.reward_sku_ids,
|
|
custom_message_contents: current.custom_message
|
|
},
|
|
expectedRevision: ref4.current
|
|
}).then((result) => {
|
|
ref4.current = result;
|
|
ref.current = current;
|
|
ref6.current = 0;
|
|
}).catch((a0) => {
|
|
ref6.current = ref6.current + 1;
|
|
c6476_4.error("Failed to sync gift customization to order", {
|
|
error: a0,
|
|
orderId: id
|
|
});
|
|
captureBillingException(a0, {
|
|
tags: {
|
|
source: "useSyncGiftOptionsToOrder"
|
|
},
|
|
extra: {
|
|
orderId: id
|
|
}
|
|
});
|
|
}).finally(() => {
|
|
ref3.current = false;
|
|
if (ref.current !== ref2.current) {
|
|
if (ref6.current === 0) {
|
|
setState((prevState) => prevState + 1);
|
|
} else if (ref6.current < 3) {
|
|
ref8.current = setTimeout(() => setState((prevState) => prevState + 1), 500 * 2 ** (ref6.current - 1));
|
|
} else {
|
|
callback(false);
|
|
}
|
|
} else {
|
|
callback(true);
|
|
}
|
|
});
|
|
} else {
|
|
callback(true);
|
|
}
|
|
}
|
|
} else {
|
|
callback(true);
|
|
}
|
|
}, [a0, a1, state, callback]);
|
|
callback2 = useCallback(() => {
|
|
let r17;
|
|
if (c17473_0 != null && ref.current !== ref2.current) {
|
|
if (ref6.current >= 3) {
|
|
ref6.current = 0;
|
|
}
|
|
r17 = new Promise((resolve) => {
|
|
ref9.current.push(resolve);
|
|
if (!(ref3.current || ref8.current != null)) {
|
|
setState((prevState) => prevState + 1);
|
|
}
|
|
});
|
|
} else {
|
|
r17 = Promise.resolve(true);
|
|
}
|
|
return r17;
|
|
}, [a0]);
|
|
return useMemo(() => ({
|
|
awaitSync: callback2
|
|
}), [callback2]);
|
|
};
|