import { MarqueeText, SquareArtwork, CancelButton, Button, TextInput, Center, Text, DollarAmount, } from "@/components"; import { KeyboardAvoidingView, ScrollView, TouchableOpacity, View, } from "react-native"; import { useState, useCallback } from "react"; import { useLocalSearchParams, useRouter } from "expo-router"; import { useAuth, useSettingsManager, useZapContent } from "@/hooks"; import { Switch } from "@rneui/themed"; import { brandColors } from "@/constants"; import { useTheme } from "@react-navigation/native"; import { ArrowTopRightOnSquareIcon } from "react-native-heroicons/solid"; import { WalletBalance } from "@/components/WalletBalance"; export default function ZapPage() { const { defaultZapAmount, title, artist, artworkUrl, trackId, timestamp, isPodcast, parentContentId, } = useLocalSearchParams<{ defaultZapAmount: string; title: string; artist: string; artworkUrl: string; trackId: string; timestamp: string; isPodcast: string; parentContentId: string; }>(); const router = useRouter(); const { pubkey } = useAuth(); const [zapAmount, setZapAmount] = useState(defaultZapAmount ?? ""); const [zapError, setZapError] = useState(""); const [comment, setComment] = useState(""); const { sendZap, isLoading: isZapping } = useZapContent({ trackId, title, artist, artworkUrl, timestamp: timestamp ? parseInt(timestamp) : 0, isPodcast: isPodcast === "true", parentContentId, }); const validateAndSetZapAmount = useCallback((value: string) => { // Remove any non-numeric characters and decimal points const cleanValue = value.replace(/[^\d]/g, ""); setZapAmount(cleanValue); if (cleanValue === "") { setZapError("Amount is required"); return; } const numericValue = parseInt(cleanValue, 10); if (isNaN(numericValue)) { setZapError("Please enter a valid number"); return; } if (numericValue < 1 || numericValue > 100000) { setZapError("Amount must be between 1 and 100,000 sats"); return; } setZapError(""); }, []); const isZapDisabled = zapAmount.length === 0 || Number(zapAmount) <= 0 || isZapping || zapError !== ""; const handleZap = async () => { const numericAmount = parseInt(zapAmount, 10); if (numericAmount >= 1 && numericAmount <= 100000) { sendZap({ comment, amount: numericAmount, useNavReplace: true }); } }; const { settings, updateSettings } = useSettingsManager(); const { colors } = useTheme(); const currentPublishKind1Setting = settings?.publishKind1 ?? false; const togglePublishKind1 = async (value: boolean) => { await updateSettings({ publishKind1: !currentPublishKind1Setting, }); }; return ( {artworkUrl && }
{title} by {artist}
} /> {!pubkey ? ( You are not connected to nostr, zaps and comments will be anonymous. { router.push("/settings"); router.push("/settings/advanced"); router.push("/settings/nsec"); }} > Connect ) : ( Publish comments to nostr Comments will show up in other clients. )}
); }