mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex-taker-v2.git
synced 2026-09-21 16:52:01 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98603d3fc5 | ||
|
|
0f16c3e0fb | ||
|
|
43b35a3553 | ||
|
|
862377b929 | ||
|
|
02e800ff6a | ||
|
|
7e1b75f965 | ||
|
|
990e41e8f6 | ||
|
|
9d35d80bcf | ||
|
|
907bb7e468 | ||
|
|
7eb5ff7821 | ||
|
|
8a982d2ef2 | ||
|
|
24bb18c77c | ||
|
|
913745ba9f | ||
|
|
f24c199dd6 | ||
|
|
e05948aa32 |
@@ -26,6 +26,7 @@ import ServerSelectView from './configuration/select-server-view'
|
|||||||
import NostrPost from './nostr/nostr-post/index.js'
|
import NostrPost from './nostr/nostr-post/index.js'
|
||||||
import NostrRead from './nostr/nostr-read/index.js'
|
import NostrRead from './nostr/nostr-read/index.js'
|
||||||
import GlobalFeed from './nostr/global-feed/index.js'
|
import GlobalFeed from './nostr/global-feed/index.js'
|
||||||
|
import ContentCreators from './nostr/content-creators/index.js'
|
||||||
import UserDataReview from './user-data-review'
|
import UserDataReview from './user-data-review'
|
||||||
import Offers from './offers'
|
import Offers from './offers'
|
||||||
function AppBody (props) {
|
function AppBody (props) {
|
||||||
@@ -48,9 +49,10 @@ function AppBody (props) {
|
|||||||
<Route path='/sign' element={<SignMessage appData={appData} />} />
|
<Route path='/sign' element={<SignMessage appData={appData} />} />
|
||||||
<Route path='/configuration' element={<ServerSelectView appData={appData} />} />
|
<Route path='/configuration' element={<ServerSelectView appData={appData} />} />
|
||||||
<Route path='/nostr-post' element={<NostrPost 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='/global-feed' element={<GlobalFeed appData={appData} />} />
|
||||||
<Route path='/user-data/:cid' element={<UserDataReview appData={appData} />} />
|
<Route path='/content-creators' element={<ContentCreators appData={appData} />} />
|
||||||
|
<Route path='/user-data/:tokenId' element={<UserDataReview appData={appData} />} />
|
||||||
<Route path='/offers' element={<Offers appData={appData} />} />
|
<Route path='/offers' element={<Offers appData={appData} />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
{/** Show in all paths except the servers view */}
|
{/** Show in all paths except the servers view */}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ function InfoButton (props) {
|
|||||||
<Col xs={4}><b>User Data</b>:</Col>
|
<Col xs={4}><b>User Data</b>:</Col>
|
||||||
<Col xs={8}>
|
<Col xs={8}>
|
||||||
<a
|
<a
|
||||||
href={`/user-data/${mutableDataCid}`}
|
href={`/user-data/${props.token.tokenId}`}
|
||||||
target='_blank'
|
target='_blank'
|
||||||
rel='noopener noreferrer'
|
rel='noopener noreferrer'
|
||||||
className='btn btn-link p-0'
|
className='btn btn-link p-0'
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
/**
|
||||||
|
* Content creators card
|
||||||
|
*/
|
||||||
|
|
||||||
|
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, followList, refreshFollowList } = props
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadProfile = async () => {
|
||||||
|
const psf = 'wss://nostr-relay.psfoundation.info'
|
||||||
|
|
||||||
|
const pool = RelayPool([psf])
|
||||||
|
pool.on('open', relay => {
|
||||||
|
relay.subscribe('subid', { limit: 5, kinds: [0], authors: [creator.pubkey] })
|
||||||
|
})
|
||||||
|
|
||||||
|
pool.on('eose', relay => {
|
||||||
|
console.log('Closing Relay')
|
||||||
|
relay.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
pool.on('event', (relay, subId, ev) => {
|
||||||
|
try {
|
||||||
|
const profile = JSON.parse(ev.content)
|
||||||
|
console.log('profile', profile)
|
||||||
|
setProfile(profile)
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error parsing profile', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setLoaded(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!loaded && creator.npub) {
|
||||||
|
loadProfile()
|
||||||
|
}
|
||||||
|
}, [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' 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 cursor-pointer'>
|
||||||
|
{/* Profile Picture */}
|
||||||
|
<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 cursor-pointer' onClick={goToProfile}>{profile.name}</h5>
|
||||||
|
<p className='text-muted medium mb-3'>{profile.about}</p>
|
||||||
|
|
||||||
|
{/* Nostr Public Key */}
|
||||||
|
<div className='mb-2'>
|
||||||
|
<div className='d-flex align-items-center gap-2 mb-1'>
|
||||||
|
<small className='text-muted fw-semibold'>Nostr Public Key:</small>
|
||||||
|
</div>
|
||||||
|
<div className='d-flex align-items-center gap-2'>
|
||||||
|
<div className='text-break small text-secondary'>
|
||||||
|
{creator.npub}
|
||||||
|
</div>
|
||||||
|
<CopyOnClick
|
||||||
|
walletProp='npub'
|
||||||
|
appData={props.appData}
|
||||||
|
value={creator.npub}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* BCH Address */}
|
||||||
|
<div className='mb-3'>
|
||||||
|
<div className='d-flex align-items-center gap-2 mb-1'>
|
||||||
|
<small className='text-muted fw-semibold'>BCH Address:</small>
|
||||||
|
</div>
|
||||||
|
<div className='d-flex align-items-center gap-2'>
|
||||||
|
<div className='text-break small text-secondary'>
|
||||||
|
{creator.bchAddr}
|
||||||
|
</div>
|
||||||
|
<CopyOnClick
|
||||||
|
walletProp='bchAddress'
|
||||||
|
appData={props.appData}
|
||||||
|
value={creator.bchAddr}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Action Buttons */}
|
||||||
|
<div className='flex-shrink-0 d-flex flex-column gap-2'>
|
||||||
|
<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' }}
|
||||||
|
>
|
||||||
|
<i className='bi bi-chat-dots me-1' />
|
||||||
|
Message
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile Layout - Vertical */}
|
||||||
|
<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} onClick={goToProfile} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Creator Info */}
|
||||||
|
<div className='w-100 mb-3'>
|
||||||
|
<h5 className='mb-2 fw-bold' onClick={goToProfile}>{profile.name}</h5>
|
||||||
|
<p className='text-muted small mb-3'>{profile.about}</p>
|
||||||
|
|
||||||
|
{/* Nostr Public Key */}
|
||||||
|
<div className='mb-3'>
|
||||||
|
<div className='mb-1'>
|
||||||
|
<small className='text-muted fw-semibold'>Nostr Public Key:</small>
|
||||||
|
</div>
|
||||||
|
<div className='d-flex align-items-center justify-content-center gap-2'>
|
||||||
|
<div className='text-break small text-secondary' style={{ maxWidth: '200px' }}>
|
||||||
|
{creator.npub}
|
||||||
|
</div>
|
||||||
|
<CopyOnClick
|
||||||
|
walletProp='npub'
|
||||||
|
appData={props.appData}
|
||||||
|
value={creator.npub}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* BCH Address */}
|
||||||
|
<div className='mb-3'>
|
||||||
|
<div className='mb-1'>
|
||||||
|
<small className='text-muted fw-semibold'>BCH Address:</small>
|
||||||
|
</div>
|
||||||
|
<div className='d-flex align-items-center justify-content-center gap-2'>
|
||||||
|
<div className='text-break small text-secondary' style={{ maxWidth: '200px' }}>
|
||||||
|
{creator.bchAddr}
|
||||||
|
</div>
|
||||||
|
<CopyOnClick
|
||||||
|
walletProp='bchAddress'
|
||||||
|
appData={props.appData}
|
||||||
|
value={creator.bchAddr}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Action Buttons */}
|
||||||
|
<div className='d-flex gap-2'>
|
||||||
|
<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' }}
|
||||||
|
>
|
||||||
|
<i className='bi bi-chat-dots me-1' />
|
||||||
|
Message
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card.Body>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ContentCard
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import React, { useState, useEffect, useCallback } from 'react'
|
||||||
|
import { Container, Spinner } 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 () => {
|
||||||
|
try {
|
||||||
|
const creators = await axios.get(`${SERVER}/sm/list/all/0`)
|
||||||
|
console.log(creators.data)
|
||||||
|
setCreators(creators.data)
|
||||||
|
setLoaded(true)
|
||||||
|
} catch (error) {
|
||||||
|
setLoaded(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!loaded) {
|
||||||
|
loadCreators()
|
||||||
|
getFollowList()
|
||||||
|
}
|
||||||
|
}, [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
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!loaded && (
|
||||||
|
<div className='text-center text-muted py-5 bg-light rounded-4 shadow-sm'>
|
||||||
|
<Spinner animation='border' />
|
||||||
|
<div className='mt-3'>Loading content creators...</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loaded && (
|
||||||
|
<div>
|
||||||
|
{creators.map((creator, i) => (
|
||||||
|
<ContentCard
|
||||||
|
key={`creator-key${i}`}
|
||||||
|
creator={creator}
|
||||||
|
appData={props.appData}
|
||||||
|
followList={followList}
|
||||||
|
refreshFollowList={getFollowList}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loaded && creators.length === 0 && (
|
||||||
|
<div className='text-center text-muted py-5 bg-light rounded-4 shadow-sm'>
|
||||||
|
<i className='bi bi-people-fill fs-1 mb-3 d-block opacity-50' />
|
||||||
|
<div>No content creators found</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ContentCreators
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { Container } from 'react-bootstrap'
|
||||||
|
import ContentCreatorsList from './content-creators-list.js'
|
||||||
|
|
||||||
|
function ContentCreators (props) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Container>
|
||||||
|
<ContentCreatorsList {...props} />
|
||||||
|
</Container>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ContentCreators
|
||||||
@@ -16,7 +16,12 @@ function ProfilePost (props) {
|
|||||||
const { bchWalletState } = props.appData
|
const { bchWalletState } = props.appData
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
name: '',
|
name: '',
|
||||||
about: ''
|
about: '',
|
||||||
|
picture: '',
|
||||||
|
display_name: '',
|
||||||
|
website: '',
|
||||||
|
banner: '',
|
||||||
|
bot: false
|
||||||
})
|
})
|
||||||
|
|
||||||
const [errorMsg, setErrorMsg] = useState('')
|
const [errorMsg, setErrorMsg] = useState('')
|
||||||
@@ -90,7 +95,12 @@ function ProfilePost (props) {
|
|||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormData({
|
setFormData({
|
||||||
name: '',
|
name: '',
|
||||||
about: ''
|
about: '',
|
||||||
|
picture: '',
|
||||||
|
display_name: '',
|
||||||
|
website: '',
|
||||||
|
banner: '',
|
||||||
|
bot: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +147,67 @@ function ProfilePost (props) {
|
|||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
|
||||||
|
<Form.Group className='mb-3'>
|
||||||
|
<Form.Label>Profile Picture URL</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
type='url'
|
||||||
|
placeholder='Enter URL to your profile picture'
|
||||||
|
name='picture'
|
||||||
|
value={formData.picture}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
|
||||||
|
<Form.Group className='mb-3'>
|
||||||
|
<Form.Label>Display Name</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
type='text'
|
||||||
|
placeholder='Enter your display name'
|
||||||
|
name='display_name'
|
||||||
|
value={formData.display_name}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
|
||||||
|
<Form.Group className='mb-3'>
|
||||||
|
<Form.Label>Website</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
type='url'
|
||||||
|
placeholder='Enter your website URL'
|
||||||
|
name='website'
|
||||||
|
value={formData.website}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
|
||||||
|
<Form.Group className='mb-3'>
|
||||||
|
<Form.Label>Banner URL</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
type='url'
|
||||||
|
placeholder='Enter URL to your banner picture (1024x768 pixels)'
|
||||||
|
name='banner'
|
||||||
|
value={formData.banner}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
|
||||||
|
<Form.Group className='mb-3'>
|
||||||
|
<Form.Check
|
||||||
|
type='checkbox'
|
||||||
|
label='This account is for a bot'
|
||||||
|
name='bot'
|
||||||
|
checked={formData.bot}
|
||||||
|
onChange={(e) => {
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
bot: e.target.checked
|
||||||
|
})
|
||||||
|
setSuccessMsg('')
|
||||||
|
setErrorMsg('')
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
|
||||||
<div className='d-flex justify-content-center'>
|
<div className='d-flex justify-content-center'>
|
||||||
{!onFetch && (
|
{!onFetch && (
|
||||||
<Button variant='primary' type='submit' disabled={onFetch}>
|
<Button variant='primary' type='submit' disabled={onFetch}>
|
||||||
|
|||||||
@@ -47,11 +47,14 @@ function PublicPost (props) {
|
|||||||
// Relay list
|
// Relay list
|
||||||
const psf = 'wss://nostr-relay.psfoundation.info'
|
const psf = 'wss://nostr-relay.psfoundation.info'
|
||||||
|
|
||||||
|
// BCH address of the user.
|
||||||
|
const bchAddr = bchWalletState.address
|
||||||
|
|
||||||
// Generate a post.
|
// Generate a post.
|
||||||
const eventTemplate = {
|
const eventTemplate = {
|
||||||
kind: 1,
|
kind: 1,
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
tags: [['t', 'slpdex-socialmedia']],
|
tags: [['t', 'slpdex-socialmedia'], ['u', bchAddr]],
|
||||||
content: formData.content
|
content: formData.content
|
||||||
}
|
}
|
||||||
console.log(`eventTemplate: ${JSON.stringify(eventTemplate, null, 2)}`)
|
console.log(`eventTemplate: ${JSON.stringify(eventTemplate, null, 2)}`)
|
||||||
|
|||||||
@@ -7,14 +7,17 @@ import React, { useState } from 'react'
|
|||||||
import { Container } from 'react-bootstrap'
|
import { Container } from 'react-bootstrap'
|
||||||
import ProfileRead from './profile-read.js'
|
import ProfileRead from './profile-read.js'
|
||||||
import PublicRead from './public-read.js'
|
import PublicRead from './public-read.js'
|
||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
|
||||||
function NostrRead (props) {
|
function NostrRead (props) {
|
||||||
const [profile, setProfile] = useState(false)
|
const [profile, setProfile] = useState(false)
|
||||||
|
const { npub } = useParams()
|
||||||
|
console.log('npub', npub)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Container>
|
<Container>
|
||||||
<ProfileRead {...props} setProfile={setProfile} />
|
<ProfileRead {...props} setProfile={setProfile} npub={npub} />
|
||||||
<PublicRead {...props} profile={profile} />
|
<PublicRead {...props} profile={profile} npub={npub} />
|
||||||
</Container>
|
</Container>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,21 +9,27 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|||||||
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
||||||
import NostrFormat from '../nostr-format'
|
import NostrFormat from '../nostr-format'
|
||||||
import { RelayPool } from 'nostr'
|
import { RelayPool } from 'nostr'
|
||||||
|
import * as nip19 from 'nostr-tools/nip19'
|
||||||
|
|
||||||
function ProfileRead (props) {
|
function ProfileRead (props) {
|
||||||
|
const { npub } = props
|
||||||
const { bchWalletState } = props.appData
|
const { bchWalletState } = props.appData
|
||||||
|
console.log('npub prop', npub)
|
||||||
const { setProfile } = props
|
const { setProfile } = props
|
||||||
const [post, setPost] = useState({})
|
const [post, setPost] = useState({})
|
||||||
const [loaded, setLoaded] = useState(false)
|
const [loaded, setLoaded] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const start = () => {
|
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 psf = 'wss://nostr-relay.psfoundation.info'
|
||||||
|
|
||||||
const pool = RelayPool([psf])
|
const pool = RelayPool([psf])
|
||||||
pool.on('open', relay => {
|
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 => {
|
pool.on('eose', relay => {
|
||||||
@@ -34,6 +40,7 @@ function ProfileRead (props) {
|
|||||||
pool.on('event', (relay, subId, ev) => {
|
pool.on('event', (relay, subId, ev) => {
|
||||||
console.log('Received event:', ev)
|
console.log('Received event:', ev)
|
||||||
const profile = JSON.parse(ev.content)
|
const profile = JSON.parse(ev.content)
|
||||||
|
console.log('Profile:', profile)
|
||||||
setPost(profile)
|
setPost(profile)
|
||||||
setProfile(profile)
|
setProfile(profile)
|
||||||
})
|
})
|
||||||
@@ -41,10 +48,10 @@ function ProfileRead (props) {
|
|||||||
setLoaded(true)
|
setLoaded(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loaded) {
|
if (!loaded && npub) {
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
}, [bchWalletState, loaded, setProfile])
|
}, [bchWalletState, loaded, setProfile, npub])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|||||||
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
||||||
import NostrFormat from '../nostr-format'
|
import NostrFormat from '../nostr-format'
|
||||||
import { RelayPool } from 'nostr'
|
import { RelayPool } from 'nostr'
|
||||||
|
import * as nip19 from 'nostr-tools/nip19'
|
||||||
|
|
||||||
function PublicRead (props) {
|
function PublicRead (props) {
|
||||||
|
const { npub } = props
|
||||||
const { bchWalletState } = props.appData
|
const { bchWalletState } = props.appData
|
||||||
const [posts, setPosts] = useState([])
|
const [posts, setPosts] = useState([])
|
||||||
const [loaded, setLoaded] = useState(false)
|
const [loaded, setLoaded] = useState(false)
|
||||||
@@ -17,13 +19,15 @@ function PublicRead (props) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Get Last post from a author
|
// Get Last post from a author
|
||||||
const start = () => {
|
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 psf = 'wss://nostr-relay.psfoundation.info'
|
||||||
|
|
||||||
const pool = RelayPool([psf])
|
const pool = RelayPool([psf])
|
||||||
pool.on('open', relay => {
|
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 => {
|
pool.on('eose', relay => {
|
||||||
@@ -38,10 +42,10 @@ function PublicRead (props) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loaded) {
|
if (!loaded && npub) {
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
}, [bchWalletState, loaded])
|
}, [bchWalletState, loaded, npub])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container className='mt-4'>
|
<Container className='mt-4'>
|
||||||
|
|||||||
@@ -5,25 +5,34 @@
|
|||||||
// Global npm libraries
|
// Global npm libraries
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
import { Container, Row, Col, Tabs, Tab, Spinner } from 'react-bootstrap'
|
import { Container, Row, Col, Spinner, Carousel } from 'react-bootstrap'
|
||||||
import ReactMarkdown from 'react-markdown'
|
import ReactMarkdown from 'react-markdown'
|
||||||
|
|
||||||
function UserDataReview (props) {
|
function UserDataReview (props) {
|
||||||
const appData = props.appData
|
const appData = props.appData
|
||||||
const [media, setMedia] = useState([])
|
const [media, setMedia] = useState([])
|
||||||
const [markdown, setMarkdown] = useState('')
|
const [markdown, setMarkdown] = useState('')
|
||||||
const [activeTab, setActiveTab] = useState('media')
|
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState(null)
|
const [error, setError] = useState(null)
|
||||||
|
const [tokenData, setTokenData] = useState(null)
|
||||||
// Get the id parameter from the URL
|
// Get the id parameter from the URL
|
||||||
const { cid } = useParams()
|
const { tokenId } = useParams()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadMedia = async () => {
|
const loadData = async () => {
|
||||||
setLoading(true)
|
|
||||||
try {
|
try {
|
||||||
|
const tokenData = await appData.wallet.getTokenData(tokenId)
|
||||||
|
|
||||||
|
setTokenData(tokenData)
|
||||||
|
setLoading(true)
|
||||||
|
|
||||||
|
if (!tokenData.mutableData) throw new Error('Mutable data not found')
|
||||||
|
|
||||||
|
const cid = parseCid(tokenData.mutableData)
|
||||||
|
|
||||||
const { json } = await appData.wallet.cid2json({ cid })
|
const { json } = await appData.wallet.cid2json({ cid })
|
||||||
const userDataString = json.userData
|
const userDataString = json.userData
|
||||||
|
|
||||||
if (userDataString) {
|
if (userDataString) {
|
||||||
const userData = JSON.parse(userDataString)
|
const userData = JSON.parse(userDataString)
|
||||||
setMedia(userData.media)
|
setMedia(userData.media)
|
||||||
@@ -34,60 +43,80 @@ function UserDataReview (props) {
|
|||||||
}
|
}
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
loadMedia()
|
loadData()
|
||||||
}, [cid, appData.wallet])
|
}, [tokenId, appData.wallet])
|
||||||
|
|
||||||
|
// Get Cid from url
|
||||||
|
const parseCid = (url) => {
|
||||||
|
// get the cid from the url format 'ipfs://bafybeicem27xbzs65uvbcgykcmscsgln3lmhbfrcoec3gdttkdgtxv5acq
|
||||||
|
if (url && url.includes('ipfs://')) {
|
||||||
|
const cid = url.split('ipfs://')[1]
|
||||||
|
return cid
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
|
{/** Error message */}
|
||||||
{error && <p className='text-danger'>{error}</p>}
|
{error && <p className='text-danger'>{error}</p>}
|
||||||
{loading
|
|
||||||
? (
|
{/** Loading spinner */}
|
||||||
|
{loading &&
|
||||||
|
(
|
||||||
<div className='text-center my-5'>
|
<div className='text-center my-5'>
|
||||||
<Spinner animation='border' role='status' variant='primary'>
|
<Spinner animation='border' role='status' variant='primary'>
|
||||||
<span className='visually-hidden'>Loading...</span>
|
<span className='visually-hidden'>Loading...</span>
|
||||||
</Spinner>
|
</Spinner>
|
||||||
</div>
|
</div>
|
||||||
)
|
)}
|
||||||
: (
|
{/** User data */}
|
||||||
<Tabs
|
{!loading && !error && (
|
||||||
activeKey={activeTab}
|
<div className='text-center'>
|
||||||
onSelect={(k) => setActiveTab(k)}
|
{/** Name */}
|
||||||
className='mb-4'
|
<h1>{tokenData.genesisData.name}</h1>
|
||||||
>
|
|
||||||
<Tab eventKey='media' title='Media'>
|
{/** Media Content Carousel */}
|
||||||
{media && media.length > 0
|
{media && media.length > 0
|
||||||
? (
|
? (
|
||||||
<Row className='mt-3'>
|
<div className='my-5 '>
|
||||||
{media.map((item, index) => (
|
<Carousel>
|
||||||
<Col key={index} xs={12} sm={6} md={4} lg={4} className='mb-3'>
|
{media.map((item, index) => (
|
||||||
<img
|
<Carousel.Item key={index}>
|
||||||
src={item.url}
|
<img
|
||||||
alt={`Review media ${index + 1}`}
|
className='d-block w-100'
|
||||||
style={{ width: '100%', height: '250px', objectFit: 'cover', borderRadius: '8px' }}
|
src={item.url}
|
||||||
/>
|
alt={`Review media ${index + 1}`}
|
||||||
</Col>
|
style={{ height: '400px', objectFit: 'contain' }}
|
||||||
))}
|
/>
|
||||||
</Row>
|
<Carousel.Caption>
|
||||||
)
|
<p>Image {index + 1} of {media.length}</p>
|
||||||
: (
|
</Carousel.Caption>
|
||||||
<p className='mt-3'>No media content available</p>
|
</Carousel.Item>
|
||||||
)}
|
))}
|
||||||
</Tab>
|
</Carousel>
|
||||||
<Tab eventKey='markdown' title='Content'>
|
<style>{'.carousel-control-next,.carousel-control-prev, .carousel-indicators {filter: invert(100%); } '}
|
||||||
{markdown
|
</style>
|
||||||
? (
|
</div>
|
||||||
<div className='markdown-content mt-3'>
|
)
|
||||||
<ReactMarkdown>{markdown}</ReactMarkdown>
|
: (
|
||||||
</div>
|
<p className='mt-3'>No media content available</p>
|
||||||
)
|
)}
|
||||||
: (
|
|
||||||
<p className='mt-3'>No content available</p>
|
{/** Markdown Content */}
|
||||||
)}
|
{markdown
|
||||||
</Tab>
|
? (
|
||||||
</Tabs>
|
<div className='markdown-content my-5 text-center'>
|
||||||
)}
|
<ReactMarkdown>{markdown}</ReactMarkdown>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<p className='mt-3'>No content available</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import Logo from './psf-logo.png'
|
|||||||
|
|
||||||
function NavMenu (props) {
|
function NavMenu (props) {
|
||||||
// Get the current path
|
// Get the current path
|
||||||
const { currentPath } = props.appData
|
const { currentPath, bchWalletState } = props.appData
|
||||||
|
|
||||||
// Navbar state
|
// Navbar state
|
||||||
const [expanded, setExpanded] = useState(false)
|
const [expanded, setExpanded] = useState(false)
|
||||||
@@ -72,11 +72,18 @@ function NavMenu (props) {
|
|||||||
</NavLink>
|
</NavLink>
|
||||||
<NavLink
|
<NavLink
|
||||||
className={currentPath === '/nostr-read' ? 'nav-link-active' : 'nav-link-inactive'}
|
className={currentPath === '/nostr-read' ? 'nav-link-active' : 'nav-link-inactive'}
|
||||||
to='/nostr-read'
|
to={`/nostr-read/${bchWalletState?.nostrKeyPair?.npub}`}
|
||||||
onClick={handleClickEvent}
|
onClick={handleClickEvent}
|
||||||
>
|
>
|
||||||
Nostr Profile
|
Nostr Profile
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
<NavLink
|
||||||
|
className={currentPath === '/content-creators' ? 'nav-link-active' : 'nav-link-inactive'}
|
||||||
|
to='/content-creators'
|
||||||
|
onClick={handleClickEvent}
|
||||||
|
>
|
||||||
|
Content Creators
|
||||||
|
</NavLink>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user