From 3796121262e54a227e8dad3629951135aad1945d Mon Sep 17 00:00:00 2001 From: Emre Bogazliyanlioglu Date: Wed, 19 Mar 2025 21:00:50 +0300 Subject: [PATCH 1/2] Gas top-up control redesign Signed-off-by: Emre Bogazliyanlioglu --- .../src/views/v2/Bridge/GasSlider/index.tsx | 119 ++++++++++-------- 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx b/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx index e8fe914cf..b07bf8727 100644 --- a/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx +++ b/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx @@ -4,11 +4,14 @@ import { makeStyles } from 'tss-react/mui'; import { useDebounce } from 'use-debounce'; import { useTheme } from '@mui/material'; +import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; import Collapse from '@mui/material/Collapse'; -import Slider from '@mui/material/Slider'; import Stack from '@mui/material/Stack'; import Switch from '@mui/material/Switch'; import { styled } from '@mui/material/styles'; +import Tooltip from '@mui/material/Tooltip'; +import ToggleButton from '@mui/material/ToggleButton'; +import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; import Typography from '@mui/material/Typography'; import { amount } from '@wormhole-foundation/sdk'; @@ -17,8 +20,9 @@ import { calculateUSDPrice } from 'utils'; import { RootState } from 'store'; import { setToNativeToken } from 'store/relay'; import { useTokens } from 'contexts/TokensContext'; +import { opacify } from 'utils/theme'; -const useStyles = makeStyles()(() => ({ +const useStyles = makeStyles()((theme: any) => ({ content: { width: '100%', cursor: 'pointer', @@ -36,36 +40,23 @@ const useStyles = makeStyles()(() => ({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', + marginTop: '8px', width: '100%', }, -})); - -type SliderProps = { - baseColor: string; - railColor: string; -}; - -const StyledSlider = styled(Slider, { - shouldForwardProp: (prop) => - !['baseColor', 'railColor'].includes(prop.toString()), -})(({ baseColor, railColor, theme }) => ({ - alignSelf: 'start', - color: baseColor, - height: 8, - left: '10px', - width: 'calc(100% - 20px)', - '& .MuiSlider-rail': { - height: '8px', - backgroundColor: railColor, - opacity: 0.1, - }, - '& .MuiSlider-track': { - height: '8px', - }, - '& .MuiSlider-thumb': { - height: 20, - width: 20, - backgroundColor: theme.palette.primary.main, + toggleButton: { + backgroundColor: opacify(theme.palette.text.primary, 0.1), + border: '1px solid transparent', + borderRadius: '8px', + '&.Mui-selected': { + border: `1px solid ${theme.palette.primary.main}`, + borderRadius: '8px', + }, + '&.MuiToggleButtonGroup-middleButton': { + margin: '0 2px', + }, + '&.MuiToggleButtonGroup-lastButton': { + margin: '0', + }, }, })); @@ -124,10 +115,11 @@ const GasSlider = (props: { props.destinationGasDrop, nativeGasToken, ); + const tokenPriceWithParanthesis = tokenPrice ? `(${tokenPrice})` : ''; return ( - - {`${tokenAmount} ${nativeGasToken.symbol} ${tokenPrice}`} + + {`+${tokenAmount} ${nativeGasToken.symbol} ${tokenPriceWithParanthesis}`} ); // We want to recompute the price after we update conversion rates (lastTokenPriceUpdate). @@ -147,7 +139,7 @@ const GasSlider = (props: { return (
- {`Need more gas on ${destChain}?`} + {`Need extra ${nativeGasToken.symbol} on ${destChain}?`}
- - {`Use the slider to buy extra ${nativeGasToken.symbol} for future transactions.`} - -
- `${percentage}%`} - valueLabelDisplay="auto" - onChange={(e: any) => setPercentage(e.target.value)} - /> + + { + if (percentValue) { + setPercentage(Number(percentValue)); + } + }} + > + + 5% + + + 10% + + + 15% + +
- - Additional gas - + + + Gas amount + + + + + {nativeGasPrice}
-
+
From 6d6583469956679bd1a89f4094a1e8a507f945a0 Mon Sep 17 00:00:00 2001 From: Emre Bogazliyanlioglu Date: Fri, 21 Mar 2025 15:31:17 +0300 Subject: [PATCH 2/2] Unselect when user clicks on the same percent value Signed-off-by: Emre Bogazliyanlioglu --- .../src/views/v2/Bridge/GasSlider/index.tsx | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx b/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx index b07bf8727..92deabd98 100644 --- a/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx +++ b/wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx @@ -162,19 +162,35 @@ const GasSlider = (props: { exclusive fullWidth value={percentage.toString()} - onChange={(_e, percentValue: string | null) => { - if (percentValue) { - setPercentage(Number(percentValue)); + onChange={(e: any) => { + const newPercentValue = Number(e.currentTarget.value); + if (newPercentValue === percentage) { + // Unselect if user clicks on the same value + setPercentage(0); + } else { + setPercentage(newPercentValue); } }} > - + 5% - + 10% - + 15%