UNPKG

bigblocks

Version:

Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React

36 lines (35 loc) 2.22 kB
"use client"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useCallback, useState } from "react"; import { useAuthMessages } from "../../lib/auth-messages.js"; import { cn } from "../../lib/utils.js"; import { useBapProfileSync } from "../bap-identity/hooks/useBapProfileSync.js"; import { DropZone, ErrorDisplay } from "../ui-components/index.js"; export function BackupImport({ onImport, disabled = false, className = "", showLabel = true, enableProfileSync = false, maxDiscoveryAttempts = 50, onImportSuccess, }) { const messages = useAuthMessages(); const [error, setError] = useState(null); // Profile synchronization - only initialize if enabled const profileSync = useBapProfileSync({ autoSync: false, // Manual trigger only maxDiscoveryAttempts, }); const handleFileChange = useCallback(async (file) => { setError(null); try { await onImport(file); // Optional: Trigger profile sync after successful backup import if (enableProfileSync && !profileSync.isScanning) { // Small delay to ensure import is fully processed setTimeout(() => { profileSync.syncProfiles(); }, 1000); } // Notify parent of successful import onImportSuccess?.(); } catch (err) { setError(err instanceof Error ? err.message : "Failed to import backup"); } }, [onImport, enableProfileSync, profileSync, onImportSuccess]); return (_jsxs("div", { className: cn("flex flex-col gap-4", className), children: [showLabel && (_jsx("div", { className: "flex flex-col gap-1", children: _jsx("p", { className: "text-sm text-muted-foreground text-center", children: messages.labels.backupImport }) })), _jsx(DropZone, { accept: ".json,.txt,.backup", disabled: disabled, title: messages.labels.importBackupFile, description: messages.labels.backupSupport, dragActiveText: "Drop your backup file here", dragActiveDescription: "Release to import", height: 150, onFileSelect: handleFileChange, onError: (error) => setError(error) }), error && _jsx(ErrorDisplay, { error: error })] })); }