import React, { ReactElement, useEffect, useState } from 'react' import get3BoxProfile from '../../../utils/profile' import { Profile } from '../../../models/Profile' import { accountTruncate } from '../../../utils/web3' import axios from 'axios' import PublisherLinks from './PublisherLinks' import Markdown from '../../atoms/Markdown' import Stats from './Stats' import Account from './Account' import styles from './Header.module.css' const isDescriptionTextClamped = () => { const el = document.getElementById('description') if (el) return el.scrollHeight > el.clientHeight } const clearedProfile: Profile = { name: null, image: null, description: null, links: null } const Link3Box = ({ accountId, text }: { accountId: string; text: string }) => { return ( {text} ) } export default function AccountHeader({ accountId }: { accountId: string }): ReactElement { const [profile, setProfile] = useState({ name: accountTruncate(accountId), image: null, description: null, links: null }) const [isShowMore, setIsShowMore] = useState(false) const toogleShowMore = () => { setIsShowMore(!isShowMore) } useEffect(() => { if (!accountId) { setProfile(clearedProfile) return } const source = axios.CancelToken.source() async function getInfoFrom3Box() { const profile3Box = await get3BoxProfile(accountId, source.token) if (profile3Box) { const { name, emoji, description, image, links } = profile3Box const newName = `${emoji || ''} ${name || accountTruncate(accountId)}` const newProfile = { name: newName, image, description, links } setProfile(newProfile) } else { setProfile(clearedProfile) } } getInfoFrom3Box() return () => { source.cancel() } }, [accountId]) return (
{isDescriptionTextClamped() ? ( ) : ( '' )} {profile.links?.length > 0 && ( )}
Profile data from
) }