"use client"; /** * Shared unlock block — password + eye + clear locked/unlocked messaging. */ import { useState } from "react"; import { Button } from "@/components/ui/button"; import { ErrorBanner } from "@/components/ui/error-banner"; import { PasswordInput } from "@/components/ui/password-input"; import { unlockVault, type UnlockedMavi } from "@/lib/mavi/storage"; export function UnlockPanel({ onUnlocked, title = "Unlock mavi", description = "Stays unlocked in this browser tab until you lock or close the tab.", submitLabel = "Unlock", autoFocus, }: { onUnlocked: (wallet: UnlockedMavi) => void; title?: string; description?: string; submitLabel?: string; autoFocus?: boolean; }) { const [password, setPassword] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function submit() { setError(null); if (!password) { setError("Enter your password."); return; } setBusy(true); try { const u = await unlockVault(password); setPassword(""); onUnlocked(u); } catch (e) { setError( e instanceof Error ? e.message : "Wrong password or damaged vault. Try again.", ); } finally { setBusy(false); } } return (

{title}

{description}

{error ? {error} : null} void submit()} placeholder="Vault password" disabled={busy} />
); }