Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple implementation #46

Open
kangfenmao opened this issue Apr 18, 2022 · 1 comment
Open

Simple implementation #46

kangfenmao opened this issue Apr 18, 2022 · 1 comment

Comments

@kangfenmao
Copy link

import jazzicon from '@metamask/jazzicon'
import React, { CSSProperties, useEffect, useRef } from 'react'

interface Props {
  account: string
  size: number
  style?: CSSProperties
}

const MetaMaskAvatar: React.FC<Props> = ({ account, size, style }) => {
  const avatarRef = useRef<HTMLDivElement>(null)

  useEffect(() => {
    const element = avatarRef.current
    if (element && account) {
      const addr = account.slice(2, 10)
      const seed = parseInt(addr, 16)
      const icon = jazzicon(size, seed)
      if (element.firstChild) {
        element.removeChild(element.firstChild)
      }
      element.appendChild(icon)
    }
  }, [account, avatarRef, size])

  return <div style={style} ref={avatarRef} />
}

export default MetaMaskAvatar
@John-Oldman-Wang
Copy link

you can use this package to solve your question. https://www.npmjs.com/package/@cfx-kit/wallet-avatar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants