From 55ebb7b25dc16aa6ec9d94ab7d67d73efc6fee27 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Wed, 6 Aug 2025 21:53:11 -0400 Subject: [PATCH] feat(nostr): Added profile photos on feeds --- .../app-body/nostr/feeds/feed-card.js | 25 ++++++++++++++++++- src/components/app-body/nostr/feeds/index.js | 11 ++++++-- src/components/app-body/nostr/nostr-format.js | 2 +- .../app-body/nostr/profile/public-read.js | 24 +++++++++++++++++- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/components/app-body/nostr/feeds/feed-card.js b/src/components/app-body/nostr/feeds/feed-card.js index defcffa..33e339a 100644 --- a/src/components/app-body/nostr/feeds/feed-card.js +++ b/src/components/app-body/nostr/feeds/feed-card.js @@ -25,6 +25,7 @@ function FeedCard (props) { const [isLiked, setIsLiked] = useState(false) const [likesCount, setLikesCount] = useState(null) const [likesFetched, setLikesFetched] = useState(false) + const [profilePictureError, setProfilePictureError] = useState(false) // function to fetch a post likes reaction const handleLikes = useCallback(async (post, userPubKey) => { @@ -76,6 +77,15 @@ function FeedCard (props) { console.warn(error) } }, []) + + const handleProfilePictureError = () => { + setProfilePictureError(true) + } + + const handleProfilePictureLoad = () => { + setProfilePictureError(false) + } + // Get npub from pubkey useEffect(() => { const npub = nip19.npubEncode(post.pubkey) @@ -170,7 +180,20 @@ function FeedCard (props) { background: 'linear-gradient(45deg, #6c757d, #495057)' }} > - + {profile?.picture && !profilePictureError + ? ( + Profile + ) + : ( + + )}
diff --git a/src/components/app-body/nostr/feeds/index.js b/src/components/app-body/nostr/feeds/index.js index 13d68b9..3f1971c 100644 --- a/src/components/app-body/nostr/feeds/index.js +++ b/src/components/app-body/nostr/feeds/index.js @@ -22,14 +22,20 @@ function Feeds (props) { const [profiles, setProfiles] = useState({}) // function to fetch profile and set it to profiles state - const fetchProfile = useCallback((pubkey) => { + const fetchProfile = useCallback(async (pubkey) => { // no fetch profile again if it exist + let hasProfileRequest = false setProfiles(currentProfiles => { if (currentProfiles[pubkey]) { + hasProfileRequest = true return currentProfiles + } else { + const newProfiles = { ...currentProfiles } + newProfiles[pubkey] = { loaded: false } + return newProfiles } - return currentProfiles }) + if (hasProfileRequest) return const pool = RelayPool(config.nostrRelays) pool.on('open', relay => { @@ -49,6 +55,7 @@ function Feeds (props) { return currentProfiles }) } catch (error) { + console.warn(error) // skip error } }) diff --git a/src/components/app-body/nostr/nostr-format.js b/src/components/app-body/nostr/nostr-format.js index 94c64a3..7d17cf8 100644 --- a/src/components/app-body/nostr/nostr-format.js +++ b/src/components/app-body/nostr/nostr-format.js @@ -26,7 +26,7 @@ const NostrFormat = ({ content }) => { } return ( -
+
) } diff --git a/src/components/app-body/nostr/profile/public-read.js b/src/components/app-body/nostr/profile/public-read.js index e17a1d5..4f71d72 100644 --- a/src/components/app-body/nostr/profile/public-read.js +++ b/src/components/app-body/nostr/profile/public-read.js @@ -18,6 +18,7 @@ function PublicRead (props) { const { bchWalletState } = props.appData const [posts, setPosts] = useState([]) const [loaded, setLoaded] = useState(false) + const [profilePictureError, setProfilePictureError] = useState(false) useEffect(() => { // Get Last post from a author @@ -49,6 +50,14 @@ function PublicRead (props) { } }, [bchWalletState, loaded, npub]) + const handleProfilePictureError = () => { + setProfilePictureError(true) + } + + const handleProfilePictureLoad = () => { + setProfilePictureError(false) + } + return ( {/* Nostr Feed Section */} @@ -76,7 +85,20 @@ function PublicRead (props) { background: 'linear-gradient(45deg, #6c757d, #495057)' }} > - + {props.profile?.picture && !profilePictureError + ? ( + Profile + ) + : ( + + )}
{props.profile?.name}