MCPcopy Create free account
hub / github.com/dailydotdev/apps / useFetchAd

Function useFetchAd

packages/shared/src/features/monetization/useFetchAd.ts:31–87  ·  view source on GitHub ↗
(enabled = true)

Source from the content-addressed store, hash-verified

29}
30
31export const useFetchAd = (enabled = true): UseFetchAds => {
32 const consent = useAdRequestConsent(enabled);
33 const { resolveAd } = useAdLifecycle(enabled);
34 const { isAuthReady, isLoggedIn, isAndroidApp } = useAuthContext();
35 const registered = isAuthReady ? isLoggedIn : undefined;
36 const { entityRef } = useAdEntityRef(enabled);
37 const { value: refreshEngineVersion } = useConditionalFeature({
38 feature: featureAdRefreshEngine,
39 shouldEvaluate: enabled,
40 });
41 const isRefreshEngine = refreshEngineVersion === AdRefreshEngineVersion.V2;
42
43 const onFetchTransition = useAdSlotFetch(consent);
44 const fetchAdQuery: UseFetchAds['fetchAd'] = useCallback(
45 async ({ active, placement = AdPlacement.Feed, refresh, onTransition }) => {
46 if (!consent) {
47 return null;
48 }
49 return resolveAd(
50 await fetchAdByPlacement({
51 ...resolveAdFetchOptions({
52 placement,
53 active,
54 consent,
55 registered,
56 entity: entityRef.current,
57 }),
58 ...(isRefreshEngine && {
59 refresh: {
60 platform: getAdRefreshPlatform(isAndroidApp),
61 count: 0,
62 ...refresh,
63 },
64 }),
65 onTransition: (transition) => {
66 const resolved = onFetchTransition(transition);
67 onTransition?.(resolved);
68 },
69 }),
70 );
71 },
72 [
73 consent,
74 entityRef,
75 isAndroidApp,
76 isRefreshEngine,
77 onFetchTransition,
78 registered,
79 resolveAd,
80 ],
81 );
82
83 return {
84 fetchAd: fetchAdQuery,
85 isAdConsentReady: !!consent,
86 };
87};

Callers 5

useFeedFunction · 0.90
useFeedAdRefreshFunction · 0.90
useAutoRotatingAdsFunction · 0.90

Calls 9

useAdRequestConsentFunction · 0.90
useAdLifecycleFunction · 0.90
useAuthContextFunction · 0.90
useAdEntityRefFunction · 0.90
useConditionalFeatureFunction · 0.90
useAdSlotFetchFunction · 0.90
fetchAdByPlacementFunction · 0.90
resolveAdFetchOptionsFunction · 0.90
getAdRefreshPlatformFunction · 0.90

Tested by

no test coverage detected