38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
const API = process.env.FREEDOM_API ?? "https://api-v1.freedom.st";
|
|
|
|
export async function getChainInfo(): Promise<Record<string, any>> {
|
|
const res = await fetch(`${API}/rpc/info`);
|
|
return res.json();
|
|
}
|
|
|
|
export async function getExchangeRates(): Promise<Record<string, number>> {
|
|
const res = await fetch(`${API}/invoice/rates`);
|
|
return res.json();
|
|
}
|
|
|
|
export async function getAddressInfo(address: string): Promise<any> {
|
|
const res = await fetch(`${API}/address/${address}`);
|
|
return res.json();
|
|
}
|
|
|
|
export async function getAddressInfoBulk(addresses: string[]): Promise<Record<string, any>> {
|
|
if (addresses.length === 0) return {};
|
|
const res = await fetch(`${API}/address`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ terms: addresses }),
|
|
});
|
|
return res.json();
|
|
}
|
|
|
|
export function getQrUrl(text: string): string {
|
|
return `${API}/invoice/qr/${encodeURIComponent(text)}`;
|
|
}
|
|
|
|
export async function getAvailableCoins(): Promise<string[]> {
|
|
const info = await getChainInfo();
|
|
return Object.entries(info)
|
|
.filter(([_, v]) => v && v.uptime != null)
|
|
.map(([k]) => k);
|
|
}
|