Placeholder avatar is incosistent across components #39

Merged
s merged 9 commits from issue-27 into main 2024-05-16 08:58:11 +00:00
4 changed files with 12 additions and 9 deletions
Showing only changes of commit 9aa10664a7 - Show all commits

View File

@ -42,12 +42,12 @@ export const AppBar = () => {
useEffect(() => {
if (metadataState && metadataState.content) {
const { picture, display_name, name } = JSON.parse(metadataState.content)
const npub = authState?.usersPubkey ? hexToNpub(authState.usersPubkey) : ''
const pubkey = authState?.usersPubkey || ''
if (picture) {
setUserAvatar(picture)
} else {
setUserAvatar(getRoboHashPicture(npub))
setUserAvatar(getRoboHashPicture(pubkey))
}
setUsername(shorten(display_name || name || '', 7))

View File

@ -490,8 +490,7 @@ const DisplayUser = ({
}, [users])
const imageLoadError = (event: any, pubkey: string) => {
const npub = hexToNpub(pubkey)
event.target.src = getRoboHashPicture(npub)
event.target.src = getRoboHashPicture(pubkey)
}
return (

View File

@ -632,8 +632,7 @@ const DisplayMeta = ({ meta, nextSigner }: DisplayMetaProps) => {
}
const getRoboImageUrl = (pubkey: string) => {
const npub = hexToNpub(pubkey)
return getRoboHashPicture(npub)
return getRoboHashPicture(pubkey)
}
return (
@ -719,8 +718,7 @@ const DisplayMeta = ({ meta, nextSigner }: DisplayMetaProps) => {
<TableBody>
{users.map((user, index) => {
const userMeta = metadata[user.pubkey]
const npub = hexToNpub(user.pubkey)
const roboUrl = getRoboHashPicture(npub)
const roboUrl = getRoboHashPicture(user.pubkey)
let signedStatus = '-'

View File

@ -140,6 +140,12 @@ export const base64DecodeAuthToken = (authToken: string): SignedEvent => {
}
}
export const getRoboHashPicture = (npub: string): string => {
/**
m marked this conversation as resolved Outdated
Outdated
Review

Allow this to accept both npub and hex, If provided value is not npub then convert it to npub

Allow this to accept both npub and hex, If provided value is not npub then convert it to npub
*
* @param pubkey in hex or npub format
* @returns robohash.org url for the avatar
*/
export const getRoboHashPicture = (pubkey: string): string => {
const npub = hexToNpub(pubkey)
return `https://robohash.org/${npub}.png?set=set3`
}