@medialane/ui 0.168.0 → 0.170.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/fast-mint/fast-mint.cjs +4 -4
- package/dist/components/fast-mint/fast-mint.cjs.map +1 -1
- package/dist/components/fast-mint/fast-mint.js +4 -4
- package/dist/components/fast-mint/fast-mint.js.map +1 -1
- package/dist/components/remixes-tab.cjs +2 -2
- package/dist/components/remixes-tab.cjs.map +1 -1
- package/dist/components/remixes-tab.d.cts +3 -3
- package/dist/components/remixes-tab.d.ts +3 -3
- package/dist/components/remixes-tab.js +2 -2
- package/dist/components/remixes-tab.js.map +1 -1
- package/dist/index.cjs +68 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +63 -3
- package/dist/index.js.map +1 -1
- package/dist/utils/ipfs-upload.cjs +11 -31
- package/dist/utils/ipfs-upload.cjs.map +1 -1
- package/dist/utils/ipfs-upload.d.cts +5 -5
- package/dist/utils/ipfs-upload.d.ts +5 -5
- package/dist/utils/ipfs-upload.js +11 -31
- package/dist/utils/ipfs-upload.js.map +1 -1
- package/dist/utils/sitemap-data.cjs +55 -0
- package/dist/utils/sitemap-data.cjs.map +1 -0
- package/dist/utils/sitemap-data.d.cts +23 -0
- package/dist/utils/sitemap-data.d.ts +23 -0
- package/dist/utils/sitemap-data.js +31 -0
- package/dist/utils/sitemap-data.js.map +1 -0
- package/dist/utils/use-coin-price.cjs +88 -0
- package/dist/utils/use-coin-price.cjs.map +1 -0
- package/dist/utils/use-coin-price.d.cts +17 -0
- package/dist/utils/use-coin-price.d.ts +17 -0
- package/dist/utils/use-coin-price.js +53 -0
- package/dist/utils/use-coin-price.js.map +1 -0
- package/dist/utils/use-collections.cjs +2 -2
- package/dist/utils/use-collections.cjs.map +1 -1
- package/dist/utils/use-collections.js +2 -2
- package/dist/utils/use-collections.js.map +1 -1
- package/dist/utils/use-drops.cjs +94 -0
- package/dist/utils/use-drops.cjs.map +1 -0
- package/dist/utils/use-drops.d.cts +39 -0
- package/dist/utils/use-drops.d.ts +39 -0
- package/dist/utils/use-drops.js +56 -0
- package/dist/utils/use-drops.js.map +1 -0
- package/dist/utils/use-notifications.cjs +2 -2
- package/dist/utils/use-notifications.cjs.map +1 -1
- package/dist/utils/use-notifications.d.cts +1 -2
- package/dist/utils/use-notifications.d.ts +1 -2
- package/dist/utils/use-notifications.js +2 -2
- package/dist/utils/use-notifications.js.map +1 -1
- package/dist/utils/use-orders.cjs +3 -3
- package/dist/utils/use-orders.cjs.map +1 -1
- package/dist/utils/use-orders.d.cts +1 -2
- package/dist/utils/use-orders.d.ts +1 -2
- package/dist/utils/use-orders.js +3 -3
- package/dist/utils/use-orders.js.map +1 -1
- package/dist/utils/use-platform-stats.cjs +50 -0
- package/dist/utils/use-platform-stats.cjs.map +1 -0
- package/dist/utils/use-platform-stats.d.cts +9 -0
- package/dist/utils/use-platform-stats.d.ts +9 -0
- package/dist/utils/use-platform-stats.js +16 -0
- package/dist/utils/use-platform-stats.js.map +1 -0
- package/dist/utils/use-pop.cjs +72 -0
- package/dist/utils/use-pop.cjs.map +1 -0
- package/dist/utils/use-pop.d.cts +28 -0
- package/dist/utils/use-pop.d.ts +28 -0
- package/dist/utils/use-pop.js +36 -0
- package/dist/utils/use-pop.js.map +1 -0
- package/dist/utils/use-remix-offers.cjs +5 -4
- package/dist/utils/use-remix-offers.cjs.map +1 -1
- package/dist/utils/use-remix-offers.d.cts +4 -9
- package/dist/utils/use-remix-offers.d.ts +4 -9
- package/dist/utils/use-remix-offers.js +5 -4
- package/dist/utils/use-remix-offers.js.map +1 -1
- package/dist/utils/use-sponsorship.cjs +131 -0
- package/dist/utils/use-sponsorship.cjs.map +1 -0
- package/dist/utils/use-sponsorship.d.cts +70 -0
- package/dist/utils/use-sponsorship.d.ts +70 -0
- package/dist/utils/use-sponsorship.js +90 -0
- package/dist/utils/use-sponsorship.js.map +1 -0
- package/dist/utils/use-tiers.cjs +137 -0
- package/dist/utils/use-tiers.cjs.map +1 -0
- package/dist/utils/use-tiers.d.cts +60 -0
- package/dist/utils/use-tiers.d.ts +60 -0
- package/dist/utils/use-tiers.js +95 -0
- package/dist/utils/use-tiers.js.map +1 -0
- package/dist/utils/use-tokens-by-ip-type.cjs +50 -0
- package/dist/utils/use-tokens-by-ip-type.cjs.map +1 -0
- package/dist/utils/use-tokens-by-ip-type.d.cts +14 -0
- package/dist/utils/use-tokens-by-ip-type.d.ts +14 -0
- package/dist/utils/use-tokens-by-ip-type.js +16 -0
- package/dist/utils/use-tokens-by-ip-type.js.map +1 -0
- package/package.json +3 -3
- package/dist/utils/api-fetch.cjs +0 -65
- package/dist/utils/api-fetch.cjs.map +0 -1
- package/dist/utils/api-fetch.d.cts +0 -17
- package/dist/utils/api-fetch.d.ts +0 -17
- package/dist/utils/api-fetch.js +0 -40
- package/dist/utils/api-fetch.js.map +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
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_coin_price_exports = {};
|
|
31
|
+
__export(use_coin_price_exports, {
|
|
32
|
+
useCoinPrice: () => useCoinPrice,
|
|
33
|
+
usePriceMap: () => usePriceMap
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(use_coin_price_exports);
|
|
36
|
+
var import_swr = __toESM(require("swr"), 1);
|
|
37
|
+
var import_sdk = require("@medialane/sdk");
|
|
38
|
+
var import_use_medialane_client = require("./use-medialane-client.js");
|
|
39
|
+
var import_sdk2 = require("@medialane/sdk");
|
|
40
|
+
const REFRESH_MS = 6e4;
|
|
41
|
+
function useAllCoinPrices(getClient) {
|
|
42
|
+
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
43
|
+
const { data, isLoading } = (0, import_swr.default)(
|
|
44
|
+
"coin-prices",
|
|
45
|
+
async () => (await client.api.getCoinPrices()).data,
|
|
46
|
+
{ revalidateOnFocus: false, refreshInterval: REFRESH_MS, shouldRetryOnError: false }
|
|
47
|
+
);
|
|
48
|
+
return { prices: data ?? null, isLoading };
|
|
49
|
+
}
|
|
50
|
+
function usePriceMap(getClient) {
|
|
51
|
+
const { prices, isLoading } = useAllCoinPrices(getClient);
|
|
52
|
+
const map = {};
|
|
53
|
+
if (prices) {
|
|
54
|
+
for (const [address, entry] of Object.entries(prices)) {
|
|
55
|
+
map[address] = entry?.usdc ?? null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { prices: map, isLoading };
|
|
59
|
+
}
|
|
60
|
+
function useCoinPrice(getClient, coin) {
|
|
61
|
+
const { prices, isLoading } = useAllCoinPrices(getClient);
|
|
62
|
+
if (isLoading || !prices) return { price: null, status: "unavailable", isLoading };
|
|
63
|
+
const usdc = prices[(0, import_sdk2.normalizeAddress)("STARKNET", coin.contractAddress)]?.usdc ?? null;
|
|
64
|
+
if (usdc == null) {
|
|
65
|
+
return {
|
|
66
|
+
price: null,
|
|
67
|
+
status: coin.isLaunched === false ? "pre-launch" : "unavailable",
|
|
68
|
+
isLoading: false
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const strk = (0, import_sdk.getTokenBySymbol)("STRK");
|
|
72
|
+
const strkUsdc = strk ? prices[(0, import_sdk2.normalizeAddress)("STARKNET", strk.address)]?.usdc ?? null : null;
|
|
73
|
+
return {
|
|
74
|
+
price: {
|
|
75
|
+
quotePerCoin: strkUsdc ? usdc / strkUsdc : usdc,
|
|
76
|
+
quoteSymbol: strkUsdc ? "STRK" : "USDC",
|
|
77
|
+
quoteUsdRate: strkUsdc ?? 1
|
|
78
|
+
},
|
|
79
|
+
status: "live",
|
|
80
|
+
isLoading: false
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
useCoinPrice,
|
|
86
|
+
usePriceMap
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=use-coin-price.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-coin-price.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { getTokenBySymbol, type ApiCoinPrices } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { CoinMarketStatus } from \"../components/coin-row.js\";\nimport type { CoinCollectionLike, CoinPriceLike } from \"../data/coins.js\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport { normalizeAddress } from \"@medialane/sdk\";\n\nconst REFRESH_MS = 60_000;\n\nfunction useAllCoinPrices(getClient: () => MedialaneClient) {\n const client = useMedialaneClient(getClient);\n const { data, isLoading } = useSWR<ApiCoinPrices>(\n \"coin-prices\",\n async () => (await client.api.getCoinPrices()).data,\n { revalidateOnFocus: false, refreshInterval: REFRESH_MS, shouldRetryOnError: false }\n );\n return { prices: data ?? null, isLoading };\n}\n\nexport function usePriceMap(getClient: () => MedialaneClient) {\n const { prices, isLoading } = useAllCoinPrices(getClient);\n const map: Record<string, number | null> = {};\n if (prices) {\n for (const [address, entry] of Object.entries(prices)) {\n map[address] = entry?.usdc ?? null;\n }\n }\n return { prices: map, isLoading };\n}\n\nexport function useCoinPrice(getClient: () => MedialaneClient, coin: CoinCollectionLike): {\n price: CoinPriceLike | null;\n status: CoinMarketStatus;\n isLoading: boolean;\n} {\n const { prices, isLoading } = useAllCoinPrices(getClient);\n\n if (isLoading || !prices) return { price: null, status: \"unavailable\", isLoading };\n\n const usdc = prices[normalizeAddress(\"STARKNET\", coin.contractAddress)]?.usdc ?? null;\n\n if (usdc == null) {\n return {\n price: null,\n status: coin.isLaunched === false ? \"pre-launch\" : \"unavailable\",\n isLoading: false,\n };\n }\n\n const strk = getTokenBySymbol(\"STRK\");\n const strkUsdc = strk ? (prices[normalizeAddress(\"STARKNET\", strk.address)]?.usdc ?? null) : null;\n\n return {\n price: {\n quotePerCoin: strkUsdc ? usdc / strkUsdc : usdc,\n quoteSymbol: strkUsdc ? \"STRK\" : \"USDC\",\n quoteUsdRate: strkUsdc ?? 1,\n },\n status: \"live\",\n isLoading: false,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAmB;AACnB,iBAAq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c,YAAY;AAAA,IAC5B;AAAA,IACA,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AACF;","names":["import_sdk","useSWR"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
2
|
+
import { CoinMarketStatus } from '../components/coin-row.cjs';
|
|
3
|
+
import { CoinCollectionLike, CoinPriceLike } from '../data/coins.cjs';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@medialane/sdk';
|
|
6
|
+
|
|
7
|
+
declare function usePriceMap(getClient: () => MedialaneClient): {
|
|
8
|
+
prices: Record<string, number | null>;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare function useCoinPrice(getClient: () => MedialaneClient, coin: CoinCollectionLike): {
|
|
12
|
+
price: CoinPriceLike | null;
|
|
13
|
+
status: CoinMarketStatus;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { useCoinPrice, usePriceMap };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
2
|
+
import { CoinMarketStatus } from '../components/coin-row.js';
|
|
3
|
+
import { CoinCollectionLike, CoinPriceLike } from '../data/coins.js';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@medialane/sdk';
|
|
6
|
+
|
|
7
|
+
declare function usePriceMap(getClient: () => MedialaneClient): {
|
|
8
|
+
prices: Record<string, number | null>;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare function useCoinPrice(getClient: () => MedialaneClient, coin: CoinCollectionLike): {
|
|
12
|
+
price: CoinPriceLike | null;
|
|
13
|
+
status: CoinMarketStatus;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { useCoinPrice, usePriceMap };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import { getTokenBySymbol } from "@medialane/sdk";
|
|
4
|
+
import { useMedialaneClient } from "./use-medialane-client.js";
|
|
5
|
+
import { normalizeAddress } from "@medialane/sdk";
|
|
6
|
+
const REFRESH_MS = 6e4;
|
|
7
|
+
function useAllCoinPrices(getClient) {
|
|
8
|
+
const client = useMedialaneClient(getClient);
|
|
9
|
+
const { data, isLoading } = useSWR(
|
|
10
|
+
"coin-prices",
|
|
11
|
+
async () => (await client.api.getCoinPrices()).data,
|
|
12
|
+
{ revalidateOnFocus: false, refreshInterval: REFRESH_MS, shouldRetryOnError: false }
|
|
13
|
+
);
|
|
14
|
+
return { prices: data ?? null, isLoading };
|
|
15
|
+
}
|
|
16
|
+
function usePriceMap(getClient) {
|
|
17
|
+
const { prices, isLoading } = useAllCoinPrices(getClient);
|
|
18
|
+
const map = {};
|
|
19
|
+
if (prices) {
|
|
20
|
+
for (const [address, entry] of Object.entries(prices)) {
|
|
21
|
+
map[address] = entry?.usdc ?? null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { prices: map, isLoading };
|
|
25
|
+
}
|
|
26
|
+
function useCoinPrice(getClient, coin) {
|
|
27
|
+
const { prices, isLoading } = useAllCoinPrices(getClient);
|
|
28
|
+
if (isLoading || !prices) return { price: null, status: "unavailable", isLoading };
|
|
29
|
+
const usdc = prices[normalizeAddress("STARKNET", coin.contractAddress)]?.usdc ?? null;
|
|
30
|
+
if (usdc == null) {
|
|
31
|
+
return {
|
|
32
|
+
price: null,
|
|
33
|
+
status: coin.isLaunched === false ? "pre-launch" : "unavailable",
|
|
34
|
+
isLoading: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const strk = getTokenBySymbol("STRK");
|
|
38
|
+
const strkUsdc = strk ? prices[normalizeAddress("STARKNET", strk.address)]?.usdc ?? null : null;
|
|
39
|
+
return {
|
|
40
|
+
price: {
|
|
41
|
+
quotePerCoin: strkUsdc ? usdc / strkUsdc : usdc,
|
|
42
|
+
quoteSymbol: strkUsdc ? "STRK" : "USDC",
|
|
43
|
+
quoteUsdRate: strkUsdc ?? 1
|
|
44
|
+
},
|
|
45
|
+
status: "live",
|
|
46
|
+
isLoading: false
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
useCoinPrice,
|
|
51
|
+
usePriceMap
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=use-coin-price.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-coin-price.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { getTokenBySymbol, type ApiCoinPrices } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { CoinMarketStatus } from \"../components/coin-row.js\";\nimport type { CoinCollectionLike, CoinPriceLike } from \"../data/coins.js\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport { normalizeAddress } from \"@medialane/sdk\";\n\nconst REFRESH_MS = 60_000;\n\nfunction useAllCoinPrices(getClient: () => MedialaneClient) {\n const client = useMedialaneClient(getClient);\n const { data, isLoading } = useSWR<ApiCoinPrices>(\n \"coin-prices\",\n async () => (await client.api.getCoinPrices()).data,\n { revalidateOnFocus: false, refreshInterval: REFRESH_MS, shouldRetryOnError: false }\n );\n return { prices: data ?? null, isLoading };\n}\n\nexport function usePriceMap(getClient: () => MedialaneClient) {\n const { prices, isLoading } = useAllCoinPrices(getClient);\n const map: Record<string, number | null> = {};\n if (prices) {\n for (const [address, entry] of Object.entries(prices)) {\n map[address] = entry?.usdc ?? null;\n }\n }\n return { prices: map, isLoading };\n}\n\nexport function useCoinPrice(getClient: () => MedialaneClient, coin: CoinCollectionLike): {\n price: CoinPriceLike | null;\n status: CoinMarketStatus;\n isLoading: boolean;\n} {\n const { prices, isLoading } = useAllCoinPrices(getClient);\n\n if (isLoading || !prices) return { price: null, status: \"unavailable\", isLoading };\n\n const usdc = prices[normalizeAddress(\"STARKNET\", coin.contractAddress)]?.usdc ?? null;\n\n if (usdc == null) {\n return {\n price: null,\n status: coin.isLaunched === false ? \"pre-launch\" : \"unavailable\",\n isLoading: false,\n };\n }\n\n const strk = getTokenBySymbol(\"STRK\");\n const strkUsdc = strk ? (prices[normalizeAddress(\"STARKNET\", strk.address)]?.usdc ?? null) : null;\n\n return {\n price: {\n quotePerCoin: strkUsdc ? usdc / strkUsdc : usdc,\n quoteSymbol: strkUsdc ? \"STRK\" : \"USDC\",\n quoteUsdRate: strkUsdc ?? 1,\n },\n status: \"live\",\n isLoading: false,\n };\n}\n"],"mappings":";AAEA,OAAO,YAAY;AACnB,SAAS,wBAA4C;AAIrD,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AAEjC,MAAM,aAAa;AAEnB,SAAS,iBAAiB,WAAkC;AAC1D,QAAM,SAAS,mBAAmB,SAAS;AAC3C,QAAM,EAAE,MAAM,UAAU,IAAI;AAAA,IAC1B;AAAA,IACA,aAAa,MAAM,OAAO,IAAI,cAAc,GAAG;AAAA,IAC/C,EAAE,mBAAmB,OAAO,iBAAiB,YAAY,oBAAoB,MAAM;AAAA,EACrF;AACA,SAAO,EAAE,QAAQ,QAAQ,MAAM,UAAU;AAC3C;AAEO,SAAS,YAAY,WAAkC;AAC5D,QAAM,EAAE,QAAQ,UAAU,IAAI,iBAAiB,SAAS;AACxD,QAAM,MAAqC,CAAC;AAC5C,MAAI,QAAQ;AACV,eAAW,CAAC,SAAS,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACrD,UAAI,OAAO,IAAI,OAAO,QAAQ;AAAA,IAChC;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,KAAK,UAAU;AAClC;AAEO,SAAS,aAAa,WAAkC,MAI7D;AACA,QAAM,EAAE,QAAQ,UAAU,IAAI,iBAAiB,SAAS;AAExD,MAAI,aAAa,CAAC,OAAQ,QAAO,EAAE,OAAO,MAAM,QAAQ,eAAe,UAAU;AAEjF,QAAM,OAAO,OAAO,iBAAiB,YAAY,KAAK,eAAe,CAAC,GAAG,QAAQ;AAEjF,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,MACL,OAAO;AAAA,MACP,QAAQ,KAAK,eAAe,QAAQ,eAAe;AAAA,MACnD,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,OAAO,iBAAiB,MAAM;AACpC,QAAM,WAAW,OAAQ,OAAO,iBAAiB,YAAY,KAAK,OAAO,CAAC,GAAG,QAAQ,OAAQ;AAE7F,SAAO;AAAA,IACL,OAAO;AAAA,MACL,cAAc,WAAW,OAAO,WAAW;AAAA,MAC3C,aAAa,WAAW,SAAS;AAAA,MACjC,cAAc,YAAY;AAAA,IAC5B;AAAA,IACA,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AACF;","names":[]}
|
|
@@ -45,7 +45,7 @@ function useCollections(getClient, page = 1, limit = 20, isFeatured, sort = "rec
|
|
|
45
45
|
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
46
46
|
key,
|
|
47
47
|
async () => {
|
|
48
|
-
const res = await client.api.
|
|
48
|
+
const res = await client.api.listCollections({ page, limit, isFeatured, sort, service, standard });
|
|
49
49
|
return hideEmpty ? { ...res, data: res.data.filter((collection) => (collection.totalSupply ?? 0) > 0) } : res;
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -74,7 +74,7 @@ function useCollectionsByOwner(getClient, owner) {
|
|
|
74
74
|
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
75
75
|
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
76
76
|
owner ? import_query_keys.queryKeys.collectionsOwner(owner) : null,
|
|
77
|
-
() => client.api.
|
|
77
|
+
() => client.api.listCollections({ owner, limit: 50 }),
|
|
78
78
|
{ revalidateOnFocus: false, refreshInterval: 6e4 }
|
|
79
79
|
);
|
|
80
80
|
return { collections: data?.data ?? [], isLoading, error, mutate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/use-collections.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { ApiCollection, ApiResponse, CollectionTokensSort } from \"@medialane/sdk\";\nimport { queryKeys } from \"./query-keys.js\";\n\nexport type CollectionSort = \"recent\" | \"supply\" | \"floor\" | \"volume\" | \"name\";\n\nexport function useCollections(\n getClient: () => MedialaneClient,\n page = 1,\n limit = 20,\n isFeatured?: boolean,\n sort: CollectionSort = \"recent\",\n hideEmpty = true,\n service?: string,\n\n standard?: string,\n\n fallback?: ApiCollection[]\n) {\n const client = useMedialaneClient(getClient);\n const key = `${queryKeys.collections(page, limit, isFeatured, sort, hideEmpty, service)}-${standard ?? \"\"}`;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiCollection[]>>(\n key,\n async () => {\n const res = await client.api.
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-collections.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { ApiCollection, ApiResponse, CollectionTokensSort } from \"@medialane/sdk\";\nimport { queryKeys } from \"./query-keys.js\";\n\nexport type CollectionSort = \"recent\" | \"supply\" | \"floor\" | \"volume\" | \"name\";\n\nexport function useCollections(\n getClient: () => MedialaneClient,\n page = 1,\n limit = 20,\n isFeatured?: boolean,\n sort: CollectionSort = \"recent\",\n hideEmpty = true,\n service?: string,\n\n standard?: string,\n\n fallback?: ApiCollection[]\n) {\n const client = useMedialaneClient(getClient);\n const key = `${queryKeys.collections(page, limit, isFeatured, sort, hideEmpty, service)}-${standard ?? \"\"}`;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiCollection[]>>(\n key,\n async () => {\n const res = await client.api.listCollections({ page, limit, isFeatured, sort, service, standard });\n return hideEmpty\n ? { ...res, data: res.data.filter((collection) => (collection.totalSupply ?? 0) > 0) }\n : res;\n },\n {\n revalidateOnFocus: false,\n ...(fallback ? { fallbackData: { data: fallback } as ApiResponse<ApiCollection[]> } : {}),\n }\n );\n\n return {\n collections: data?.data ?? [],\n meta: data?.meta,\n isLoading,\n error,\n mutate,\n };\n}\n\nexport function useCollection(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading } = useSWR(\n contract ? queryKeys.collection(contract) : null,\n () => client.api.getCollection(contract!),\n { revalidateOnFocus: false }\n );\n\n return { collection: data?.data ?? null, isLoading, error };\n}\n\nexport function useCollectionsByOwner(getClient: () => MedialaneClient, owner: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading, mutate } = useSWR(\n owner ? queryKeys.collectionsOwner(owner) : null,\n () => client.api.listCollections({ owner: owner!, limit: 50 }),\n { revalidateOnFocus: false, refreshInterval: 60_000 }\n );\n\n return { collections: data?.data ?? [], isLoading, error, mutate };\n}\n\nexport function useCollectionTokens(\n getClient: () => MedialaneClient,\n contract: string | null,\n page = 1,\n limit = 24,\n sort: CollectionTokensSort = \"recent\"\n) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading, mutate } = useSWR(\n contract ? queryKeys.collectionTokens(contract, page, limit, sort) : null,\n () => client.api.getCollectionTokens(contract!, page, limit, sort),\n { revalidateOnFocus: false }\n );\n\n return { tokens: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };\n}\n\nfunction pickNearbyTokens<T extends { tokenId: string }>(\n tokens: T[],\n currentTokenId: string | null,\n count: number\n): T[] {\n if (!currentTokenId) return tokens.slice(0, count);\n const idx = tokens.findIndex((t) => String(t.tokenId) === String(currentTokenId));\n if (idx === -1) return tokens.slice(0, count);\n\n const picked: T[] = [];\n let after = idx + 1;\n let before = idx - 1;\n while (picked.length < count && (after < tokens.length || before >= 0)) {\n if (after < tokens.length) picked.push(tokens[after++]);\n if (picked.length < count && before >= 0) picked.push(tokens[before--]);\n }\n return picked.sort((a, b) => Number(a.tokenId) - Number(b.tokenId));\n}\n\nexport function useNearbyCollectionTokens(\n getClient: () => MedialaneClient,\n contract: string | null,\n currentTokenId: string | null,\n count = 4,\n poolSize = 60\n) {\n const { tokens, isLoading, error } = useCollectionTokens(getClient, contract, 1, poolSize, \"oldest\");\n return { tokens: pickNearbyTokens(tokens, currentTokenId, count), isLoading, error };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAmB;AACnB,kCAAmC;AAGnC,wBAA0B;AAInB,SAAS,eACd,WACA,OAAO,GACP,QAAQ,IACR,YACA,OAAuB,UACvB,YAAY,MACZ,SAEA,UAEA,UACA;AACA,QAAM,aAAS,gDAAmB,SAAS;AAC3C,QAAM,MAAM,GAAG,4BAAU,YAAY,MAAM,OAAO,YAAY,MAAM,WAAW,OAAO,CAAC,IAAI,YAAY,EAAE;AAEzG,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC;AAAA,IACA,YAAY;AACV,YAAM,MAAM,MAAM,OAAO,IAAI,gBAAgB,EAAE,MAAM,OAAO,YAAY,MAAM,SAAS,SAAS,CAAC;AACjG,aAAO,YACH,EAAE,GAAG,KAAK,MAAM,IAAI,KAAK,OAAO,CAAC,gBAAgB,WAAW,eAAe,KAAK,CAAC,EAAE,IACnF;AAAA,IACN;AAAA,IACA;AAAA,MACE,mBAAmB;AAAA,MACnB,GAAI,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,EAAkC,IAAI,CAAC;AAAA,IACzF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,aAAa,MAAM,QAAQ,CAAC;AAAA,IAC5B,MAAM,MAAM;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,cAAc,WAAkC,UAAyB;AACvF,QAAM,aAAS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,MAAI,QAAQ,GAAI,QAAO,OAAO,MAAM,GAAG,KAAK;AAE5C,QAAM,SAAc,CAAC;AACrB,MAAI,QAAQ,MAAM;AAClB,MAAI,SAAS,MAAM;AACnB,SAAO,OAAO,SAAS,UAAU,QAAQ,OAAO,UAAU,UAAU,IAAI;AACtE,QAAI,QAAQ,OAAO,OAAQ,QAAO,KAAK,OAAO,OAAO,CAAC;AACtD,QAAI,OAAO,SAAS,SAAS,UAAU,EAAG,QAAO,KAAK,OAAO,QAAQ,CAAC;AAAA,EACxE;AACA,SAAO,OAAO,KAAK,CAAC,GAAG,MAAM,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,CAAC;AACpE;AAEO,SAAS,0BACd,WACA,UACA,gBACA,QAAQ,GACR,WAAW,IACX;AACA,QAAM,EAAE,QAAQ,WAAW,MAAM,IAAI,oBAAoB,WAAW,UAAU,GAAG,UAAU,QAAQ;AACnG,SAAO,EAAE,QAAQ,iBAAiB,QAAQ,gBAAgB,KAAK,GAAG,WAAW,MAAM;AACrF;","names":["useSWR"]}
|
|
@@ -8,7 +8,7 @@ function useCollections(getClient, page = 1, limit = 20, isFeatured, sort = "rec
|
|
|
8
8
|
const { data, error, isLoading, mutate } = useSWR(
|
|
9
9
|
key,
|
|
10
10
|
async () => {
|
|
11
|
-
const res = await client.api.
|
|
11
|
+
const res = await client.api.listCollections({ page, limit, isFeatured, sort, service, standard });
|
|
12
12
|
return hideEmpty ? { ...res, data: res.data.filter((collection) => (collection.totalSupply ?? 0) > 0) } : res;
|
|
13
13
|
},
|
|
14
14
|
{
|
|
@@ -37,7 +37,7 @@ function useCollectionsByOwner(getClient, owner) {
|
|
|
37
37
|
const client = useMedialaneClient(getClient);
|
|
38
38
|
const { data, error, isLoading, mutate } = useSWR(
|
|
39
39
|
owner ? queryKeys.collectionsOwner(owner) : null,
|
|
40
|
-
() => client.api.
|
|
40
|
+
() => client.api.listCollections({ owner, limit: 50 }),
|
|
41
41
|
{ revalidateOnFocus: false, refreshInterval: 6e4 }
|
|
42
42
|
);
|
|
43
43
|
return { collections: data?.data ?? [], isLoading, error, mutate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/use-collections.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { ApiCollection, ApiResponse, CollectionTokensSort } from \"@medialane/sdk\";\nimport { queryKeys } from \"./query-keys.js\";\n\nexport type CollectionSort = \"recent\" | \"supply\" | \"floor\" | \"volume\" | \"name\";\n\nexport function useCollections(\n getClient: () => MedialaneClient,\n page = 1,\n limit = 20,\n isFeatured?: boolean,\n sort: CollectionSort = \"recent\",\n hideEmpty = true,\n service?: string,\n\n standard?: string,\n\n fallback?: ApiCollection[]\n) {\n const client = useMedialaneClient(getClient);\n const key = `${queryKeys.collections(page, limit, isFeatured, sort, hideEmpty, service)}-${standard ?? \"\"}`;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiCollection[]>>(\n key,\n async () => {\n const res = await client.api.
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-collections.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport type { ApiCollection, ApiResponse, CollectionTokensSort } from \"@medialane/sdk\";\nimport { queryKeys } from \"./query-keys.js\";\n\nexport type CollectionSort = \"recent\" | \"supply\" | \"floor\" | \"volume\" | \"name\";\n\nexport function useCollections(\n getClient: () => MedialaneClient,\n page = 1,\n limit = 20,\n isFeatured?: boolean,\n sort: CollectionSort = \"recent\",\n hideEmpty = true,\n service?: string,\n\n standard?: string,\n\n fallback?: ApiCollection[]\n) {\n const client = useMedialaneClient(getClient);\n const key = `${queryKeys.collections(page, limit, isFeatured, sort, hideEmpty, service)}-${standard ?? \"\"}`;\n\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiCollection[]>>(\n key,\n async () => {\n const res = await client.api.listCollections({ page, limit, isFeatured, sort, service, standard });\n return hideEmpty\n ? { ...res, data: res.data.filter((collection) => (collection.totalSupply ?? 0) > 0) }\n : res;\n },\n {\n revalidateOnFocus: false,\n ...(fallback ? { fallbackData: { data: fallback } as ApiResponse<ApiCollection[]> } : {}),\n }\n );\n\n return {\n collections: data?.data ?? [],\n meta: data?.meta,\n isLoading,\n error,\n mutate,\n };\n}\n\nexport function useCollection(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading } = useSWR(\n contract ? queryKeys.collection(contract) : null,\n () => client.api.getCollection(contract!),\n { revalidateOnFocus: false }\n );\n\n return { collection: data?.data ?? null, isLoading, error };\n}\n\nexport function useCollectionsByOwner(getClient: () => MedialaneClient, owner: string | null) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading, mutate } = useSWR(\n owner ? queryKeys.collectionsOwner(owner) : null,\n () => client.api.listCollections({ owner: owner!, limit: 50 }),\n { revalidateOnFocus: false, refreshInterval: 60_000 }\n );\n\n return { collections: data?.data ?? [], isLoading, error, mutate };\n}\n\nexport function useCollectionTokens(\n getClient: () => MedialaneClient,\n contract: string | null,\n page = 1,\n limit = 24,\n sort: CollectionTokensSort = \"recent\"\n) {\n const client = useMedialaneClient(getClient);\n\n const { data, error, isLoading, mutate } = useSWR(\n contract ? queryKeys.collectionTokens(contract, page, limit, sort) : null,\n () => client.api.getCollectionTokens(contract!, page, limit, sort),\n { revalidateOnFocus: false }\n );\n\n return { tokens: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };\n}\n\nfunction pickNearbyTokens<T extends { tokenId: string }>(\n tokens: T[],\n currentTokenId: string | null,\n count: number\n): T[] {\n if (!currentTokenId) return tokens.slice(0, count);\n const idx = tokens.findIndex((t) => String(t.tokenId) === String(currentTokenId));\n if (idx === -1) return tokens.slice(0, count);\n\n const picked: T[] = [];\n let after = idx + 1;\n let before = idx - 1;\n while (picked.length < count && (after < tokens.length || before >= 0)) {\n if (after < tokens.length) picked.push(tokens[after++]);\n if (picked.length < count && before >= 0) picked.push(tokens[before--]);\n }\n return picked.sort((a, b) => Number(a.tokenId) - Number(b.tokenId));\n}\n\nexport function useNearbyCollectionTokens(\n getClient: () => MedialaneClient,\n contract: string | null,\n currentTokenId: string | null,\n count = 4,\n poolSize = 60\n) {\n const { tokens, isLoading, error } = useCollectionTokens(getClient, contract, 1, poolSize, \"oldest\");\n return { tokens: pickNearbyTokens(tokens, currentTokenId, count), isLoading, error };\n}\n"],"mappings":";AAEA,OAAO,YAAY;AACnB,SAAS,0BAA0B;AAGnC,SAAS,iBAAiB;AAInB,SAAS,eACd,WACA,OAAO,GACP,QAAQ,IACR,YACA,OAAuB,UACvB,YAAY,MACZ,SAEA,UAEA,UACA;AACA,QAAM,SAAS,mBAAmB,SAAS;AAC3C,QAAM,MAAM,GAAG,UAAU,YAAY,MAAM,OAAO,YAAY,MAAM,WAAW,OAAO,CAAC,IAAI,YAAY,EAAE;AAEzG,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI;AAAA,IACzC;AAAA,IACA,YAAY;AACV,YAAM,MAAM,MAAM,OAAO,IAAI,gBAAgB,EAAE,MAAM,OAAO,YAAY,MAAM,SAAS,SAAS,CAAC;AACjG,aAAO,YACH,EAAE,GAAG,KAAK,MAAM,IAAI,KAAK,OAAO,CAAC,gBAAgB,WAAW,eAAe,KAAK,CAAC,EAAE,IACnF;AAAA,IACN;AAAA,IACA;AAAA,MACE,mBAAmB;AAAA,MACnB,GAAI,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,EAAkC,IAAI,CAAC;AAAA,IACzF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,aAAa,MAAM,QAAQ,CAAC;AAAA,IAC5B,MAAM,MAAM;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,cAAc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C;AAChF,MAAI,QAAQ,GAAI,QAAO,OAAO,MAAM,GAAG,KAAK;AAE5C,QAAM,SAAc,CAAC;AACrB,MAAI,QAAQ,MAAM;AAClB,MAAI,SAAS,MAAM;AACnB,SAAO,OAAO,SAAS,UAAU,QAAQ,OAAO,UAAU,UAAU,IAAI;AACtE,QAAI,QAAQ,OAAO,OAAQ,QAAO,KAAK,OAAO,OAAO,CAAC;AACtD,QAAI,OAAO,SAAS,SAAS,UAAU,EAAG,QAAO,KAAK,OAAO,QAAQ,CAAC;AAAA,EACxE;AACA,SAAO,OAAO,KAAK,CAAC,GAAG,MAAM,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,CAAC;AACpE;AAEO,SAAS,0BACd,WACA,UACA,gBACA,QAAQ,GACR,WAAW,IACX;AACA,QAAM,EAAE,QAAQ,WAAW,MAAM,IAAI,oBAAoB,WAAW,UAAU,GAAG,UAAU,QAAQ;AACnG,SAAO,EAAE,QAAQ,iBAAiB,QAAQ,gBAAgB,KAAK,GAAG,WAAW,MAAM;AACrF;","names":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
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_drops_exports = {};
|
|
31
|
+
__export(use_drops_exports, {
|
|
32
|
+
useDropCollections: () => useDropCollections,
|
|
33
|
+
useDropInfo: () => useDropInfo,
|
|
34
|
+
useDropMintStatus: () => useDropMintStatus,
|
|
35
|
+
useMyDrops: () => useMyDrops,
|
|
36
|
+
useOnChainDropState: () => useOnChainDropState
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(use_drops_exports);
|
|
39
|
+
var import_swr = __toESM(require("swr"), 1);
|
|
40
|
+
var import_use_medialane_client = require("./use-medialane-client.js");
|
|
41
|
+
function useDropCollections(getClient) {
|
|
42
|
+
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
43
|
+
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
44
|
+
"drop-collections",
|
|
45
|
+
() => client.api.listCollections({ service: "drop-collection", hideEmpty: false, limit: 50 }),
|
|
46
|
+
{ revalidateOnFocus: false }
|
|
47
|
+
);
|
|
48
|
+
return { collections: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };
|
|
49
|
+
}
|
|
50
|
+
function useMyDrops(getClient, owner) {
|
|
51
|
+
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
52
|
+
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
53
|
+
owner ? `my-drops-${owner}` : null,
|
|
54
|
+
async () => (await client.api.listCollections({ service: "drop-collection", owner, limit: 50 })).data ?? [],
|
|
55
|
+
{ revalidateOnFocus: false }
|
|
56
|
+
);
|
|
57
|
+
return { drops: data ?? [], isLoading, error, mutate };
|
|
58
|
+
}
|
|
59
|
+
function useDropMintStatus(getClient, collection, wallet) {
|
|
60
|
+
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
61
|
+
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
62
|
+
collection && wallet ? `drop-mint-status-${collection}-${wallet}` : null,
|
|
63
|
+
() => client.api.getDropMintStatus(collection, wallet),
|
|
64
|
+
{ revalidateOnFocus: false, shouldRetryOnError: false }
|
|
65
|
+
);
|
|
66
|
+
return { mintStatus: data ?? null, isLoading, error, mutate };
|
|
67
|
+
}
|
|
68
|
+
function useDropInfo(getClient, contract) {
|
|
69
|
+
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
70
|
+
const { data, error, isLoading } = (0, import_swr.default)(
|
|
71
|
+
contract ? `drop-info-${contract}` : null,
|
|
72
|
+
() => client.api.getDropInfo(contract),
|
|
73
|
+
{ revalidateOnFocus: false, shouldRetryOnError: false }
|
|
74
|
+
);
|
|
75
|
+
return { dropInfo: data ?? null, isLoading, error };
|
|
76
|
+
}
|
|
77
|
+
function useOnChainDropState(getClient, contract) {
|
|
78
|
+
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
79
|
+
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
80
|
+
contract ? `drop-onchain-${contract}` : null,
|
|
81
|
+
() => client.api.getDropState(contract),
|
|
82
|
+
{ revalidateOnFocus: false, refreshInterval: 3e4, shouldRetryOnError: false }
|
|
83
|
+
);
|
|
84
|
+
return { state: data ?? null, isLoading, error, mutate };
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
useDropCollections,
|
|
89
|
+
useDropInfo,
|
|
90
|
+
useDropMintStatus,
|
|
91
|
+
useMyDrops,
|
|
92
|
+
useOnChainDropState
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=use-drops.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-drops.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport type { ApiCollection, ApiDropInfo, ApiDropState, ApiMeta, DropMintStatus } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\n\nexport function useDropCollections(getClient: () => MedialaneClient) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<{ data: ApiCollection[]; meta?: ApiMeta }>(\n \"drop-collections\",\n () => client.api.listCollections({ service: \"drop-collection\", hideEmpty: false, limit: 50 }),\n { revalidateOnFocus: false }\n );\n return { collections: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };\n}\n\nexport function useMyDrops(getClient: () => MedialaneClient, owner: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<ApiCollection[]>(\n owner ? `my-drops-${owner}` : null,\n async () => (await client.api.listCollections({ service: \"drop-collection\", owner: owner!, limit: 50 })).data ?? [],\n { revalidateOnFocus: false }\n );\n return { drops: data ?? [], isLoading, error, mutate };\n}\n\nexport function useDropMintStatus(getClient: () => MedialaneClient, collection: string | null, wallet: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<DropMintStatus>(\n collection && wallet ? `drop-mint-status-${collection}-${wallet}` : null,\n () => client.api.getDropMintStatus(collection!, wallet!),\n { revalidateOnFocus: false, shouldRetryOnError: false }\n );\n return { mintStatus: data ?? null, isLoading, error, mutate };\n}\n\nexport function useDropInfo(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading } = useSWR<ApiDropInfo | null>(\n contract ? `drop-info-${contract}` : null,\n () => client.api.getDropInfo(contract!),\n { revalidateOnFocus: false, shouldRetryOnError: false }\n );\n return { dropInfo: data ?? null, isLoading, error };\n}\n\nexport function useOnChainDropState(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<ApiDropState>(\n contract ? `drop-onchain-${contract}` : null,\n () => client.api.getDropState(contract!),\n { revalidateOnFocus: false, refreshInterval: 30_000, shouldRetryOnError: false }\n );\n return { state: data ?? null, isLoading, error, mutate };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAmB;AAGnB,kCAAmC;AAE5B,SAAS,mBAAmB,WAAkC;AACnE,QAAM,aAAS,gDAAmB,SAAS;AAC3C,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC;AAAA,IACA,MAAM,OAAO,IAAI,gBAAgB,EAAE,SAAS,mBAAmB,WAAW,OAAO,OAAO,GAAG,CAAC;AAAA,IAC5F,EAAE,mBAAmB,MAAM;AAAA,EAC7B;AACA,SAAO,EAAE,aAAa,MAAM,QAAQ,CAAC,GAAG,MAAM,MAAM,MAAM,WAAW,OAAO,OAAO;AACrF;AAEO,SAAS,WAAW,WAAkC,OAAsB;AACjF,QAAM,aAAS,gDAAmB,SAAS;AAC3C,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC,QAAQ,YAAY,KAAK,KAAK;AAAA,IAC9B,aAAa,MAAM,OAAO,IAAI,gBAAgB,EAAE,SAAS,mBAAmB,OAAe,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC;AAAA,IAClH,EAAE,mBAAmB,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k';
|
|
3
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
4
|
+
|
|
5
|
+
declare function useDropCollections(getClient: () => MedialaneClient): {
|
|
6
|
+
collections: ApiCollection[];
|
|
7
|
+
meta: ApiMeta | undefined;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
error: any;
|
|
10
|
+
mutate: swr.KeyedMutator<{
|
|
11
|
+
data: ApiCollection[];
|
|
12
|
+
meta?: ApiMeta;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
declare function useMyDrops(getClient: () => MedialaneClient, owner: string | null): {
|
|
16
|
+
drops: ApiCollection[];
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
error: any;
|
|
19
|
+
mutate: swr.KeyedMutator<ApiCollection[]>;
|
|
20
|
+
};
|
|
21
|
+
declare function useDropMintStatus(getClient: () => MedialaneClient, collection: string | null, wallet: string | null): {
|
|
22
|
+
mintStatus: DropMintStatus | null;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
error: any;
|
|
25
|
+
mutate: swr.KeyedMutator<DropMintStatus>;
|
|
26
|
+
};
|
|
27
|
+
declare function useDropInfo(getClient: () => MedialaneClient, contract: string | null): {
|
|
28
|
+
dropInfo: ApiDropInfo | null;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
error: any;
|
|
31
|
+
};
|
|
32
|
+
declare function useOnChainDropState(getClient: () => MedialaneClient, contract: string | null): {
|
|
33
|
+
state: ApiDropState | null;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
error: any;
|
|
36
|
+
mutate: swr.KeyedMutator<ApiDropState>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { useDropCollections, useDropInfo, useDropMintStatus, useMyDrops, useOnChainDropState };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as swr from 'swr';
|
|
2
|
+
import { ApiCollection, ApiMeta, ApiDropInfo, DropMintStatus, ApiDropState } from '@medialane/sdk';
|
|
3
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
4
|
+
|
|
5
|
+
declare function useDropCollections(getClient: () => MedialaneClient): {
|
|
6
|
+
collections: ApiCollection[];
|
|
7
|
+
meta: ApiMeta | undefined;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
error: any;
|
|
10
|
+
mutate: swr.KeyedMutator<{
|
|
11
|
+
data: ApiCollection[];
|
|
12
|
+
meta?: ApiMeta;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
declare function useMyDrops(getClient: () => MedialaneClient, owner: string | null): {
|
|
16
|
+
drops: ApiCollection[];
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
error: any;
|
|
19
|
+
mutate: swr.KeyedMutator<ApiCollection[]>;
|
|
20
|
+
};
|
|
21
|
+
declare function useDropMintStatus(getClient: () => MedialaneClient, collection: string | null, wallet: string | null): {
|
|
22
|
+
mintStatus: DropMintStatus | null;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
error: any;
|
|
25
|
+
mutate: swr.KeyedMutator<DropMintStatus>;
|
|
26
|
+
};
|
|
27
|
+
declare function useDropInfo(getClient: () => MedialaneClient, contract: string | null): {
|
|
28
|
+
dropInfo: ApiDropInfo | null;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
error: any;
|
|
31
|
+
};
|
|
32
|
+
declare function useOnChainDropState(getClient: () => MedialaneClient, contract: string | null): {
|
|
33
|
+
state: ApiDropState | null;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
error: any;
|
|
36
|
+
mutate: swr.KeyedMutator<ApiDropState>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { useDropCollections, useDropInfo, useDropMintStatus, useMyDrops, useOnChainDropState };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import { useMedialaneClient } from "./use-medialane-client.js";
|
|
4
|
+
function useDropCollections(getClient) {
|
|
5
|
+
const client = useMedialaneClient(getClient);
|
|
6
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
7
|
+
"drop-collections",
|
|
8
|
+
() => client.api.listCollections({ service: "drop-collection", hideEmpty: false, limit: 50 }),
|
|
9
|
+
{ revalidateOnFocus: false }
|
|
10
|
+
);
|
|
11
|
+
return { collections: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };
|
|
12
|
+
}
|
|
13
|
+
function useMyDrops(getClient, owner) {
|
|
14
|
+
const client = useMedialaneClient(getClient);
|
|
15
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
16
|
+
owner ? `my-drops-${owner}` : null,
|
|
17
|
+
async () => (await client.api.listCollections({ service: "drop-collection", owner, limit: 50 })).data ?? [],
|
|
18
|
+
{ revalidateOnFocus: false }
|
|
19
|
+
);
|
|
20
|
+
return { drops: data ?? [], isLoading, error, mutate };
|
|
21
|
+
}
|
|
22
|
+
function useDropMintStatus(getClient, collection, wallet) {
|
|
23
|
+
const client = useMedialaneClient(getClient);
|
|
24
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
25
|
+
collection && wallet ? `drop-mint-status-${collection}-${wallet}` : null,
|
|
26
|
+
() => client.api.getDropMintStatus(collection, wallet),
|
|
27
|
+
{ revalidateOnFocus: false, shouldRetryOnError: false }
|
|
28
|
+
);
|
|
29
|
+
return { mintStatus: data ?? null, isLoading, error, mutate };
|
|
30
|
+
}
|
|
31
|
+
function useDropInfo(getClient, contract) {
|
|
32
|
+
const client = useMedialaneClient(getClient);
|
|
33
|
+
const { data, error, isLoading } = useSWR(
|
|
34
|
+
contract ? `drop-info-${contract}` : null,
|
|
35
|
+
() => client.api.getDropInfo(contract),
|
|
36
|
+
{ revalidateOnFocus: false, shouldRetryOnError: false }
|
|
37
|
+
);
|
|
38
|
+
return { dropInfo: data ?? null, isLoading, error };
|
|
39
|
+
}
|
|
40
|
+
function useOnChainDropState(getClient, contract) {
|
|
41
|
+
const client = useMedialaneClient(getClient);
|
|
42
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
43
|
+
contract ? `drop-onchain-${contract}` : null,
|
|
44
|
+
() => client.api.getDropState(contract),
|
|
45
|
+
{ revalidateOnFocus: false, refreshInterval: 3e4, shouldRetryOnError: false }
|
|
46
|
+
);
|
|
47
|
+
return { state: data ?? null, isLoading, error, mutate };
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
useDropCollections,
|
|
51
|
+
useDropInfo,
|
|
52
|
+
useDropMintStatus,
|
|
53
|
+
useMyDrops,
|
|
54
|
+
useOnChainDropState
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=use-drops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-drops.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport type { ApiCollection, ApiDropInfo, ApiDropState, ApiMeta, DropMintStatus } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\n\nexport function useDropCollections(getClient: () => MedialaneClient) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<{ data: ApiCollection[]; meta?: ApiMeta }>(\n \"drop-collections\",\n () => client.api.listCollections({ service: \"drop-collection\", hideEmpty: false, limit: 50 }),\n { revalidateOnFocus: false }\n );\n return { collections: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };\n}\n\nexport function useMyDrops(getClient: () => MedialaneClient, owner: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<ApiCollection[]>(\n owner ? `my-drops-${owner}` : null,\n async () => (await client.api.listCollections({ service: \"drop-collection\", owner: owner!, limit: 50 })).data ?? [],\n { revalidateOnFocus: false }\n );\n return { drops: data ?? [], isLoading, error, mutate };\n}\n\nexport function useDropMintStatus(getClient: () => MedialaneClient, collection: string | null, wallet: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<DropMintStatus>(\n collection && wallet ? `drop-mint-status-${collection}-${wallet}` : null,\n () => client.api.getDropMintStatus(collection!, wallet!),\n { revalidateOnFocus: false, shouldRetryOnError: false }\n );\n return { mintStatus: data ?? null, isLoading, error, mutate };\n}\n\nexport function useDropInfo(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading } = useSWR<ApiDropInfo | null>(\n contract ? `drop-info-${contract}` : null,\n () => client.api.getDropInfo(contract!),\n { revalidateOnFocus: false, shouldRetryOnError: false }\n );\n return { dropInfo: data ?? null, isLoading, error };\n}\n\nexport function useOnChainDropState(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<ApiDropState>(\n contract ? `drop-onchain-${contract}` : null,\n () => client.api.getDropState(contract!),\n { revalidateOnFocus: false, refreshInterval: 30_000, shouldRetryOnError: false }\n );\n return { state: data ?? null, isLoading, error, mutate };\n}\n"],"mappings":";AAEA,OAAO,YAAY;AAGnB,SAAS,0BAA0B;AAE5B,SAAS,mBAAmB,WAAkC;AACnE,QAAM,SAAS,mBAAmB,SAAS;AAC3C,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI;AAAA,IACzC;AAAA,IACA,MAAM,OAAO,IAAI,gBAAgB,EAAE,SAAS,mBAAmB,WAAW,OAAO,OAAO,GAAG,CAAC;AAAA,IAC5F,EAAE,mBAAmB,MAAM;AAAA,EAC7B;AACA,SAAO,EAAE,aAAa,MAAM,QAAQ,CAAC,GAAG,MAAM,MAAM,MAAM,WAAW,OAAO,OAAO;AACrF;AAEO,SAAS,WAAW,WAAkC,OAAsB;AACjF,QAAM,SAAS,mBAAmB,SAAS;AAC3C,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI;AAAA,IACzC,QAAQ,YAAY,KAAK,KAAK;AAAA,IAC9B,aAAa,MAAM,OAAO,IAAI,gBAAgB,EAAE,SAAS,mBAAmB,OAAe,OAAO,GAAG,CAAC,GA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48
|
-
function useNotifications(getClient,
|
|
48
|
+
function useNotifications(getClient, address) {
|
|
49
49
|
const [readIds, setReadIds] = (0, import_react.useState)(() => /* @__PURE__ */ new Set());
|
|
50
50
|
(0, import_react.useEffect)(() => {
|
|
51
51
|
setReadIds((0, import_notification_storage.getReadIds)());
|
|
52
52
|
}, []);
|
|
53
53
|
const { orders: userOrders, isLoading: ordersLoading } = (0, import_use_orders.useUserOrders)(getClient, address ?? null);
|
|
54
|
-
const { orders: receivedOffers, isLoading: receivedLoading } = (0, import_use_orders.useReceivedOffers)(
|
|
54
|
+
const { orders: receivedOffers, isLoading: receivedLoading } = (0, import_use_orders.useReceivedOffers)(getClient, address ?? null);
|
|
55
55
|
const { activities, isLoading: activitiesLoading } = (0, import_use_activities.useActivitiesByAddress)(getClient, address ?? null);
|
|
56
56
|
const { data: announcements = [] } = (0, import_swr.default)(
|
|
57
57
|
"announcements",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/use-notifications.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, 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 { notificationsAreLoading } from \"./notification-readiness.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>>(() => new Set<string>());\n\n useEffect(() => {\n setReadIds(getReadIds());\n }, []);\n\n const { orders: userOrders, isLoading: ordersLoading } = useUserOrders(getClient, address ?? null);\n\n const { orders: receivedOffers, isLoading: receivedLoading } = useReceivedOffers(apiConfig, address ?? null);\n const { activities, isLoading: activitiesLoading } = 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 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 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 (activities as ApiActivity[]).slice(0, 50).forEach((event) => {\n const id = `activity-${event.txHash}-${event.type}-${event.nftTokenId ?? \"\"}`;\n\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 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.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 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 const isLoading = notificationsAreLoading({\n ordersLoading,\n receivedLoading,\n activitiesLoading,\n hasAddress: !!address,\n });\n\n return {\n notifications,\n unreadCount,\n isLoading,\n markAllRead: () => markNotificationsRead(notifications.map((n) => n.id)),\n markRead: (id: string) => markNotificationsRead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E,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,QAAM,gBAAY,uDAAwB;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,CAAC,CAAC;AAAA,EAChB,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-notifications.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, 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 { notificationsAreLoading } from \"./notification-readiness.js\";\nimport {\n formatActivity,\n formatOrderNotification,\n formatOfferAcceptedNotification,\n formatAssetReceivedNotification,\n} from \"./format-activity.js\";\nimport type { Notification, Announcement } from \"../data/notification.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 address: string | null | undefined\n) {\n const [readIds, setReadIds] = useState<Set<string>>(() => new Set<string>());\n\n useEffect(() => {\n setReadIds(getReadIds());\n }, []);\n\n const { orders: userOrders, isLoading: ordersLoading } = useUserOrders(getClient, address ?? null);\n\n const { orders: receivedOffers, isLoading: receivedLoading } = useReceivedOffers(getClient, address ?? null);\n const { activities, isLoading: activitiesLoading } = 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 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 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 (activities as ApiActivity[]).slice(0, 50).forEach((event) => {\n const id = `activity-${event.txHash}-${event.type}-${event.nftTokenId ?? \"\"}`;\n\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 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.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 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 const isLoading = notificationsAreLoading({\n ordersLoading,\n receivedLoading,\n activitiesLoading,\n hasAddress: !!address,\n });\n\n return {\n notifications,\n unreadCount,\n isLoading,\n markAllRead: () => markNotificationsRead(notifications.map((n) => n.id)),\n markRead: (id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