import { useEffect, useState } from 'react'; import { Plus, Lock, Unlock, Trash2, RefreshCw, AlertCircle, CheckCircle, Download, Timer, Info, } from 'lucide-react'; // Using Timer as VaultIcon since lucide-react doesn't export Vault const VaultIcon = Timer; import { useVaultsStore, Vault, formatTimeRemaining, getVaultStatusColor, LOCK_DURATION_PRESETS, } from '../../store/vaults'; import { LoadingSpinner } from '../../components/LoadingStates'; /** * Create Vault Modal */ function CreateVaultModal({ onClose }: { onClose: () => void }) { const { createVault, isLoading } = useVaultsStore(); const [name, setName] = useState(''); const [amount, setAmount] = useState(''); const [duration, setDuration] = useState(86400); // 24 hours default const [customDuration, setCustomDuration] = useState(''); const [useCustom, setUseCustom] = useState(false); const [description, setDescription] = useState(''); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); const amountNum = parseFloat(amount); if (!name.trim()) { setError('Vault name is required'); return; } if (isNaN(amountNum) || amountNum <= 0) { setError('Invalid amount'); return; } const lockDuration = useCustom ? parseInt(customDuration) * 3600 // Custom is in hours : duration; if (lockDuration < 60) { setError('Lock duration must be at least 1 minute'); return; } try { await createVault({ name: name.trim(), amount: Math.floor(amountNum * 100_000_000), // Convert SYN to sompi lockDurationSecs: lockDuration, description: description.trim() || undefined, }); onClose(); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to create vault'); } }; return (

Create Time-Locked Vault

setName(e.target.value)} placeholder="e.g., Savings Goal, Emergency Fund" className="w-full bg-gray-800 border border-gray-700 rounded-lg px-4 py-2 text-white" />
setAmount(e.target.value)} placeholder="0.00000000" className="w-full bg-gray-800 border border-gray-700 rounded-lg px-4 py-2 text-white" />
{LOCK_DURATION_PRESETS.slice(0, 4).map((preset) => ( ))}
{LOCK_DURATION_PRESETS.slice(4).map((preset) => ( ))}
{useCustom && (
setCustomDuration(e.target.value)} placeholder="Duration in hours" className="flex-1 bg-gray-800 border border-gray-700 rounded-lg px-4 py-2 text-white" /> hours
)}