From ae213b796b24d444c1b15bf61b390f9fdccc2d9a Mon Sep 17 00:00:00 2001 From: Davinci Date: Fri, 17 May 2024 09:37:30 +0200 Subject: [PATCH] fix: looping trough robo sets, image not shown when visiting profile while not logged in --- .env.example | 2 +- src/pages/profile/index.tsx | 17 ++++++++++++----- src/utils/nostr.ts | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 7239454..6b61434 100644 --- a/.env.example +++ b/.env.example @@ -1 +1 @@ -VITE_MOST_POPULAR_RELAYS=wss://relay.damus.io wss://eden.nostr.land wss://nos.lol wss://relay.snort.social wss://relay.current.fyi wss://brb.io wss://nostr.orangepill.dev wss://nostr-pub.wellorder.net wss://nostr.wine wss://nostr.oxtr.dev wss://relay.nostr.bg wss://nostr.mom wss://nostr.fmt.wiz.biz wss://relay.nostr.band wss://nostr-pub.semisol.dev wss://nostr.milou.lol wss://puravida.nostr.land wss://nostr.onsats.org wss://relay.nostr.info wss://offchain.pub wss://relay.orangepill.dev wss://no.str.cr wss://atlas.nostr.land wss://nostr.zebedee.cloud wss://nostr-relay.wlvs.space wss://relay.nostrati.com wss://relay.nostr.com.au wss://nostr.inosta.cc wss://nostr.rocks \ No newline at end of file +VITE_MOST_POPULAR_RELAYS=wss://relay.damus.io wss://eden.nostr.land wss://nos.lol wss://relay.snort.social wss://relay.current.fyi wss://brb.io wss://nostr.orangepill.dev wss://nostr-pub.wellorder.net wss://nostr.bitcoiner.social wss://nostr.wine wss://nostr.oxtr.dev wss://relay.nostr.bg wss://nostr.mom wss://nostr.fmt.wiz.biz wss://relay.nostr.band wss://nostr-pub.semisol.dev wss://nostr.milou.lol wss://puravida.nostr.land wss://nostr.onsats.org wss://relay.nostr.info wss://offchain.pub wss://relay.orangepill.dev wss://no.str.cr wss://atlas.nostr.land wss://nostr.zebedee.cloud wss://nostr-relay.wlvs.space wss://relay.nostrati.com wss://relay.nostr.com.au wss://nostr.inosta.cc wss://nostr.rocks \ No newline at end of file diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index ca6fbd5..677bbe7 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -12,7 +12,7 @@ import { useTheme } from '@mui/material' import { UnsignedEvent, nip19, kinds, VerifiedEvent } from 'nostr-tools' -import { useEffect, useMemo, useState } from 'react' +import { useEffect, useMemo, useRef, useState } from 'react' import { Link, useParams } from 'react-router-dom' import { toast } from 'react-toastify' import { MetadataController, NostrController } from '../../controllers' @@ -26,6 +26,7 @@ import { setMetadataEvent } from '../../store/actions' import { LoadingSpinner } from '../../components/LoadingSpinner' import { LoginMethods } from '../../store/auth/types' import { SmartToy } from '@mui/icons-material' +import { getRoboHashPicture } from '../../utils' export const ProfilePage = () => { const theme = useTheme() @@ -52,6 +53,8 @@ export const ProfilePage = () => { const [isLoading, setIsLoading] = useState(true) const [loadingSpinnerDesc] = useState('Fetching metadata') + const robotSet = useRef(1) + useEffect(() => { if (npub) { try { @@ -213,7 +216,10 @@ export const ProfilePage = () => { const generateRobotAvatar = () => { setAvatarLoading(true) - const robotAvatarLink = `https://robohash.org/${npub}.png?set=set3` + robotSet.current++ + if (robotSet.current > 5) robotSet.current = 1 + + const robotAvatarLink = getRoboHashPicture(npub!, robotSet.current) setProfileMetadata((prev) => ({ ...prev, @@ -233,8 +239,6 @@ export const ProfilePage = () => { * @returns robohash generate button, loading spinner or no button */ const robohashButton = () => { - if (profileMetadata?.picture?.includes('robohash')) return null - return ( {avatarLoading ? ( @@ -280,6 +284,9 @@ export const ProfilePage = () => { }} > { + event.target.src = npub ? getRoboHashPicture(npub) : '' + }} onLoad={() => { setAvatarLoading(false) }} @@ -305,7 +312,7 @@ export const ProfilePage = () => { {editItem('picture', 'Picture URL', undefined, undefined, { - endAdornment: robohashButton() + endAdornment: isUsersOwnProfile ? robohashButton() : undefined })} {editItem('name', 'Username')} diff --git a/src/utils/nostr.ts b/src/utils/nostr.ts index a39502f..7d5b23d 100644 --- a/src/utils/nostr.ts +++ b/src/utils/nostr.ts @@ -145,7 +145,7 @@ export const base64DecodeAuthToken = (authToken: string): SignedEvent => { * @param pubkey in hex or npub format * @returns robohash.org url for the avatar */ -export const getRoboHashPicture = (pubkey: string): string => { +export const getRoboHashPicture = (pubkey: string, set: number = 1): string => { const npub = hexToNpub(pubkey) - return `https://robohash.org/${npub}.png?set=set3` + return `https://robohash.org/${npub}.png?set=set${set}` }