From a2232cd4202fde5eed750602760b80cbb0118b8a Mon Sep 17 00:00:00 2001 From: Davinci Date: Thu, 16 May 2024 08:55:24 +0200 Subject: [PATCH] fix: getRobohash function will do the conversion of pubkey --- src/components/AppBar/AppBar.tsx | 4 ++-- src/pages/create/index.tsx | 3 +-- src/pages/verify/index.tsx | 6 ++---- src/utils/nostr.ts | 8 +++++++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/AppBar/AppBar.tsx b/src/components/AppBar/AppBar.tsx index 7312621..eef58b7 100644 --- a/src/components/AppBar/AppBar.tsx +++ b/src/components/AppBar/AppBar.tsx @@ -46,12 +46,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)) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index c154385..2847c76 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -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 ( diff --git a/src/pages/verify/index.tsx b/src/pages/verify/index.tsx index af7da88..9a884d3 100644 --- a/src/pages/verify/index.tsx +++ b/src/pages/verify/index.tsx @@ -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) => { {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 = '-' diff --git a/src/utils/nostr.ts b/src/utils/nostr.ts index d3eba8b..a39502f 100644 --- a/src/utils/nostr.ts +++ b/src/utils/nostr.ts @@ -140,6 +140,12 @@ export const base64DecodeAuthToken = (authToken: string): SignedEvent => { } } -export const getRoboHashPicture = (npub: string): string => { +/** + * + * @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` }