'use client'; import { useEffect, useRef, useState } from 'react'; export function useAction() { const [busy, setBusy] = useState(null); const [error, setError] = useState(null); const run = async (label: string, fn: () => Promise | void) => { setBusy(label); setError(null); try { await fn(); } catch (e: any) { setError(e?.shortMessage || e?.message || String(e)); } finally { setBusy(null); } }; return { busy, error, setError, run }; } export function Btn({ busy, label, children, ...rest }: React.ButtonHTMLAttributes & { busy?: string | null; label?: string }) { const mine = busy && label && busy === label; return ( ); } export function Copy({ text, label = 'Copy' }: { text: string; label?: string }) { const [ok, setOk] = useState(false); return ( ); } export function QR({ text, size = 180 }: { text: string; size?: number }) { const ref = useRef(null); useEffect(() => { import('qrcode').then((Q) => ref.current && Q.toCanvas(ref.current, text, { width: size, margin: 0 })); }, [text, size]); return ; } export function FileButton({ accept, onFile, children, className = 'btn ghost sm' }: { accept?: string; onFile: (bytes: Uint8Array, name: string) => void; children: React.ReactNode; className?: string }) { const ref = useRef(null); return ( <> { const f = e.target.files?.[0]; if (!f) return; onFile(new Uint8Array(await f.arrayBuffer()), f.name); e.target.value = ''; }} /> ); } export function SigBar({ have, need }: { have: number; need: number }) { return {Array.from({ length: need }, (_, i) => )}; } export function Err({ error }: { error: string | null }) { return error ?

{error}

: null; } export const short = (s: string, n = 6) => (s.length > 2 * n + 3 ? `${s.slice(0, n + 2)}…${s.slice(-n)}` : s);