"use client"; import { useState, useRef, useEffect } from "react"; import Template from "./Template"; import { Button } from "@/components/ui/button"; import { useModal } from "@/app/_providers/modal/provider"; import { toast } from "sonner"; import { useNDK } from "@/app/_providers/ndk"; import useCurrentUser from "@/lib/hooks/useCurrentUser"; import { HiOutlineLightningBolt } from "react-icons/hi"; import { RiSubtractFill, RiAddFill } from "react-icons/ri"; import { formatCount } from "@/lib/utils"; import { Textarea } from "@/components/ui/textarea"; import { Label } from "@/components/ui/label"; import { type NostrEvent } from "@nostr-dev-kit/ndk"; import { sendZap } from "@/lib/actions/zap"; const intervals = [ 10, 25, 50, 75, 100, 150, 200, 250, 350, 500, 750, 1000, 1250, 1500, 2_000, 2_500, 3_000, 3_500, 4_000, 5_000, 6_000, 7_500, 10_000, 12_500, 15_000, 20_000, 25_000, 30_000, 40_000, 50_000, 75_000, 100_000, 150_000, 200_000, 300_000, 500_000, 750_000, 1_000_000, 1_250_000, 1_500_000, 2_000_000, ]; type ZapPickerProps = { event: NostrEvent; }; export default function ZapPicker({ event }: ZapPickerProps) { const { loginWithNip07 } = useNDK(); const { loginWithPubkey, currentUser } = useCurrentUser(); const [isLoading, setIsLoading] = useState(false); const [note, setNote] = useState(""); const modal = useModal(); const [sats, setSats] = useState(2000); const { ndk } = useNDK(); function onClick(type: "+" | "-") { setSats((prev) => { let index = intervals.findIndex((i) => prev === i); if (type === "+") { index++; } else { index--; } return intervals.at(index) ?? 2000; }); } async function handleSendZap() { try { setIsLoading(true); const result = await sendZap(ndk!, sats, event, note); toast.success("Zap Sent!"); } catch (err) { console.log("error sending zap", err); } finally { setIsLoading(false); } } return (