mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Reduce the default slippage from 3% to 2% (#14863)
This commit is contained in:
parent
2fd4549333
commit
9705531671
4
app/_locales/en/messages.json
generated
4
app/_locales/en/messages.json
generated
@ -3440,6 +3440,10 @@
|
|||||||
"swapSlippageNegative": {
|
"swapSlippageNegative": {
|
||||||
"message": "Slippage must be greater or equal to zero"
|
"message": "Slippage must be greater or equal to zero"
|
||||||
},
|
},
|
||||||
|
"swapSlippagePercent": {
|
||||||
|
"message": "$1%",
|
||||||
|
"description": "$1 is the amount of % for slippage"
|
||||||
|
},
|
||||||
"swapSource": {
|
"swapSource": {
|
||||||
"message": "Liquidity source"
|
"message": "Liquidity source"
|
||||||
},
|
},
|
||||||
|
@ -206,3 +206,8 @@ export const TOKEN_BUCKET_PRIORITY = {
|
|||||||
OWNED: 'owned',
|
OWNED: 'owned',
|
||||||
TOP: 'top',
|
TOP: 'top',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const SLIPPAGE = {
|
||||||
|
DEFAULT: 2,
|
||||||
|
HIGH: 3,
|
||||||
|
};
|
||||||
|
@ -80,6 +80,7 @@ import {
|
|||||||
SWAP_FAILED_ERROR,
|
SWAP_FAILED_ERROR,
|
||||||
SWAPS_FETCH_ORDER_CONFLICT,
|
SWAPS_FETCH_ORDER_CONFLICT,
|
||||||
ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS,
|
ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS,
|
||||||
|
SLIPPAGE,
|
||||||
} from '../../../shared/constants/swaps';
|
} from '../../../shared/constants/swaps';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
@ -108,7 +109,7 @@ const initialState = {
|
|||||||
fromTokenInputValue: '',
|
fromTokenInputValue: '',
|
||||||
fromTokenError: null,
|
fromTokenError: null,
|
||||||
isFeatureFlagLoaded: false,
|
isFeatureFlagLoaded: false,
|
||||||
maxSlippage: 3,
|
maxSlippage: SLIPPAGE.DEFAULT,
|
||||||
quotesFetchStartTime: null,
|
quotesFetchStartTime: null,
|
||||||
reviewSwapClickedTimestamp: null,
|
reviewSwapClickedTimestamp: null,
|
||||||
topAssets: {},
|
topAssets: {},
|
||||||
@ -733,7 +734,7 @@ export const fetchQuotesAndSetQuoteState = (
|
|||||||
token_to: toTokenSymbol,
|
token_to: toTokenSymbol,
|
||||||
request_type: balanceError ? 'Quote' : 'Order',
|
request_type: balanceError ? 'Quote' : 'Order',
|
||||||
slippage: maxSlippage,
|
slippage: maxSlippage,
|
||||||
custom_slippage: maxSlippage !== 2,
|
custom_slippage: maxSlippage !== SLIPPAGE.DEFAULT,
|
||||||
is_hardware_wallet: hardwareWalletUsed,
|
is_hardware_wallet: hardwareWalletUsed,
|
||||||
hardware_wallet_type: hardwareWalletType,
|
hardware_wallet_type: hardwareWalletType,
|
||||||
stx_enabled: smartTransactionsEnabled,
|
stx_enabled: smartTransactionsEnabled,
|
||||||
@ -787,7 +788,7 @@ export const fetchQuotesAndSetQuoteState = (
|
|||||||
token_to: toTokenSymbol,
|
token_to: toTokenSymbol,
|
||||||
request_type: balanceError ? 'Quote' : 'Order',
|
request_type: balanceError ? 'Quote' : 'Order',
|
||||||
slippage: maxSlippage,
|
slippage: maxSlippage,
|
||||||
custom_slippage: maxSlippage !== 2,
|
custom_slippage: maxSlippage !== SLIPPAGE.DEFAULT,
|
||||||
is_hardware_wallet: hardwareWalletUsed,
|
is_hardware_wallet: hardwareWalletUsed,
|
||||||
hardware_wallet_type: hardwareWalletType,
|
hardware_wallet_type: hardwareWalletType,
|
||||||
stx_enabled: smartTransactionsEnabled,
|
stx_enabled: smartTransactionsEnabled,
|
||||||
@ -812,7 +813,7 @@ export const fetchQuotesAndSetQuoteState = (
|
|||||||
),
|
),
|
||||||
request_type: balanceError ? 'Quote' : 'Order',
|
request_type: balanceError ? 'Quote' : 'Order',
|
||||||
slippage: maxSlippage,
|
slippage: maxSlippage,
|
||||||
custom_slippage: maxSlippage !== 2,
|
custom_slippage: maxSlippage !== SLIPPAGE.DEFAULT,
|
||||||
response_time: Date.now() - fetchStartTime,
|
response_time: Date.now() - fetchStartTime,
|
||||||
best_quote_source: newSelectedQuote.aggregator,
|
best_quote_source: newSelectedQuote.aggregator,
|
||||||
available_quotes: Object.values(fetchedQuotes)?.length,
|
available_quotes: Object.values(fetchedQuotes)?.length,
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
renderWithProvider,
|
renderWithProvider,
|
||||||
createSwapsMockStore,
|
createSwapsMockStore,
|
||||||
} from '../../../../test/jest';
|
} from '../../../../test/jest';
|
||||||
|
import { SLIPPAGE } from '../../../../shared/constants/swaps';
|
||||||
import AwaitingSwap from '.';
|
import AwaitingSwap from '.';
|
||||||
|
|
||||||
const createProps = (customProps = {}) => {
|
const createProps = (customProps = {}) => {
|
||||||
@ -14,7 +15,7 @@ const createProps = (customProps = {}) => {
|
|||||||
tokensReceived: 'tokens received:',
|
tokensReceived: 'tokens received:',
|
||||||
submittingSwap: true,
|
submittingSwap: true,
|
||||||
inputValue: 5,
|
inputValue: 5,
|
||||||
maxSlippage: 3,
|
maxSlippage: SLIPPAGE.DEFAULT,
|
||||||
...customProps,
|
...customProps,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -6,16 +6,16 @@ exports[`BuildQuote renders the component with initial props 1`] = `
|
|||||||
role="radiogroup"
|
role="radiogroup"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
aria-checked="false"
|
aria-checked="true"
|
||||||
class="button-group__button radio-button"
|
class="button-group__button radio-button button-group__button--active radio-button--active"
|
||||||
data-testid="button-group__button0"
|
data-testid="button-group__button0"
|
||||||
role="radio"
|
role="radio"
|
||||||
>
|
>
|
||||||
2%
|
2%
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
aria-checked="true"
|
aria-checked="false"
|
||||||
class="button-group__button radio-button button-group__button--active radio-button--active"
|
class="button-group__button radio-button"
|
||||||
data-testid="button-group__button1"
|
data-testid="button-group__button1"
|
||||||
role="radio"
|
role="radio"
|
||||||
>
|
>
|
||||||
|
@ -21,16 +21,16 @@ exports[`SlippageButtons renders the component with initial props 2`] = `
|
|||||||
role="radiogroup"
|
role="radiogroup"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
aria-checked="true"
|
aria-checked="false"
|
||||||
class="button-group__button radio-button button-group__button--active radio-button--active"
|
class="button-group__button radio-button"
|
||||||
data-testid="button-group__button0"
|
data-testid="button-group__button0"
|
||||||
role="radio"
|
role="radio"
|
||||||
>
|
>
|
||||||
2%
|
2%
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
aria-checked="false"
|
aria-checked="true"
|
||||||
class="button-group__button radio-button"
|
class="button-group__button radio-button button-group__button--active radio-button--active"
|
||||||
data-testid="button-group__button1"
|
data-testid="button-group__button1"
|
||||||
role="radio"
|
role="radio"
|
||||||
>
|
>
|
||||||
@ -68,16 +68,16 @@ exports[`SlippageButtons renders the component with the Smart Transaction opt-in
|
|||||||
role="radiogroup"
|
role="radiogroup"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
aria-checked="true"
|
aria-checked="false"
|
||||||
class="button-group__button radio-button button-group__button--active radio-button--active"
|
class="button-group__button radio-button"
|
||||||
data-testid="button-group__button0"
|
data-testid="button-group__button0"
|
||||||
role="radio"
|
role="radio"
|
||||||
>
|
>
|
||||||
2%
|
2%
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
aria-checked="false"
|
aria-checked="true"
|
||||||
class="button-group__button radio-button"
|
class="button-group__button radio-button button-group__button--active radio-button--active"
|
||||||
data-testid="button-group__button1"
|
data-testid="button-group__button1"
|
||||||
role="radio"
|
role="radio"
|
||||||
>
|
>
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
DISPLAY,
|
DISPLAY,
|
||||||
} from '../../../helpers/constants/design-system';
|
} from '../../../helpers/constants/design-system';
|
||||||
import { getTranslatedStxErrorMessage } from '../swaps.util';
|
import { getTranslatedStxErrorMessage } from '../swaps.util';
|
||||||
|
import { SLIPPAGE } from '../../../../shared/constants/swaps';
|
||||||
|
|
||||||
export default function SlippageButtons({
|
export default function SlippageButtons({
|
||||||
onSelect,
|
onSelect,
|
||||||
@ -30,8 +31,7 @@ export default function SlippageButtons({
|
|||||||
const [customValue, setCustomValue] = useState(() => {
|
const [customValue, setCustomValue] = useState(() => {
|
||||||
if (
|
if (
|
||||||
typeof currentSlippage === 'number' &&
|
typeof currentSlippage === 'number' &&
|
||||||
currentSlippage !== 2 &&
|
!Object.values(SLIPPAGE).includes(currentSlippage)
|
||||||
currentSlippage !== 3
|
|
||||||
) {
|
) {
|
||||||
return currentSlippage.toString();
|
return currentSlippage.toString();
|
||||||
}
|
}
|
||||||
@ -39,17 +39,17 @@ export default function SlippageButtons({
|
|||||||
});
|
});
|
||||||
const [enteringCustomValue, setEnteringCustomValue] = useState(false);
|
const [enteringCustomValue, setEnteringCustomValue] = useState(false);
|
||||||
const [activeButtonIndex, setActiveButtonIndex] = useState(() => {
|
const [activeButtonIndex, setActiveButtonIndex] = useState(() => {
|
||||||
if (currentSlippage === 3) {
|
if (currentSlippage === SLIPPAGE.HIGH) {
|
||||||
return 1;
|
return 1; // 3% slippage.
|
||||||
} else if (currentSlippage === 2) {
|
} else if (currentSlippage === SLIPPAGE.DEFAULT) {
|
||||||
return 0;
|
return 0; // 2% slippage.
|
||||||
} else if (typeof currentSlippage === 'number') {
|
} else if (typeof currentSlippage === 'number') {
|
||||||
return 2;
|
return 2; // Custom slippage.
|
||||||
}
|
}
|
||||||
return 1; // Choose activeButtonIndex = 1 for 3% slippage by default.
|
return 0;
|
||||||
});
|
});
|
||||||
const [open, setOpen] = useState(() => {
|
const [open, setOpen] = useState(() => {
|
||||||
return currentSlippage !== 3; // Only open Advanced Options by default if it's not default 3% slippage.
|
return currentSlippage !== SLIPPAGE.DEFAULT; // Only open Advanced Options by default if it's not default slippage.
|
||||||
});
|
});
|
||||||
const [inputRef, setInputRef] = useState(null);
|
const [inputRef, setInputRef] = useState(null);
|
||||||
|
|
||||||
@ -133,20 +133,20 @@ export default function SlippageButtons({
|
|||||||
setCustomValue('');
|
setCustomValue('');
|
||||||
setEnteringCustomValue(false);
|
setEnteringCustomValue(false);
|
||||||
setActiveButtonIndex(0);
|
setActiveButtonIndex(0);
|
||||||
onSelect(2);
|
onSelect(SLIPPAGE.DEFAULT);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
2%
|
{t('swapSlippagePercent', [SLIPPAGE.DEFAULT])}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setCustomValue('');
|
setCustomValue('');
|
||||||
setEnteringCustomValue(false);
|
setEnteringCustomValue(false);
|
||||||
setActiveButtonIndex(1);
|
setActiveButtonIndex(1);
|
||||||
onSelect(3);
|
onSelect(SLIPPAGE.HIGH);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
3%
|
{t('swapSlippagePercent', [SLIPPAGE.HIGH])}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
className={classnames(
|
className={classnames(
|
||||||
|
@ -7,7 +7,7 @@ const createProps = (customProps = {}) => {
|
|||||||
return {
|
return {
|
||||||
onSelect: jest.fn(),
|
onSelect: jest.fn(),
|
||||||
maxAllowedSlippage: 15,
|
maxAllowedSlippage: 15,
|
||||||
currentSlippage: 2,
|
currentSlippage: 3,
|
||||||
smartTransactionsEnabled: false,
|
smartTransactionsEnabled: false,
|
||||||
...customProps,
|
...customProps,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user