Files
solace-bg-dubai/frontend/lib/hooks/useTreasury.ts
defiQUG a03417be98
All checks were successful
CI / lint-and-test (push) Successful in 9m52s
chore: consolidate local WIP (repo cleanup 20260707)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 09:41:38 -07:00

35 lines
1020 B
TypeScript

"use client";
import { useEffect, useState } from "react";
import { CONTRACT_ADDRESSES } from "@/lib/web3/contracts";
import { fetchTreasury, type TreasuryRecord } from "@/lib/api/client";
export function useTreasury() {
const [treasury, setTreasury] = useState<TreasuryRecord | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const wallet = CONTRACT_ADDRESSES.TreasuryWallet;
if (!wallet) {
setLoading(false);
setError("Treasury wallet not configured");
return;
}
fetchTreasury(wallet)
.then((record) => {
setTreasury(record);
if (!record) {
setError("Treasury not found in backend");
}
})
.catch((err: unknown) => {
setError(err instanceof Error ? err.message : "Failed to load treasury");
})
.finally(() => setLoading(false));
}, []);
return { treasury, treasuryId: treasury?.id ?? null, loading, error };
}