Advertisement
Guest User

Untitled

a guest
Aug 31st, 2021
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. import { useRef, useState, useEffect } from 'react'
  2. import { useMoralis } from "react-moralis";
  3. import Auxi from '../../hoc/Auxi/Auxi'
  4. import Navigation from './Navigation/Navigation'
  5.  
  6. import Jazzicon from '@metamask/jazzicon'
  7. import { Button } from '@chakra-ui/button'
  8. import { toast } from 'react-toastify'
  9. import classes from './Header.module.css'
  10.  
  11.  
  12. import Logo from '../UI/Logo/Logo'
  13.  
  14. const Header = (props) => {
  15. const { Moralis, authenticate, isAuthenticated, isAuthenticating, user, logout } = useMoralis();
  16. // const [ethAddress, setEthAddress] = useState('')
  17. // const identicon = useRef(null)
  18.  
  19. // useEffect(() => {
  20.  
  21. // if(isAuthenticated) {
  22. // setEthAddress(user.get('ethAddress'))
  23. // }
  24.  
  25. // if (ethAddress && identicon.current) {
  26. // identicon.current.innerHTML = ''
  27. // identicon.current.appendChild(Jazzicon(18, parseInt(ethAddress.slice(2, 10), 16)))
  28. // }
  29. // }, [ethAddress, isAuthenticated])
  30.  
  31. let metamaskLogin;
  32.  
  33. if (!isAuthenticated) {
  34. metamaskLogin = <Button isLoading={isAuthenticating} className={classes.walletbtn}
  35. onClick={() => authenticate()}>Login with Metamask</Button>
  36. }
  37. else
  38. {
  39. metamaskLogin = <div> <Button className={classes.walletbtn} onClick={() => logout()}>Logout</Button>
  40. <span> {user.get('ethAddress')} </span>
  41. {/* <div style={{ height: '1.1em' }} ref={identicon}></div> */}
  42. </div>
  43. }
  44.  
  45. // Moralis.Web3.onAccountsChanged(function(accounts) {
  46. // logout()
  47. // });
  48.  
  49. return (
  50. <Auxi>
  51. <div className={classes.Header}>
  52. <div className={classes.HeaderLeft}>
  53. <Logo/>
  54. {metamaskLogin}
  55. </div>
  56. <Navigation />
  57. </div>
  58. </Auxi>
  59. )
  60. }
  61.  
  62.  
  63. export default Header;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement