Skip to content

Instantly share code, notes, and snippets.

@tigransimonyan
Created July 3, 2021 15:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tigransimonyan/17df0952dce8f1696f68139cc7f7d927 to your computer and use it in GitHub Desktop.
Save tigransimonyan/17df0952dce8f1696f68139cc7f7d927 to your computer and use it in GitHub Desktop.
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