@@ -4,11 +4,14 @@ import { makeStyles } from 'tss-react/mui';
4
4
import { useDebounce } from 'use-debounce' ;
5
5
6
6
import { useTheme } from '@mui/material' ;
7
+ import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined' ;
7
8
import Collapse from '@mui/material/Collapse' ;
8
- import Slider from '@mui/material/Slider' ;
9
9
import Stack from '@mui/material/Stack' ;
10
10
import Switch from '@mui/material/Switch' ;
11
11
import { styled } from '@mui/material/styles' ;
12
+ import Tooltip from '@mui/material/Tooltip' ;
13
+ import ToggleButton from '@mui/material/ToggleButton' ;
14
+ import ToggleButtonGroup from '@mui/material/ToggleButtonGroup' ;
12
15
import Typography from '@mui/material/Typography' ;
13
16
import { amount } from '@wormhole-foundation/sdk' ;
14
17
@@ -17,8 +20,9 @@ import { calculateUSDPrice } from 'utils';
17
20
import { RootState } from 'store' ;
18
21
import { setToNativeToken } from 'store/relay' ;
19
22
import { useTokens } from 'contexts/TokensContext' ;
23
+ import { opacify } from 'utils/theme' ;
20
24
21
- const useStyles = makeStyles ( ) ( ( ) => ( {
25
+ const useStyles = makeStyles ( ) ( ( theme : any ) => ( {
22
26
content : {
23
27
width : '100%' ,
24
28
cursor : 'pointer' ,
@@ -36,36 +40,23 @@ const useStyles = makeStyles()(() => ({
36
40
display : 'flex' ,
37
41
justifyContent : 'space-between' ,
38
42
alignItems : 'center' ,
43
+ marginTop : '8px' ,
39
44
width : '100%' ,
40
45
} ,
41
- } ) ) ;
42
-
43
- type SliderProps = {
44
- baseColor : string ;
45
- railColor : string ;
46
- } ;
47
-
48
- const StyledSlider = styled ( Slider , {
49
- shouldForwardProp : ( prop ) =>
50
- ! [ 'baseColor' , 'railColor' ] . includes ( prop . toString ( ) ) ,
51
- } ) < SliderProps > ( ( { baseColor, railColor, theme } ) => ( {
52
- alignSelf : 'start' ,
53
- color : baseColor ,
54
- height : 8 ,
55
- left : '10px' ,
56
- width : 'calc(100% - 20px)' ,
57
- '& .MuiSlider-rail' : {
58
- height : '8px' ,
59
- backgroundColor : railColor ,
60
- opacity : 0.1 ,
61
- } ,
62
- '& .MuiSlider-track' : {
63
- height : '8px' ,
64
- } ,
65
- '& .MuiSlider-thumb' : {
66
- height : 20 ,
67
- width : 20 ,
68
- backgroundColor : theme . palette . primary . main ,
46
+ toggleButton : {
47
+ backgroundColor : opacify ( theme . palette . text . primary , 0.1 ) ,
48
+ border : '1px solid transparent' ,
49
+ borderRadius : '8px' ,
50
+ '&.Mui-selected' : {
51
+ border : `1px solid ${ theme . palette . primary . main } ` ,
52
+ borderRadius : '8px' ,
53
+ } ,
54
+ '&.MuiToggleButtonGroup-middleButton' : {
55
+ margin : '0 2px' ,
56
+ } ,
57
+ '&.MuiToggleButtonGroup-lastButton' : {
58
+ margin : '0' ,
59
+ } ,
69
60
} ,
70
61
} ) ) ;
71
62
@@ -124,10 +115,11 @@ const GasSlider = (props: {
124
115
props . destinationGasDrop ,
125
116
nativeGasToken ,
126
117
) ;
118
+ const tokenPriceWithParanthesis = tokenPrice ? `(${ tokenPrice } )` : '' ;
127
119
128
120
return (
129
- < Typography fontSize = { 14 } >
130
- { `${ tokenAmount } ${ nativeGasToken . symbol } ${ tokenPrice } ` }
121
+ < Typography color = { theme . palette . primary . main } fontSize = { 14 } >
122
+ { `+ ${ tokenAmount } ${ nativeGasToken . symbol } ${ tokenPriceWithParanthesis } ` }
131
123
</ Typography >
132
124
) ;
133
125
// We want to recompute the price after we update conversion rates (lastTokenPriceUpdate).
@@ -147,7 +139,7 @@ const GasSlider = (props: {
147
139
return (
148
140
< div className = { classes . content } >
149
141
< Stack direction = "row" alignItems = "center" justifyContent = "space-between" >
150
- < Typography > { `Need more gas on ${ destChain } ?` } </ Typography >
142
+ < Typography > { `Need extra ${ nativeGasToken . symbol } on ${ destChain } ?` } </ Typography >
151
143
< StyledSwitch
152
144
checked = { isGasSliderOpen }
153
145
disabled = { props . disabled }
@@ -165,33 +157,66 @@ const GasSlider = (props: {
165
157
</ Stack >
166
158
< Collapse in = { isGasSliderOpen } unmountOnExit >
167
159
< div className = { classes . container } >
168
- < Typography color = { theme . palette . text . secondary } fontSize = { 14 } >
169
- { `Use the slider to buy extra ${ nativeGasToken . symbol } for future transactions.` }
170
- </ Typography >
171
- < div >
172
- < StyledSlider
173
- aria-label = "Native gas conversion amount"
174
- defaultValue = { 0 }
175
- disabled = { props . disabled }
176
- value = { percentage }
177
- baseColor = { theme . palette . primary . main }
178
- railColor = { theme . palette . secondary . main }
179
- step = { 1 }
180
- min = { 0 }
181
- max = { 100 }
182
- valueLabelFormat = { ( ) => `${ percentage } %` }
183
- valueLabelDisplay = "auto"
184
- onChange = { ( e : any ) => setPercentage ( e . target . value ) }
185
- />
160
+ < Stack >
161
+ < ToggleButtonGroup
162
+ exclusive
163
+ fullWidth
164
+ value = { percentage . toString ( ) }
165
+ onChange = { ( e : any ) => {
166
+ const newPercentValue = Number ( e . currentTarget . value ) ;
167
+ if ( newPercentValue === percentage ) {
168
+ // Unselect if user clicks on the same value
169
+ setPercentage ( 0 ) ;
170
+ } else {
171
+ setPercentage ( newPercentValue ) ;
172
+ }
173
+ } }
174
+ >
175
+ < ToggleButton
176
+ className = { classes . toggleButton }
177
+ disableRipple
178
+ value = "5"
179
+ >
180
+ 5%
181
+ </ ToggleButton >
182
+ < ToggleButton
183
+ className = { classes . toggleButton }
184
+ disableRipple
185
+ value = "10"
186
+ >
187
+ 10%
188
+ </ ToggleButton >
189
+ < ToggleButton
190
+ className = { classes . toggleButton }
191
+ disableRipple
192
+ value = "15"
193
+ >
194
+ 15%
195
+ </ ToggleButton >
196
+ </ ToggleButtonGroup >
186
197
< div className = { classes . amounts } >
187
- < Typography color = { theme . palette . text . secondary } fontSize = { 14 } >
188
- Additional gas
189
- </ Typography >
198
+ < Stack alignItems = "center" flexDirection = "row" >
199
+ < Typography
200
+ color = { theme . palette . text . secondary }
201
+ fontSize = { 14 }
202
+ marginRight = "4px"
203
+ >
204
+ Gas amount
205
+ </ Typography >
206
+ < Tooltip title = "This additional gas is swapped from a percentage of your transfer amount." >
207
+ < InfoOutlinedIcon
208
+ sx = { {
209
+ color : theme . palette . text . secondary ,
210
+ fontSize : '16px' ,
211
+ } }
212
+ />
213
+ </ Tooltip >
214
+ </ Stack >
190
215
< Typography color = { theme . palette . text . secondary } fontSize = { 14 } >
191
216
{ nativeGasPrice }
192
217
</ Typography >
193
218
</ div >
194
- </ div >
219
+ </ Stack >
195
220
</ div >
196
221
</ Collapse >
197
222
</ div >
0 commit comments