New '/mints' page: browse Community MintRadar mints with health (online/latency/ degraded/archived), NUT count, terms, and add-to-wallet on native. MintRadar has no CORS, so it's fetched same-origin at /api/mints/*: - prod: Netlify proxy redirect in public/_redirects (+ 10m cache in _headers) - dev: Vite server.proxy in vite.config.ts This also hides users' IPs from MintRadar. Data is unofficial/rate-limited; the page degrades to a friendly error state. Nav entry + smoke route added.
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
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<MintDirectoryEntry[]>({
|
|
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,
|
|
);
|
|
},
|
|
});
|
|
}
|