Compare commits

...
2 Commits
Author SHA1 Message Date
Chris Troutner 98603d3fc5 Merge pull request #30 from Permissionless-Software-Foundation/dh-profile-url
feat(nostr): Added npub to Profile URL to lookup any Nostr Profile
2025-07-14 17:47:46 -07:00
Daniel Gonzalez 0f16c3e0fb feat(nostr): Added npub to Profile URL to lookup any Nostr Profile 2025-07-14 13:25:27 -04:00
6 changed files with 38 additions and 20 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ function AppBody (props) {
<Route path='/sign' element={<SignMessage appData={appData} />} />
<Route path='/configuration' element={<ServerSelectView appData={appData} />} />
<Route path='/nostr-post' element={<NostrPost appData={appData} />} />
<Route path='/nostr-read' element={<NostrRead appData={appData} />} />
<Route path='/nostr-read/:npub' element={<NostrRead appData={appData} />} />
<Route path='/global-feed' element={<GlobalFeed appData={appData} />} />
<Route path='/content-creators' element={<ContentCreators appData={appData} />} />
<Route path='/user-data/:tokenId' element={<UserDataReview appData={appData} />} />
@@ -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 (
<>
<Card className='mb-4 bg-light rounded-4 shadow-sm border-0'>
<Card.Body className='p-4'>
{/* Desktop Layout - Horizontal */}
<div className='d-flex justify-content-end mb-2'>
<div className='d-flex justify-content-end mb-2' onClick={goToProfile}>
<small className='text-muted'>
{new Date(creator.createdAt).toLocaleString()}
</small>
</div>
<div className='d-none d-md-flex align-items-center gap-4'>
<div className='d-none d-md-flex align-items-center gap-4 cursor-pointer'>
{/* Profile Picture */}
<div className='flex-shrink-0'>
<div className='flex-shrink-0' onClick={goToProfile}>
<Jdenticon size='140' value={creator.npub} />
</div>
{/* Creator Info */}
<div className='flex-grow-1'>
<h5 className='mb-2 fw-bold'>{profile.name}</h5>
<h5 className='mb-2 fw-bold cursor-pointer' onClick={goToProfile}>{profile.name}</h5>
<p className='text-muted medium mb-3'>{profile.about}</p>
{/* Nostr Public Key */}
@@ -126,12 +131,12 @@ function ContentCard (props) {
<div className='d-flex d-md-none flex-column align-items-center text-center'>
{/* Profile Picture */}
<div className='mb-3'>
<Jdenticon size='100' value={creator.npub} />
<Jdenticon size='100' value={creator.npub} onClick={goToProfile} />
</div>
{/* Creator Info */}
<div className='w-100 mb-3'>
<h5 className='mb-2 fw-bold'>{profile.name}</h5>
<h5 className='mb-2 fw-bold' onClick={goToProfile}>{profile.name}</h5>
<p className='text-muted small mb-3'>{profile.about}</p>
{/* Nostr Public Key */}
@@ -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 (
<>
<Container>
<ProfileRead {...props} setProfile={setProfile} />
<PublicRead {...props} profile={profile} />
<ProfileRead {...props} setProfile={setProfile} npub={npub} />
<PublicRead {...props} profile={profile} npub={npub} />
</Container>
</>
)
@@ -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 (
<Container>
@@ -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 (
<Container className='mt-4'>
+2 -2
View File
@@ -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) {
</NavLink>
<NavLink
className={currentPath === '/nostr-read' ? 'nav-link-active' : 'nav-link-inactive'}
to='/nostr-read'
to={`/nostr-read/${bchWalletState?.nostrKeyPair?.npub}`}
onClick={handleClickEvent}
>
Nostr Profile