Skip to content

Commit cc49133

Browse files
committed
refactor: account popover
1 parent 8ce20bb commit cc49133

File tree

2 files changed

+93
-21
lines changed

2 files changed

+93
-21
lines changed

packages/apps/staking/src/components/Account/index.tsx

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { FC } from 'react';
1+
import { FC, useState } from 'react';
22
import {
33
Avatar,
4-
Box,
54
Button,
5+
Popover,
66
Typography,
77
useMediaQuery,
88
useTheme,
99
} from '@mui/material';
1010
import { useAccount, useDisconnect, useEnsAvatar, useEnsName } from 'wagmi';
1111

1212
import { formatAddress } from '../../utils/string';
13-
import { AvatarIcon } from '../../icons';
13+
import { AvatarIcon, ChevronIcon, PowerIcon } from '../../icons';
1414

1515
const 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
};

packages/apps/staking/src/icons/index.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,25 @@ export const CloseIcon: FC<SvgIconProps> = (props) => {
222222
</SvgIcon>
223223
);
224224
};
225+
226+
export const ChevronIcon: FC<SvgIconProps> = (props) => {
227+
return (
228+
<SvgIcon {...props} viewBox="0 0 24 24" fill="none">
229+
<path
230+
fill="#24046D"
231+
d="M16.59 8.295L12 12.875L7.41 8.295L6 9.705L12 15.705L18 9.705L16.59 8.295Z"
232+
/>
233+
</SvgIcon>
234+
);
235+
};
236+
237+
export const PowerIcon: FC<SvgIconProps> = (props) => {
238+
return (
239+
<SvgIcon {...props} viewBox="0 0 24 24" fill="none">
240+
<path
241+
fill="currentColor"
242+
d="M13.5 3H11.5V13H13.5V3ZM18.33 5.17L16.91 6.59C18.49 7.86 19.5 9.81 19.5 12C19.5 15.87 16.37 19 12.5 19C8.63 19 5.5 15.87 5.5 12C5.5 9.81 6.51 7.86 8.08 6.58L6.67 5.17C4.73 6.82 3.5 9.26 3.5 12C3.5 16.97 7.53 21 12.5 21C17.47 21 21.5 16.97 21.5 12C21.5 9.26 20.27 6.82 18.33 5.17Z"
243+
/>
244+
</SvgIcon>
245+
);
246+
};

0 commit comments

Comments
 (0)