-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionStatusDisplay.tsx
More file actions
74 lines (67 loc) · 2.48 KB
/
Copy pathTransactionStatusDisplay.tsx
File metadata and controls
74 lines (67 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from 'react';
import { useTransactionUpdates } from '../hooks/useTransactionUpdates';
import { Loader2, CheckCircle, XCircle, Clock, WifiOff } from 'lucide-react';
interface TransactionStatusDisplayProps {
transactionHashes: string[];
}
const getStatusIcon = (status: string) => {
switch (status) {
case 'pending':
case 'confirming':
return <Loader2 className="h-4 w-4 animate-spin text-blue-500" />;
case 'completed':
return <CheckCircle className="h-4 w-4 text-green-500" />;
case 'failed':
return <XCircle className="h-4 w-4 text-red-500" />;
default:
return <Clock className="h-4 w-4 text-gray-500" />;
}
};
const getStatusText = (status: string) => {
switch (status) {
case 'pending':
return 'Pending submission...';
case 'confirming':
return 'Confirming on network...';
case 'completed':
return 'Completed!';
case 'failed':
return 'Failed!';
default:
return 'Unknown status';
}
};
export const TransactionStatusDisplay: React.FC<TransactionStatusDisplayProps> = ({ transactionHashes }) => {
const { transactions, isWsConnected, isPolling } = useTransactionUpdates({
initialTransactions: transactionHashes,
});
const activeTransactions = transactions.filter(
(tx) => tx.status === 'pending' || tx.status === 'confirming'
);
if (activeTransactions.length === 0 && !isWsConnected && !isPolling) {
return null; // Don't show anything if no active transactions and no monitoring
}
return (
<div className="p-4 bg-gray-800 text-white rounded-lg shadow-lg mt-4">
<div className="flex items-center justify-between mb-2">
<h3 className="text-lg font-semibold">Transaction Status</h3>
<span className={`text-sm flex items-center ${isWsConnected ? 'text-green-400' : 'text-yellow-400'}`}>
{isWsConnected ? 'Real-time Connected' : isPolling ? 'Polling Fallback' : 'Disconnected'}
{!isWsConnected && <WifiOff className="ml-1 h-4 w-4" />}
</span>
</div>
{activeTransactions.length === 0 ? (
<p className="text-gray-400">No active transactions.</p>
) : (
<ul className="space-y-2">
{activeTransactions.map((tx) => (
<li key={tx.hash} className="flex items-center space-x-2 text-sm">
{getStatusIcon(tx.status)}
<span>{getStatusText(tx.status)} (Hash: {tx.hash.substring(0, 8)}...)</span>
</li>
))}
</ul>
)}
</div>
);
};