diff --git a/src/app/auth/import.tsx b/src/app/auth/import.tsx index d105deda..7a995d3a 100644 --- a/src/app/auth/import.tsx +++ b/src/app/auth/import.tsx @@ -145,6 +145,7 @@ export function ImportAccountScreen() {
Continue with nsecBunker -
-

Note:

-

- If you're using nsecbunker token, keep in mind it only can - redeem one-time, you need to login again in the next launch -

-
) : null} + {npub.indexOf('#') > -1 ? ( +

+ You're using nsecbunker token, keep in mind it only can redeem + one-time, you need to login again in the next launch +

+ ) : null} diff --git a/src/app/chats/components/chatListItem.tsx b/src/app/chats/components/chatListItem.tsx index 99f1707d..68d827a9 100644 --- a/src/app/chats/components/chatListItem.tsx +++ b/src/app/chats/components/chatListItem.tsx @@ -12,14 +12,14 @@ import { useProfile } from '@utils/hooks/useProfile'; import { displayNpub } from '@utils/shortenKey'; export const ChatListItem = memo(function ChatListItem({ event }: { event: NDKEvent }) { - const { status, user } = useProfile(event.pubkey); + const { isLoading, user } = useProfile(event.pubkey); const decryptedContent = useDecryptMessage(event); const createdAt = formatCreatedAt(event.created_at, true); const svgURI = 'data:image/svg+xml;utf8,' + encodeURIComponent(minidenticon(event.pubkey, 90, 50)); - if (status === 'pending') { + if (isLoading) { return (
diff --git a/src/app/explore/components/groupTitle.tsx b/src/app/explore/components/groupTitle.tsx index 1d9c1ca6..14828d7f 100644 --- a/src/app/explore/components/groupTitle.tsx +++ b/src/app/explore/components/groupTitle.tsx @@ -3,9 +3,9 @@ import { memo } from 'react'; import { useProfile } from '@utils/hooks/useProfile'; export const GroupTitle = memo(function GroupTitle({ pubkey }: { pubkey: string }) { - const { status, user } = useProfile(pubkey); + const { isLoading, user } = useProfile(pubkey); - if (status === 'pending') { + if (isLoading) { return
; } diff --git a/src/app/explore/components/userWithDrawer.tsx b/src/app/explore/components/userWithDrawer.tsx index 9feb6035..f498b70b 100644 --- a/src/app/explore/components/userWithDrawer.tsx +++ b/src/app/explore/components/userWithDrawer.tsx @@ -23,7 +23,7 @@ export const UserWithDrawer = memo(function UserWithDrawer({ }) { const { db } = useStorage(); const { ndk } = useNDK(); - const { status, user } = useProfile(pubkey); + const { isLoading, user } = useProfile(pubkey); const [followed, setFollowed] = useState(false); @@ -82,7 +82,7 @@ export const UserWithDrawer = memo(function UserWithDrawer({
- {status === 'pending' ? ( + {isLoading ? (

Loading...

diff --git a/src/app/new/components/mentionPopupItem.tsx b/src/app/new/components/mentionPopupItem.tsx index d4e8f95d..f91fe830 100644 --- a/src/app/new/components/mentionPopupItem.tsx +++ b/src/app/new/components/mentionPopupItem.tsx @@ -1,10 +1,18 @@ +import * as Avatar from '@radix-ui/react-avatar'; +import { minidenticon } from 'minidenticons'; +import { useMemo } from 'react'; + import { useProfile } from '@utils/hooks/useProfile'; import { displayNpub } from '@utils/shortenKey'; export function MentionPopupItem({ pubkey, embed }: { pubkey: string; embed?: string }) { - const { status, user } = useProfile(pubkey, embed); + const { isLoading, user } = useProfile(pubkey, embed); + const svgURI = useMemo( + () => 'data:image/svg+xml;utf8,' + encodeURIComponent(minidenticon(pubkey, 90, 50)), + [pubkey] + ); - if (status === 'pending') { + if (isLoading) { return (
@@ -18,14 +26,25 @@ export function MentionPopupItem({ pubkey, embed }: { pubkey: string; embed?: st return (
- {pubkey} + + + + {pubkey} + +
- {user.display_name || user.displayName || user.name} + {user?.display_name || user?.displayName || user?.name}
{displayNpub(pubkey, 16)} diff --git a/src/app/settings/components/profileCard.tsx b/src/app/settings/components/profileCard.tsx index 8b409198..f8c8429c 100644 --- a/src/app/settings/components/profileCard.tsx +++ b/src/app/settings/components/profileCard.tsx @@ -11,7 +11,7 @@ import { displayNpub } from '@utils/shortenKey'; export function ProfileCard() { const { db } = useStorage(); - const { status, user } = useProfile(db.account.pubkey); + const { isLoading, user } = useProfile(db.account.pubkey); const svgURI = 'data:image/svg+xml;utf8,' + @@ -19,7 +19,7 @@ export function ProfileCard() { return (
- {status === 'pending' ? ( + {isLoading ? (
diff --git a/src/app/users/components/profile.tsx b/src/app/users/components/profile.tsx index 0e357482..07629ed6 100644 --- a/src/app/users/components/profile.tsx +++ b/src/app/users/components/profile.tsx @@ -114,7 +114,7 @@ export function UserProfile({ pubkey }: { pubkey: string }) {
- {user.name || user.display_name || user.displayName || 'No name'} + {user?.name || user?.display_name || user?.displayName || 'No name'}
{user?.nip05 ? (
- Send tip to {user?.name || user?.display_name || user?.displayName} + Send tip to{' '} + {user?.name || user?.displayName || displayNpub(event.pubkey, 16)} diff --git a/src/shared/notes/mentions/user.tsx b/src/shared/notes/mentions/user.tsx index 338c349b..cc1df7d9 100644 --- a/src/shared/notes/mentions/user.tsx +++ b/src/shared/notes/mentions/user.tsx @@ -20,12 +20,7 @@ export const MentionUser = memo(function MentionUser({ pubkey }: { pubkey: strin } className="break-words text-blue-500 hover:text-blue-600" > - {'@' + - (user?.name || - user?.display_name || - user?.displayName || - user?.username || - 'unknown')} + {'@' + (user?.name || user?.displayName || user?.username || 'unknown')} ); }); diff --git a/src/shared/user.tsx b/src/shared/user.tsx index b2498a18..d348cf3c 100644 --- a/src/shared/user.tsx +++ b/src/shared/user.tsx @@ -40,20 +40,33 @@ export const User = memo(function User({ embedProfile?: string; subtext?: string; }) { - const { isFetching, user } = useProfile(pubkey, embedProfile); + const { isLoading, user } = useProfile(pubkey, embedProfile); - const createdAt = useMemo(() => formatCreatedAt(time, variant === 'chat'), [pubkey]); - const svgURI = useMemo( + const createdAt = useMemo(() => formatCreatedAt(time, variant === 'chat'), [time]); + const fallbackName = useMemo(() => displayNpub(pubkey, 16), [pubkey]); + const fallbackAvatar = useMemo( () => 'data:image/svg+xml;utf8,' + encodeURIComponent(minidenticon(pubkey, 90, 50)), [pubkey] ); if (variant === 'mention') { - if (isFetching) { + if (isLoading) { return (
-
-
+ + + +
+
+ {fallbackName} +
+ · + {createdAt} +
); } @@ -70,7 +83,7 @@ export const User = memo(function User({ /> {pubkey} @@ -78,10 +91,7 @@ export const User = memo(function User({
- {user?.name || - user?.display_name || - user?.displayName || - displayNpub(pubkey, 16)} + {user?.name || user?.display_name || user?.displayName || fallbackName}
· {createdAt} @@ -91,11 +101,19 @@ export const User = memo(function User({ } if (variant === 'notify') { - if (isFetching) { + if (isLoading) { return (
-
-
+ + + +
+ {fallbackName} +
); } @@ -112,24 +130,21 @@ export const User = memo(function User({ /> {pubkey}
- {user?.name || - user?.display_name || - user?.displayName || - displayNpub(pubkey, 16)} + {user?.name || user?.display_name || user?.displayName || fallbackName}
); } if (variant === 'large') { - if (isFetching) { + if (isLoading) { return (
@@ -153,7 +168,7 @@ export const User = memo(function User({ /> {pubkey} @@ -172,7 +187,7 @@ export const User = memo(function User({ } if (variant === 'simple') { - if (isFetching) { + if (isLoading) { return (
@@ -196,7 +211,7 @@ export const User = memo(function User({ /> {pubkey} @@ -207,7 +222,7 @@ export const User = memo(function User({ {user?.name || user?.display_name || user?.displayName}

- {user?.nip05 || user?.username || displayNpub(pubkey, 16)} + {user?.nip05 || user?.username || fallbackName}

@@ -215,7 +230,7 @@ export const User = memo(function User({ } if (variant === 'avatar') { - if (isFetching) { + if (isLoading) { return (
); @@ -232,7 +247,7 @@ export const User = memo(function User({ /> {pubkey} @@ -242,7 +257,7 @@ export const User = memo(function User({ } if (variant === 'miniavatar') { - if (isFetching) { + if (isLoading) { return (
); @@ -259,7 +274,7 @@ export const User = memo(function User({ /> {pubkey} @@ -269,9 +284,23 @@ export const User = memo(function User({ } if (variant === 'childnote') { - if (isFetching) { + if (isLoading) { return ( -
+ <> + + + +
+
{fallbackName}
+
+ {subtext}: +
+
+ ); } @@ -287,7 +316,7 @@ export const User = memo(function User({ /> {pubkey} @@ -295,10 +324,7 @@ export const User = memo(function User({
- {user?.display_name || - user?.name || - user?.displayName || - displayNpub(pubkey, 16)}{' '} + {user?.display_name || user?.name || user?.displayName || fallbackName}{' '}
{subtext}: @@ -309,7 +335,7 @@ export const User = memo(function User({ } if (variant === 'stacked') { - if (isFetching) { + if (isLoading) { return (
); @@ -326,7 +352,7 @@ export const User = memo(function User({ /> {pubkey} @@ -336,7 +362,7 @@ export const User = memo(function User({ } if (variant === 'ministacked') { - if (isFetching) { + if (isLoading) { return (
); @@ -353,7 +379,7 @@ export const User = memo(function User({ /> {pubkey} @@ -363,7 +389,7 @@ export const User = memo(function User({ } if (variant === 'repost') { - if (isFetching) { + if (isLoading) { return (
@@ -393,7 +419,7 @@ export const User = memo(function User({ /> {pubkey} @@ -401,10 +427,7 @@ export const User = memo(function User({
- {user?.name || - user?.display_name || - user?.displayName || - displayNpub(pubkey, 16)} + {user?.name || user?.display_name || user?.displayName || fallbackName}
reposted
@@ -414,13 +437,13 @@ export const User = memo(function User({ } if (variant === 'thread') { - if (isFetching) { + if (isLoading) { return ( -
+
-
+
-
+
); @@ -438,7 +461,7 @@ export const User = memo(function User({ /> {pubkey} @@ -451,19 +474,27 @@ export const User = memo(function User({
{createdAt} · - {displayNpub(pubkey, 16)} + {fallbackName}
); } - if (isFetching) { + if (isLoading) { return (
-
+ + +
-
+
+ {fallbackName} +
); @@ -483,7 +514,7 @@ export const User = memo(function User({ /> {pubkey} @@ -492,10 +523,7 @@ export const User = memo(function User({
- {user?.name || - user?.display_name || - user?.displayName || - displayNpub(pubkey, 16)} + {user?.name || user?.display_name || user?.displayName || fallbackName}
{createdAt}
@@ -519,7 +547,7 @@ export const User = memo(function User({ /> {pubkey} @@ -541,7 +569,7 @@ export const User = memo(function User({ /> ) : ( - {displayNpub(pubkey, 16)} + {fallbackName} )}
diff --git a/src/utils/hooks/useProfile.ts b/src/utils/hooks/useProfile.ts index ef7a17b6..d7ebf9ad 100644 --- a/src/utils/hooks/useProfile.ts +++ b/src/utils/hooks/useProfile.ts @@ -7,7 +7,7 @@ import { useNDK } from '@libs/ndk/provider'; export function useProfile(pubkey: string, embed?: string) { const { ndk } = useNDK(); const { - isFetching, + isLoading, isError, data: user, } = useQuery({ @@ -31,12 +31,6 @@ export function useProfile(pubkey: string, embed?: string) { const user = ndk.getUser({ pubkey: hexstring }); const profile = await user.fetchProfile(); - - if (!profile) - throw new Error( - `Cannot get metadata for ${pubkey}, will be retry after 10 seconds` - ); - return profile; } catch (e) { console.error(e); @@ -50,5 +44,5 @@ export function useProfile(pubkey: string, embed?: string) { retry: 2, }); - return { isFetching, isError, user }; + return { isLoading, isError, user }; }