forked from Vero-protocol/vero-guardian-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
95 lines (86 loc) · 2.76 KB
/
Copy pathindex.tsx
File metadata and controls
95 lines (86 loc) · 2.76 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use client';
import type { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import { CheckCircle2, XCircle, Loader2 } from 'lucide-react';
import type { VoteTxState } from '@/hooks/useVoteTransaction';
import { getStellarExplorerTxUrl } from '@/lib/stellar-expert';
interface TransactionNotificationProps {
state: VoteTxState;
/** Called when the user dismisses an error notification. */
onDismiss?: () => void;
}
/**
* Inline transaction status notification for the vote flow.
* Renders nothing while idle; shows a spinner for PENDING,
* a success message with an explorer link for SUCCESS,
* and a contextual error for ERROR (distinguishing user rejection
* from contract/network failures).
*/
export default function TransactionNotification({
state,
onDismiss,
}: TransactionNotificationProps): ReactElement | null {
const { t } = useTranslation();
if (state.status === 'idle') return null;
if (state.status === 'pending') {
return (
<div
role="status"
aria-live="polite"
className="flex items-center gap-2 text-sm text-indigo-600 dark:text-indigo-400"
>
<Loader2 className="w-4 h-4 animate-spin" aria-hidden="true" />
<span>{t('vote.tx.pending')}</span>
</div>
);
}
if (state.status === 'success' && state.txHash) {
const explorerUrl = getStellarExplorerTxUrl(state.txHash);
return (
<div
role="status"
aria-live="polite"
className="flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400"
>
<CheckCircle2 className="w-4 h-4 shrink-0" aria-hidden="true" />
<span>
{t('vote.tx.success')}{' '}
<a
href={explorerUrl}
target="_blank"
rel="noopener noreferrer"
className="underline hover:no-underline font-medium"
>
{t('vote.tx.viewTx')}
</a>
</span>
</div>
);
}
if (state.status === 'error') {
const label =
state.errorKind === 'user_rejected'
? t('vote.tx.errorUserRejected')
: t('vote.tx.errorNetwork');
return (
<div
role="alert"
aria-live="assertive"
className="flex items-start gap-2 text-sm text-red-600 dark:text-red-400"
>
<XCircle className="w-4 h-4 shrink-0 mt-0.5" aria-hidden="true" />
<span className="flex-1">{label}</span>
{onDismiss && (
<button
onClick={onDismiss}
className="text-red-400 hover:text-red-600 dark:hover:text-red-300 transition-colors focus:outline-none focus:ring-2 focus:ring-red-500 rounded"
aria-label={t('toast.closeNotification')}
>
×
</button>
)}
</div>
);
}
return null;
}