import { ImageWithFallback } from '@components/imageWithFallback'; import { createCacheProfile, getCacheProfile } from '@utils/storage'; import { truncate } from '@utils/truncate'; import { fetch } from '@tauri-apps/api/http'; import Avatar from 'boring-avatars'; import { memo, useCallback, useEffect, useState } from 'react'; export const UserMini = memo(function UserMini({ pubkey }: { pubkey: string }) { const [profile, setProfile] = useState(null); const fetchProfile = useCallback(async (id: string) => { const res = await fetch(`https://rbr.bio/${id}/metadata.json`, { method: 'GET', timeout: 30, }); return res.data; }, []); useEffect(() => { getCacheProfile(pubkey).then((res) => { if (res) { setProfile(JSON.parse(res.metadata)); } else { fetchProfile(pubkey) .then((res: any) => { setProfile(JSON.parse(res.content)); createCacheProfile(pubkey, res.content); }) .catch(console.error); } }); }, [fetchProfile, pubkey]); return (
{profile?.display_name || profile?.name || truncate(pubkey, 16, ' .... ')}