import { useState } from 'react'; import { open, save } from '@tauri-apps/plugin-dialog'; import { Download, Upload, FileJson, Shield, AlertCircle, Check, Clock, HardDrive, Lock, } from 'lucide-react'; import { useBackupStore } from '../../store/backup'; export default function BackupPage() { const { isExporting, isImporting, lastExport, lastHistoryExport, error, clearError, exportWallet, importWallet, exportHistory, } = useBackupStore(); const [exportPassword, setExportPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [importPassword, setImportPassword] = useState(''); const [selectedFile, setSelectedFile] = useState(null); const [exportSuccess, setExportSuccess] = useState(false); const [importSuccess, setImportSuccess] = useState(false); const handleExportWallet = async () => { if (!exportPassword || exportPassword !== confirmPassword) return; try { const path = await save({ defaultPath: `synor-wallet-backup-${Date.now()}.enc`, filters: [{ name: 'Encrypted Backup', extensions: ['enc'] }], }); if (path) { await exportWallet(exportPassword, path); setExportPassword(''); setConfirmPassword(''); setExportSuccess(true); setTimeout(() => setExportSuccess(false), 5000); } } catch { // Error handled by store } }; const handleSelectFile = async () => { try { const selected = await open({ multiple: false, filters: [{ name: 'Encrypted Backup', extensions: ['enc'] }], }); if (selected && typeof selected === 'string') { setSelectedFile(selected); } } catch { // User cancelled } }; const handleImportWallet = async () => { if (!selectedFile || !importPassword) return; try { await importWallet(selectedFile, importPassword); setSelectedFile(null); setImportPassword(''); setImportSuccess(true); setTimeout(() => setImportSuccess(false), 5000); } catch { // Error handled by store } }; const handleExportHistory = async (format: 'json' | 'csv') => { try { const path = await save({ defaultPath: `synor-history-${Date.now()}.${format}`, filters: [ format === 'json' ? { name: 'JSON', extensions: ['json'] } : { name: 'CSV', extensions: ['csv'] }, ], }); if (path) { await exportHistory(path, format); } } catch { // Error handled by store } }; const passwordsMatch = exportPassword && exportPassword === confirmPassword; return (
{/* Header */}

Backup & Export

Securely backup your wallet and export transaction history

{/* Error Alert */} {error && (

{error}

)} {/* Success Alerts */} {exportSuccess && (

Wallet backup exported successfully!

)} {importSuccess && (

Wallet imported successfully!

)}
{/* Export Wallet */}

Export Wallet

Create an encrypted backup of your wallet

setExportPassword(e.target.value)} placeholder="Enter a strong password" className="w-full px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg text-white placeholder-gray-500 focus:outline-none focus:border-synor-500" />
setConfirmPassword(e.target.value)} placeholder="Confirm password" className={`w-full px-4 py-2 bg-gray-800 border rounded-lg text-white placeholder-gray-500 focus:outline-none ${ confirmPassword && !passwordsMatch ? 'border-red-500' : 'border-gray-700 focus:border-synor-500' }`} /> {confirmPassword && !passwordsMatch && (

Passwords do not match

)}
{lastExport && (
Last export: {new Date(lastExport.createdAt).toLocaleString()}
)}
{/* Import Wallet */}

Import Wallet

Restore from an encrypted backup file

setImportPassword(e.target.value)} placeholder="Enter backup password" className="w-full px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg text-white placeholder-gray-500 focus:outline-none focus:border-synor-500" />
{/* Export History */}

Export History

Export your transaction history for records

Export your complete transaction history for tax purposes, accounting, or personal records.

{lastHistoryExport && (
Last export: {lastHistoryExport.transactionCount} transactions on{' '} {new Date(lastHistoryExport.createdAt).toLocaleDateString()}
)}
{/* Security Info */}

Security Tips

Keep your backup safe

  • Use a strong, unique password for your backup
  • Store backups in multiple secure locations
  • Never share your backup file or password
  • Consider using cold storage for large amounts
  • Create a new backup after important changes
); }