-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAvatar.tsx
More file actions
72 lines (69 loc) · 1.81 KB
/
Avatar.tsx
File metadata and controls
72 lines (69 loc) · 1.81 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Box } from '@chakra-ui/react'
import type { ComponentProps, FC } from 'react'
import Jazzicon, { jsNumberForAddress } from 'react-jazzicon'
interface AvatarProps extends ComponentProps<'div'> {
address: string
ensImage: string | null | undefined
ensName: string | null | undefined
size?: number
}
/**
* Avatar component, displays an avatar with an ENS image or Jazzicon based on the provided props.
*
* If an ENS image is provided, it will be displayed, otherwise a Jazzicon will be displayed based on the address.
* This component is used as a custom avatar for the WalletProvider.
*
* @param {object} props - Avatar component props.
* @param {string} props.address - The address to infer the avatar from
* @param {string | null | undefined} props.ensImage - The ENS image URL for the avatar
* @param {string | null | undefined} props.ensName - The ENS name
* @param {number} [props.size=100] - The size of the avatar
*
* @example
* ```tsx
* <Avatar
* address="0x1234567890abcdef1234567890abcdef12345678"
* ensImage="avatar.png"
* ensName="test.eth"
* radius={96}
* size={96}
* />
* ```
*/
const Avatar: FC<AvatarProps> = ({
address,
ensImage,
ensName,
size = 100,
}: {
address: string
ensImage: string | null | undefined
ensName: string | null | undefined
size?: number
}) => {
return (
<Box
borderRadius="50%"
height={`${size}px`}
overflow="hidden"
width={`${size}px`}
>
{ensImage ? (
<img
alt={ensName ?? address}
height="100%"
loading="lazy"
src={ensImage}
width="100%"
/>
) : (
<Jazzicon
data-testid="avatar-icon"
diameter={size}
seed={jsNumberForAddress(address)}
/>
)}
</Box>
)
}
export default Avatar