@adland/react 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @adland/react
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 99431e5: fix fetching ad
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adland/react",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useRef, useCallback } from "react";
2
2
  import { sendTrackRequest } from "../utils/sdk";
3
3
  import sdk from "@farcaster/miniapp-sdk";
4
- import { Loader, SquareDashed } from "lucide-react";
4
+ import { FileWarningIcon, Loader, SquareDashed } from "lucide-react";
5
5
  import { type AdData } from "@adland/data";
6
6
  import { useFetch } from "../hooks/useFetch";
7
7
  import BasicAdBody from "./BasicAdBody";
@@ -13,6 +13,7 @@ import FarcasterProfileAdContent from "./content/FarcasterProfileAdContent";
13
13
  import { AdDataQueryError, AdProps } from "../types";
14
14
  import { getBaseUrl } from "../utils";
15
15
  import { adlandApiUrl } from "../utils/constants";
16
+ import { fetchAd } from "../fetch";
16
17
 
17
18
  /**
18
19
  * Simple Ad component with built-in view and click tracking
@@ -39,36 +40,13 @@ export function Ad({
39
40
  error,
40
41
  } = useFetch<AdData>(
41
42
  `ad-data-${owner}-${slotId}`,
42
- async () => {
43
- const url = `${adlandApiUrl}/ad/owner/${owner.toLowerCase()}/slot/${slotId}`;
44
-
45
- const res = await fetch(url, {
46
- method: "GET",
47
- headers: {
48
- "Content-Type": "application/json",
49
- },
50
- });
51
-
52
- if (!res.ok) {
53
- throw new Error(AdDataQueryError.ERROR);
54
- }
55
-
56
- const data = await res.json();
57
-
58
- if (data.error) {
59
- throw new Error(data.error);
60
- }
61
-
62
- return data;
63
- },
43
+ () => fetchAd(owner, slotId),
64
44
  {
65
45
  enabled: !!owner && !!slotId,
66
46
  },
67
47
  );
68
48
  const networkBaseUrl = baseUrl ?? getBaseUrl(network);
69
49
 
70
- console.log({ error, adData });
71
-
72
50
  const send = useCallback(
73
51
  (type: "view" | "click") => {
74
52
  const trackEndpoint = `${networkBaseUrl}/api/analytics/track`;
@@ -187,7 +165,7 @@ function ErrorAdContent({ error }: { error: unknown }) {
187
165
  return (
188
166
  <BasicAdBody>
189
167
  <div className="flex flex-row items-center gap-2">
190
- <SquareDashed className="w-5 h-5 md:w-7 md:h-7" />
168
+ <FileWarningIcon className="w-5 h-5 md:w-7 md:h-7" />
191
169
  <p className="font-bold text-primary">ERROR</p>
192
170
  </div>
193
171
  </BasicAdBody>
@@ -216,7 +194,12 @@ function EmtpyAdContent({ data }: { data: { url: string } }) {
216
194
  >
217
195
  <div className="flex flex-row items-center gap-2">
218
196
  <SquareDashed className="w-5 h-5 md:w-7 md:h-7" />
219
- <p className="font-bold text-primary">NO AD</p>
197
+ <p className="font-bold text-primary">
198
+ NO AD{" "}
199
+ <span className="text-xs text-muted-foreground/80 font-normal">
200
+ (Your ad here)
201
+ </span>
202
+ </p>
220
203
  </div>
221
204
  </BasicAdBody>
222
205
  );
package/src/fetch.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { AdDataQueryError } from "./types";
2
+ import { adlandApiUrl } from "./utils/constants";
3
+
4
+ export const fetchAd = async (owner: string, slotId: string) => {
5
+ const url = `${adlandApiUrl}/ad/owner/${owner.toLowerCase()}/slot/${slotId}`;
6
+
7
+ const res = await fetch(url, {
8
+ method: "GET",
9
+ headers: {
10
+ "Content-Type": "application/json",
11
+ },
12
+ });
13
+
14
+ if (!res.ok) {
15
+ if (res.status === 404) {
16
+ throw new Error(AdDataQueryError.NO_AD);
17
+ }
18
+ throw new Error(AdDataQueryError.ERROR);
19
+ }
20
+
21
+ const data = await res.json();
22
+
23
+ if (data.error) {
24
+ throw new Error(data.error);
25
+ }
26
+
27
+ return data;
28
+ };