Extends the POC from #2 beyond the Dashboard so every portal page that can benefit from on-chain signal now pulls from live backends while preserving its existing UX. Pages without an on-chain analogue (the IFRS/GAAP/IPSAS report rows, the dbis_core compliance alerts) stay on sample data with an explicit 'mocked' note. New shared primitives --------------------- src/hooks/useLatestTransactions.ts — polls SolaceScan /transactions every 15s src/hooks/useAddressTransactions.ts — per-address tx feed, 60s polling src/components/portal/LiveTransactionsPanel.tsx — reusable live-tx card src/components/portal/LiveChainBanner.tsx — slim status banner src/components/portal/OnChainBalanceTag.tsx — shared live/off-chain pill Per-page wiring --------------- AccountsPage — on-chain pill + META balance + SolaceScan link on each account row that carries a walletAddress; overlay renders only on wallet rows (negative check). SettlementsPage — replaces the static 'Settlement Rate' tile with a live Chain-138 block + tx-today tile; adds a LiveTransactionsPanel above the CSD queue so the page no longer renders identical output when RPC is dead. ReportingPage — new On-Chain Reporting Snapshot row (Blockscout /stats: block depth, total tx, total addrs, utilisation, avg block time). Clear note that the IFRS/GAAP/IPSAS rows come from dbis_core and are still mocked. TreasuryPage — two new summary tiles: live Chain-138 gas + aggregated on-chain custody (META) from sample wallet addresses. Uses the same useOnChainBalances hook as Accounts. CompliancePage — AML monitor strip with wallet selector; dedicated 'On-Chain Tx Feed' card shows IN/OUT per tracked wallet via SolaceScan. dbis_core alerts still mocked (no public deploy). TransactionBuilder — LiveChainBanner inserted above the composer so users know chain health + gas + latency before composing; transaction-builder-module made a flex column so the banner doesn't cover the canvas. Assertions baked into every live widget --------------------------------------- - RPC failure flips colour + text to 'degraded'/'—' (no silent freeze). - Loading state is distinct from both live and degraded. - Each overlay is only rendered where real data differs from sample data (walletAddress rows for balances, tracked custody for AML, etc.) so a page without live overlays is proof-of-scope, not proof-of-brokenness. Verified locally ---------------- - tsc --noEmit: clean - npm run build: clean (2066 modules, 565 ms) Still intentionally mocked -------------------------- - proxmox.ts — CF-Access protected; a BFF route is now open in orchestrator PR (see companion PR for /api/proxmox/*). - dbisCore.ts — no public deployment exists yet.
93 lines
3.8 KiB
TypeScript
93 lines
3.8 KiB
TypeScript
import { useLatestTransactions } from '../../hooks/useLatestTransactions';
|
|
import { explorerTxUrl, explorerAddressUrl, type ExplorerTx } from '../../services/explorer';
|
|
import { formatEther } from 'ethers';
|
|
import { Activity } from 'lucide-react';
|
|
|
|
const shortHash = (h: string) => `${h.slice(0, 10)}…${h.slice(-6)}`;
|
|
const shortAddr = (a: string) => `${a.slice(0, 6)}…${a.slice(-4)}`;
|
|
const formatMETA = (wei: string) => {
|
|
try { return `${Number(formatEther(BigInt(wei))).toFixed(4)} META`; } catch { return `${wei} wei`; }
|
|
};
|
|
const relativeTime = (iso: string) => {
|
|
const then = new Date(iso).getTime();
|
|
const dt = Date.now() - then;
|
|
if (dt < 60_000) return `${Math.max(1, Math.round(dt / 1000))}s ago`;
|
|
if (dt < 3_600_000) return `${Math.round(dt / 60_000)}m ago`;
|
|
return `${Math.round(dt / 3_600_000)}h ago`;
|
|
};
|
|
|
|
interface Props {
|
|
/** Max rows to show (default 10). */
|
|
limit?: number;
|
|
/** Custom card header label — defaults to "Live Chain-138 Transactions". */
|
|
title?: string;
|
|
}
|
|
|
|
/**
|
|
* Renders the most recent on-chain transactions from SolaceScan.
|
|
* Degraded state shows the error message; empty state shows a one-liner.
|
|
* Links every hash/address to the explorer.
|
|
*/
|
|
export default function LiveTransactionsPanel({ limit = 10, title = 'Live Chain-138 Transactions' }: Props) {
|
|
const { transactions, loading, error, lastUpdated } = useLatestTransactions(limit);
|
|
|
|
return (
|
|
<div className="dashboard-card live-transactions-card">
|
|
<div className="card-header">
|
|
<h3><Activity size={16} /> {title}</h3>
|
|
<span className="small" style={{ color: '#6b7280' }}>
|
|
{error
|
|
? <span style={{ color: '#ef4444' }}>RPC degraded · {error}</span>
|
|
: loading
|
|
? 'loading…'
|
|
: `${transactions.length} tx · ${lastUpdated ? lastUpdated.toLocaleTimeString() : '—'}`}
|
|
</span>
|
|
</div>
|
|
<div className="live-transactions-list">
|
|
{!loading && transactions.length === 0 && !error && (
|
|
<div style={{ padding: 12, color: '#6b7280', fontSize: 12 }}>
|
|
No transactions returned yet — SolaceScan may be indexing.
|
|
</div>
|
|
)}
|
|
{transactions.map((tx: ExplorerTx) => (
|
|
<div
|
|
key={tx.hash}
|
|
className="live-tx-row"
|
|
style={{
|
|
display: 'grid',
|
|
gridTemplateColumns: '1.3fr 1fr 1fr 0.9fr 0.7fr 0.4fr',
|
|
gap: 8,
|
|
padding: '6px 12px',
|
|
borderBottom: '1px solid rgba(255,255,255,0.04)',
|
|
fontSize: 11,
|
|
alignItems: 'center',
|
|
}}
|
|
>
|
|
<a href={explorerTxUrl(tx.hash)} target="_blank" rel="noreferrer" className="mono" style={{ color: '#60a5fa' }}>
|
|
{shortHash(tx.hash)}
|
|
</a>
|
|
<a href={explorerAddressUrl(tx.from.hash)} target="_blank" rel="noreferrer" className="mono" style={{ color: '#cbd5e1' }}>
|
|
{shortAddr(tx.from.hash)}
|
|
</a>
|
|
<span className="mono" style={{ color: tx.to ? '#cbd5e1' : '#6b7280' }}>
|
|
{tx.to ? shortAddr(tx.to.hash) : '— contract create —'}
|
|
</span>
|
|
<span className="mono">{formatMETA(tx.value)}</span>
|
|
<span className="small" style={{ color: '#6b7280' }}>{relativeTime(tx.timestamp)}</span>
|
|
<span style={{
|
|
color: tx.status === 'error' ? '#ef4444' : tx.status === 'ok' ? '#22c55e' : '#eab308',
|
|
fontSize: 9,
|
|
}}>
|
|
{tx.status ?? 'pending'}
|
|
</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
<div style={{ padding: '6px 12px', fontSize: 10, color: '#6b7280' }}>
|
|
Source: <a href="https://explorer.d-bis.org" target="_blank" rel="noreferrer" style={{ color: '#60a5fa' }}>SolaceScan Explorer</a>
|
|
{' · polls every 15s · Blockscout v2 /transactions'}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|