import { useQuery } from '@tanstack/react-query'; /** * A mint from the MintRadar community directory (https://mintradar.org). * * Fetched **same-origin** at `/api/mints/*` — MintRadar has no CORS, so prod * proxies it via a Netlify redirect (see `public/_redirects`) and dev via the * Vite proxy in `vite.config.ts`. The data is unofficial, rate-limited and may * change without notice — treat it as a hint, not gospel. */ export interface MintDirectoryEntry { url: string; name?: string; iconUrl?: string; descriptionLong?: string; online?: boolean; degraded?: boolean; archived?: boolean; latencyMs?: number; version?: string; nutCount?: number; tosUrl?: string; lastOnlineAt?: string; } export function useMintDirectory() { return useQuery({ queryKey: ['mint-directory'], staleTime: 10 * 60 * 1000, retry: 1, queryFn: async (c) => { const res = await fetch('/api/mints/known', { signal: AbortSignal.any([c.signal, AbortSignal.timeout(15000)]), headers: { accept: 'application/json' }, }); if (!res.ok) { throw new Error(`The mint directory is unavailable right now (HTTP ${res.status}).`); } const data = (await res.json()) as unknown; if (!Array.isArray(data)) throw new Error('Unexpected mint directory response.'); return (data as MintDirectoryEntry[]).filter( (m) => m && typeof m.url === 'string' && m.url.length > 0, ); }, }); }