diff --git a/src/components/TransactionHistoryTable.tsx b/src/components/TransactionHistoryTable.tsx index d425f06..a3a456c 100644 --- a/src/components/TransactionHistoryTable.tsx +++ b/src/components/TransactionHistoryTable.tsx @@ -15,7 +15,7 @@ import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { Input } from "@/components/ui/Input"; import { useSorokit } from "@/context/useSorokit"; -import type { Transaction } from "@/lib/client"; +import type { NetworkInfo, Transaction } from "@/lib/client"; import { getClient } from "@/lib/client"; import { cn, truncateAddress } from "@/lib/utils"; @@ -82,6 +82,26 @@ function compareValues(a: Transaction, b: Transaction, field: SortField, dir: So return dir === "asc" ? aNum - bNum : bNum - aNum; } +/** + * Maps a Stellar network to its Stellar Expert explorer URL segment. + * Returns `null` for networks Stellar Expert does not index (futurenet, + * localnet), in which case the hash stays as plain text. + */ +function explorerTxUrl( + network: NetworkInfo | null, + hash: string, +): string | null { + if (!network) return null; + const segment = + network.name === "mainnet" + ? "public" + : network.name === "testnet" + ? "testnet" + : null; + if (!segment) return null; + return `https://stellar.expert/explorer/${segment}/tx/${hash}`; +} + /* ------------------------------------------------------------------ */ /* CSV Export (RFC 4180) */ /* ------------------------------------------------------------------ */ @@ -266,7 +286,7 @@ function SortHeader({ label, field, currentField, direction, onChange, className /* ------------------------------------------------------------------ */ export function TransactionHistoryTable({ className, pageSize = PAGE_SIZE }: TransactionHistoryTableProps) { - const { address, isConnected } = useSorokit(); + const { address, isConnected, network } = useSorokit(); const [allTxs, setAllTxs] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); @@ -410,9 +430,25 @@ export function TransactionHistoryTable({ className, pageSize = PAGE_SIZE }: Tra - - {truncateAddress(tx.hash, 8, 6)} - + {(() => { + const url = explorerTxUrl(network, tx.hash); + return url ? ( + + {truncateAddress(tx.hash, 8, 6)} + + + ) : ( + + {truncateAddress(tx.hash, 8, 6)} + + ); + })()} {tx.memo && ( {truncateMemo(tx.memo)} @@ -453,9 +489,24 @@ export function TransactionHistoryTable({ className, pageSize = PAGE_SIZE }: Tra
- - {truncateAddress(tx.hash, 8, 6)} - + {(() => { + const url = explorerTxUrl(network, tx.hash); + return url ? ( + + {truncateAddress(tx.hash, 8, 6)} + + ) : ( + + {truncateAddress(tx.hash, 8, 6)} + + ); + })()} {tx.successful ? "Success" : "Failed"}