import React, { useMemo } from 'react'; import { useProfile } from "nostr-react"; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; import { AvatarImage } from '@radix-ui/react-avatar'; import { Avatar } from '@/components/ui/avatar'; import NIP05 from '@/components/nip05'; import { nip19 } from "nostr-tools"; import Link from 'next/link'; import { Button } from './ui/button'; import { ImStatsDots } from "react-icons/im"; import FollowButton from './FollowButton'; import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer" import { Input } from './ui/input'; import { Share1Icon } from '@radix-ui/react-icons'; import { toast } from './ui/use-toast'; interface ProfileInfoCardProps { pubkey: string; } const ProfileInfoCard: React.FC = React.memo(({ pubkey }) => { let userPubkey = ''; let host = ''; if (typeof window !== 'undefined') { userPubkey = window.localStorage.getItem('pubkey') ?? ''; host = window.location.host; } const { data: userData, isLoading } = useProfile({ pubkey }); const npubShortened = useMemo(() => { let encoded = nip19.npubEncode(pubkey); let parts = encoded.split('npub'); return 'npub' + parts[1].slice(0, 4) + ':' + parts[1].slice(-3); }, [pubkey]); const title = userData?.username || userData?.display_name || userData?.name || userData?.npub || npubShortened; const description = userData?.about?.replace(/(?:\r\n|\r|\n)/g, '
'); const nip05 = userData?.nip05; const handleCopyLink = async () => { try { await navigator.clipboard.writeText(host+"/profile/"+nip19.npubEncode(pubkey)); toast({ description: 'URL copied to clipboard', title: 'Copied' }); } catch (err) { toast({ description: 'Error copying URL to clipboard', title: 'Error', variant: 'destructive' }); } }; const handleCopyPublicKey = async () => { try { await navigator.clipboard.writeText(nip19.npubEncode(pubkey)); toast({ description: 'PublicKey copied to clipboard', title: 'Copied' }); } catch (err) { toast({ description: 'Error copying PublicKey to clipboard', title: 'Error', variant: 'destructive' }); } }; return (
{title}
Share this Profile Share this Profile with others.

); }); ProfileInfoCard.displayName = 'ProfileInfoCard'; export default ProfileInfoCard;