From 0f16c3e0fb2d11b3421080c52883009cc574e358 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Mon, 14 Jul 2025 13:25:27 -0400 Subject: [PATCH] feat(nostr): Added npub to Profile URL to lookup any Nostr Profile --- src/components/app-body/index.js | 2 +- .../nostr/content-creators/content-card.js | 17 +++++++++++------ .../app-body/nostr/nostr-read/index.js | 7 +++++-- .../app-body/nostr/nostr-read/profile-read.js | 14 ++++++++++---- .../app-body/nostr/nostr-read/public-read.js | 14 +++++++++----- src/components/nav-menu/index.js | 4 ++-- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/components/app-body/index.js b/src/components/app-body/index.js index 21c34bf..6aa02a9 100644 --- a/src/components/app-body/index.js +++ b/src/components/app-body/index.js @@ -49,7 +49,7 @@ function AppBody (props) { } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/src/components/app-body/nostr/content-creators/content-card.js b/src/components/app-body/nostr/content-creators/content-card.js index 4e54310..5a592d8 100644 --- a/src/components/app-body/nostr/content-creators/content-card.js +++ b/src/components/app-body/nostr/content-creators/content-card.js @@ -45,26 +45,31 @@ function ContentCard (props) { } }, [loaded, creator]) + const goToProfile = () => { + const profileUrl = `${window.location.origin}/nostr-read/${creator.npub}` + window.open(profileUrl, '_blank') + } + return ( <> {/* Desktop Layout - Horizontal */} -
+
{new Date(creator.createdAt).toLocaleString()}
-
+
{/* Profile Picture */} -
+
{/* Creator Info */}
-
{profile.name}
+
{profile.name}

{profile.about}

{/* Nostr Public Key */} @@ -126,12 +131,12 @@ function ContentCard (props) {
{/* Profile Picture */}
- +
{/* Creator Info */}
-
{profile.name}
+
{profile.name}

{profile.about}

{/* Nostr Public Key */} diff --git a/src/components/app-body/nostr/nostr-read/index.js b/src/components/app-body/nostr/nostr-read/index.js index 9b53889..1cc910b 100644 --- a/src/components/app-body/nostr/nostr-read/index.js +++ b/src/components/app-body/nostr/nostr-read/index.js @@ -7,14 +7,17 @@ import React, { useState } from 'react' import { Container } from 'react-bootstrap' import ProfileRead from './profile-read.js' import PublicRead from './public-read.js' +import { useParams } from 'react-router-dom' function NostrRead (props) { const [profile, setProfile] = useState(false) + const { npub } = useParams() + console.log('npub', npub) return ( <> - - + + ) diff --git a/src/components/app-body/nostr/nostr-read/profile-read.js b/src/components/app-body/nostr/nostr-read/profile-read.js index a332658..b3d8a02 100644 --- a/src/components/app-body/nostr/nostr-read/profile-read.js +++ b/src/components/app-body/nostr/nostr-read/profile-read.js @@ -9,21 +9,27 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faUser } from '@fortawesome/free-solid-svg-icons' import NostrFormat from '../nostr-format' import { RelayPool } from 'nostr' +import * as nip19 from 'nostr-tools/nip19' function ProfileRead (props) { + const { npub } = props const { bchWalletState } = props.appData + console.log('npub prop', npub) const { setProfile } = props const [post, setPost] = useState({}) const [loaded, setLoaded] = useState(false) useEffect(() => { const start = () => { - const { nostrKeyPair } = bchWalletState + const pubHexData = nip19.decode(npub) + const pubHex = pubHexData.data + console.log('pubhex', pubHex) const psf = 'wss://nostr-relay.psfoundation.info' const pool = RelayPool([psf]) pool.on('open', relay => { - relay.subscribe('subid', { limit: 5, kinds: [0], authors: [nostrKeyPair.pubHex] }) + relay.subscribe('subid', { limit: 5, kinds: [0], authors: [pubHex] }) + setLoaded(true) }) pool.on('eose', relay => { @@ -42,10 +48,10 @@ function ProfileRead (props) { setLoaded(true) } - if (!loaded) { + if (!loaded && npub) { start() } - }, [bchWalletState, loaded, setProfile]) + }, [bchWalletState, loaded, setProfile, npub]) return ( diff --git a/src/components/app-body/nostr/nostr-read/public-read.js b/src/components/app-body/nostr/nostr-read/public-read.js index 24204fc..c3c3d1c 100644 --- a/src/components/app-body/nostr/nostr-read/public-read.js +++ b/src/components/app-body/nostr/nostr-read/public-read.js @@ -8,8 +8,10 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faUser } from '@fortawesome/free-solid-svg-icons' import NostrFormat from '../nostr-format' import { RelayPool } from 'nostr' +import * as nip19 from 'nostr-tools/nip19' function PublicRead (props) { + const { npub } = props const { bchWalletState } = props.appData const [posts, setPosts] = useState([]) const [loaded, setLoaded] = useState(false) @@ -17,13 +19,15 @@ function PublicRead (props) { useEffect(() => { // Get Last post from a author const start = () => { - const { nostrKeyPair } = bchWalletState - + const pubHexData = nip19.decode(npub) + const pubHex = pubHexData.data + console.log('pubhex', pubHex) const psf = 'wss://nostr-relay.psfoundation.info' const pool = RelayPool([psf]) pool.on('open', relay => { - relay.subscribe('subid', { limit: 5, kinds: [1], authors: [nostrKeyPair.pubHex] }) + relay.subscribe('subid', { limit: 5, kinds: [1], authors: [pubHex] }) + setLoaded(true) }) pool.on('eose', relay => { @@ -38,10 +42,10 @@ function PublicRead (props) { }) } - if (!loaded) { + if (!loaded && npub) { start() } - }, [bchWalletState, loaded]) + }, [bchWalletState, loaded, npub]) return ( diff --git a/src/components/nav-menu/index.js b/src/components/nav-menu/index.js index a957ba3..0737add 100644 --- a/src/components/nav-menu/index.js +++ b/src/components/nav-menu/index.js @@ -15,7 +15,7 @@ import Logo from './psf-logo.png' function NavMenu (props) { // Get the current path - const { currentPath } = props.appData + const { currentPath, bchWalletState } = props.appData // Navbar state const [expanded, setExpanded] = useState(false) @@ -72,7 +72,7 @@ function NavMenu (props) { Nostr Profile