-
Notifications
You must be signed in to change notification settings - Fork 489
Expand file tree
/
Copy pathApprovalMethodToggleButton.tsx
More file actions
99 lines (94 loc) · 2.91 KB
/
Copy pathApprovalMethodToggleButton.tsx
File metadata and controls
99 lines (94 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { CheckIcon } from '@heroicons/react/outline';
import { CogIcon } from '@heroicons/react/solid';
import { Trans } from '@lingui/macro';
import {
Box,
ListItemIcon,
ListItemText,
Menu,
MenuItem,
SvgIcon,
Typography,
} from '@mui/material';
import * as React from 'react';
import { ApprovalMethod } from 'src/store/walletSlice';
interface ApprovalMethodToggleButtonProps {
currentMethod: ApprovalMethod;
setMethod: (newMethod: ApprovalMethod) => void;
}
export const ApprovalMethodToggleButton = ({
currentMethod,
setMethod,
}: ApprovalMethodToggleButtonProps) => {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
<>
<Box
onClick={handleClick}
sx={{ display: 'flex', alignItems: 'center', cursor: 'pointer' }}
data-cy={`approveButtonChange`}
>
<Typography variant="subheader2" color="info.main">
<Trans>{currentMethod}</Trans>
</Typography>
<SvgIcon sx={{ fontSize: 16, ml: 1, color: 'info.main' }}>
<CogIcon />
</SvgIcon>
</Box>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
MenuListProps={{
'aria-labelledby': 'basic-button',
}}
keepMounted={true}
data-cy={`approveMenu_${currentMethod}`}
>
<MenuItem
data-cy={`approveOption_${ApprovalMethod.PERMIT}`}
selected={currentMethod === ApprovalMethod.PERMIT}
value={ApprovalMethod.PERMIT}
onClick={() => {
if (currentMethod === ApprovalMethod.APPROVE) {
setMethod(ApprovalMethod.PERMIT);
}
handleClose();
}}
>
<ListItemText primaryTypographyProps={{ variant: 'subheader1' }}>
<Trans>{ApprovalMethod.PERMIT}</Trans>
</ListItemText>
<ListItemIcon>
<SvgIcon>{currentMethod === ApprovalMethod.PERMIT && <CheckIcon />}</SvgIcon>
</ListItemIcon>
</MenuItem>
<MenuItem
data-cy={`approveOption_${ApprovalMethod.APPROVE}`}
selected={currentMethod === ApprovalMethod.APPROVE}
value={ApprovalMethod.APPROVE}
onClick={() => {
if (currentMethod === ApprovalMethod.PERMIT) {
setMethod(ApprovalMethod.APPROVE);
}
handleClose();
}}
>
<ListItemText primaryTypographyProps={{ variant: 'subheader1' }}>
<Trans>{ApprovalMethod.APPROVE}</Trans>
</ListItemText>
<ListItemIcon>
<SvgIcon>{currentMethod === ApprovalMethod.APPROVE && <CheckIcon />}</SvgIcon>
</ListItemIcon>
</MenuItem>
</Menu>
</>
);
};