import CardContainer from './CardContainer'; import { ArrowUpTrayIcon, CpuChipIcon } from '@heroicons/react/24/outline'; import { useState } from 'react'; import { generatePrivateKey, getPublicKey, finishEvent } from 'nostr-tools'; import { minePow } from '../../utils/mine'; import { publish } from '../../utils/relays'; import NostrImg from '../../utils/ImgUpload'; const difficulty = 20 const NewThreadCard: React.FC = () => { const [comment, setComment] = useState(""); const [file, setFile] = useState(""); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); let sk = generatePrivateKey(); try { const event = minePow({ kind: 1, tags: [], content: comment + " " + file, created_at: Math.floor(Date.now() / 1000), pubkey: getPublicKey(sk), }, difficulty); const signedEvent = finishEvent(event, sk); await publish(signedEvent); setComment("") setFile("") } catch (error) { setComment(comment + " " + error); } }; async function attachFile(file_input: File | null) { try { if (file_input) { const rx = await NostrImg(file_input); if (rx.url) { setFile(rx.url); } else if (rx?.error) { setFile(rx.error); } } } catch (error: unknown) { if (error instanceof Error) { setFile(error?.message); } } } return ( <>