import { useState } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Label } from '@/components/ui/label'; import { useOfferActions } from '@/hooks/useMarketplaceOffers'; import { useToast } from '@/hooks/useToast'; import { Handshake, Loader2 } from 'lucide-react'; /** Buyer: make a structured offer (amount + note) on a listing. */ export function OfferDialog({ open, onOpenChange, listing, sellerName, }: { open: boolean; onOpenChange: (open: boolean) => void; listing: { pubkey: string; identifier: string }; sellerName: string; }) { const { createOffer } = useOfferActions(); const { toast } = useToast(); const [amount, setAmount] = useState(''); const [note, setNote] = useState(''); const [busy, setBusy] = useState(false); const submit = async () => { const parsed = amount.trim() ? Number(amount) : undefined; if (parsed !== undefined && (!Number.isFinite(parsed) || parsed <= 0)) { toast({ title: 'Enter a valid amount', variant: 'destructive' }); return; } setBusy(true); try { await createOffer({ listing, amount: parsed, currency: 'SATS', note }); toast({ title: 'Offer sent', description: `${sellerName} can accept or decline it.`, }); onOpenChange(false); setAmount(''); setNote(''); } catch (e) { toast({ title: 'Could not send the offer', description: e instanceof Error ? e.message : 'Something went wrong.', variant: 'destructive', }); } finally { setBusy(false); } }; return ( Make an offer Offer an amount for this listing. {sellerName} can accept or decline; you arrange payment between yourselves.
setAmount(e.target.value)} inputMode="numeric" placeholder="e.g. 45000" className="h-11 border-gray-700 bg-gray-900 text-white" />