// Metro module 14606 (f14607). import { useCallback, useEffect, useMemo } from "react"; import ExperimentStore from "../../experiments/ExperimentStore"; import CollectiblesCategoryStore from "../CollectiblesCategoryStore"; import CollectiblesShopHomeStore from "../CollectiblesShopHomeStore"; import { COLLECTIBLES_SHOP_CACHE_DURATION_MS, COLLECTIBLES_SHOP_FETCH_ERROR_RETRY_THRESHOLD_MS } from "../CollectiblesShopConstants"; import { useStateFromStores, useStateFromStoresArray } from "../../../_bundle/Module589"; import { ShopVariantsReturnStyle } from "../../../_bundle/Module5847"; import { areRequestOptionsEqual, fetchCollectiblesShopHome } from "../CollectiblesActionCreators"; import { useHasExpiredShopBlocks } from "./useHasExpiredShopBlocks"; export function useMaybeFetchCollectiblesShopHome(a0, a1, a2) { let stateFromStores2, c21248_5, c21248_6, c21248_7, c21248_8, c21248_9, c21248_10, shopHomeConfig, memo, memo2, hasExpiredShopBlocks, memo3; let r20 = arguments[3]; if (r20 === void 0) { r20 = false; } stateFromStores2 = void 0; c21248_5 = void 0; c21248_6 = void 0; c21248_7 = void 0; c21248_8 = void 0; c21248_9 = void 0; c21248_10 = void 0; shopHomeConfig = void 0; memo = void 0; memo2 = void 0; hasExpiredShopBlocks = void 0; memo3 = void 0; const stateFromStores = useStateFromStores([ExperimentStore], () => ExperimentStore.hasLoadedExperiments); stateFromStores2 = useStateFromStores([CollectiblesCategoryStore], () => CollectiblesCategoryStore.skipNumCategories); let shopBlocks, r18, r16, r40, fetchShopHomeError, isFetchingShopHome, r14; [shopBlocks, r18, r16, r40, fetchShopHomeError, isFetchingShopHome, r14, shopHomeConfig] = useStateFromStoresArray([CollectiblesShopHomeStore], () => { const r8 = [CollectiblesShopHomeStore.getShopBlocks(a0), , , , , , , ,]; let r10 = CollectiblesShopHomeStore.getLastSuccessfulFetch(a0); if (r10 == null) { r10 = 0; } r8[1] = r10; let r12 = CollectiblesShopHomeStore.getLastErrorTimestamp(a0); if (r12 == null) { r12 = 0; } r8[2] = r12; r8[3] = CollectiblesShopHomeStore.getLastFetchOptions(a0); r8[4] = CollectiblesShopHomeStore.getFetchShopHomeError(a0); r8[5] = CollectiblesShopHomeStore.getIsFetchingShopHome(a0); r8[6] = CollectiblesShopHomeStore.getHasKnownStaleData(a0); r8[7] = CollectiblesShopHomeStore.getShopHomeConfigOverride(); return r8; }); c21248_5 = r18; c21248_6 = r16; c21248_7 = r40; c21248_8 = fetchShopHomeError; c21248_9 = isFetchingShopHome; c21248_10 = r14; memo = useMemo(() => ({ ...a1, variantsReturnStyle: ShopVariantsReturnStyle.VARIANTS_GROUP, includeBundles: true, includeDynamicBlocks: true, shopHomeConfig, skipNumCategories: stateFromStores2 }), [a1, shopHomeConfig, stateFromStores2]); memo2 = useMemo(() => !areRequestOptionsEqual(c21248_7, memo), [r40, memo]); let r52 = isFetchingShopHome; if (r52 == null) { r52 = false; } hasExpiredShopBlocks = useHasExpiredShopBlocks(shopBlocks, r52, r20); memo3 = useMemo(() => hasExpiredShopBlocks ? !hasExpiredShopBlocks : Date.now() - c21248_5 < COLLECTIBLES_SHOP_CACHE_DURATION_MS, [r18, hasExpiredShopBlocks]); useEffect(() => { if (stateFromStores && !c21248_9) { const r1 = Date.now() - c21248_6 < COLLECTIBLES_SHOP_FETCH_ERROR_RETRY_THRESHOLD_MS; if (!(c21248_8 != null && r1)) { let r16 = memo2; if (!memo2) { r16 = !memo3; } if (!r16) { r16 = c21248_10; } if (r16) { fetchCollectiblesShopHome(a0, memo, a2); } } } }, [stateFromStores, isFetchingShopHome, fetchShopHomeError, r16, memo3, r14, memo2, memo, a0, a2]); return { isFetchingShopHome, fetchShopHomeError, shopBlocks, refreshShopHome: useCallback(() => { fetchCollectiblesShopHome(a0, memo, a2); }, [a0, memo, a2]) }; }