@medialane/ui 0.107.0 → 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.
- package/dist/components/remixes-tab.cjs +91 -0
- package/dist/components/remixes-tab.cjs.map +1 -0
- package/dist/components/remixes-tab.d.cts +11 -0
- package/dist/components/remixes-tab.d.ts +11 -0
- package/dist/components/remixes-tab.js +57 -0
- package/dist/components/remixes-tab.js.map +1 -0
- package/dist/data/notification.cjs +17 -0
- package/dist/data/notification.cjs.map +1 -0
- package/dist/data/notification.d.cts +34 -0
- package/dist/data/notification.d.ts +34 -0
- package/dist/data/notification.js +1 -0
- package/dist/data/notification.js.map +1 -0
- package/dist/index.cjs +31 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +26 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/api-fetch.cjs +65 -0
- package/dist/utils/api-fetch.cjs.map +1 -0
- package/dist/utils/api-fetch.d.cts +38 -0
- package/dist/utils/api-fetch.d.ts +38 -0
- package/dist/utils/api-fetch.js +40 -0
- package/dist/utils/api-fetch.js.map +1 -0
- package/dist/utils/use-collections.cjs +7 -4
- package/dist/utils/use-collections.cjs.map +1 -1
- package/dist/utils/use-collections.d.cts +6 -1
- package/dist/utils/use-collections.d.ts +6 -1
- package/dist/utils/use-collections.js +7 -4
- package/dist/utils/use-collections.js.map +1 -1
- package/dist/utils/use-notifications.cjs +169 -0
- package/dist/utils/use-notifications.cjs.map +1 -0
- package/dist/utils/use-notifications.d.cts +12 -0
- package/dist/utils/use-notifications.d.ts +12 -0
- package/dist/utils/use-notifications.js +140 -0
- package/dist/utils/use-notifications.js.map +1 -0
- package/dist/utils/use-orders.cjs +153 -0
- package/dist/utils/use-orders.cjs.map +1 -0
- package/dist/utils/use-orders.d.cts +55 -0
- package/dist/utils/use-orders.d.ts +55 -0
- package/dist/utils/use-orders.js +113 -0
- package/dist/utils/use-orders.js.map +1 -0
- package/dist/utils/use-remix-offers.cjs +49 -0
- package/dist/utils/use-remix-offers.cjs.map +1 -0
- package/dist/utils/use-remix-offers.d.cts +19 -0
- package/dist/utils/use-remix-offers.d.ts +19 -0
- package/dist/utils/use-remix-offers.js +15 -0
- package/dist/utils/use-remix-offers.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,169 @@
|
|
|
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_notifications_exports = {};
|
|
31
|
+
__export(use_notifications_exports, {
|
|
32
|
+
useNotifications: () => useNotifications
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(use_notifications_exports);
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_swr = __toESM(require("swr"), 1);
|
|
37
|
+
var import_sdk = require("@medialane/sdk");
|
|
38
|
+
var import_use_orders = require("./use-orders.js");
|
|
39
|
+
var import_use_activities = require("./use-activities.js");
|
|
40
|
+
var import_notification_storage = require("./notification-storage.js");
|
|
41
|
+
var import_format_activity = require("./format-activity.js");
|
|
42
|
+
async function fetchAnnouncements() {
|
|
43
|
+
const res = await fetch("/api/announcements");
|
|
44
|
+
if (!res.ok) return [];
|
|
45
|
+
return res.json();
|
|
46
|
+
}
|
|
47
|
+
function useNotifications(getClient, apiConfig, address) {
|
|
48
|
+
const [readIds, setReadIds] = (0, import_react.useState)(() => (0, import_notification_storage.getReadIds)());
|
|
49
|
+
const { orders: userOrders } = (0, import_use_orders.useUserOrders)(getClient, address ?? null);
|
|
50
|
+
const { orders: receivedOffers } = (0, import_use_orders.useReceivedOffers)(apiConfig, address ?? null);
|
|
51
|
+
const { activities } = (0, import_use_activities.useActivitiesByAddress)(getClient, address ?? null);
|
|
52
|
+
const { data: announcements = [] } = (0, import_swr.default)(
|
|
53
|
+
"announcements",
|
|
54
|
+
fetchAnnouncements,
|
|
55
|
+
{ revalidateOnFocus: false, dedupingInterval: 6e4 }
|
|
56
|
+
);
|
|
57
|
+
const notifications = (0, import_react.useMemo)(() => {
|
|
58
|
+
const items = [];
|
|
59
|
+
userOrders.filter((o) => o.offer.itemType === "ERC20" && o.status === "FULFILLED").forEach((order) => {
|
|
60
|
+
const id = `offer-accepted-${order.orderHash}`;
|
|
61
|
+
const fmt = (0, import_format_activity.formatOfferAcceptedNotification)(order);
|
|
62
|
+
items.push({
|
|
63
|
+
id,
|
|
64
|
+
type: "offer_accepted",
|
|
65
|
+
priority: "spotlight",
|
|
66
|
+
celebratory: true,
|
|
67
|
+
...fmt,
|
|
68
|
+
timestamp: order.updatedAt ?? order.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
69
|
+
isUnread: !readIds.has(id),
|
|
70
|
+
metadata: {
|
|
71
|
+
amount: order.price?.formatted ?? void 0,
|
|
72
|
+
currency: order.price?.currency ?? void 0,
|
|
73
|
+
txHash: order.txHash?.fulfilled ?? void 0,
|
|
74
|
+
assetName: order.token?.name ?? void 0
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
receivedOffers.forEach((order) => {
|
|
79
|
+
const id = `order-${order.orderHash}`;
|
|
80
|
+
const fmt = (0, import_format_activity.formatOrderNotification)(order);
|
|
81
|
+
items.push({
|
|
82
|
+
id,
|
|
83
|
+
type: "offer",
|
|
84
|
+
priority: "spotlight",
|
|
85
|
+
celebratory: false,
|
|
86
|
+
...fmt,
|
|
87
|
+
timestamp: order.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
88
|
+
isUnread: !readIds.has(id),
|
|
89
|
+
metadata: {
|
|
90
|
+
amount: order.price?.formatted ?? void 0,
|
|
91
|
+
currency: order.price?.currency ?? void 0,
|
|
92
|
+
assetName: order.token?.name ?? void 0
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
activities.slice(0, 50).forEach((event) => {
|
|
97
|
+
const id = `activity-${event.txHash}-${event.type}-${event.nftTokenId ?? ""}`;
|
|
98
|
+
if (event.type === "transfer" && address && !!event.to && (0, import_sdk.normalizeAddress)("STARKNET", event.to) === (0, import_sdk.normalizeAddress)("STARKNET", address)) {
|
|
99
|
+
const fmt2 = (0, import_format_activity.formatAssetReceivedNotification)(event);
|
|
100
|
+
items.push({
|
|
101
|
+
id,
|
|
102
|
+
type: "asset_received",
|
|
103
|
+
priority: "spotlight",
|
|
104
|
+
celebratory: true,
|
|
105
|
+
...fmt2,
|
|
106
|
+
timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
107
|
+
isUnread: !readIds.has(id),
|
|
108
|
+
metadata: {
|
|
109
|
+
txHash: event.txHash ?? void 0,
|
|
110
|
+
assetName: event.token?.name ?? void 0
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const isMySale = event.type === "sale" && address && (!!event.offerer && (0, import_sdk.normalizeAddress)("STARKNET", event.offerer) === (0, import_sdk.normalizeAddress)("STARKNET", address) || !!event.from && (0, import_sdk.normalizeAddress)("STARKNET", event.from) === (0, import_sdk.normalizeAddress)("STARKNET", address));
|
|
116
|
+
const fmt = (0, import_format_activity.formatActivity)(event);
|
|
117
|
+
items.push({
|
|
118
|
+
id,
|
|
119
|
+
type: event.type,
|
|
120
|
+
priority: isMySale ? "spotlight" : "normal",
|
|
121
|
+
celebratory: !!isMySale,
|
|
122
|
+
...fmt,
|
|
123
|
+
timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
124
|
+
isUnread: !readIds.has(id),
|
|
125
|
+
metadata: {
|
|
126
|
+
amount: event.price?.formatted ?? void 0,
|
|
127
|
+
currency: event.price?.currency ?? void 0,
|
|
128
|
+
txHash: event.txHash ?? void 0,
|
|
129
|
+
assetName: event.token?.name ?? void 0
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
announcements.forEach((ann) => {
|
|
134
|
+
const id = `ann-${ann.id}`;
|
|
135
|
+
items.push({
|
|
136
|
+
id,
|
|
137
|
+
type: "announcement",
|
|
138
|
+
priority: ann.pinned ? "spotlight" : "normal",
|
|
139
|
+
celebratory: false,
|
|
140
|
+
title: ann.title,
|
|
141
|
+
description: ann.body,
|
|
142
|
+
image: ann.image,
|
|
143
|
+
href: ann.href,
|
|
144
|
+
timestamp: ann.created_at,
|
|
145
|
+
isUnread: !readIds.has(id)
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
items.sort(
|
|
149
|
+
(a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()
|
|
150
|
+
);
|
|
151
|
+
return items;
|
|
152
|
+
}, [userOrders, receivedOffers, activities, announcements, address, readIds]);
|
|
153
|
+
const unreadCount = notifications.filter((n) => n.isUnread).length;
|
|
154
|
+
const markNotificationsRead = (0, import_react.useCallback)((ids) => {
|
|
155
|
+
(0, import_notification_storage.markRead)(ids);
|
|
156
|
+
setReadIds((0, import_notification_storage.getReadIds)());
|
|
157
|
+
}, []);
|
|
158
|
+
return {
|
|
159
|
+
notifications,
|
|
160
|
+
unreadCount,
|
|
161
|
+
markAllRead: () => markNotificationsRead(notifications.map((n) => n.id)),
|
|
162
|
+
markRead: (id) => markNotificationsRead([id])
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
useNotifications
|
|
168
|
+
});
|
|
169
|
+
//# sourceMappingURL=use-notifications.cjs.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA+C;AAC/C,iBAAmB;AACnB,iBAAiC;AAGjC,wBAAiD;AACjD,4BAAuC;AACvC,kCAAqC;AACrC,6BAKO;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,QAAI,uBAAsB,UAAM,wCAAW,CAAC;AAGtE,QAAM,EAAE,QAAQ,WAAW,QAAI,iCAAc,WAAW,WAAW,IAAI;AAEvE,QAAM,EAAE,QAAQ,eAAe,QAAI,qCAAkB,WAAW,WAAW,IAAI;AAC/E,QAAM,EAAE,WAAW,QAAI,8CAAuB,WAAW,WAAW,IAAI;AACxE,QAAM,EAAE,MAAM,gBAAgB,CAAC,EAAE,QAAI,WAAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA,EAAE,mBAAmB,OAAO,kBAAkB,IAAO;AAAA,EACvD;AAEA,QAAM,oBAAgC,sBAAQ,MAAM;AAClD,UAAM,QAAwB,CAAC;AAG/B,eACG,OAAO,CAAC,MAAM,EAAE,MAAM,aAAa,WAAW,EAAE,WAAW,WAAW,EACtE,QAAQ,CAAC,UAAU;AAClB,YAAM,KAAK,kBAAkB,MAAM,SAAS;AAC5C,YAAM,UAAM,wDAAgC,KAAK;AACjD,YAAM,KAAK;AAAA,QACT;AAAA,QACA,MAAM;AAAA,QACN,UAAU;AAAA,QACV,aAAa;AAAA,QACb,GAAG;AAAA,QAC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AM,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,4BAAwB,0BAAY,CAAC,QAAkB;AAC3D,8CAAS,GAAG;AACZ,mBAAW,wCAAW,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":["useSWR","fmt"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
2
|
+
import { Notification } from '../data/notification.cjs';
|
|
3
|
+
import { ApiFetchConfig } from './api-fetch.cjs';
|
|
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,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;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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":";;;;;;;;;;;;;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Aa,cAAU,6BAAiB,YAAY,OAAO,IAAI;AAErE,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC,aAAa,CAAC,mBAAmB,UAAU,IAAI;AAAA,IAC/C,UAAM,2BAAkC,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,aAAS,gDAAmB,SAAS;AAC3C,QAAM,MAAM,WAAW,4BAAU,cAAc,UAAU,KAAK,IAAI;AAElE,QAAM,EAAE,MAAM,OAAO,UAAU,QAAI,WAAAA;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":["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 };
|