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 | |
|---|---|---|---|
|
|
02e800ff6a | ||
|
|
7e1b75f965 | ||
|
|
990e41e8f6 | ||
|
|
9d35d80bcf | ||
|
|
907bb7e468 | ||
|
|
7eb5ff7821 | ||
|
|
8a982d2ef2 | ||
|
|
24bb18c77c | ||
|
|
913745ba9f | ||
|
|
f24c199dd6 | ||
|
|
0da9d4c567 | ||
|
|
e05948aa32 | ||
|
|
3cf69cbd95 | ||
|
|
45b28c168f | ||
|
|
3d622e9d99 | ||
|
|
a89d4c21cc |
Generated
+17
-2
@@ -21,6 +21,7 @@
|
||||
"bch-token-sweep": "2.2.1",
|
||||
"bootstrap": "5.2.0",
|
||||
"crypto-browserify": "3.12.1",
|
||||
"marked": "^15.0.12",
|
||||
"nostr-tools": "2.10.4",
|
||||
"p2wdb": "2.4.1",
|
||||
"process": "0.11.10",
|
||||
@@ -18223,8 +18224,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/marked": {
|
||||
"version": "12.0.2",
|
||||
"dev": true,
|
||||
"version": "15.0.12",
|
||||
"resolved": "https://registry.npmjs.org/marked/-/marked-15.0.12.tgz",
|
||||
"integrity": "sha512-8dD6FusOQSrpv9Z1rdNMdlSgQOIP880DHqnohobOmYLElGEqAL/JvxvuxZO16r4HtjTlfPRDC1hbvxC9dPN2nA==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"marked": "bin/marked.js"
|
||||
@@ -26496,6 +26498,19 @@
|
||||
"js-yaml": "bin/js-yaml.js"
|
||||
}
|
||||
},
|
||||
"node_modules/semantic-release/node_modules/marked": {
|
||||
"version": "12.0.2",
|
||||
"resolved": "https://registry.npmjs.org/marked/-/marked-12.0.2.tgz",
|
||||
"integrity": "sha512-qXUm7e/YKFoqFPYPa3Ukg9xlI5cyAtGmyEIzMfW//m6kXwCy2Ps9DYf5ioijFKQ8qyuscrHoY04iJGctu2Kg0Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"marked": "bin/marked.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/semantic-release/node_modules/npm-run-path": {
|
||||
"version": "6.0.0",
|
||||
"dev": true,
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"bch-token-sweep": "2.2.1",
|
||||
"bootstrap": "5.2.0",
|
||||
"crypto-browserify": "3.12.1",
|
||||
"marked": "15.0.12",
|
||||
"nostr-tools": "2.10.4",
|
||||
"p2wdb": "2.4.1",
|
||||
"process": "0.11.10",
|
||||
|
||||
@@ -26,6 +26,7 @@ import ServerSelectView from './configuration/select-server-view'
|
||||
import NostrPost from './nostr/nostr-post/index.js'
|
||||
import NostrRead from './nostr/nostr-read/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 Offers from './offers'
|
||||
function AppBody (props) {
|
||||
@@ -50,7 +51,8 @@ function AppBody (props) {
|
||||
<Route path='/nostr-post' element={<NostrPost appData={appData} />} />
|
||||
<Route path='/nostr-read' element={<NostrRead 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} />} />
|
||||
</Routes>
|
||||
{/** 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={8}>
|
||||
<a
|
||||
href={`/user-data/${mutableDataCid}`}
|
||||
href={`/user-data/${props.token.tokenId}`}
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
className='btn btn-link p-0'
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* 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 { RelayPool } from 'nostr'
|
||||
|
||||
function ContentCard (props) {
|
||||
const [profile, setProfile] = useState([])
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
const { creator } = 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])
|
||||
|
||||
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'>
|
||||
<small className='text-muted'>
|
||||
{new Date(creator.createdAt).toLocaleString()}
|
||||
</small>
|
||||
</div>
|
||||
<div className='d-none d-md-flex align-items-center gap-4'>
|
||||
{/* Profile Picture */}
|
||||
<div className='flex-shrink-0'>
|
||||
<Jdenticon size='140' value={creator.npub} />
|
||||
</div>
|
||||
|
||||
{/* Creator Info */}
|
||||
<div className='flex-grow-1'>
|
||||
<h5 className='mb-2 fw-bold'>{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'>
|
||||
<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>
|
||||
<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} />
|
||||
</div>
|
||||
|
||||
{/* Creator Info */}
|
||||
<div className='w-100 mb-3'>
|
||||
<h5 className='mb-2 fw-bold'>{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'>
|
||||
<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>
|
||||
<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,65 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { Container, Spinner } from 'react-bootstrap'
|
||||
|
||||
import axios from 'axios'
|
||||
// Local libraries
|
||||
import config from '../../../../config'
|
||||
import ContentCard from './content-card'
|
||||
// Global variables and constants
|
||||
const SERVER = config.dexServer
|
||||
function ContentCreators (props) {
|
||||
const [creators, setCreators] = useState([])
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
|
||||
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()
|
||||
}
|
||||
}, [loaded])
|
||||
|
||||
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} />
|
||||
))}
|
||||
</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,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
|
||||
@@ -7,6 +7,7 @@ import { Card, Spinner } from 'react-bootstrap'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
||||
import * as nip19 from 'nostr-tools/nip19'
|
||||
import NostrFormat from '../nostr-format'
|
||||
|
||||
function FeedCard (props) {
|
||||
const { post, appData, profiles } = props
|
||||
@@ -87,7 +88,7 @@ function FeedCard (props) {
|
||||
</div>
|
||||
<div className='mb-4'>
|
||||
<div className='fs-5 ms-5 text-dark' style={{ lineHeight: '1.3' }}>
|
||||
{post.content}
|
||||
<NostrFormat content={post.content} />
|
||||
</div>
|
||||
</div>
|
||||
</Card.Body>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Parse nostr content to html , support markdown , links , line breaks
|
||||
*/
|
||||
import React from 'react'
|
||||
import { marked } from 'marked' // https://www.npmjs.com/package/marked/v/0.3.9
|
||||
|
||||
const NostrFormat = ({ content }) => {
|
||||
const formatContent = (content) => {
|
||||
if (!content) return ''
|
||||
// create marked renderer
|
||||
const renderer = new marked.Renderer()
|
||||
// customize link renderer to open in new tab
|
||||
renderer.link = function ({ href, text }) {
|
||||
return `<a href="${href}" target="_blank" >${text}</a>`
|
||||
}
|
||||
// set marked options
|
||||
marked.setOptions({
|
||||
renderer,
|
||||
breaks: true
|
||||
|
||||
})
|
||||
// parse content to html
|
||||
const html = marked.parse(content)
|
||||
|
||||
return html
|
||||
}
|
||||
|
||||
return (
|
||||
<div dangerouslySetInnerHTML={{ __html: formatContent(content) }} />
|
||||
)
|
||||
}
|
||||
|
||||
export default NostrFormat
|
||||
@@ -16,7 +16,12 @@ function ProfilePost (props) {
|
||||
const { bchWalletState } = props.appData
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
about: ''
|
||||
about: '',
|
||||
picture: '',
|
||||
display_name: '',
|
||||
website: '',
|
||||
banner: '',
|
||||
bot: false
|
||||
})
|
||||
|
||||
const [errorMsg, setErrorMsg] = useState('')
|
||||
@@ -90,7 +95,12 @@ function ProfilePost (props) {
|
||||
const resetForm = () => {
|
||||
setFormData({
|
||||
name: '',
|
||||
about: ''
|
||||
about: '',
|
||||
picture: '',
|
||||
display_name: '',
|
||||
website: '',
|
||||
banner: '',
|
||||
bot: false
|
||||
})
|
||||
}
|
||||
|
||||
@@ -137,6 +147,67 @@ function ProfilePost (props) {
|
||||
/>
|
||||
</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'>
|
||||
{!onFetch && (
|
||||
<Button variant='primary' type='submit' disabled={onFetch}>
|
||||
|
||||
@@ -47,11 +47,14 @@ function PublicPost (props) {
|
||||
// Relay list
|
||||
const psf = 'wss://nostr-relay.psfoundation.info'
|
||||
|
||||
// BCH address of the user.
|
||||
const bchAddr = bchWalletState.address
|
||||
|
||||
// Generate a post.
|
||||
const eventTemplate = {
|
||||
kind: 1,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [['t', 'slpdex-socialmedia']],
|
||||
tags: [['t', 'slpdex-socialmedia'], ['u', bchAddr]],
|
||||
content: formData.content
|
||||
}
|
||||
console.log(`eventTemplate: ${JSON.stringify(eventTemplate, null, 2)}`)
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Container, Button } from 'react-bootstrap'
|
||||
import CopyOnClick from '../../bch-wallet/copy-on-click.js'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
import NostrFormat from '../nostr-format'
|
||||
import { RelayPool } from 'nostr'
|
||||
|
||||
function ProfileRead (props) {
|
||||
@@ -34,6 +34,7 @@ function ProfileRead (props) {
|
||||
pool.on('event', (relay, subId, ev) => {
|
||||
console.log('Received event:', ev)
|
||||
const profile = JSON.parse(ev.content)
|
||||
console.log('Profile:', profile)
|
||||
setPost(profile)
|
||||
setProfile(profile)
|
||||
})
|
||||
@@ -74,7 +75,9 @@ function ProfileRead (props) {
|
||||
</span>
|
||||
<CopyOnClick walletProp='npub' appData={props.appData} value={bchWalletState.nostrKeyPair.npub} />
|
||||
</div>
|
||||
<div className='fs-6 text-secondary'>{post.about}</div>
|
||||
<div className='fs-6 text-secondary'>
|
||||
<NostrFormat content={post.about} />
|
||||
</div>
|
||||
</div>
|
||||
<div className='d-flex gap-2 align-items-center flex-wrap justify-content-center'>
|
||||
<Button
|
||||
|
||||
@@ -6,7 +6,7 @@ import React, { useEffect, useState } from 'react'
|
||||
import { Container, Card, Spinner } from 'react-bootstrap'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { faUser } from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
import NostrFormat from '../nostr-format'
|
||||
import { RelayPool } from 'nostr'
|
||||
|
||||
function PublicRead (props) {
|
||||
@@ -72,7 +72,7 @@ function PublicRead (props) {
|
||||
</div>
|
||||
<div className='mb-4'>
|
||||
<div className='fs-5 ms-5 text-dark' style={{ lineHeight: '1.3' }}>
|
||||
{post.content}
|
||||
<NostrFormat content={post.content} />
|
||||
</div>
|
||||
</div>
|
||||
</Card.Body>
|
||||
|
||||
@@ -5,25 +5,34 @@
|
||||
// Global npm libraries
|
||||
import React, { useState, useEffect } from 'react'
|
||||
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'
|
||||
|
||||
function UserDataReview (props) {
|
||||
const appData = props.appData
|
||||
const [media, setMedia] = useState([])
|
||||
const [markdown, setMarkdown] = useState('')
|
||||
const [activeTab, setActiveTab] = useState('media')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState(null)
|
||||
const [tokenData, setTokenData] = useState(null)
|
||||
// Get the id parameter from the URL
|
||||
const { cid } = useParams()
|
||||
const { tokenId } = useParams()
|
||||
|
||||
useEffect(() => {
|
||||
const loadMedia = async () => {
|
||||
setLoading(true)
|
||||
const loadData = async () => {
|
||||
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 userDataString = json.userData
|
||||
|
||||
if (userDataString) {
|
||||
const userData = JSON.parse(userDataString)
|
||||
setMedia(userData.media)
|
||||
@@ -34,60 +43,80 @@ function UserDataReview (props) {
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
loadMedia()
|
||||
}, [cid, appData.wallet])
|
||||
loadData()
|
||||
}, [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 (
|
||||
<Container>
|
||||
<Row>
|
||||
<Col>
|
||||
{/** Error message */}
|
||||
{error && <p className='text-danger'>{error}</p>}
|
||||
{loading
|
||||
? (
|
||||
|
||||
{/** Loading spinner */}
|
||||
{loading &&
|
||||
(
|
||||
<div className='text-center my-5'>
|
||||
<Spinner animation='border' role='status' variant='primary'>
|
||||
<span className='visually-hidden'>Loading...</span>
|
||||
</Spinner>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onSelect={(k) => setActiveTab(k)}
|
||||
className='mb-4'
|
||||
>
|
||||
<Tab eventKey='media' title='Media'>
|
||||
{media && media.length > 0
|
||||
? (
|
||||
<Row className='mt-3'>
|
||||
{media.map((item, index) => (
|
||||
<Col key={index} xs={12} sm={6} md={4} lg={4} className='mb-3'>
|
||||
<img
|
||||
src={item.url}
|
||||
alt={`Review media ${index + 1}`}
|
||||
style={{ width: '100%', height: '250px', objectFit: 'cover', borderRadius: '8px' }}
|
||||
/>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
)
|
||||
: (
|
||||
<p className='mt-3'>No media content available</p>
|
||||
)}
|
||||
</Tab>
|
||||
<Tab eventKey='markdown' title='Content'>
|
||||
{markdown
|
||||
? (
|
||||
<div className='markdown-content mt-3'>
|
||||
<ReactMarkdown>{markdown}</ReactMarkdown>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<p className='mt-3'>No content available</p>
|
||||
)}
|
||||
</Tab>
|
||||
</Tabs>
|
||||
)}
|
||||
)}
|
||||
{/** User data */}
|
||||
{!loading && !error && (
|
||||
<div className='text-center'>
|
||||
{/** Name */}
|
||||
<h1>{tokenData.genesisData.name}</h1>
|
||||
|
||||
{/** Media Content Carousel */}
|
||||
{media && media.length > 0
|
||||
? (
|
||||
<div className='my-5 '>
|
||||
<Carousel>
|
||||
{media.map((item, index) => (
|
||||
<Carousel.Item key={index}>
|
||||
<img
|
||||
className='d-block w-100'
|
||||
src={item.url}
|
||||
alt={`Review media ${index + 1}`}
|
||||
style={{ height: '400px', objectFit: 'contain' }}
|
||||
/>
|
||||
<Carousel.Caption>
|
||||
<p>Image {index + 1} of {media.length}</p>
|
||||
</Carousel.Caption>
|
||||
</Carousel.Item>
|
||||
))}
|
||||
</Carousel>
|
||||
<style>{'.carousel-control-next,.carousel-control-prev, .carousel-indicators {filter: invert(100%); } '}
|
||||
</style>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<p className='mt-3'>No media content available</p>
|
||||
)}
|
||||
|
||||
{/** Markdown Content */}
|
||||
{markdown
|
||||
? (
|
||||
<div className='markdown-content my-5 text-center'>
|
||||
<ReactMarkdown>{markdown}</ReactMarkdown>
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<p className='mt-3'>No content available</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
|
||||
@@ -77,6 +77,13 @@ function NavMenu (props) {
|
||||
>
|
||||
Nostr Profile
|
||||
</NavLink>
|
||||
<NavLink
|
||||
className={currentPath === '/content-creators' ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
to='/content-creators'
|
||||
onClick={handleClickEvent}
|
||||
>
|
||||
Content Creators
|
||||
</NavLink>
|
||||
|
||||
<hr />
|
||||
|
||||
|
||||
+4
-2
@@ -13,7 +13,8 @@ function useAppState () {
|
||||
ssr: true,
|
||||
defaultValue: {
|
||||
serverUrl: 'https://free-bch.fullstack.cash' // Default server
|
||||
}
|
||||
},
|
||||
nftData: {}
|
||||
})
|
||||
|
||||
console.log('lsState: ', lsState)
|
||||
@@ -38,7 +39,7 @@ function useAppState () {
|
||||
const [denyClose, setDenyClose] = useState(false)
|
||||
|
||||
// NFTs for sale stored data to improve performance
|
||||
const [nftForSaleCacheData, setNftForSaleCacheData] = useState({})
|
||||
const [nftForSaleCacheData, setNftForSaleCacheData] = useState(lsState.nftData || {})
|
||||
|
||||
// The wallet state makes this a true progressive web app (PWA). As
|
||||
// balances, UTXOs, and tokens are retrieved, this state is updated.
|
||||
@@ -107,6 +108,7 @@ function useAppState () {
|
||||
const newCacheData = Object.assign({}, cacheData, data) // Merge the new data with the cache data
|
||||
allCacheData[tokenId] = newCacheData // Update the cache data
|
||||
setNftForSaleCacheData(allCacheData) // Update the state
|
||||
updateLocalStorage({ nftData: allCacheData }) // Update the local storage
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user