@medialane/ui 0.107.1 → 0.108.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.
Files changed (43) hide show
  1. package/dist/components/remixes-tab.cjs +91 -0
  2. package/dist/components/remixes-tab.cjs.map +1 -0
  3. package/dist/components/remixes-tab.d.cts +11 -0
  4. package/dist/components/remixes-tab.d.ts +11 -0
  5. package/dist/components/remixes-tab.js +57 -0
  6. package/dist/components/remixes-tab.js.map +1 -0
  7. package/dist/data/notification.cjs +17 -0
  8. package/dist/data/notification.cjs.map +1 -0
  9. package/dist/data/notification.d.cts +34 -0
  10. package/dist/data/notification.d.ts +34 -0
  11. package/dist/data/notification.js +1 -0
  12. package/dist/data/notification.js.map +1 -0
  13. package/dist/index.cjs +31 -2
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +6 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.js +26 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/utils/api-fetch.cjs +65 -0
  20. package/dist/utils/api-fetch.cjs.map +1 -0
  21. package/dist/utils/api-fetch.d.cts +38 -0
  22. package/dist/utils/api-fetch.d.ts +38 -0
  23. package/dist/utils/api-fetch.js +40 -0
  24. package/dist/utils/api-fetch.js.map +1 -0
  25. package/dist/utils/use-notifications.cjs +169 -0
  26. package/dist/utils/use-notifications.cjs.map +1 -0
  27. package/dist/utils/use-notifications.d.cts +12 -0
  28. package/dist/utils/use-notifications.d.ts +12 -0
  29. package/dist/utils/use-notifications.js +140 -0
  30. package/dist/utils/use-notifications.js.map +1 -0
  31. package/dist/utils/use-orders.cjs +153 -0
  32. package/dist/utils/use-orders.cjs.map +1 -0
  33. package/dist/utils/use-orders.d.cts +55 -0
  34. package/dist/utils/use-orders.d.ts +55 -0
  35. package/dist/utils/use-orders.js +113 -0
  36. package/dist/utils/use-orders.js.map +1 -0
  37. package/dist/utils/use-remix-offers.cjs +49 -0
  38. package/dist/utils/use-remix-offers.cjs.map +1 -0
  39. package/dist/utils/use-remix-offers.d.cts +19 -0
  40. package/dist/utils/use-remix-offers.d.ts +19 -0
  41. package/dist/utils/use-remix-offers.js +15 -0
  42. package/dist/utils/use-remix-offers.js.map +1 -0
  43. package/package.json +1 -1
