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