Allow 0% slippage, show a warning for 0 < slippage <= 1, disable "Review Swap" button for negative slippage (#10936)

* Allow 0% slippage, show a warning for 0 < slippage <= 1, disable “Review Swap” button for negative slippage

* Update a translation key, use both new and old key until it’s translated everywhere

* Keep an old key for `en`: swapSlippageTooLow

* Fix an ESLint issue

* Only use swapSlippageNegative, remove swapSlippageTooLow
feature/default_network_editable
Daniel 4 years ago committed by Dan Miller
parent ce8b173f56
commit 91601ebe5e
  1. 4
      app/_locales/en/messages.json
  2. 3
      app/_locales/es/messages.json
  3. 3
      app/_locales/es_419/messages.json
  4. 3
      app/_locales/hi/messages.json
  5. 3
      app/_locales/id/messages.json
  6. 3
      app/_locales/it/messages.json
  7. 3
      app/_locales/ja/messages.json
  8. 3
      app/_locales/ko/messages.json
  9. 3
      app/_locales/ru/messages.json
  10. 3
      app/_locales/tl/messages.json
  11. 3
      app/_locales/vi/messages.json
  12. 3
      app/_locales/zh_CN/messages.json
  13. 2
      ui/pages/swaps/build-quote/build-quote.js
  14. 23
      ui/pages/swaps/slippage-buttons/slippage-buttons.js

@ -1958,8 +1958,8 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "Below are all the quotes gathered from multiple liquidity sources." "message": "Below are all the quotes gathered from multiple liquidity sources."
}, },
"swapSlippageTooLow": { "swapSlippageNegative": {
"message": "Slippage must be greater than zero" "message": "Slippage must be greater or equal to zero"
}, },
"swapSource": { "swapSource": {
"message": "Liquidity source" "message": "Liquidity source"

@ -1690,9 +1690,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "A continuación se muestran todas las cotizaciones recopiladas de múltiples fuentes de liquidez." "message": "A continuación se muestran todas las cotizaciones recopiladas de múltiples fuentes de liquidez."
}, },
"swapSlippageTooLow": {
"message": "El deslizamiento debe ser mayor que cero"
},
"swapSource": { "swapSource": {
"message": "Fuente de liquidez" "message": "Fuente de liquidez"
}, },

@ -1690,9 +1690,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "A continuación se muestran todas las cotizaciones recopiladas de múltiples fuentes de liquidez." "message": "A continuación se muestran todas las cotizaciones recopiladas de múltiples fuentes de liquidez."
}, },
"swapSlippageTooLow": {
"message": "El deslizamiento debe ser mayor que cero"
},
"swapSource": { "swapSource": {
"message": "Fuente de liquidez" "message": "Fuente de liquidez"
}, },

@ -1660,9 +1660,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "निए गए सभ उदधरण कई चलनिि एकतर किए गए ह।" "message": "निए गए सभ उदधरण कई चलनिि एकतर किए गए ह।"
}, },
"swapSlippageTooLow": {
"message": "सिज शय स अधिक हिए"
},
"swapSource": { "swapSource": {
"message": "चलनिित" "message": "चलनिित"
}, },

@ -1660,9 +1660,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "Di bawah ini adalah semua kuota yang dikumpulkan dari beberapa sumber likuiditas." "message": "Di bawah ini adalah semua kuota yang dikumpulkan dari beberapa sumber likuiditas."
}, },
"swapSlippageTooLow": {
"message": "Slippage harus lebih besar dari nol"
},
"swapSource": { "swapSource": {
"message": "Sumber likuiditas" "message": "Sumber likuiditas"
}, },

@ -1702,9 +1702,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "Sotto trovi tutte le quotazioni raccolte da multiple sorgenti di liquidità." "message": "Sotto trovi tutte le quotazioni raccolte da multiple sorgenti di liquidità."
}, },
"swapSlippageTooLow": {
"message": "Lo slippage deve essere maggiore di zero"
},
"swapSource": { "swapSource": {
"message": "Sorgente di liquidità" "message": "Sorgente di liquidità"
}, },

@ -1690,9 +1690,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "以下は複数の流動性ソースから収集したすべての見積です。" "message": "以下は複数の流動性ソースから収集したすべての見積です。"
}, },
"swapSlippageTooLow": {
"message": "スリッページは 0 より多くする必要があります。"
},
"swapSource": { "swapSource": {
"message": "流動性ソース" "message": "流動性ソース"
}, },

@ -1660,9 +1660,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "다음은 여러 유동성 소스에서 수집한 전체 견적입니다." "message": "다음은 여러 유동성 소스에서 수집한 전체 견적입니다."
}, },
"swapSlippageTooLow": {
"message": "슬리패지는 0보다 커야 합니다."
},
"swapSource": { "swapSource": {
"message": "유동성 소스" "message": "유동성 소스"
}, },

@ -1660,9 +1660,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "Ниже приведены все котировки, собранные из нескольких источников ликвидности." "message": "Ниже приведены все котировки, собранные из нескольких источников ликвидности."
}, },
"swapSlippageTooLow": {
"message": "Проскальзывание должно быть больше нуля"
},
"swapSource": { "swapSource": {
"message": "Источник ликвидности" "message": "Источник ликвидности"
}, },

@ -1657,9 +1657,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "Makikita sa ibaba ang lahat ng quote na nakuha mula sa maraming pinagkukunan ng liquidity." "message": "Makikita sa ibaba ang lahat ng quote na nakuha mula sa maraming pinagkukunan ng liquidity."
}, },
"swapSlippageTooLow": {
"message": "Dapat ay mas malaki sa zero ang slippage"
},
"swapSource": { "swapSource": {
"message": "Pinagkunan ng liquidity" "message": "Pinagkunan ng liquidity"
}, },

@ -1660,9 +1660,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "Dưới đây là tất cả các báo giá thu thập từ nhiều nguồn thanh khoản." "message": "Dưới đây là tất cả các báo giá thu thập từ nhiều nguồn thanh khoản."
}, },
"swapSlippageTooLow": {
"message": "Mức trượt giá phải lớn hơn 0"
},
"swapSource": { "swapSource": {
"message": "Nguồn thanh khoản" "message": "Nguồn thanh khoản"
}, },

@ -1690,9 +1690,6 @@
"swapSelectQuotePopoverDescription": { "swapSelectQuotePopoverDescription": {
"message": "以下是从多个流动资金来源收集到的所有报价。" "message": "以下是从多个流动资金来源收集到的所有报价。"
}, },
"swapSlippageTooLow": {
"message": "滑点必须大于零"
},
"swapSource": { "swapSource": {
"message": "流动资金来源" "message": "流动资金来源"
}, },

@ -533,7 +533,7 @@ export default function BuildQuote({
!isFeatureFlagLoaded || !isFeatureFlagLoaded ||
!Number(inputValue) || !Number(inputValue) ||
!selectedToToken?.address || !selectedToToken?.address ||
Number(maxSlippage) === 0 || Number(maxSlippage) < 0 ||
Number(maxSlippage) > MAX_ALLOWED_SLIPPAGE || Number(maxSlippage) > MAX_ALLOWED_SLIPPAGE ||
(toTokenIsNotDefault && occurances < 2 && !verificationClicked) (toTokenIsNotDefault && occurances < 2 && !verificationClicked)
} }

@ -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 || ''}
/> />

Loading…
Cancel
Save