From 323f9e4b0a30bb14496fe94734d9811a58cf5a6f Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Tue, 22 Jul 2025 20:26:51 -0400 Subject: [PATCH] feat(nostr): Implemented extra profile data --- .../app-body/nostr/profile/profile-read.js | 108 ++++++++++++++---- 1 file changed, 87 insertions(+), 21 deletions(-) diff --git a/src/components/app-body/nostr/profile/profile-read.js b/src/components/app-body/nostr/profile/profile-read.js index b3d8a02..ba3c1e8 100644 --- a/src/components/app-body/nostr/profile/profile-read.js +++ b/src/components/app-body/nostr/profile/profile-read.js @@ -6,7 +6,7 @@ import React, { useEffect, useState } from 'react' 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 { faUser, faGlobe } from '@fortawesome/free-solid-svg-icons' import NostrFormat from '../nostr-format' import { RelayPool } from 'nostr' import * as nip19 from 'nostr-tools/nip19' @@ -18,6 +18,7 @@ function ProfileRead (props) { const { setProfile } = props const [post, setPost] = useState({}) const [loaded, setLoaded] = useState(false) + const [imageError, setImageError] = useState({ picture: false, banner: false }) useEffect(() => { const start = () => { @@ -39,10 +40,14 @@ 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) + try { + const profile = JSON.parse(ev.content) + console.log('Profile:', profile) + setPost(profile) + setProfile(profile) + } catch (error) { + console.error('Error parsing profile:', error) + } }) setLoaded(true) @@ -53,23 +58,62 @@ function ProfileRead (props) { } }, [bchWalletState, loaded, setProfile, npub]) + const handleImageError = (type) => { + setImageError(prev => ({ ...prev, [type]: true })) + } + + const handleImageLoad = (type) => { + setImageError(prev => ({ ...prev, [type]: false })) + } + return ( -
-
-
- -
+ {/* Banner Section */} + {post.banner && !imageError.banner && ( +
+ Profile banner handleImageError('banner')} + onLoad={() => handleImageLoad('banner')} + />
+ )} + +
+ {/* Profile Picture */} +
+ {post.picture && !imageError.picture + ? ( + Profile picture handleImageError('picture')} + onLoad={() => handleImageLoad('picture')} + /> + ) + : ( +
+ +
+ )} +
+ + {/* Profile Information */}
-

{post.name}

+

{post.name || 'username'}

+
@@ -81,10 +125,32 @@ function ProfileRead (props) {
-
- -
+ + {/* About Section */} + {post.about && ( +
+ +
+ )} + + {/* Website Link */} + {post.website && ( + + )}
+ + {/* Action Buttons */}