1- import { FC } from 'react' ;
1+ import { FC , useState } from 'react' ;
22import {
33 Avatar ,
4- Box ,
54 Button ,
5+ Popover ,
66 Typography ,
77 useMediaQuery ,
88 useTheme ,
99} from '@mui/material' ;
1010import { useAccount , useDisconnect , useEnsAvatar , useEnsName } from 'wagmi' ;
1111
1212import { formatAddress } from '../../utils/string' ;
13- import { AvatarIcon } from '../../icons' ;
13+ import { AvatarIcon , ChevronIcon , PowerIcon } from '../../icons' ;
1414
1515const Account : FC = ( ) => {
16+ const [ anchorEl , setAnchorEl ] = useState < HTMLButtonElement | null > ( null ) ;
1617 const { address } = useAccount ( ) ;
1718 const { disconnect } = useDisconnect ( ) ;
1819 const { data : ensName } = useEnsName ( { address } ) ;
@@ -23,16 +24,25 @@ const Account: FC = () => {
2324
2425 const formattedAddress = formatAddress ( address ) ;
2526
27+ const handleClosePopover = ( ) => setAnchorEl ( null ) ;
28+
2629 return (
2730 < >
28- < Box
29- display = "flex"
30- alignItems = "center"
31- gap = { 1 }
32- bgcolor = "#f6f7fe"
33- borderRadius = "4px"
34- paddingX = { 1 }
35- height = { isMobile ? '42px' : '100%' }
31+ < Button
32+ aria-describedby = "account-popover"
33+ onClick = { ( event ) => setAnchorEl ( event . currentTarget ) }
34+ sx = { {
35+ bgcolor : '#f6f7fe' ,
36+ borderRadius : '4px' ,
37+ height : isMobile ? '42px' : '100%' ,
38+ paddingX : 1 ,
39+ fontWeight : 600 ,
40+ borderBottomLeftRadius : 0 ,
41+ borderBottomRightRadius : 0 ,
42+ '& .MuiTouchRipple-root' : {
43+ display : 'none' ,
44+ } ,
45+ } }
3646 >
3747 { ensAvatar ? (
3848 < Avatar
@@ -43,20 +53,60 @@ const Account: FC = () => {
4353 ) : (
4454 < AvatarIcon />
4555 ) }
46- < Typography variant = "body2" color = "textPrimary" fontWeight = { 600 } >
56+ < Typography variant = "body2" color = "textPrimary" paddingX = { 1 } >
4757 { formattedAddress }
4858 </ Typography >
49- </ Box >
50- < Button
51- variant = "contained"
52- size = "medium"
53- onClick = { ( ) => disconnect ( ) }
54- sx = { {
55- height : isMobile ? '42px' : '100%' ,
59+ < ChevronIcon
60+ sx = { {
61+ transform : anchorEl ? 'rotate(180deg)' : 'rotate(0deg)' ,
62+ transition : 'transform 0.2s ease-in-out' ,
63+ } }
64+ />
65+ </ Button >
66+ < Popover
67+ id = "account-popover"
68+ open = { ! ! anchorEl }
69+ onClose = { handleClosePopover }
70+ anchorEl = { anchorEl }
71+ anchorOrigin = { {
72+ vertical : 'bottom' ,
73+ horizontal : 'left' ,
74+ } }
75+ transformOrigin = { {
76+ vertical : 'top' ,
77+ horizontal : 'left' ,
78+ } }
79+ slotProps = { {
80+ paper : {
81+ elevation : 0 ,
82+ sx : {
83+ backgroundColor : '#f6f7fe' ,
84+ width : anchorEl ?. getBoundingClientRect ( ) . width ,
85+ minWidth : 'fit-content' ,
86+ borderTopLeftRadius : 0 ,
87+ borderTopRightRadius : 0 ,
88+ border : 'none' ,
89+ } ,
90+ } ,
5691 } }
5792 >
58- Disconnect
59- </ Button >
93+ < Button
94+ onClick = { ( ) => disconnect ( ) }
95+ sx = { {
96+ color : 'sky.main' ,
97+ padding : 1 ,
98+ width : '100%' ,
99+ gap : 1 ,
100+ '&:hover' : {
101+ color : 'primary.main' ,
102+ backgroundColor : 'unset' ,
103+ } ,
104+ } }
105+ >
106+ < PowerIcon />
107+ Disconnect wallet
108+ </ Button >
109+ </ Popover >
60110 </ >
61111 ) ;
62112} ;
0 commit comments