From 09131670f6d6a6f750ea86eae72a5b273f729476 Mon Sep 17 00:00:00 2001 From: SwiftHawk Date: Fri, 17 May 2024 13:59:03 +0500 Subject: [PATCH] chore: add comments --- src/components/AppBar/AppBar.tsx | 6 +++--- src/components/username.tsx | 4 ++++ src/layouts/Main.tsx | 17 +++++++++-------- src/pages/login/index.tsx | 1 - src/pages/sign/index.tsx | 2 ++ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/AppBar/AppBar.tsx b/src/components/AppBar/AppBar.tsx index a1971ed..aecdc65 100644 --- a/src/components/AppBar/AppBar.tsx +++ b/src/components/AppBar/AppBar.tsx @@ -53,8 +53,8 @@ export const AppBar = () => { metadataState.content ) - if (picture || userRobotImage) { - setUserAvatar(picture || userRobotImage) + if (picture) { + setUserAvatar(picture) } setUsername(shorten(display_name || name || '', 7)) @@ -91,8 +91,8 @@ export const AppBar = () => { nsecBunkerPubkey: undefined }) ) + dispatch(setMetadataEvent(metadataController.getEmptyMetadataEvent())) - dispatch(setUserRobotImage(null)) // clear authToken saved in local storage clearAuthToken() diff --git a/src/components/username.tsx b/src/components/username.tsx index 387a4c6..ff93494 100644 --- a/src/components/username.tsx +++ b/src/components/username.tsx @@ -54,6 +54,10 @@ type UserProps = { image?: string } +/** + * This component will be used for the displaying username and profile picture. + * If image is not available, robohash image will be displayed + */ export const UserComponent = ({ pubkey, name, image }: UserProps) => { const theme = useTheme() diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx index c1a827e..d31af6c 100644 --- a/src/layouts/Main.tsx +++ b/src/layouts/Main.tsx @@ -5,7 +5,12 @@ import { useDispatch, useSelector } from 'react-redux' import { Outlet } from 'react-router-dom' import { AppBar } from '../components/AppBar/AppBar' import { restoreState, setAuthState, setMetadataEvent } from '../store/actions' -import { clearAuthToken, clearState, getRoboHashPicture, loadState, saveNsecBunkerDelegatedKey } from '../utils' +import { + clearAuthToken, + clearState, + loadState, + saveNsecBunkerDelegatedKey +} from '../utils' import { LoadingSpinner } from '../components/LoadingSpinner' import { Dispatch } from '../store/store' import { MetadataController, NostrController } from '../controllers' @@ -32,9 +37,7 @@ export const MainLayout = () => { }) ) - dispatch( - setMetadataEvent(metadataController.getEmptyMetadataEvent()) - ) + dispatch(setMetadataEvent(metadataController.getEmptyMetadataEvent())) // clear authToken saved in local storage clearAuthToken() @@ -78,11 +81,9 @@ export const MainLayout = () => { useEffect(() => { if (authState && authState.loggedIn) { const pubkey = authState.usersPubkey || authState.keyPair?.public - + if (pubkey) { - dispatch( - setUserRobotImage(getRoboHashPicture(pubkey)) - ) + dispatch(setUserRobotImage(getRoboHashPicture(pubkey))) } } }, [authState]) diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 566721f..a4a49b7 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -63,7 +63,6 @@ export const Login = () => { dispatch(updateLoginMethod(LoginMethods.extension)) setLoadingSpinnerDesc('Authenticating and finding metadata') - const redirectPath = await authController.authAndGetMetadataAndRelaysMap(pubkey) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index e320ac3..7ce64f4 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -90,6 +90,8 @@ export const SignPage = () => { } else { for (const signer of meta.signers) { if (!signedBy.includes(signer)) { + // signers in meta.json are in npub1 format + // so, convert it to hex before setting to nextSigner setNextSinger(npubToHex(signer)!) const usersNpub = hexToNpub(usersPubkey!)