Created
July 3, 2021 15:14
-
-
Save tigransimonyan/17df0952dce8f1696f68139cc7f7d927 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from 'react'; | |
import jazzicon from '@metamask/jazzicon'; | |
function MetaMaskAvatar({ account }) { | |
const avatarRef = useRef(); | |
useEffect(() => { | |
const element = avatarRef.current; | |
if (element && account) { | |
const addr = account.slice(2, 10); | |
const seed = parseInt(addr, 16); | |
const icon = jazzicon(40, seed); | |
if (element.firstChild) { | |
element.removeChild(element.firstChild); | |
} | |
element.appendChild(icon); | |
} | |
}, [account, avatarRef]); | |
return <div ref={avatarRef} />; | |
} | |
export default MetaMaskAvatar; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment