diff --git a/src/components/ProfileSection.tsx b/src/components/ProfileSection.tsx index b441582..c2ab74a 100644 --- a/src/components/ProfileSection.tsx +++ b/src/components/ProfileSection.tsx @@ -14,9 +14,11 @@ import '../styles/author.css' import '../styles/innerPage.css' import '../styles/socialPosts.css' import { UserProfile } from '../types' -import { copyTextToClipboard, log, LogType, now } from '../utils' +import { copyTextToClipboard, log, LogType, now, npubToHex } from '../utils' import { LoadingSpinner } from './LoadingSpinner' import { ZapPopUp } from './Zap' +import { NDKUserProfile } from '@nostr-dev-kit/ndk' +import _ from 'lodash' type Props = { pubkey: string @@ -32,106 +34,13 @@ export const ProfileSection = ({ pubkey }: Props) => { }) }) - const handleCopy = async () => { - copyTextToClipboard(profile?.npub as string).then((isCopied) => { - if (isCopied) { - toast.success('Npub copied to clipboard!') - } else { - toast.error( - 'Failed to copy, look into console for more details on error!' - ) - } - }) - } - if (!profile) return null - const profileRoute = getProfilePageRoute( - nip19.nprofileEncode({ - pubkey - }) - ) - return (
-
-
-
- -
-
-
-
-
-
-
-
-

- {profile.displayName || profile.name || ''} -

-

- {profile.nip05 || ''} -

-
-
-
- -
-
-

- {profile.npub} -

-
-
-
- - - -
- - -
-
-
-
-

- {profile.bio || profile.about} -

-
-
-
- -
+
@@ -181,6 +90,117 @@ export const ProfileSection = ({ pubkey }: Props) => { ) } +type ProfileProps = { + profile: NDKUserProfile +} + +export const Profile = ({ profile }: ProfileProps) => { + const handleCopy = async () => { + copyTextToClipboard(profile.npub as string).then((isCopied) => { + if (isCopied) { + toast.success('Npub copied to clipboard!') + } else { + toast.error( + 'Failed to copy, look into console for more details on error!' + ) + } + }) + } + + const hexPubkey = npubToHex(profile.pubkey as string) + + if (!hexPubkey) return null + + const profileRoute = getProfilePageRoute( + nip19.nprofileEncode({ + pubkey: hexPubkey + }) + ) + + const npub = (profile.npub as string) || '' + const displayName = + profile.displayName || + profile.name || + _.truncate(npub, { + length: 16 + }) + const nip05 = profile.nip05 || '' + const about = profile.bio || profile.about || '' + + return ( +
+
+
+ +
+
+
+
+
+
+
+
+

{displayName}

+

{nip05}

+
+
+
+ +
+
+

+ {npub} +

+
+
+
+ + + +
+ + +
+
+
+
+

{about}

+
+
+
+ +
+ ) +} + interface Post { name: string link: string