Skip to content

Commit f4aff98

Browse files
committed
Update gas top-up control
Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
1 parent 681da52 commit f4aff98

File tree

2 files changed

+67
-66
lines changed

2 files changed

+67
-66
lines changed

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

+56-58
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { useTheme } from '@mui/material';
77
import Card from '@mui/material/Card';
88
import CardContent from '@mui/material/CardContent';
99
import Collapse from '@mui/material/Collapse';
10-
import Slider from '@mui/material/Slider';
1110
import Stack from '@mui/material/Stack';
1211
import Switch from '@mui/material/Switch';
1312
import { styled } from '@mui/material/styles';
13+
import ToggleButton from '@mui/material/ToggleButton';
14+
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
1415
import Typography from '@mui/material/Typography';
1516
import { amount } from '@wormhole-foundation/sdk';
1617

@@ -40,34 +41,8 @@ const useStyles = makeStyles()(() => ({
4041
alignItems: 'center',
4142
width: '100%',
4243
},
43-
}));
44-
45-
type SliderProps = {
46-
baseColor: string;
47-
railColor: string;
48-
};
49-
50-
const StyledSlider = styled(Slider, {
51-
shouldForwardProp: (prop) =>
52-
!['baseColor', 'railColor'].includes(prop.toString()),
53-
})<SliderProps>(({ baseColor, railColor, theme }) => ({
54-
alignSelf: 'start',
55-
color: baseColor,
56-
height: 8,
57-
left: '10px',
58-
width: 'calc(100% - 20px)',
59-
'& .MuiSlider-rail': {
60-
height: '8px',
61-
backgroundColor: railColor,
62-
opacity: 0.1,
63-
},
64-
'& .MuiSlider-track': {
65-
height: '8px',
66-
},
67-
'& .MuiSlider-thumb': {
68-
height: 20,
69-
width: 20,
70-
backgroundColor: theme.palette.primary.main,
44+
gasButton: {
45+
borderRadius: '8px',
7146
},
7247
}));
7348

@@ -105,6 +80,7 @@ const GasSlider = (props: {
10580

10681
const [isGasSliderOpen, setIsGasSliderOpen] = useState(false);
10782
const [percentage, setPercentage] = useState(0);
83+
const [gasSelection, setGasSelection] = useState();
10884

10985
const [debouncedPercentage] = useDebounce(percentage, 500);
11086

@@ -154,7 +130,7 @@ const GasSlider = (props: {
154130
alignItems="center"
155131
justifyContent="space-between"
156132
>
157-
<Typography>{`Need more gas on ${destChain}?`}</Typography>
133+
<Typography>{`Need extra ${nativeGasToken.symbol} on ${destChain}?`}</Typography>
158134
<StyledSwitch
159135
checked={isGasSliderOpen}
160136
disabled={props.disabled}
@@ -165,41 +141,63 @@ const GasSlider = (props: {
165141

166142
if (!checked) {
167143
setPercentage(0);
144+
setGasSelection(undefined);
168145
dispatch(setToNativeToken(0));
169146
}
170147
}}
171148
/>
172149
</Stack>
173150
<Collapse in={isGasSliderOpen} unmountOnExit>
174-
<div className={classes.container}>
175-
<Typography color={theme.palette.text.secondary} fontSize={14}>
176-
{`Use the slider to buy extra ${nativeGasToken.symbol} for future transactions.`}
177-
</Typography>
178-
<div>
179-
<StyledSlider
180-
aria-label="Native gas conversion amount"
181-
defaultValue={0}
182-
disabled={props.disabled}
183-
value={percentage}
184-
baseColor={theme.palette.primary.main}
185-
railColor={theme.palette.background.default}
186-
step={1}
187-
min={0}
188-
max={100}
189-
valueLabelFormat={() => `${percentage}%`}
190-
valueLabelDisplay="auto"
191-
onChange={(e: any) => setPercentage(e.target.value)}
192-
/>
193-
<div className={classes.amounts}>
194-
<Typography color={theme.palette.text.secondary} fontSize={14}>
195-
Additional gas
196-
</Typography>
197-
<Typography color={theme.palette.text.secondary} fontSize={14}>
198-
{nativeGasPrice}
199-
</Typography>
200-
</div>
151+
<Stack className={classes.container}>
152+
<ToggleButtonGroup
153+
color="primary"
154+
value={gasSelection}
155+
exclusive
156+
fullWidth
157+
onChange={(_, selection) => {
158+
setGasSelection(selection);
159+
setPercentage(
160+
selection === 'small'
161+
? 25
162+
: selection === 'medium'
163+
? 50
164+
: selection === 'large'
165+
? 100
166+
: 0,
167+
);
168+
}}
169+
>
170+
<ToggleButton
171+
disableRipple
172+
className={classes.gasButton}
173+
value="small"
174+
>
175+
Small
176+
</ToggleButton>
177+
<ToggleButton
178+
disableRipple
179+
className={classes.gasButton}
180+
value="medium"
181+
>
182+
Medium
183+
</ToggleButton>
184+
<ToggleButton
185+
disableRipple
186+
className={classes.gasButton}
187+
value="large"
188+
>
189+
Large
190+
</ToggleButton>
191+
</ToggleButtonGroup>
192+
<div className={classes.amounts}>
193+
<Typography color={theme.palette.text.secondary} fontSize={14}>
194+
Additional gas
195+
</Typography>
196+
<Typography color={theme.palette.text.secondary} fontSize={14}>
197+
{nativeGasPrice}
198+
</Typography>
201199
</div>
202-
</div>
200+
</Stack>
203201
</Collapse>
204202
</CardContent>
205203
</Card>

wormhole-connect/src/views/v2/Bridge/Routes/SingleRoute.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,17 @@ const SingleRoute = (props: Props) => {
631631
{warningMessages}
632632
</CardContent>
633633
{showGasSlider && (
634-
<Collapse in={showGasSlider}>
635-
<GasSlider
636-
destinationGasDrop={
637-
receiveNativeAmount || amount.fromBaseUnits(0n, 8)
638-
}
639-
disabled={isGasSliderDisabled}
640-
/>
641-
</Collapse>
634+
<>
635+
<Divider flexItem sx={{ margin: '0px 16px' }} />
636+
<Collapse in={showGasSlider}>
637+
<GasSlider
638+
destinationGasDrop={
639+
receiveNativeAmount || amount.fromBaseUnits(0n, 8)
640+
}
641+
disabled={isGasSliderDisabled}
642+
/>
643+
</Collapse>
644+
</>
642645
)}
643646
</CardActionArea>
644647
</Card>

0 commit comments

Comments
 (0)