This commit is contained in:
2026-04-05 00:43:23 +05:30
commit 8be37d3e92
425 changed files with 101853 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
'use client';
import { getCUSDContract, getProvider } from '@/lib/contracts';
import { useQuery } from '@tanstack/react-query';
import { ethers } from 'ethers';
export function useCUSDBalance(address: string | null) {
return useQuery({
queryKey: ['cusd-balance', address],
queryFn: async () => {
if (!address) return '0';
const provider = getProvider();
const cUSDContract = getCUSDContract(provider);
const balance = await cUSDContract.balanceOf(address);
return ethers.formatEther(balance);
},
enabled: !!address,
refetchInterval: 10000, // Refetch every 10 seconds
});
}
export function useCUSDAllowance(owner: string | null, spender: string) {
return useQuery({
queryKey: ['cusd-allowance', owner, spender],
queryFn: async () => {
if (!owner) return '0';
const provider = getProvider();
const cUSDContract = getCUSDContract(provider);
const allowance = await cUSDContract.allowance(owner, spender);
return ethers.formatEther(allowance);
},
enabled: !!owner,
});
}