@@ -0,0 +1,12 @@
1
+ import { MedialaneClient } from '@medialane/sdk/starknet';
2
+ import { Notification } from '../data/notification.js';
3
+ import { ApiFetchConfig } from './api-fetch.js';
4
+
5
+ declare function useNotifications(getClient: () => MedialaneClient, apiConfig: ApiFetchConfig, address: string | null | undefined): {
6
+ notifications: Notification[];
7
+ unreadCount: number;
8
+ markAllRead: () => void;
9
+ markRead: (id: string) => void;
10
+ };
11
+
12
+ export { useNotifications };
@@ -0,0 +1,140 @@
1
+ "use client";
2
+ import { useCallback, useMemo, useState } from "react";
3
+ import useSWR from "swr";
4
+ import { normalizeAddress } from "@medialane/sdk";
5
+ import { useUserOrders, useReceivedOffers } from "./use-orders.js";
6
+ import { useActivitiesByAddress } from "./use-activities.js";
7
+ import { getReadIds, markRead } from "./notification-storage.js";
8
+ import {
9
+ formatActivity,
10
+ formatOrderNotification,
11
+ formatOfferAcceptedNotification,
12
+ formatAssetReceivedNotification
13
+ } from "./format-activity.js";
14
+ async function fetchAnnouncements() {
15
+ const res = await fetch("/api/announcements");
16
+ if (!res.ok) return [];
17
+ return res.json();
18
+ }
19
+ function useNotifications(getClient, apiConfig, address) {
20
+ const [readIds, setReadIds] = useState(() => getReadIds());
21
+ const { orders: userOrders } = useUserOrders(getClient, address ?? null);
22
+ const { orders: receivedOffers } = useReceivedOffers(apiConfig, address ?? null);
23
+ const { activities } = useActivitiesByAddress(getClient, address ?? null);
24
+ const { data: announcements = [] } = useSWR(
25
+ "announcements",
26
+ fetchAnnouncements,
27
+ { revalidateOnFocus: false, dedupingInterval: 6e4 }
28
+ );
29
+ const notifications = useMemo(() => {
30
+ const items = [];
31
+ userOrders.filter((o) => o.offer.itemType === "ERC20" && o.status === "FULFILLED").forEach((order) => {
32
+ const id = `offer-accepted-${order.orderHash}`;
33
+ const fmt = formatOfferAcceptedNotification(order);
34
+ items.push({
35
+ id,
36
+ type: "offer_accepted",
37
+ priority: "spotlight",
38
+ celebratory: true,
39
+ ...fmt,
40
+ timestamp: order.updatedAt ?? order.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
41
+ isUnread: !readIds.has(id),
42
+ metadata: {
43
+ amount: order.price?.formatted ?? void 0,
44
+ currency: order.price?.currency ?? void 0,
45
+ txHash: order.txHash?.fulfilled ?? void 0,
46
+ assetName: order.token?.name ?? void 0
47
+ }
48
+ });
49
+ });
50
+ receivedOffers.forEach((order) => {
51
+ const id = `order-${order.orderHash}`;
52
+ const fmt = formatOrderNotification(order);
53
+ items.push({
54
+ id,
55
+ type: "offer",
56
+ priority: "spotlight",
57
+ celebratory: false,
58
+ ...fmt,
59
+ timestamp: order.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
60
+ isUnread: !readIds.has(id),
61
+ metadata: {
62
+ amount: order.price?.formatted ?? void 0,
63
+ currency: order.price?.currency ?? void 0,
64
+ assetName: order.token?.name ?? void 0
65
+ }
66
+ });
67
+ });
68
+ activities.slice(0, 50).forEach((event) => {
69
+ const id = `activity-${event.txHash}-${event.type}-${event.nftTokenId ?? ""}`;
70
+ if (event.type === "transfer" && address && !!event.to && normalizeAddress("STARKNET", event.to) === normalizeAddress("STARKNET", address)) {
71
+ const fmt2 = formatAssetReceivedNotification(event);
72
+ items.push({
73
+ id,
74
+ type: "asset_received",
75
+ priority: "spotlight",
76
+ celebratory: true,
77
+ ...fmt2,
78
+ timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
79
+ isUnread: !readIds.has(id),
80
+ metadata: {
81
+ txHash: event.txHash ?? void 0,
82
+ assetName: event.token?.name ?? void 0
83
+ }
84
+ });
85
+ return;
86
+ }
87
+ const isMySale = event.type === "sale" && address && (!!event.offerer && normalizeAddress("STARKNET", event.offerer) === normalizeAddress("STARKNET", address) || !!event.from && normalizeAddress("STARKNET", event.from) === normalizeAddress("STARKNET", address));
88
+ const fmt = formatActivity(event);
89
+ items.push({
90
+ id,
91
+ type: event.type,
92
+ priority: isMySale ? "spotlight" : "normal",
93
+ celebratory: !!isMySale,
94
+ ...fmt,
95
+ timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
96
+ isUnread: !readIds.has(id),
97
+ metadata: {
98
+ amount: event.price?.formatted ?? void 0,
99
+ currency: event.price?.currency ?? void 0,
100
+ txHash: event.txHash ?? void 0,
101
+ assetName: event.token?.name ?? void 0
102
+ }
103
+ });
104
+ });
105
+ announcements.forEach((ann) => {
106
+ const id = `ann-${ann.id}`;
107
+ items.push({
108
+ id,
109
+ type: "announcement",
110
+ priority: ann.pinned ? "spotlight" : "normal",
111
+ celebratory: false,
112
+ title: ann.title,
113
+ description: ann.body,
114
+ image: ann.image,
115
+ href: ann.href,
116
+ timestamp: ann.created_at,
117
+ isUnread: !readIds.has(id)
118
+ });
119
+ });
120
+ items.sort(
121
+ (a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()
122
+ );
123
+ return items;
124
+ }, [userOrders, receivedOffers, activities, announcements, address, readIds]);
125
+ const unreadCount = notifications.filter((n) => n.isUnread).length;
126
+ const markNotificationsRead = useCallback((ids) => {
127
+ markRead(ids);
128
+ setReadIds(getReadIds());
129
+ }, []);
130
+ return {
131
+ notifications,
132
+ unreadCount,
133
+ markAllRead: () => markNotificationsRead(notifications.map((n) => n.id)),
134
+ markRead: (id) => markNotificationsRead([id])
135
+ };
136
+ }
137
+ export {
138
+ useNotifications
139
+ };
140
+ //# sourceMappingURL=use-notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/use-notifications.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useMemo, useState } from \"react\";\nimport useSWR from \"swr\";\nimport { normalizeAddress } from \"@medialane/sdk\";\nimport type { ApiActivity } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport { useUserOrders, useReceivedOffers } from \"./use-orders.js\";\nimport { useActivitiesByAddress } from \"./use-activities.js\";\nimport { getReadIds, markRead } from \"./notification-storage.js\";\nimport {\n formatActivity,\n formatOrderNotification,\n formatOfferAcceptedNotification,\n formatAssetReceivedNotification,\n} from \"./format-activity.js\";\nimport type { Notification, Announcement } from \"../data/notification.js\";\nimport type { ApiFetchConfig } from \"./api-fetch.js\";\n\nasync function fetchAnnouncements(): Promise<Announcement[]> {\n const res = await fetch(\"/api/announcements\");\n if (!res.ok) return [];\n return res.json();\n}\n\nexport function useNotifications(\n getClient: () => MedialaneClient,\n apiConfig: ApiFetchConfig,\n address: string | null | undefined\n) {\n const [readIds, setReadIds] = useState<Set<string>>(() => getReadIds());\n\n // Offers this user placed (to detect accepted ones)\n const { orders: userOrders } = useUserOrders(getClient, address ?? null);\n // Offers received on tokens the user holds\n const { orders: receivedOffers } = useReceivedOffers(apiConfig, address ?? null);\n const { activities } = useActivitiesByAddress(getClient, address ?? null);\n const { data: announcements = [] } = useSWR<Announcement[]>(\n \"announcements\",\n fetchAnnouncements,\n { revalidateOnFocus: false, dedupingInterval: 60_000 }\n );\n\n const notifications: Notification[] = useMemo(() => {\n const items: Notification[] = [];\n\n // ── Offers accepted (buyer: my ERC20 bid was fulfilled) ──────────────────\n userOrders\n .filter((o) => o.offer.itemType === \"ERC20\" && o.status === \"FULFILLED\")\n .forEach((order) => {\n const id = `offer-accepted-${order.orderHash}`;\n const fmt = formatOfferAcceptedNotification(order);\n items.push({\n id,\n type: \"offer_accepted\",\n priority: \"spotlight\",\n celebratory: true,\n ...fmt,\n timestamp: order.updatedAt ?? order.createdAt ?? new Date().toISOString(),\n isUnread: !readIds.has(id),\n metadata: {\n amount: order.price?.formatted ?? undefined,\n currency: order.price?.currency ?? undefined,\n txHash: order.txHash?.fulfilled ?? undefined,\n assetName: order.token?.name ?? undefined,\n },\n });\n });\n\n // ── Received offers (someone bid on my asset) ────────────────────────────\n receivedOffers.forEach((order) => {\n const id = `order-${order.orderHash}`;\n const fmt = formatOrderNotification(order);\n items.push({\n id,\n type: \"offer\",\n priority: \"spotlight\",\n celebratory: false,\n ...fmt,\n timestamp: order.createdAt ?? new Date().toISOString(),\n isUnread: !readIds.has(id),\n metadata: {\n amount: order.price?.formatted ?? undefined,\n currency: order.price?.currency ?? undefined,\n assetName: order.token?.name ?? undefined,\n },\n });\n });\n\n // ── Activity events ──────────────────────────────────────────────────────\n (activities as ApiActivity[]).slice(0, 50).forEach((event) => {\n const id = `activity-${event.txHash}-${event.type}-${event.nftTokenId ?? \"\"}`;\n\n // Asset received: transfer where this user is the recipient\n if (\n event.type === \"transfer\" &&\n address &&\n !!event.to && normalizeAddress(\"STARKNET\", event.to) === normalizeAddress(\"STARKNET\", address)\n ) {\n const fmt = formatAssetReceivedNotification(event);\n items.push({\n id,\n type: \"asset_received\",\n priority: \"spotlight\",\n celebratory: true,\n ...fmt,\n timestamp: event.timestamp ?? new Date().toISOString(),\n isUnread: !readIds.has(id),\n metadata: {\n txHash: event.txHash ?? undefined,\n assetName: event.token?.name ?? undefined,\n },\n });\n return;\n }\n\n // Sale (seller perspective): activity sale where offerer = address\n const isMySale =\n event.type === \"sale\" &&\n address &&\n ((!!event.offerer && normalizeAddress(\"STARKNET\", event.offerer) === normalizeAddress(\"STARKNET\", address)) ||\n (!!event.from && normalizeAddress(\"STARKNET\", event.from) === normalizeAddress(\"STARKNET\", address)));\n\n const fmt = formatActivity(event);\n items.push({\n id,\n type: event.type as Notification[\"type\"],\n priority: isMySale ? \"spotlight\" : \"normal\",\n celebratory: !!isMySale,\n ...fmt,\n timestamp: event.timestamp ?? new Date().toISOString(),\n isUnread: !readIds.has(id),\n metadata: {\n amount: event.price?.formatted ?? undefined,\n currency: event.price?.currency ?? undefined,\n txHash: event.txHash ?? undefined,\n assetName: event.token?.name ?? undefined,\n },\n });\n });\n\n // ── Announcements ────────────────────────────────────────────────────────\n announcements.forEach((ann) => {\n const id = `ann-${ann.id}`;\n items.push({\n id,\n type: \"announcement\",\n priority: ann.pinned ? \"spotlight\" : \"normal\",\n celebratory: false,\n title: ann.title,\n description: ann.body,\n image: ann.image,\n href: ann.href,\n timestamp: ann.created_at,\n isUnread: !readIds.has(id),\n });\n });\n\n // Chronological, newest first\n items.sort(\n (a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()\n );\n\n return items;\n }, [userOrders, receivedOffers, activities, announcements, address, readIds]);\n\n const unreadCount = notifications.filter((n) => n.isUnread).length;\n\n const markNotificationsRead = useCallback((ids: string[]) => {\n markRead(ids);\n setReadIds(getReadIds());\n }, []);\n\n return {\n notifications,\n unreadCount,\n markAllRead: () => markNotificationsRead(notifications.map((n) => n.id)),\n markRead: (id: string) => markNotificationsRead([id]),\n };\n}\n"],"mappings":";AAEA,SAAS,aAAa,SAAS,gBAAgB;AAC/C,OAAO,YAAY;AACnB,SAAS,wBAAwB;AAGjC,SAAS,eAAe,yBAAyB;AACjD,SAAS,8BAA8B;AACvC,SAAS,YAAY,gBAAgB;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,eAAe,qBAA8C;AAC3D,QAAM,MAAM,MAAM,MAAM,oBAAoB;AAC5C,MAAI,CAAC,IAAI,GAAI,QAAO,CAAC;AACrB,SAAO,IAAI,KAAK;AAClB;AAEO,SAAS,iBACd,WACA,WACA,SACA;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,SAAsB,MAAM,WAAW,CAAC;AAGtE,QAAM,EAAE,QAAQ,WAAW,IAAI,cAAc,WAAW,WAAW,IAAI;AAEvE,QAAM,EAAE,QAAQ,eAAe,IAAI,kBAAkB,WAAW,WAAW,IAAI;AAC/E,QAAM,EAAE,WAAW,IAAI,uBAAuB,WAAW,WAAW,IAAI;AACxE,QAAM,EAAE,MAAM,gBAAgB,CAAC,EAAE,IAAI;AAAA,IACnC;AAAA,IACA;AAAA,IACA,EAAE,mBAAmB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C7B,YAAM,KAAK,OAAO,IAAI,EAAE;AACxB,YAAM,KAAK;AAAA,QACT;AAAA,QACA,MAAM;AAAA,QACN,UAAU,IAAI,SAAS,cAAc;AAAA,QACrC,aAAa;AAAA,QACb,OAAO,IAAI;AAAA,QACX,aAAa,IAAI;AAAA,QACjB,OAAO,IAAI;AAAA,QACX,MAAM,IAAI;AAAA,QACV,WAAW,IAAI;AAAA,QACf,UAAU,CAAC,QAAQ,IAAI,EAAE;AAAA,MAC3B,CAAC;AAAA,IACH,CAAC;AAGD,UAAM;AAAA,MACJ,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,SAAS,EAAE,QAAQ,IAAI,IAAI,KAAK,EAAE,SAAS,EAAE,QAAQ;AAAA,IAC5E;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,YAAY,gBAAgB,YAAY,eAAe,SAAS,OAAO,CAAC;AAE5E,QAAM,cAAc,cAAc,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE;AAE5D,QAAM,wBAAwB,YAAY,CAAC,QAAkB;AAC3D,aAAS,GAAG;AACZ,eAAW,WAAW,CAAC;AAAA,EACzB,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,aAAa,MAAM,sBAAsB,cAAc,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAAA,IACvE,UAAU,CAAC,OAAe,sBAAsB,CAAC,EAAE,CAAC;AAAA,EACtD;AACF;","names":["fmt"]}
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var use_orders_exports = {};
31
+ __export(use_orders_exports, {
32
+ useCollectionFloorListings: () => useCollectionFloorListings,
33
+ useCounterOffers: () => useCounterOffers,
34
+ useOrder: () => useOrder,
35
+ useOrders: () => useOrders,
36
+ useReceivedOffers: () => useReceivedOffers,
37
+ useTokenListings: () => useTokenListings,
38
+ useUserOrders: () => useUserOrders
39
+ });
40
+ module.exports = __toCommonJS(use_orders_exports);
41
+ var import_swr = __toESM(require("swr"), 1);
42
+ var import_sdk = require("@medialane/sdk");
43
+ var import_use_medialane_client = require("./use-medialane-client.js");
44
+ var import_query_keys = require("./query-keys.js");
45
+ var import_api_fetch = require("./api-fetch.js");
46
+ const ACTIVE_ORDER_REFRESH_INTERVAL = 6e4;
47
+ const ACTIVE_ORDER_DEDUPING_INTERVAL = 1e4;
48
+ function useOrders(getClient, query = {}) {
49
+ const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
50
+ const key = import_query_keys.queryKeys.orders(query);
51
+ const { data, error, isLoading, mutate } = (0, import_swr.default)(
52
+ key,
53
+ () => client.api.getOrders(query),
54
+ { revalidateOnFocus: false, refreshInterval: 3e4, dedupingInterval: 5e3 }
55
+ );
56
+ return {
57
+ orders: data?.data ?? [],
58
+ meta: data?.meta,
59
+ isLoading,
60
+ error,
61
+ mutate
62
+ };
63
+ }
64
+ function useOrder(getClient, orderHash) {
65
+ const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
66
+ const { data, error, isLoading } = (0, import_swr.default)(
67
+ orderHash ? import_query_keys.queryKeys.order(orderHash) : null,
68
+ () => client.api.getOrder(orderHash),
69
+ { revalidateOnFocus: false }
70
+ );
71
+ return { order: data?.data ?? null, isLoading, error };
72
+ }
73
+ function useTokenListings(getClient, contract, tokenId) {
74
+ const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
75
+ const { data, error, isLoading, mutate } = (0, import_swr.default)(
76
+ contract && tokenId ? import_query_keys.queryKeys.listings(contract, tokenId) : null,
77
+ () => client.api.getActiveOrdersForToken(contract, tokenId),
78
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
79
+ );
80
+ return { listings: data?.data ?? [], isLoading, error, mutate };
81
+ }
82
+ function useUserOrders(getClient, address) {
83
+ const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
84
+ const normalized = address ? (0, import_sdk.normalizeAddress)("STARKNET", address) : null;
85
+ const { data, error, isLoading, mutate } = (0, import_swr.default)(
86
+ normalized ? import_query_keys.queryKeys.userOrders(normalized) : null,
87
+ () => client.api.getOrdersByUser(normalized),
88
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
89
+ );
90
+ return { orders: data?.data ?? [], isLoading, error, mutate };
91
+ }
92
+ function useCounterOffers(getClient, {
93
+ originalOrderHash,
94
+ sellerAddress
95
+ }) {
96
+ const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
97
+ const normalized = sellerAddress ? (0, import_sdk.normalizeAddress)("STARKNET", sellerAddress) : null;
98
+ const key = originalOrderHash ? import_query_keys.queryKeys.counterOffersByOrder(originalOrderHash) : normalized ? import_query_keys.queryKeys.counterOffersBySeller(normalized) : null;
99
+ const { data, error, isLoading, mutate } = (0, import_swr.default)(
100
+ key,
101
+ () => client.api.getCounterOffers({
102
+ ...originalOrderHash ? { originalOrderHash } : {},
103
+ ...normalized ? { sellerAddress: normalized } : {}
104
+ }),
105
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
106
+ );
107
+ return {
108
+ counterOffers: data?.data ?? [],
109
+ total: data?.meta?.total ?? 0,
110
+ isLoading,
111
+ error,
112
+ mutate
113
+ };
114
+ }
115
+ function useReceivedOffers(apiConfig, address) {
116
+ const normalized = address ? (0, import_sdk.normalizeAddress)("STARKNET", address) : null;
117
+ const { data, error, isLoading, mutate } = (0, import_swr.default)(
118
+ normalized ? ["received-offers", normalized] : null,
119
+ () => (0, import_api_fetch.apiFetch)(apiConfig, `/v1/orders/received/${normalized}?limit=50`),
120
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
121
+ );
122
+ return { orders: data?.data ?? [], isLoading, error, mutate };
123
+ }
124
+ function useCollectionFloorListings(getClient, contract, limit = 20) {
125
+ const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
126
+ const key = contract ? import_query_keys.queryKeys.floorListings(contract, limit) : null;
127
+ const { data, error, isLoading } = (0, import_swr.default)(
128
+ key,
129
+ () => client.api.getOrders({
130
+ collection: contract,
131
+ status: "ACTIVE",
132
+ sort: "price_asc",
133
+ limit
134
+ }),
135
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL }
136
+ );
137
+ return {
138
+ listings: data?.data ?? [],
139
+ isLoading,
140
+ error
141
+ };
142
+ }
143
+ // Annotate the CommonJS export names for ESM import in node:
144
+ 0 && (module.exports = {
145
+ useCollectionFloorListings,
146
+ useCounterOffers,
147
+ useOrder,
148
+ useOrders,
149
+ useReceivedOffers,
150
+ useTokenListings,
151
+ useUserOrders
152
+ });
153
+ //# sourceMappingURL=use-orders.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/use-orders.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { normalizeAddress } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { ApiOrdersQuery, ApiOrder, ApiResponse } from \"@medialane/sdk\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport { queryKeys } from \"./query-keys.js\";\nimport { apiFetch, type ApiFetchConfig } from \"./api-fetch.js\";\n\nconst ACTIVE_ORDER_REFRESH_INTERVAL = 60_000;\nconst ACTIVE_ORDER_DEDUPING_INTERVAL = 10_000;\n\nexport function useOrders(getClient: () => MedialaneClient, query: ApiOrdersQuery = {}) {\n const client = useMedialaneClient(getClient);\n const key = queryKeys.orders(query);\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiOrder[]>>(\n key,\n () => client.api.getOrders(query),\n { revalidateOnFocus: false, refreshInterval: 30000, dedupingInterval: 5000 }\n );\n\n return {\n orders: data?.data ?? [],\n meta: data?.meta,\n isLoading,\n error,\n mutate,\n };\n}\n\nexport function useOrder(getClient: () => MedialaneClient, orderHash: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading } = useSWR(\n orderHash ? queryKeys.order(orderHash) : null,\n () => client.api.getOrder(orderHash!),\n { revalidateOnFocus: false }\n );\n\n return { order: data?.data ?? null, isLoading, error };\n}\n\nexport function useTokenListings(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading, mutate } = useSWR(\n contract && tokenId ? queryKeys.listings(contract, tokenId) : null,\n () => client.api.getActiveOrdersForToken(contract!, tokenId!),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return { listings: data?.data ?? [], isLoading, error, mutate };\n}\n\nexport function useUserOrders(getClient: () => MedialaneClient, address: string | null) {\n const client = useMedialaneClient(getClient);\n const normalized = address ? normalizeAddress(\"STARKNET\", address) : null;\n\n const { data, error, isLoading, mutate } = useSWR(\n normalized ? queryKeys.userOrders(normalized) : null,\n () => client.api.getOrdersByUser(normalized!),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return { orders: data?.data ?? [], isLoading, error, mutate };\n}\n\n/** Fetch counter-offers for a specific original bid (buyer view) or by seller address. */\nexport function useCounterOffers(\n getClient: () => MedialaneClient,\n {\n originalOrderHash,\n sellerAddress,\n }: {\n originalOrderHash?: string | null;\n sellerAddress?: string | null;\n }\n) {\n const client = useMedialaneClient(getClient);\n const normalized = sellerAddress ? normalizeAddress(\"STARKNET\", sellerAddress) : null;\n const key =\n originalOrderHash\n ? queryKeys.counterOffersByOrder(originalOrderHash)\n : normalized\n ? queryKeys.counterOffersBySeller(normalized)\n : null;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiOrder[]>>(\n key,\n () => client.api.getCounterOffers({\n ...(originalOrderHash ? { originalOrderHash } : {}),\n ...(normalized ? { sellerAddress: normalized } : {}),\n }),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return {\n counterOffers: data?.data ?? [],\n total: data?.meta?.total ?? 0,\n isLoading,\n error,\n mutate,\n };\n}\n\n/** Fetch active ERC20 offers received by the given address (offers on tokens they hold). */\nexport function useReceivedOffers(apiConfig: ApiFetchConfig, address: string | null) {\n const normalized = address ? normalizeAddress(\"STARKNET\", address) : null;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiOrder[]>>(\n normalized ? [\"received-offers\", normalized] : null,\n () => apiFetch<ApiResponse<ApiOrder[]>>(apiConfig, `/v1/orders/received/${normalized}?limit=50`),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return { orders: data?.data ?? [], isLoading, error, mutate };\n}\n\nexport function useCollectionFloorListings(getClient: () => MedialaneClient, contract: string | null, limit = 20) {\n const client = useMedialaneClient(getClient);\n const key = contract ? queryKeys.floorListings(contract, limit) : null;\n\n const { data, error, isLoading } = useSWR<ApiResponse<ApiOrder[]>>(\n key,\n () =>\n client.api.getOrders({\n collection: contract!,\n status: \"ACTIVE\",\n sort: \"price_asc\",\n limit,\n }),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL }\n );\n\n return {\n listings: data?.data ?? [],\n isLoading,\n error,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAmB;AACnB,iBAAiC;AAGjC,kCAAmC;AACnC,wBAA0B;AAC1B,uBAA8C;AAE9C,MAAM,gCAAgC;AACtC,MAAM,iCAAiC;AAEhC,SAAS,UAAU,WAAkC,QAAwB,CAAC,GAAG;AACtF,QAAM,aAAS,gDAAmB,SAAS;AAC3C,QAAM,MAAM,4BAAU,OAAO,KAAK;AAElC,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC;AAAA,IACA,MAAM,OAAO,IAAI,UAAU,KAAK;AAAA,IAChC,EAAE,mBAAmB,OAAO,iBAAiB,KAAO,kBAAkB,IAAK;AAAA,EAC7E;AAEA,SAAO;AAAA,IACL,QAAQ,MAAM,QAAQ,CAAC;AAAA,IACvB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AAO,IAAI,UAAU;AAAA,MACnB,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,IACH,EAAE,mBAAmB,OAAO,iBAAiB,8BAA8B;AAAA,EAC7E;AAEA,SAAO;AAAA,IACL,UAAU,MAAM,QAAQ,CAAC;AAAA,IACzB;AAAA,IACA;AAAA,EACF;AACF;","names":["useSWR"]}
@@ -0,0 +1,55 @@
1
+ import * as swr from 'swr';
2
+ import * as _medialane_sdk from '@medialane/sdk';
3
+ import { ApiOrder, ApiResponse, ApiOrdersQuery } from '@medialane/sdk';
4
+ import { MedialaneClient } from '@medialane/sdk/starknet';
5
+ import { ApiFetchConfig } from './api-fetch.cjs';
6
+
7
+ declare function useOrders(getClient: () => MedialaneClient, query?: ApiOrdersQuery): {
8
+ orders: ApiOrder[];
9
+ meta: _medialane_sdk.ApiMeta | undefined;
10
+ isLoading: boolean;
11
+ error: any;
12
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
13
+ };
14
+ declare function useOrder(getClient: () => MedialaneClient, orderHash: string | null): {
15
+ order: ApiOrder | null;
16
+ isLoading: boolean;
17
+ error: any;
18
+ };
19
+ declare function useTokenListings(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null): {
20
+ listings: ApiOrder[];
21
+ isLoading: boolean;
22
+ error: any;
23
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
24
+ };
25
+ declare function useUserOrders(getClient: () => MedialaneClient, address: string | null): {
26
+ orders: ApiOrder[];
27
+ isLoading: boolean;
28
+ error: any;
29
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
30
+ };
31
+ /** Fetch counter-offers for a specific original bid (buyer view) or by seller address. */
32
+ declare function useCounterOffers(getClient: () => MedialaneClient, { originalOrderHash, sellerAddress, }: {
33
+ originalOrderHash?: string | null;
34
+ sellerAddress?: string | null;
35
+ }): {
36
+ counterOffers: ApiOrder[];
37
+ total: number;
38
+ isLoading: boolean;
39
+ error: any;
40
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
41
+ };
42
+ /** Fetch active ERC20 offers received by the given address (offers on tokens they hold). */
43
+ declare function useReceivedOffers(apiConfig: ApiFetchConfig, address: string | null): {
44
+ orders: ApiOrder[];
45
+ isLoading: boolean;
46
+ error: any;
47
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
48
+ };
49
+ declare function useCollectionFloorListings(getClient: () => MedialaneClient, contract: string | null, limit?: number): {
50
+ listings: ApiOrder[];
51
+ isLoading: boolean;
52
+ error: any;
53
+ };
54
+
55
+ export { useCollectionFloorListings, useCounterOffers, useOrder, useOrders, useReceivedOffers, useTokenListings, useUserOrders };
@@ -0,0 +1,55 @@
1
+ import * as swr from 'swr';
2
+ import * as _medialane_sdk from '@medialane/sdk';
3
+ import { ApiOrder, ApiResponse, ApiOrdersQuery } from '@medialane/sdk';
4
+ import { MedialaneClient } from '@medialane/sdk/starknet';
5
+ import { ApiFetchConfig } from './api-fetch.js';
6
+
7
+ declare function useOrders(getClient: () => MedialaneClient, query?: ApiOrdersQuery): {
8
+ orders: ApiOrder[];
9
+ meta: _medialane_sdk.ApiMeta | undefined;
10
+ isLoading: boolean;
11
+ error: any;
12
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
13
+ };
14
+ declare function useOrder(getClient: () => MedialaneClient, orderHash: string | null): {
15
+ order: ApiOrder | null;
16
+ isLoading: boolean;
17
+ error: any;
18
+ };
19
+ declare function useTokenListings(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null): {
20
+ listings: ApiOrder[];
21
+ isLoading: boolean;
22
+ error: any;
23
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
24
+ };
25
+ declare function useUserOrders(getClient: () => MedialaneClient, address: string | null): {
26
+ orders: ApiOrder[];
27
+ isLoading: boolean;
28
+ error: any;
29
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
30
+ };
31
+ /** Fetch counter-offers for a specific original bid (buyer view) or by seller address. */
32
+ declare function useCounterOffers(getClient: () => MedialaneClient, { originalOrderHash, sellerAddress, }: {
33
+ originalOrderHash?: string | null;
34
+ sellerAddress?: string | null;
35
+ }): {
36
+ counterOffers: ApiOrder[];
37
+ total: number;
38
+ isLoading: boolean;
39
+ error: any;
40
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
41
+ };
42
+ /** Fetch active ERC20 offers received by the given address (offers on tokens they hold). */
43
+ declare function useReceivedOffers(apiConfig: ApiFetchConfig, address: string | null): {
44
+ orders: ApiOrder[];
45
+ isLoading: boolean;
46
+ error: any;
47
+ mutate: swr.KeyedMutator<ApiResponse<ApiOrder[]>>;
48
+ };
49
+ declare function useCollectionFloorListings(getClient: () => MedialaneClient, contract: string | null, limit?: number): {
50
+ listings: ApiOrder[];
51
+ isLoading: boolean;
52
+ error: any;
53
+ };
54
+
55
+ export { useCollectionFloorListings, useCounterOffers, useOrder, useOrders, useReceivedOffers, useTokenListings, useUserOrders };
@@ -0,0 +1,113 @@
1
+ "use client";
2
+ import useSWR from "swr";
3
+ import { normalizeAddress } from "@medialane/sdk";
4
+ import { useMedialaneClient } from "./use-medialane-client.js";
5
+ import { queryKeys } from "./query-keys.js";
6
+ import { apiFetch } from "./api-fetch.js";
7
+ const ACTIVE_ORDER_REFRESH_INTERVAL = 6e4;
8
+ const ACTIVE_ORDER_DEDUPING_INTERVAL = 1e4;
9
+ function useOrders(getClient, query = {}) {
10
+ const client = useMedialaneClient(getClient);
11
+ const key = queryKeys.orders(query);
12
+ const { data, error, isLoading, mutate } = useSWR(
13
+ key,
14
+ () => client.api.getOrders(query),
15
+ { revalidateOnFocus: false, refreshInterval: 3e4, dedupingInterval: 5e3 }
16
+ );
17
+ return {
18
+ orders: data?.data ?? [],
19
+ meta: data?.meta,
20
+ isLoading,
21
+ error,
22
+ mutate
23
+ };
24
+ }
25
+ function useOrder(getClient, orderHash) {
26
+ const client = useMedialaneClient(getClient);
27
+ const { data, error, isLoading } = useSWR(
28
+ orderHash ? queryKeys.order(orderHash) : null,
29
+ () => client.api.getOrder(orderHash),
30
+ { revalidateOnFocus: false }
31
+ );
32
+ return { order: data?.data ?? null, isLoading, error };
33
+ }
34
+ function useTokenListings(getClient, contract, tokenId) {
35
+ const client = useMedialaneClient(getClient);
36
+ const { data, error, isLoading, mutate } = useSWR(
37
+ contract && tokenId ? queryKeys.listings(contract, tokenId) : null,
38
+ () => client.api.getActiveOrdersForToken(contract, tokenId),
39
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
40
+ );
41
+ return { listings: data?.data ?? [], isLoading, error, mutate };
42
+ }
43
+ function useUserOrders(getClient, address) {
44
+ const client = useMedialaneClient(getClient);
45
+ const normalized = address ? normalizeAddress("STARKNET", address) : null;
46
+ const { data, error, isLoading, mutate } = useSWR(
47
+ normalized ? queryKeys.userOrders(normalized) : null,
48
+ () => client.api.getOrdersByUser(normalized),
49
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
50
+ );
51
+ return { orders: data?.data ?? [], isLoading, error, mutate };
52
+ }
53
+ function useCounterOffers(getClient, {
54
+ originalOrderHash,
55
+ sellerAddress
56
+ }) {
57
+ const client = useMedialaneClient(getClient);
58
+ const normalized = sellerAddress ? normalizeAddress("STARKNET", sellerAddress) : null;
59
+ const key = originalOrderHash ? queryKeys.counterOffersByOrder(originalOrderHash) : normalized ? queryKeys.counterOffersBySeller(normalized) : null;
60
+ const { data, error, isLoading, mutate } = useSWR(
61
+ key,
62
+ () => client.api.getCounterOffers({
63
+ ...originalOrderHash ? { originalOrderHash } : {},
64
+ ...normalized ? { sellerAddress: normalized } : {}
65
+ }),
66
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
67
+ );
68
+ return {
69
+ counterOffers: data?.data ?? [],
70
+ total: data?.meta?.total ?? 0,
71
+ isLoading,
72
+ error,
73
+ mutate
74
+ };
75
+ }
76
+ function useReceivedOffers(apiConfig, address) {
77
+ const normalized = address ? normalizeAddress("STARKNET", address) : null;
78
+ const { data, error, isLoading, mutate } = useSWR(
79
+ normalized ? ["received-offers", normalized] : null,
80
+ () => apiFetch(apiConfig, `/v1/orders/received/${normalized}?limit=50`),
81
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }
82
+ );
83
+ return { orders: data?.data ?? [], isLoading, error, mutate };
84
+ }
85
+ function useCollectionFloorListings(getClient, contract, limit = 20) {
86
+ const client = useMedialaneClient(getClient);
87
+ const key = contract ? queryKeys.floorListings(contract, limit) : null;
88
+ const { data, error, isLoading } = useSWR(
89
+ key,
90
+ () => client.api.getOrders({
91
+ collection: contract,
92
+ status: "ACTIVE",
93
+ sort: "price_asc",
94
+ limit
95
+ }),
96
+ { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL }
97
+ );
98
+ return {
99
+ listings: data?.data ?? [],
100
+ isLoading,
101
+ error
102
+ };
103
+ }
104
+ export {
105
+ useCollectionFloorListings,
106
+ useCounterOffers,
107
+ useOrder,
108
+ useOrders,
109
+ useReceivedOffers,
110
+ useTokenListings,
111
+ useUserOrders
112
+ };
113
+ //# sourceMappingURL=use-orders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/use-orders.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { normalizeAddress } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { ApiOrdersQuery, ApiOrder, ApiResponse } from \"@medialane/sdk\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport { queryKeys } from \"./query-keys.js\";\nimport { apiFetch, type ApiFetchConfig } from \"./api-fetch.js\";\n\nconst ACTIVE_ORDER_REFRESH_INTERVAL = 60_000;\nconst ACTIVE_ORDER_DEDUPING_INTERVAL = 10_000;\n\nexport function useOrders(getClient: () => MedialaneClient, query: ApiOrdersQuery = {}) {\n const client = useMedialaneClient(getClient);\n const key = queryKeys.orders(query);\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiOrder[]>>(\n key,\n () => client.api.getOrders(query),\n { revalidateOnFocus: false, refreshInterval: 30000, dedupingInterval: 5000 }\n );\n\n return {\n orders: data?.data ?? [],\n meta: data?.meta,\n isLoading,\n error,\n mutate,\n };\n}\n\nexport function useOrder(getClient: () => MedialaneClient, orderHash: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading } = useSWR(\n orderHash ? queryKeys.order(orderHash) : null,\n () => client.api.getOrder(orderHash!),\n { revalidateOnFocus: false }\n );\n\n return { order: data?.data ?? null, isLoading, error };\n}\n\nexport function useTokenListings(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading, mutate } = useSWR(\n contract && tokenId ? queryKeys.listings(contract, tokenId) : null,\n () => client.api.getActiveOrdersForToken(contract!, tokenId!),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return { listings: data?.data ?? [], isLoading, error, mutate };\n}\n\nexport function useUserOrders(getClient: () => MedialaneClient, address: string | null) {\n const client = useMedialaneClient(getClient);\n const normalized = address ? normalizeAddress(\"STARKNET\", address) : null;\n\n const { data, error, isLoading, mutate } = useSWR(\n normalized ? queryKeys.userOrders(normalized) : null,\n () => client.api.getOrdersByUser(normalized!),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return { orders: data?.data ?? [], isLoading, error, mutate };\n}\n\n/** Fetch counter-offers for a specific original bid (buyer view) or by seller address. */\nexport function useCounterOffers(\n getClient: () => MedialaneClient,\n {\n originalOrderHash,\n sellerAddress,\n }: {\n originalOrderHash?: string | null;\n sellerAddress?: string | null;\n }\n) {\n const client = useMedialaneClient(getClient);\n const normalized = sellerAddress ? normalizeAddress(\"STARKNET\", sellerAddress) : null;\n const key =\n originalOrderHash\n ? queryKeys.counterOffersByOrder(originalOrderHash)\n : normalized\n ? queryKeys.counterOffersBySeller(normalized)\n : null;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiOrder[]>>(\n key,\n () => client.api.getCounterOffers({\n ...(originalOrderHash ? { originalOrderHash } : {}),\n ...(normalized ? { sellerAddress: normalized } : {}),\n }),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return {\n counterOffers: data?.data ?? [],\n total: data?.meta?.total ?? 0,\n isLoading,\n error,\n mutate,\n };\n}\n\n/** Fetch active ERC20 offers received by the given address (offers on tokens they hold). */\nexport function useReceivedOffers(apiConfig: ApiFetchConfig, address: string | null) {\n const normalized = address ? normalizeAddress(\"STARKNET\", address) : null;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiOrder[]>>(\n normalized ? [\"received-offers\", normalized] : null,\n () => apiFetch<ApiResponse<ApiOrder[]>>(apiConfig, `/v1/orders/received/${normalized}?limit=50`),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL, dedupingInterval: ACTIVE_ORDER_DEDUPING_INTERVAL }\n );\n\n return { orders: data?.data ?? [], isLoading, error, mutate };\n}\n\nexport function useCollectionFloorListings(getClient: () => MedialaneClient, contract: string | null, limit = 20) {\n const client = useMedialaneClient(getClient);\n const key = contract ? queryKeys.floorListings(contract, limit) : null;\n\n const { data, error, isLoading } = useSWR<ApiResponse<ApiOrder[]>>(\n key,\n () =>\n client.api.getOrders({\n collection: contract!,\n status: \"ACTIVE\",\n sort: \"price_asc\",\n limit,\n }),\n { revalidateOnFocus: false, refreshInterval: ACTIVE_ORDER_REFRESH_INTERVAL }\n );\n\n return {\n listings: data?.data ?? [],\n isLoading,\n error,\n };\n}\n"],"mappings":";AAEA,OAAO,YAAY;AACnB,SAAS,wBAAwB;AAGjC,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,gBAAqC;AAE9C,MAAM,gCAAgC;AACtC,MAAM,iCAAiC;AAEhC,SAAS,UAAU,WAAkC,QAAwB,CAAC,GAAG;AACtF,QAAM,SAAS,mBAAmB,SAAS;AAC3C,QAAM,MAAM,UAAU,OAAO,KAAK;AAElC,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI;AAAA,IACzC;AAAA,IACA,MAAM,OAAO,IAAI,UAAU,KAAK;AAAA,IAChC,EAAE,mBAAmB,OAAO,iBAAiB,KAAO,kBAAkB,IAAK;AAAA,EAC7E;AAEA,SAAO;AAAA,IACL,QAAQ,MAAM,QAAQ,CAAC;AAAA,IACvB,MAAM,MAAM;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,SAAS,WAAkC,WAA0B;AACnF,QAAM,SAAS,mBAAmB,SAAS;AAE3C,QAAM,EAAE,MAAM,OAAO,UAAU,IAAI;AAAA,IACjC,YAAY,UAAU,MAAM,SAAS,IAAI;AAAA,IACzC,MAAM,OAAO,IAAI,SAAS,SAAU;AAAA,IACpC,EAAE,mBAAmB,MAAM;AAAA,EAC7B;AAEA,SAAO,EAAE,OAAO,MAAM,QAAQ,MAAM,WAAW,MAAM;AACvD;AAEO,SAAS,iBAAiB,WAAkC,UAAyB,SAAwB;AAClH,QAAM,SAAS,mBAAmB,SAAS;AAE3C,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI;AAAA,IACzC,YAAY,UAAU,UAAU,SAAS,U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MAAM,SAAS;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAGO,SAAS,kBAAkB,WAA2B,SAAwB;AACnF,QAAM,aAAa,UAAU,iBAAiB,YAAY,OAAO,IAAI;AAErE,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI;AAAA,IACzC,aAAa,CAAC,mBAAmB,UAAU,IAAI;AAAA,IAC/C,MAAM,SAAkC,WAAW,uBAAuB,UAAU,WAAW;AAAA,IAC/F,EAAE,mBAAmB,OAAO,iBAAiB,+BAA+B,kBAAkB,+BAA+B;AAAA,EAC/H;AAEA,SAAO,EAAE,QAAQ,MAAM,QAAQ,CAAC,GAAG,WAAW,OAAO,OAAO;AAC9D;AAEO,SAAS,2BAA2B,WAAkC,UAAyB,QAAQ,IAAI;AAChH,QAAM,SAAS,mBAAmB,SAAS;AAC3C,QAAM,MAAM,WAAW,UAAU,cAAc,UAAU,KAAK,IAAI;AAElE,QAAM,EAAE,MAAM,OAAO,UAAU,IAAI;AAAA,IACjC;AAAA,IACA,MACE,OAAO,IAAI,UAAU;AAAA,MACnB,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,IACH,EAAE,mBAAmB,OAAO,iBAAiB,8BAA8B;AAAA,EAC7E;AAEA,SAAO;AAAA,IACL,UAAU,MAAM,QAAQ,CAAC;AAAA,IACzB;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var use_remix_offers_exports = {};
31
+ __export(use_remix_offers_exports, {
32
+ useTokenRemixes: () => useTokenRemixes
33
+ });
34
+ module.exports = __toCommonJS(use_remix_offers_exports);
35
+ var import_swr = __toESM(require("swr"), 1);
36
+ var import_api_fetch = require("./api-fetch.js");
37
+ function useTokenRemixes(apiConfig, contract, tokenId) {
38
+ const { data, error, isLoading, mutate } = (0, import_swr.default)(
39
+ contract && tokenId ? `token-remixes-${contract}-${tokenId}` : null,
40
+ () => (0, import_api_fetch.apiFetch)(apiConfig, `/v1/tokens/${contract}/${tokenId}/remixes`),
41
+ { refreshInterval: 6e4, revalidateOnFocus: false }
42
+ );
43
+ return { remixes: data?.data ?? [], total: data?.meta.total ?? 0, isLoading, error, mutate };
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ useTokenRemixes
48
+ });
49
+ //# sourceMappingURL=use-remix-offers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/use-remix-offers.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { apiFetch, type ApiFetchConfig } from \"./api-fetch.js\";\nimport type { ApiPublicRemix } from \"@medialane/sdk\";\n\n/** Public remixes of a token — no wallet/auth dependency. */\nexport function useTokenRemixes(apiConfig: ApiFetchConfig, contract: string | null, tokenId: string | null) {\n const { data, error, isLoading, mutate } = useSWR<{ data: ApiPublicRemix[]; meta: { total: number } }>(\n contract && tokenId ? `token-remixes-${contract}-${tokenId}` : null,\n () => apiFetch(apiConfig, `/v1/tokens/${contract}/${tokenId}/remixes`),\n { refreshInterval: 60000, revalidateOnFocus: false }\n );\n\n return { remixes: data?.data ?? [], total: data?.meta.total ?? 0, isLoading, error, mutate };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAmB;AACnB,uBAA8C;AAIvC,SAAS,gBAAgB,WAA2B,UAAyB,SAAwB;AAC1G,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC,YAAY,UAAU,iBAAiB,QAAQ,IAAI,OAAO,KAAK;AAAA,IAC/D,UAAM,2BAAS,WAAW,cAAc,QAAQ,IAAI,OAAO,UAAU;AAAA,IACrE,EAAE,iBAAiB,KAAO,mBAAmB,MAAM;AAAA,EACrD;AAEA,SAAO,EAAE,SAAS,MAAM,QAAQ,CAAC,GAAG,OAAO,MAAM,KAAK,SAAS,GAAG,WAAW,OAAO,OAAO;AAC7F;","names":["useSWR"]}