import { useTxNormalizedEvents } from "@alphscan/sdk-react";
function TransactionEvents({ txId }: { txId: string | undefined }) {
const { data, loading, error, refetch } = useTxNormalizedEvents(txId, {
baseUrl: "https://api.alphscan.io",
apiKey: process.env.NEXT_PUBLIC_ALPHSCAN_API_KEY,
enabled: !!txId,
});
if (!txId) return <p>Enter a transaction ID</p>;
if (loading) return <p>Loading events…</p>;
if (error) return <p>Error: {error.message}</p>;
if (!data) return null;
return (
<div>
<p>Transaction {data.transaction_id}: {data.events.length} events</p>
<ul>
{data.events.map((e) => (
<li key={e.id}>{e.category} – {e.sub_kind}</li>
))}
</ul>
<button onClick={refetch}>Refetch</button>
</div>
);
}