forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAvatar.tsx
More file actions
47 lines (42 loc) · 1.4 KB
/
Copy pathUserAvatar.tsx
File metadata and controls
47 lines (42 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { useEffect, useState } from "react";
import BoringAvatar from "boring-avatars";
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
import { getProfileAvatarUrl } from "@/lib/profile/profileStorage";
export interface UserAvatarProps {
address?: string;
avatarUrl?: string; // Explicit override
size?: number;
className?: string;
}
export function UserAvatar({
address = "default",
avatarUrl,
size = 40,
className,
}: UserAvatarProps) {
const [localUrl, setLocalUrl] = useState<string | null>(getProfileAvatarUrl(address));
// Listen for local updates to sync avatars across tabs/components
useEffect(() => {
const handleUpdate = () => {
setLocalUrl(getProfileAvatarUrl(address));
};
window.addEventListener("avatar_updated", handleUpdate);
return () => window.removeEventListener("avatar_updated", handleUpdate);
}, [address]);
const url = avatarUrl || localUrl;
return (
<Avatar className={className} style={{ width: size, height: size }}>
{url ? (
<AvatarImage src={url} alt={address} className="object-cover" />
) : null}
<AvatarFallback className="bg-transparent text-transparent">
<BoringAvatar
size={size}
name={address}
variant="beam"
colors={["#0ea5e9", "#14b8a6", "#f59e0b", "#f43f5e", "#8b5cf6"]}
/>
</AvatarFallback>
</Avatar>
);
}