import React, { useState } from 'react'; import { Send, Loader2, CheckCircle, XCircle } from 'lucide-react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { useWallet } from '@/contexts/WalletContext'; import { Alert, AlertDescription } from '@/components/ui/alert'; interface TransactionModalProps { isOpen: boolean; onClose: () => void; type: 'send' | 'vote' | 'delegate'; data?: any; } export const TransactionModal: React.FC = ({ isOpen, onClose, type, data }) => { const { address, signTransaction, signMessage } = useWallet(); const [recipient, setRecipient] = useState(''); const [amount, setAmount] = useState(''); const [message, setMessage] = useState(''); const [loading, setLoading] = useState(false); const [txHash, setTxHash] = useState(null); const [error, setError] = useState(null); const handleSendTransaction = async () => { if (!recipient || !amount) { setError('Please fill in all fields'); return; } setLoading(true); setError(null); try { const tx = { to: recipient, value: '0x' + (parseFloat(amount) * 1e18).toString(16), data: '0x', }; const hash = await signTransaction(tx); setTxHash(hash); } catch (err: any) { setError(err.message || 'Transaction failed'); } finally { setLoading(false); } }; const handleSignMessage = async () => { if (!message) { setError('Please enter a message to sign'); return; } setLoading(true); setError(null); try { const signature = await signMessage(message); setTxHash(signature); } catch (err: any) { setError(err.message || 'Failed to sign message'); } finally { setLoading(false); } }; const resetForm = () => { setRecipient(''); setAmount(''); setMessage(''); setTxHash(null); setError(null); onClose(); }; return ( {type === 'send' ? 'Send HEZ' : type === 'vote' ? 'Cast Vote' : 'Delegate Voting Power'} {type === 'send' ? 'Send HEZ tokens to another address' : type === 'vote' ? 'Submit your vote for the proposal' : 'Delegate your voting power to another address'} {!txHash ? (
{type === 'send' && ( <>
setRecipient(e.target.value)} className="font-mono" />
setAmount(e.target.value)} />
)} {type === 'vote' && (