import React, { useEffect, useState } from "react"; import Image from "next/image"; import { useRouter } from "next/router"; import { formatTimestampToHowLongAgo } from "@/utils/time"; import { useImageProxy } from "@/hooks/useImageProxy"; import { useNostr } from "@/hooks/useNostr"; import { getSatAmountFromInvoice } from "@/utils/lightning"; const ResourceTemplate = (resource) => { const [zaps, setZaps] = useState([]); const [zapAmount, setZapAmount] = useState(null); const router = useRouter(); const { returnImageProxy } = useImageProxy(); const { fetchZapsForEvent } = useNostr(); useEffect(() => { const fetchZaps = async () => { try { const zaps = await fetchZapsForEvent(resource.id); setZaps(zaps); } catch (error) { console.error("Error fetching zaps:", error); } }; fetchZaps(); }, [fetchZapsForEvent, resource]); useEffect(() => { if (zaps.length > 0) { zaps.map((zap) => { const bolt11Tag = zap.tags.find((tag) => tag[0] === "bolt11"); const invoice = bolt11Tag ? bolt11Tag[1] : null; if (invoice) { const amount = getSatAmountFromInvoice(invoice); setZapAmount(zapAmount + amount); } }); } }, [zaps]); return (
{resource.summary}
{formatTimestampToHowLongAgo(resource.published_at)}
{zapAmount}