const API = process.env.FREEDOM_API ?? "https://api.freedom.st"; export async function getChainInfo(): Promise> { const res = await fetch(`${API}/info`); return res.json(); } export async function getExchangeRates(): Promise> { const res = await fetch(`${API}/rates`); return res.json(); } export async function getAddressInfo(address: string): Promise { const res = await fetch(`${API}/address/${address}`); return res.json(); } export async function getAddressInfoBulk(addresses: string[]): Promise> { if (addresses.length === 0) return {}; const res = await fetch(`${API}/address`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ addresses }), }); return res.json(); } export async function fetchQrBase64(text: string): Promise { const url = `${API}/qr/${encodeURIComponent(text)}`; try { const res = await fetch(url); if (!res.ok) return url; const buf = await res.arrayBuffer(); const type = res.headers.get("content-type") || "image/png"; const b64 = Buffer.from(buf).toString("base64"); return `data:${type};base64,${b64}`; } catch { return url; } } export async function getAvailableCoins(): Promise { const info = await getChainInfo(); return Object.entries(info) .filter(([_, v]) => v != null) .map(([k]) => k); }