1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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
This commit is contained in:
Daniel 2021-05-05 10:17:38 -07:00 committed by Dan Miller
parent ce8b173f56
commit 91601ebe5e
14 changed files with 16 additions and 46 deletions

View File

@ -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"

View File

@ -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"
}, },

View File

@ -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"
}, },

View File

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

View File

@ -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"
}, },

View File

@ -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à"
}, },

View File

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

View File

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

View File

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

View File

@ -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"
}, },

View File

@ -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"
}, },

View File

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

View File

@ -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)
} }

View File

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