import { useState, useEffect, useRef, forwardRef } from 'react'; import { Zap, Copy, Check, ExternalLink, Sparkle, Sparkles, Star, Rocket, ArrowLeft, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger, DrawerClose, } from '@/components/ui/drawer'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Card, CardContent } from '@/components/ui/card'; import { Separator } from '@/components/ui/separator'; import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useAuthor } from '@/hooks/useAuthor'; import { useToast } from '@/hooks/useToast'; import { useZaps } from '@/hooks/useZaps'; import { useWallet } from '@/hooks/useWallet'; import { useIsMobile } from '@/hooks/useIsMobile'; import type { Event } from 'nostr-tools'; import QRCode from 'qrcode'; interface ZapDialogProps { target: Event; children?: React.ReactNode; className?: string; } const presetAmounts = [ { amount: 1, icon: Sparkle }, { amount: 50, icon: Sparkles }, { amount: 100, icon: Zap }, { amount: 250, icon: Star }, { amount: 1000, icon: Rocket }, ]; interface ZapContentProps { invoice: string | null; amount: number | string; comment: string; isZapping: boolean; qrCodeUrl: string; copied: boolean; hasWebLN: boolean; handleZap: () => void; handleCopy: () => void; openInWallet: () => void; setAmount: (amount: number | string) => void; setComment: (comment: string) => void; inputRef: React.RefObject; zap: (amount: number, comment: string) => void; } // Moved ZapContent outside of ZapDialog to prevent re-renders causing focus loss const ZapContent = forwardRef(({ invoice, amount, comment, isZapping, qrCodeUrl, copied, hasWebLN, handleZap, handleCopy, openInWallet, setAmount, setComment, inputRef, zap, }, ref) => (
{invoice ? (
{/* Payment amount display */}
{amount} sats
{/* QR Code */}
{qrCodeUrl ? ( Lightning Invoice QR Code ) : (
)}
{/* Invoice input */}
e.currentTarget.select()} />
{/* Payment buttons */}
{hasWebLN && ( )}
Scan the QR code or copy the invoice to pay with any Lightning wallet.
) : ( <>
{ if (value) { setAmount(parseInt(value, 10)); } }} className="grid grid-cols-5 gap-1 w-full" > {presetAmounts.map(({ amount: presetAmount, icon: Icon }) => ( {presetAmount} ))}
OR
setAmount(e.target.value)} className="w-full text-sm" />