import useSWR from 'swr';
import { useUpload } from 'storacha-sol';
const useSolPrice = ()=> {
const client = useUpload(Environment.testnet);
const { data, error, isLoading } = useSWR(
'sol-price',
() => client.getSolPrice(),
{
refreshInterval: 60000, // Refresh every 60 seconds
revalidateOnFocus: false,
}
);
return {
price: data ?? null,
error,
isLoading,
};
}
// Usage in component
function PriceDisplay() {
const { price, isLoading } = useSolPrice();
if (isLoading) return <p>Loading price...</p>;
if (!price) return <p>Price unavailable</p>;
return <p>SOL: ${price.toFixed(2)}</p>;
}