-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathApproveConfirmButtons.tsx
144 lines (127 loc) · 3.64 KB
/
ApproveConfirmButtons.tsx
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { styled } from 'styled-components'
import { ChevronRightIcon, Button as UIKitButton, AutoRenewIcon, ChevronDownIcon, Box, Flex } from '@pancakeswap/uikit'
import { useTranslation } from '@pancakeswap/localization'
export enum ButtonArrangement {
ROW = 'row',
SEQUENTIAL = 'sequential',
}
interface ApproveConfirmButtonsProps {
isApproveDisabled: boolean
isApproving: boolean
isConfirming: boolean
isConfirmDisabled: boolean
onApprove: () => void
onConfirm: () => void
buttonArrangement?: ButtonArrangement
confirmLabel?: string
confirmId?: string
useMinWidth?: boolean
}
const StyledApproveConfirmButtonRow = styled.div`
align-items: center;
display: grid;
grid-template-columns: 1fr;
justify-content: center;
${({ theme }) => theme.mediaQueries.md} {
grid-template-columns: 1fr 24px 1fr;
}
`
const Button = styled(UIKitButton)<{ useMinWidth?: boolean }>`
width: 100%;
${({ theme }) => theme.mediaQueries.md} {
${({ useMinWidth }) =>
useMinWidth &&
`
min-width: 160px;
`}
}
`
const iconAttrs = { width: '24px', color: 'textDisabled' }
const ChevronRight = styled(ChevronRightIcon).attrs(iconAttrs)`
display: none;
${({ theme }) => theme.mediaQueries.md} {
display: block;
}
`
const ChevronBottom = styled(ChevronDownIcon).attrs(iconAttrs)`
display: block;
${({ theme }) => theme.mediaQueries.md} {
display: none;
}
`
const spinnerIcon = <AutoRenewIcon spin color="currentColor" />
const ApproveConfirmButtons: React.FC<React.PropsWithChildren<ApproveConfirmButtonsProps>> = ({
isApproveDisabled,
isApproving,
isConfirming,
isConfirmDisabled,
onApprove,
onConfirm,
buttonArrangement = ButtonArrangement.ROW,
confirmLabel,
confirmId,
useMinWidth = true,
}) => {
const { t } = useTranslation()
const confirmButtonText = confirmLabel ?? t('Confirm')
const ApproveConfirmRow = () => {
return (
<StyledApproveConfirmButtonRow>
<Box>
<Button
disabled={isApproveDisabled}
onClick={onApprove}
endIcon={isApproving ? spinnerIcon : undefined}
isLoading={isApproving}
useMinWidth={useMinWidth}
>
{isApproving ? t('Enabling') : t('Enable')}
</Button>
</Box>
<Flex justifyContent="center">
<ChevronRight />
<ChevronBottom />
</Flex>
<Box>
<Button
id={confirmId}
onClick={onConfirm}
disabled={isConfirmDisabled}
isLoading={isConfirming}
endIcon={isConfirming ? spinnerIcon : undefined}
useMinWidth={useMinWidth}
>
{isConfirming ? t('Confirming') : confirmButtonText}
</Button>
</Box>
</StyledApproveConfirmButtonRow>
)
}
const ApproveConfirmSequential = () => {
return (
<>
{isApproveDisabled ? (
<Box>
<Button
id={confirmId}
onClick={onConfirm}
disabled={isConfirmDisabled}
isLoading={isConfirming}
endIcon={isConfirming ? spinnerIcon : undefined}
>
{isConfirming ? t('Confirming') : confirmButtonText}
</Button>
</Box>
) : (
<Box>
<Button onClick={onApprove} endIcon={isApproving ? spinnerIcon : undefined} isLoading={isApproving}>
{isApproving ? t('Enabling') : t('Enable')}
</Button>
</Box>
)}
</>
)
}
return buttonArrangement === ButtonArrangement.ROW ? ApproveConfirmRow() : ApproveConfirmSequential()
}
export default ApproveConfirmButtons