All checks were successful
CI / lint-and-test (push) Successful in 9m52s
Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
1020 B
TypeScript
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 };
|
|
}
|