@ -13,8 +13,12 @@ export default function SlippageButtons({
} ) {
} ) {
const t = useContext ( I18nContext ) ;
const t = useContext ( I18nContext ) ;
const [ customValue , setCustomValue ] = useState ( ( ) => {
const [ customValue , setCustomValue ] = useState ( ( ) => {
if ( currentSlippage && currentSlippage !== 2 && currentSlippage !== 3 ) {
if (
return currentSlippage ;
typeof currentSlippage === 'number' &&
currentSlippage !== 2 &&
currentSlippage !== 3
) {
return currentSlippage . toString ( ) ;
}
}
return '' ;
return '' ;
} ) ;
} ) ;
@ -24,7 +28,7 @@ export default function SlippageButtons({
return 1 ;
return 1 ;
} else if ( currentSlippage === 2 ) {
} else if ( currentSlippage === 2 ) {
return 0 ;
return 0 ;
} else if ( currentSlippage ) {
} else if ( typeof currentSlippage === 'number' ) {
return 2 ;
return 2 ;
}
}
return 1 ; // Choose activeButtonIndex = 1 for 3% slippage by default.
return 1 ; // Choose activeButtonIndex = 1 for 3% slippage by default.
@ -33,9 +37,12 @@ export default function SlippageButtons({
let errorText = '' ;
let errorText = '' ;
if ( customValue ) {
if ( customValue ) {
if ( Number ( customValue ) <= 0 ) {
// customValue is a string, e.g. '0'
errorText = t ( 'swapSlippageTooLow' ) ;
if ( Number ( customValue ) < 0 ) {
} else if ( Number ( customValue ) < 0.5 ) {
errorText = t ( 'swapSlippageNegative' ) ;
} else if ( Number ( customValue ) > 0 && Number ( customValue ) <= 1 ) {
// We will not show this warning for 0% slippage, because we will only
// return non-slippage quotes from off-chain makers.
errorText = t ( 'swapLowSlippageError' ) ;
errorText = t ( 'swapLowSlippageError' ) ;
} else if (
} else if (
Number ( customValue ) >= 5 &&
Number ( customValue ) >= 5 &&
@ -136,10 +143,6 @@ export default function SlippageButtons({
ref = { setInputRef }
ref = { setInputRef }
onBlur = { ( ) => {
onBlur = { ( ) => {
setEnteringCustomValue ( false ) ;
setEnteringCustomValue ( false ) ;
if ( customValue === '0' ) {
setCustomValue ( '' ) ;
setActiveButtonIndex ( 1 ) ;
}
} }
} }
value = { customValue || '' }
value = { customValue || '' }
/ >
/ >