import React from "react"; import { PublicKey } from "@solana/web3.js"; import { FetchStatus } from "providers/cache"; import { useAccountInfo, useAccountHistory } from "providers/accounts"; import { useFetchAccountHistory } from "providers/accounts/history"; import { Signature } from "components/common/Signature"; import { ErrorCard } from "components/common/ErrorCard"; import { LoadingCard } from "components/common/LoadingCard"; import { Slot } from "components/common/Slot"; export function TransactionHistoryCard({ pubkey }: { pubkey: PublicKey }) { const address = pubkey.toBase58(); const info = useAccountInfo(address); const history = useAccountHistory(address); const fetchAccountHistory = useFetchAccountHistory(); const refresh = () => fetchAccountHistory(pubkey, true); const loadMore = () => fetchAccountHistory(pubkey); React.useEffect(() => { if (!history) refresh(); }, [address]); // eslint-disable-line react-hooks/exhaustive-deps if (!history || info?.data === undefined) { return null; } if (history?.data === undefined) { if (history.status === FetchStatus.Fetching) { return ; } return ( ); } const transactions = history.data.fetched; if (transactions.length === 0) { if (history.status === FetchStatus.Fetching) { return ; } return ( ); } const detailsList: React.ReactNode[] = []; for (var i = 0; i < transactions.length; i++) { const slot = transactions[i].slot; const slotTransactions = [transactions[i]]; while (i + 1 < transactions.length) { const nextSlot = transactions[i + 1].slot; if (nextSlot !== slot) break; slotTransactions.push(transactions[++i]); } slotTransactions.forEach(({ signature, err }) => { let statusText; let statusClass; if (err) { statusClass = "warning"; statusText = "Failed"; } else { statusClass = "success"; statusText = "Success"; } detailsList.push( {statusText} ); }); } const fetching = history.status === FetchStatus.Fetching; return (

Transaction History

{detailsList}
Slot Result Transaction Signature
{history.data.foundOldest ? (
Fetched full history
) : ( )}
); }