diff --git a/src/components/ZapThreadsWrapper.js b/src/components/ZapThreadsWrapper.js index b7cb409..2e94f0d 100644 --- a/src/components/ZapThreadsWrapper.js +++ b/src/components/ZapThreadsWrapper.js @@ -1,6 +1,6 @@ import React, { useEffect, useRef } from 'react'; -const ZapThreadsWrapper = ({ anchor, relays, disable }) => { +const ZapThreadsWrapper = ({ anchor, user, relays, disable }) => { // Create a ref to store the reference to the
element const zapRef = useRef(null); @@ -17,8 +17,9 @@ const ZapThreadsWrapper = ({ anchor, relays, disable }) => { // Create a new element const zapElement = document.createElement('zap-threads'); zapElement.setAttribute('anchor', anchor); - zapElement.setAttribute('relays', relays); - zapElement.setAttribute('disable', disable); + if (user) zapElement.setAttribute('user', user); + zapElement.setAttribute('relays', relays.replace(/\s/g, '')); + if (disable) zapElement.setAttribute('disable', disable); // Remove any existing element before appending a new one if (zapRef.current && zapRef.current.firstChild) { @@ -48,7 +49,7 @@ const ZapThreadsWrapper = ({ anchor, relays, disable }) => { // Remove the load event listener from the script script.removeEventListener('load', handleScriptLoad); }; - }, [anchor, relays, disable]); + }, [anchor, user, relays, disable]); // Render a
element and attach the zapRef to it return
; diff --git a/src/components/feeds/messages/CommunityMessage.js b/src/components/feeds/messages/CommunityMessage.js index 027ee1b..0e6f5f0 100644 --- a/src/components/feeds/messages/CommunityMessage.js +++ b/src/components/feeds/messages/CommunityMessage.js @@ -10,7 +10,6 @@ import NostrIcon from '../../../../public/images/nostr.png'; import Image from 'next/image'; import { nip19 } from 'nostr-tools'; import ZapThreadsWrapper from '@/components/ZapThreadsWrapper'; -import useWindowWidth from '@/hooks/useWindowWidth'; const StackerNewsIconComponent = () => ( @@ -38,13 +37,19 @@ const headerTemplate = (options, windowWidth, platform, id) => { const CommunityMessage = ({ message, searchQuery, windowWidth, platform }) => { const [npub, setNpub] = useState(null); + const [nsec, setNsec] = useState(null); const [collapsed, setCollapsed] = useState(true); const { data: session } = useSession(); - const isMobileView = windowWidth <= 768; useEffect(() => { - if (session?.user?.pubkey) { - setNpub(nip19.npubEncode(session.user.pubkey)); + if (session?.user?.pubkey || session?.user?.privkey) { + let privkeyBuffer; + if (session.user.privkey) { + privkeyBuffer = Buffer.from(session.user.privkey, 'hex'); + setNsec(nip19.nsecEncode(privkeyBuffer)); + } else { + setNpub(nip19.npubEncode(session.user.pubkey)); + } } }, [session]); @@ -83,12 +88,14 @@ const CommunityMessage = ({ message, searchQuery, windowWidth, platform }) => { className="w-full" >
- + {nsec || npub ? ( + + ) : null}
) : ( diff --git a/src/pages/details/[slug]/index.js b/src/pages/details/[slug]/index.js index 1c5596d..e430588 100644 --- a/src/pages/details/[slug]/index.js +++ b/src/pages/details/[slug]/index.js @@ -21,6 +21,8 @@ const Details = () => { const [authorView, setAuthorView] = useState(false); const [loading, setLoading] = useState(true); const [lessons, setLessons] = useState([]); + const [npub, setNpub] = useState(null); + const [nsec, setNsec] = useState(null); const { data: session, update } = useSession(); const { ndk } = useNDKContext(); const { decryptContent } = useDecryptContent(); @@ -68,6 +70,15 @@ const Details = () => { } }, [author, event, fetchAuthor]); + useEffect(() => { + if (session?.user?.privkey) { + const privkeyBuffer = Buffer.from(session.user.privkey, 'hex'); + setNsec(nip19.nsecEncode(privkeyBuffer)); + } else if (session?.user?.pubkey) { + setNpub(nip19.npubEncode(session.user.pubkey)); + } + }, [session]); + useEffect(() => { const fetchAndProcessEvent = async () => { if (!router.isReady || !router.query.slug) return;