From 2545e74aa6ef610295bb8b85c7ec1dd6b0b8a65c Mon Sep 17 00:00:00 2001 From: en Date: Fri, 14 Feb 2025 13:04:44 +0100 Subject: [PATCH] feat(profile): add minimal profile link component --- src/components/ProfileSection.tsx | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/ProfileSection.tsx b/src/components/ProfileSection.tsx index 4f4d7b4..d00d289 100644 --- a/src/components/ProfileSection.tsx +++ b/src/components/ProfileSection.tsx @@ -21,7 +21,8 @@ import { log, LogType, now, - npubToHex + npubToHex, + truncate } from '../utils' import { LoadingSpinner } from './LoadingSpinner' import { ZapPopUp } from './Zap' @@ -575,3 +576,33 @@ const FollowButton = ({ pubkey }: FollowButtonProps) => { ) } + +export const ProfileLink = ({ pubkey }: Props) => { + let hexPubkey: string | null = null + let profileRoute: string | undefined = appRoutes.home + let nprofile: string | undefined + const npub = hexToNpub(pubkey) + + try { + hexPubkey = npubToHex(pubkey) + + if (hexPubkey) { + nprofile = hexPubkey + ? nip19.nprofileEncode({ + pubkey: hexPubkey + }) + : undefined + } + } catch (error) { + // Silently ignore + log(true, LogType.Error, 'Failed to encode profile.', error) + } + + profileRoute = nprofile ? getProfilePageRoute(nprofile) : appRoutes.home + const profile = useProfile(hexPubkey!, { + cacheUsage: NDKSubscriptionCacheUsage.PARALLEL + }) + + const displayName = profile?.displayName || profile?.name || truncate(npub) + return @{displayName} +}