@ -6,12 +6,29 @@ import ButtonGroup from '../../../components/ui/button-group';
import Button from '../../../components/ui/button' ;
import InfoTooltip from '../../../components/ui/info-tooltip' ;
export default function SlippageButtons ( { onSelect , maxAllowedSlippage } ) {
export default function SlippageButtons ( {
onSelect ,
maxAllowedSlippage ,
currentSlippage ,
} ) {
const t = useContext ( I18nContext ) ;
const [ open , setOpen ] = useState ( false ) ;
const [ customValue , setCustomValue ] = useState ( '' ) ;
const [ customValue , setCustomValue ] = useState ( ( ) => {
if ( currentSlippage && currentSlippage !== 2 && currentSlippage !== 3 ) {
return currentSlippage ;
}
return '' ;
} ) ;
const [ enteringCustomValue , setEnteringCustomValue ] = useState ( false ) ;
const [ activeButtonIndex , setActiveButtonIndex ] = useState ( 1 ) ;
const [ activeButtonIndex , setActiveButtonIndex ] = useState ( ( ) => {
if ( currentSlippage === 3 ) {
return 1 ;
} else if ( currentSlippage === 2 ) {
return 0 ;
} else if ( currentSlippage ) {
return 2 ;
}
return 1 ; // Choose activeButtonIndex = 1 for 3% slippage by default.
} ) ;
const [ inputRef , setInputRef ] = useState ( null ) ;
let errorText = '' ;
@ -44,23 +61,12 @@ export default function SlippageButtons({ onSelect, maxAllowedSlippage }) {
return (
< div className = "slippage-buttons" >
< button
onClick = { ( ) => setOpen ( ! open ) }
className = { classnames ( 'slippage-buttons__header' , {
'slippage-buttons__header--open' : open ,
} ) }
>
< div className = "slippage-buttons__header" >
< div className = "slippage-buttons__header-text" >
{ t ( 'swapsAdvancedOptions' ) }
< / d i v >
{ open ? (
< i className = "fa fa-angle-up" / >
) : (
< i className = "fa fa-angle-down" / >
) }
< / b u t t o n >
< / d i v >
< div className = "slippage-buttons__content" >
{ open && (
< div className = "slippage-buttons__dropdown-content" >
< div className = "slippage-buttons__buttons-prefix" >
< div className = "slippage-buttons__prefix-text" >
@ -87,20 +93,20 @@ export default function SlippageButtons({ onSelect, maxAllowedSlippage }) {
setCustomValue ( '' ) ;
setEnteringCustomValue ( false ) ;
setActiveButtonIndex ( 0 ) ;
onSelect ( 1 ) ;
onSelect ( 2 ) ;
} }
>
1 %
2 %
< / B u t t o n >
< Button
onClick = { ( ) => {
setCustomValue ( '' ) ;
setEnteringCustomValue ( false ) ;
setActiveButtonIndex ( 1 ) ;
onSelect ( 2 ) ;
onSelect ( 3 ) ;
} }
>
2 %
3 %
< / B u t t o n >
< Button
className = { classnames (
@ -147,7 +153,6 @@ export default function SlippageButtons({ onSelect, maxAllowedSlippage }) {
< / B u t t o n >
< / B u t t o n G r o u p >
< / d i v >
) }
{ errorText && (
< div className = "slippage-buttons__error-text" > { errorText } < / d i v >
) }
@ -159,4 +164,5 @@ export default function SlippageButtons({ onSelect, maxAllowedSlippage }) {
SlippageButtons . propTypes = {
onSelect : PropTypes . func . isRequired ,
maxAllowedSlippage : PropTypes . number . isRequired ,
currentSlippage : PropTypes . number ,
} ;