import { useState } from "react"; import { useLightningStore, ZapTargetSpec } from "../../stores/lightning"; import { useUIStore } from "../../stores/ui"; const AMOUNT_PRESETS = [21, 100, 500, 1000, 5000]; type ZapState = "idle" | "paying" | "success" | "error"; interface ZapModalProps { target: ZapTargetSpec; recipientName: string; onClose: () => void; } export function ZapModal({ target, recipientName, onClose }: ZapModalProps) { const { nwcUri, zap } = useLightningStore(); const { setView } = useUIStore(); const [amountSats, setAmountSats] = useState(21); const [customAmount, setCustomAmount] = useState(""); const [useCustom, setUseCustom] = useState(false); const [comment, setComment] = useState(""); const [state, setState] = useState("idle"); const [errorMsg, setErrorMsg] = useState(""); const effectiveAmount = useCustom ? (parseInt(customAmount) || 0) : amountSats; const handleZap = async () => { if (effectiveAmount <= 0) return; setState("paying"); setErrorMsg(""); try { await zap(target, effectiveAmount, comment.trim() || undefined); setState("success"); setTimeout(onClose, 1500); } catch (err) { setState("error"); setErrorMsg(err instanceof Error ? err.message : String(err)); } }; const handleBackdrop = (e: React.MouseEvent) => { if (e.target === e.currentTarget) onClose(); }; return (
{/* Header */}
⚡ Zap {recipientName}
{!nwcUri &&
No wallet connected
}
{/* No wallet state */} {!nwcUri && (

Connect a Lightning wallet using a Nostr Wallet Connect (NWC) URI to send zaps.

)} {/* Zap form */} {nwcUri && state === "idle" && (
{/* Amount presets */}
Amount (sats)
{AMOUNT_PRESETS.map((amt) => ( ))}
{ setCustomAmount(e.target.value.replace(/\D/g, "")); setUseCustom(true); }} onFocus={() => setUseCustom(true)} placeholder="custom amount…" className={`w-full bg-bg border px-3 py-1.5 text-text text-[12px] focus:outline-none transition-colors ${ useCustom ? "border-accent/60" : "border-border" }`} />
{/* Comment */}
Comment (optional)
setComment(e.target.value)} placeholder="Great post!" maxLength={140} className="w-full bg-bg border border-border px-3 py-1.5 text-text text-[12px] focus:outline-none focus:border-accent/50" />
{/* Zap button */}
)} {/* Paying state */} {nwcUri && state === "paying" && (

Sending {effectiveAmount} sats…

)} {/* Success state */} {state === "success" && (

Zapped!

{effectiveAmount} sats sent to {recipientName}

)} {/* Error state */} {state === "error" && (

{errorMsg}

)}
); }