import { NDKUser } from '@nostr-dev-kit/ndk'; import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { toast } from 'sonner'; import { useNDK } from '@libs/ndk/provider'; import { useStorage } from '@libs/storage/provider'; import { FollowIcon } from '@shared/icons'; import { shortenKey } from '@utils/shortenKey'; export interface Profile { pubkey: string; profile: { content: string }; } export function NostrBandUserProfile({ data }: { data: Profile }) { const { db } = useStorage(); const { ndk } = useNDK(); const [followed, setFollowed] = useState(false); const navigate = useNavigate(); const profile = data.profile ? JSON.parse(data.profile.content) : null; const follow = async (pubkey: string) => { try { if (!ndk.signer) return navigate('/new/privkey'); setFollowed(true); const user = ndk.getUser({ pubkey: db.account.pubkey }); const contacts = await user.follows(); const add = await user.follow(new NDKUser({ pubkey: pubkey }), contacts); if (!add) { toast.success('You already follow this user'); setFollowed(false); } } catch (e) { toast.error(e); setFollowed(false); } }; useEffect(() => { if (db.account.contacts.includes(data.pubkey)) { setFollowed(true); } }, []); if (!profile) { return (

Can't fetch profile

); } return (
{data.pubkey}

{profile.display_name || profile.name}

{profile.nip05 || shortenKey(data.pubkey)}

{!followed ? ( ) : null}
{profile.about || profile.bio}
); }