Compare commits

..
9 Commits
9 changed files with 258 additions and 40 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} />} />
@@ -6,12 +6,13 @@ import React, { useState, useEffect } from 'react'
import { Card } from 'react-bootstrap'
import Jdenticon from '@chris.troutner/react-jdenticon'
import CopyOnClick from '../../bch-wallet/copy-on-click.js'
import FollowBtn from './follow-btn.js'
import { RelayPool } from 'nostr'
function ContentCard (props) {
const [profile, setProfile] = useState([])
const [loaded, setLoaded] = useState(false)
const { creator } = props
const { creator, followList, refreshFollowList } = props
useEffect(() => {
const loadProfile = async () => {
@@ -44,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 */}
@@ -103,13 +109,15 @@ function ContentCard (props) {
{/* Action Buttons */}
<div className='flex-shrink-0 d-flex flex-column gap-2'>
<button
className='btn btn-outline-danger btn-sm rounded-pill px-3'
style={{ fontSize: '0.875rem', minWidth: '100px' }}
>
<i className='bi bi-person-plus me-1' />
Follow
</button>
<FollowBtn
creator={creator}
appData={props.appData}
creatorProfile={profile}
followList={followList}
refreshFollowList={refreshFollowList}
/>
<button
className='btn btn-primary btn-sm rounded-pill px-3'
style={{ fontSize: '0.875rem', minWidth: '100px' }}
@@ -117,6 +125,8 @@ function ContentCard (props) {
<i className='bi bi-chat-dots me-1' />
Message
</button>
<small>Followers: {creator.followerCnt}</small>
</div>
</div>
@@ -124,12 +134,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 */}
@@ -169,13 +179,13 @@ function ContentCard (props) {
{/* Action Buttons */}
<div className='d-flex gap-2'>
<button
className='btn btn-outline-danger btn-sm rounded-pill px-3'
style={{ fontSize: '0.875rem' }}
>
<i className='bi bi-person-plus me-1' />
Follow
</button>
<FollowBtn
creator={creator}
appData={props.appData}
creatorProfile={profile}
followList={followList}
refreshFollowList={refreshFollowList}
/>
<button
className='btn btn-primary btn-sm rounded-pill px-3'
style={{ fontSize: '0.875rem' }}
@@ -1,15 +1,51 @@
import React, { useState, useEffect } from 'react'
import { Container, Spinner } from 'react-bootstrap'
import React, { useState, useEffect, useCallback } from 'react'
import { Container, Spinner, Form } from 'react-bootstrap'
import axios from 'axios'
// Local libraries
import config from '../../../../config'
import ContentCard from './content-card'
import { RelayPool } from 'nostr'
// Global variables and constants
const SERVER = config.dexServer
function ContentCreators (props) {
const [creators, setCreators] = useState([])
const [loaded, setLoaded] = useState(false)
const { appData } = props
const [followList, setFollowList] = useState([])
const getFollowList = useCallback(async () => {
const list = await new Promise((resolve, reject) => {
let list = []
const { nostrKeyPair } = appData.bchWalletState
const psf = 'wss://nostr-relay.psfoundation.info'
const pool = RelayPool([psf])
pool.on('open', relay => {
relay.subscribe('subid', { limit: 1, kinds: [3], authors: [nostrKeyPair.pubHex] })
})
pool.on('eose', relay => {
console.log('Closing Relay')
relay.close()
/** This ensures to return an empty array if no records are found!
* Applies for new users that don't have a follow list
*/
resolve(list)
})
pool.on('event', (relay, subId, ev) => {
console.log('Received event:', ev)
list = ev.tags
resolve(list)
})
})
console.log('Follow List', list)
setFollowList(list)
}, [appData])
useEffect(() => {
const loadCreators = async () => {
@@ -25,18 +61,28 @@ function ContentCreators (props) {
if (!loaded) {
loadCreators()
getFollowList()
}
}, [loaded])
}, [loaded, followList, getFollowList])
return (
<Container className='mt-4 mb-5'>
<div className='mb-4'>
<h2 className='text-center mb-3'>Content Creators</h2>
<p className='text-center text-muted'>
Discover amazing content creators in the Bitcoin Cash ecosystem
Discover amazing creators tokenizing their content.
</p>
</div>
<div className='mb-4'>
<h3>Filters</h3>
<Form.Select>
<option>Most Followers</option>
<option>Most Tokens</option>
<option>Most Likes</option>
</Form.Select>
</div>
{!loaded && (
<div className='text-center text-muted py-5 bg-light rounded-4 shadow-sm'>
<Spinner animation='border' />
@@ -47,7 +93,13 @@ function ContentCreators (props) {
{loaded && (
<div>
{creators.map((creator, i) => (
<ContentCard key={`creator-key${i}`} creator={creator} appData={props.appData} />
<ContentCard
key={`creator-key${i}`}
creator={creator}
appData={props.appData}
followList={followList}
refreshFollowList={getFollowList}
/>
))}
</div>
)}
@@ -0,0 +1,142 @@
import React, { useState, useEffect } from 'react'
import { Spinner } from 'react-bootstrap'
import { finalizeEvent } from 'nostr-tools/pure'
import { Relay } from 'nostr-tools/relay'
import { hexToBytes } from '@noble/hashes/utils'
function FollowBtn (props) {
const [onFetch, setOnFetch] = useState(false)
const [isFollowing, setIsFollowing] = useState(false)
const { creator, appData, creatorProfile, followList, refreshFollowList } = props
useEffect(() => {
const isFollowing = followList.find(item => item[1] === creator.pubkey)
setIsFollowing(isFollowing)
}, [followList, creator.pubkey])
// Add creator to the follow list
const handleFollow = async () => {
try {
setOnFetch(true)
// Get current follow list
const currentList = followList
console.log('currentList', currentList)
// find if creator is in the list
const existing = currentList.find(item => item[1] === creator.pubkey)
if (!existing) {
const creatorName = creatorProfile.name || ''
// add creator to the list
currentList.push(['p', creator.pubkey, 'wss://nostr-relay.psfoundation.info', creatorName])
await submitFollowList(currentList)
await refreshFollowList()
} else {
console.log('Already Followed')
}
setOnFetch(false)
} catch (error) {
console.warn(error)
setOnFetch(false)
}
}
// Add creator to the follow list
const handleUnfollow = async () => {
try {
setOnFetch(true)
// Get current follow list
const currentList = followList
console.log('currentList', currentList)
// find if creator is in the list
const existing = currentList.find(item => item[1] === creator.pubkey)
if (existing) {
// remove creator from the list
currentList.splice(currentList.indexOf(existing), 1)
await submitFollowList(currentList)
await refreshFollowList()
}
setOnFetch(false)
} catch (error) {
console.warn(error)
setOnFetch(false)
}
}
const submitFollowList = async (newList) => {
try {
const { nostrKeyPair } = appData.bchWalletState
// Convert private key to binary
const privateKeyBin = hexToBytes(nostrKeyPair.privHex)
// Relay list
const psf = 'wss://nostr-relay.psfoundation.info'
// Generate a post.
const eventTemplate = {
kind: 3,
created_at: Math.floor(Date.now() / 1000),
tags: newList,
content: ''
}
console.log(`eventTemplate: ${JSON.stringify(eventTemplate, null, 2)}`)
// Sign the post
const signedEvent = finalizeEvent(eventTemplate, privateKeyBin)
console.log('signedEvent: ', signedEvent)
// Connect to a relay.
const relay = await Relay.connect(psf)
console.log(`connected to ${relay.url}`)
// Publish the message to the relay.
const result = await relay.publish(signedEvent)
console.log('result: ', result)
// Close the connection to the relay.
relay.close()
setTimeout(() => {
setOnFetch(false)
}, 1000)
} catch (error) {
console.warn(error)
setOnFetch(false)
}
}
return (
<>
{onFetch && (
<div className='d-flex justify-content-center'>
<Spinner animation='border' />
</div>
)}
{!onFetch && !isFollowing && (
<button
className='btn btn-outline-danger btn-sm rounded-pill px-3'
style={{ fontSize: '0.875rem', minWidth: '100px' }}
onClick={handleFollow}
>
<i className='bi bi-person-plus me-1' />
Follow
</button>
)}
{!onFetch && isFollowing && (
<button
className='btn btn-outline-danger btn-sm rounded-pill px-3'
style={{ fontSize: '0.875rem', minWidth: '100px' }}
onClick={handleUnfollow}
>
<i className='bi bi-person-plus me-1' />
Unfollow
</button>
)}
</>
)
}
export default FollowBtn
@@ -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
+1
View File
@@ -15,6 +15,7 @@ const config = {
radicleUrl: 'https://app.radicle.network/seeds/maple.radicle.garden/rad:git:hnrkd5cjwwb5tzx37hq9uqm5ubon7ee468xcy/remotes/hyyycncbn9qzqmobnhjq9rry6t4mbjiadzjoyhaknzxjcz3cxkpfpc',
dexServer: 'https://dex-api.fullstack.cash',
//dexServer: 'http://localhost:5700',
nostrTopic: 'bch-dex-test-topic-02',
nostrRelay: 'wss://nostr-relay.psfoundation.info'