Skip to content

Commit ee63afa

Browse files
authored
Gas slider redesign (#3374)
* Gas top-up control redesign Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz> * Unselect when user clicks on the same percent value Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz> --------- Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
1 parent a4b8cd1 commit ee63afa

File tree

1 file changed

+80
-55
lines changed
  • wormhole-connect/src/views/v2/Bridge/GasSlider

1 file changed

+80
-55
lines changed

wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx

+80-55
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { makeStyles } from 'tss-react/mui';
44
import { useDebounce } from 'use-debounce';
55

66
import { useTheme } from '@mui/material';
7+
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
78
import Collapse from '@mui/material/Collapse';
8-
import Slider from '@mui/material/Slider';
99
import Stack from '@mui/material/Stack';
1010
import Switch from '@mui/material/Switch';
1111
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';
1215
import Typography from '@mui/material/Typography';
1316
import { amount } from '@wormhole-foundation/sdk';
1417

@@ -17,8 +20,9 @@ import { calculateUSDPrice } from 'utils';
1720
import { RootState } from 'store';
1821
import { setToNativeToken } from 'store/relay';
1922
import { useTokens } from 'contexts/TokensContext';
23+
import { opacify } from 'utils/theme';
2024

21-
const useStyles = makeStyles()(() => ({
25+
const useStyles = makeStyles()((theme: any) => ({
2226
content: {
2327
width: '100%',
2428
cursor: 'pointer',
@@ -36,36 +40,23 @@ const useStyles = makeStyles()(() => ({
3640
display: 'flex',
3741
justifyContent: 'space-between',
3842
alignItems: 'center',
43+
marginTop: '8px',
3944
width: '100%',
4045
},
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+
},
6960
},
7061
}));
7162

@@ -124,10 +115,11 @@ const GasSlider = (props: {
124115
props.destinationGasDrop,
125116
nativeGasToken,
126117
);
118+
const tokenPriceWithParanthesis = tokenPrice ? `(${tokenPrice})` : '';
127119

128120
return (
129-
<Typography fontSize={14}>
130-
{`${tokenAmount} ${nativeGasToken.symbol} ${tokenPrice}`}
121+
<Typography color={theme.palette.primary.main} fontSize={14}>
122+
{`+${tokenAmount} ${nativeGasToken.symbol} ${tokenPriceWithParanthesis}`}
131123
</Typography>
132124
);
133125
// We want to recompute the price after we update conversion rates (lastTokenPriceUpdate).
@@ -147,7 +139,7 @@ const GasSlider = (props: {
147139
return (
148140
<div className={classes.content}>
149141
<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>
151143
<StyledSwitch
152144
checked={isGasSliderOpen}
153145
disabled={props.disabled}
@@ -165,33 +157,66 @@ const GasSlider = (props: {
165157
</Stack>
166158
<Collapse in={isGasSliderOpen} unmountOnExit>
167159
<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>
186197
<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>
190215
<Typography color={theme.palette.text.secondary} fontSize={14}>
191216
{nativeGasPrice}
192217
</Typography>
193218
</div>
194-
</div>
219+
</Stack>
195220
</div>
196221
</Collapse>
197222
</div>

0 commit comments

Comments
 (0)