Skip to content

Commit

Permalink
Reduce the default slippage from 3% to 2% (#14863)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan437 authored Jun 7, 2022
1 parent 2fd4549 commit 9705531
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 31 deletions.
4 changes: 4 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions shared/constants/swaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,8 @@ export const TOKEN_BUCKET_PRIORITY = {
OWNED: 'owned',
TOP: 'top',
};

export const SLIPPAGE = {
DEFAULT: 2,
HIGH: 3,
};
9 changes: 5 additions & 4 deletions ui/ducks/swaps/swaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
SWAP_FAILED_ERROR,
SWAPS_FETCH_ORDER_CONFLICT,
ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS,
SLIPPAGE,
} from '../../../shared/constants/swaps';
import {
TRANSACTION_TYPES,
Expand Down Expand Up @@ -108,7 +109,7 @@ const initialState = {
fromTokenInputValue: '',
fromTokenError: null,
isFeatureFlagLoaded: false,
maxSlippage: 3,
maxSlippage: SLIPPAGE.DEFAULT,
quotesFetchStartTime: null,
reviewSwapClickedTimestamp: null,
topAssets: {},
Expand Down Expand Up @@ -733,7 +734,7 @@ export const fetchQuotesAndSetQuoteState = (
token_to: toTokenSymbol,
request_type: balanceError ? 'Quote' : 'Order',
slippage: maxSlippage,
custom_slippage: maxSlippage !== 2,
custom_slippage: maxSlippage !== SLIPPAGE.DEFAULT,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
stx_enabled: smartTransactionsEnabled,
Expand Down Expand Up @@ -787,7 +788,7 @@ export const fetchQuotesAndSetQuoteState = (
token_to: toTokenSymbol,
request_type: balanceError ? 'Quote' : 'Order',
slippage: maxSlippage,
custom_slippage: maxSlippage !== 2,
custom_slippage: maxSlippage !== SLIPPAGE.DEFAULT,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
stx_enabled: smartTransactionsEnabled,
Expand All @@ -812,7 +813,7 @@ export const fetchQuotesAndSetQuoteState = (
),
request_type: balanceError ? 'Quote' : 'Order',
slippage: maxSlippage,
custom_slippage: maxSlippage !== 2,
custom_slippage: maxSlippage !== SLIPPAGE.DEFAULT,
response_time: Date.now() - fetchStartTime,
best_quote_source: newSelectedQuote.aggregator,
available_quotes: Object.values(fetchedQuotes)?.length,
Expand Down
3 changes: 2 additions & 1 deletion ui/pages/swaps/awaiting-swap/awaiting-swap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
renderWithProvider,
createSwapsMockStore,
} from '../../../../test/jest';
import { SLIPPAGE } from '../../../../shared/constants/swaps';
import AwaitingSwap from '.';

const createProps = (customProps = {}) => {
Expand All @@ -14,7 +15,7 @@ const createProps = (customProps = {}) => {
tokensReceived: 'tokens received:',
submittingSwap: true,
inputValue: 5,
maxSlippage: 3,
maxSlippage: SLIPPAGE.DEFAULT,
...customProps,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ exports[`BuildQuote renders the component with initial props 1`] = `
role="radiogroup"
>
<button
aria-checked="false"
class="button-group__button radio-button"
aria-checked="true"
class="button-group__button radio-button button-group__button--active radio-button--active"
data-testid="button-group__button0"
role="radio"
>
2%
</button>
<button
aria-checked="true"
class="button-group__button radio-button button-group__button--active radio-button--active"
aria-checked="false"
class="button-group__button radio-button"
data-testid="button-group__button1"
role="radio"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ exports[`SlippageButtons renders the component with initial props 2`] = `
role="radiogroup"
>
<button
aria-checked="true"
class="button-group__button radio-button button-group__button--active radio-button--active"
aria-checked="false"
class="button-group__button radio-button"
data-testid="button-group__button0"
role="radio"
>
2%
</button>
<button
aria-checked="false"
class="button-group__button radio-button"
aria-checked="true"
class="button-group__button radio-button button-group__button--active radio-button--active"
data-testid="button-group__button1"
role="radio"
>
Expand Down Expand Up @@ -68,16 +68,16 @@ exports[`SlippageButtons renders the component with the Smart Transaction opt-in
role="radiogroup"
>
<button
aria-checked="true"
class="button-group__button radio-button button-group__button--active radio-button--active"
aria-checked="false"
class="button-group__button radio-button"
data-testid="button-group__button0"
role="radio"
>
2%
</button>
<button
aria-checked="false"
class="button-group__button radio-button"
aria-checked="true"
class="button-group__button radio-button button-group__button--active radio-button--active"
data-testid="button-group__button1"
role="radio"
>
Expand Down
26 changes: 13 additions & 13 deletions ui/pages/swaps/slippage-buttons/slippage-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
DISPLAY,
} from '../../../helpers/constants/design-system';
import { getTranslatedStxErrorMessage } from '../swaps.util';
import { SLIPPAGE } from '../../../../shared/constants/swaps';

export default function SlippageButtons({
onSelect,
Expand All @@ -30,26 +31,25 @@ export default function SlippageButtons({
const [customValue, setCustomValue] = useState(() => {
if (
typeof currentSlippage === 'number' &&
currentSlippage !== 2 &&
currentSlippage !== 3
!Object.values(SLIPPAGE).includes(currentSlippage)
) {
return currentSlippage.toString();
}
return '';
});
const [enteringCustomValue, setEnteringCustomValue] = useState(false);
const [activeButtonIndex, setActiveButtonIndex] = useState(() => {
if (currentSlippage === 3) {
return 1;
} else if (currentSlippage === 2) {
return 0;
if (currentSlippage === SLIPPAGE.HIGH) {
return 1; // 3% slippage.
} else if (currentSlippage === SLIPPAGE.DEFAULT) {
return 0; // 2% slippage.
} 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(() => {
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);

Expand Down Expand Up @@ -133,20 +133,20 @@ export default function SlippageButtons({
setCustomValue('');
setEnteringCustomValue(false);
setActiveButtonIndex(0);
onSelect(2);
onSelect(SLIPPAGE.DEFAULT);
}}
>
2%
{t('swapSlippagePercent', [SLIPPAGE.DEFAULT])}
</Button>
<Button
onClick={() => {
setCustomValue('');
setEnteringCustomValue(false);
setActiveButtonIndex(1);
onSelect(3);
onSelect(SLIPPAGE.HIGH);
}}
>
3%
{t('swapSlippagePercent', [SLIPPAGE.HIGH])}
</Button>
<Button
className={classnames(
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/swaps/slippage-buttons/slippage-buttons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const createProps = (customProps = {}) => {
return {
onSelect: jest.fn(),
maxAllowedSlippage: 15,
currentSlippage: 2,
currentSlippage: 3,
smartTransactionsEnabled: false,
...customProps,
};
Expand Down

0 comments on commit 9705531

Please sign in to comment.