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

Function useFetchAd

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

Source from the content-addressed store, hash-verified

24}
25
26export const useFetchAd = (enabled = true): UseFetchAds => {
27 const consent = useAdRequestConsent(enabled);
28 const { isAuthReady, isLoggedIn, isAndroidApp } = useAuthContext();
29 const registered = isAuthReady ? isLoggedIn : undefined;
30 const { value: refreshEngineVersion } = useConditionalFeature({
31 feature: featureAdRefreshEngine,
32 shouldEvaluate: enabled,
33 });
34 const isRefreshEngine = refreshEngineVersion === AdRefreshEngineVersion.V2;
35
36 const fetchAdQuery: UseFetchAds['fetchAd'] = useCallback(
37 async ({ active, placement = AdPlacement.Feed, refresh }) => {
38 if (!consent) {
39 return null;
40 }
41 return fetchAdByPlacement({
42 ...resolveAdFetchOptions({
43 placement,
44 active,
45 consent,
46 registered,
47 }),
48 ...(isRefreshEngine && {
49 refresh: {
50 platform: getAdRefreshPlatform(isAndroidApp),
51 count: 0,
52 ...refresh,
53 },
54 }),
55 });
56 },
57 [consent, isAndroidApp, isRefreshEngine, registered],
58 );
59
60 return {
61 fetchAd: fetchAdQuery,
62 isAdConsentReady: !!consent,
63 };
64};

Callers 4

useFeedFunction · 0.90
useFeedAdRefreshFunction · 0.90
useAutoRotatingAdsFunction · 0.90

Calls 6

useAdRequestConsentFunction · 0.90
useAuthContextFunction · 0.90
useConditionalFeatureFunction · 0.90
fetchAdByPlacementFunction · 0.90
resolveAdFetchOptionsFunction · 0.90
getAdRefreshPlatformFunction · 0.90

Tested by

no test coverage detected