Skip to content

feat: [PAN-4634] Enable-auto-slippage #11387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7ded51b
chore: hook initialize
Chef-Yogi Mar 24, 2025
d4fb8ef
chore: auto slippage part2
Chef-Yogi Mar 25, 2025
8c955fa
chore: support v4 swap
Chef-Yogi Mar 25, 2025
6f254ee
chore: auto slippage
Chef-Yogi Mar 25, 2025
afc315d
chore: displau auto slippage
Chef-Yogi Mar 26, 2025
f9e1625
chore: add log to see
Chef-Yogi Mar 26, 2025
17e5085
chore: display it on swap details
Chef-Yogi Mar 26, 2025
1c4159a
chore: refactor to functions
Chef-Yogi Mar 27, 2025
fa942be
chore: auto slippage new design
Chef-Yogi Apr 1, 2025
217850c
chore: auto slippage new design part2
Chef-Yogi Apr 1, 2025
3069fca
chore: auto slippage details
Chef-Yogi Apr 1, 2025
b1def57
fix: min parameter
Chef-Yogi Apr 1, 2025
b7d4866
chore: auto slippage issue
Chef-Yogi Apr 2, 2025
a2152df
fix: type and import issue
Chef-Yogi Apr 2, 2025
319dc28
chore: set auto slippage by default
Chef-Yogi Apr 2, 2025
78cad15
chore: remove auto slippage toggle
Chef-Yogi Apr 2, 2025
4ef7ac7
fix: asset insufficient
Chef-Yogi Apr 2, 2025
17b10f4
chore: fix button logic also
Chef-Yogi Apr 2, 2025
29718e1
chore: fix type issue
Chef-Yogi Apr 2, 2025
b8f0d37
chore: fix null issue
Chef-Yogi Apr 2, 2025
8c37e37
chore: fix reset slippage issue
Chef-Yogi Apr 3, 2025
11b926b
chore: fix unconnected wallet issue
Chef-Yogi Apr 3, 2025
233357e
chore: add input base slippage
Chef-Yogi Apr 4, 2025
4e0ef3a
chore: fix display issue
Chef-Yogi Apr 4, 2025
6ebd7d4
chore: fix mobile UI
Chef-Yogi Apr 4, 2025
f7e5100
chore: UI details
Chef-Yogi Apr 4, 2025
3ceca4d
chore: fix edge case slippage
Chef-Yogi Apr 4, 2025
4830f31
chore: fix xOrder issue
Chef-Yogi Apr 4, 2025
fd335ce
chore: fix unit test
Chef-Yogi Apr 4, 2025
577feff
chore: add translation keys
Chef-Yogi Apr 4, 2025
076d843
chore: change console
Chef-Yogi Apr 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
11 changes: 10 additions & 1 deletion apps/web/src/components/AccessRisk/SwapRevampRiskDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { keyframes, styled } from 'styled-components'
import { useUserSlippage } from '@pancakeswap/utils/user'
import { DEFAULT_SLIPPAGE_TOLERANCE } from 'components/Menu/GlobalSettings/TransactionSettings'
import { useActiveChainId } from 'hooks/useActiveChainId'
import { useAutoSlippageEnabled } from 'hooks/useAutoSlippageWithFallback'
import { TOKEN_RISK, TOKEN_RISK_T, useTokenRisk } from './index'

const appearAni = keyframes`
Expand Down Expand Up @@ -205,6 +206,7 @@ const PriceImpactDetails: React.FC = () => {
const SlippageDetails: React.FC = () => {
const { t } = useTranslation()
const [, setUserSlippageTolerance] = useUserSlippage()
const [, setAutoSlippageEnabled] = useAutoSlippageEnabled()

return (
<FlexGap alignItems="flex-start">
Expand All @@ -214,7 +216,14 @@ const SlippageDetails: React.FC = () => {
'You may only get the amount of “Minimum received” with a high slippage setting. Reset your slippage to avoid potential losses.',
)}
</Text>
<StyledTextButton onClick={() => setUserSlippageTolerance(DEFAULT_SLIPPAGE_TOLERANCE)} scale="sm" px="0">
<StyledTextButton
onClick={() => {
setAutoSlippageEnabled(false)
setUserSlippageTolerance(DEFAULT_SLIPPAGE_TOLERANCE)
}}
scale="sm"
px="0"
>
{t('Reset Slippage')}
</StyledTextButton>
</FlexGap>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { useTranslation } from '@pancakeswap/localization'
import { Box, Button, Flex, FlexGap, Input, Message, QuestionHelper, Text } from '@pancakeswap/uikit'
import {
Box,
Button,
Flex,
FlexGap,
Input,
Message,
QuestionHelper,
Text,
useMatchBreakpoints,
} from '@pancakeswap/uikit'
import { useUserSlippage } from '@pancakeswap/utils/user'
import { useEffect, useState } from 'react'
import { escapeRegExp } from 'utils'

import { VerticalDivider } from '@pancakeswap/widgets-internal'
import { useAutoSlippageEnabled } from 'hooks/useAutoSlippageWithFallback'
import { useUserTransactionTTL } from 'hooks/useTransactionDeadline'
import styled from 'styled-components'
import { PrimaryOutlineButton } from './styles'
Expand All @@ -19,7 +30,12 @@ const ButtonsContainer = styled(FlexGap).attrs({ flexWrap: 'wrap', gap: '4px' })
`

const StyledButton = styled(Button)`
height: 52px;
height: 48px;
padding: 0 8px;
${({ theme }) => theme.mediaQueries.md} {
height: 52px;
padding: 0 16px;
}
`

const StyledVerticalDivider = styled(VerticalDivider).attrs(({ theme }) => ({ bg: theme.colors.inputSecondary }))`
Expand Down Expand Up @@ -49,7 +65,8 @@ const SlippageTabs = () => {
const [ttl, setTTL] = useUserTransactionTTL()
const [slippageInput, setSlippageInput] = useState('')
const [deadlineInput, setDeadlineInput] = useState('')

const [isAutoSlippageEnabled, setIsAutoSlippageEnabled] = useAutoSlippageEnabled()
const { isMobile } = useMatchBreakpoints()
const { t } = useTranslation()

const slippageInputIsValid =
Expand Down Expand Up @@ -124,14 +141,26 @@ const SlippageTabs = () => {
ml="4px"
/>
</Flex>
<ButtonsContainer>

<ButtonsContainer style={{ flexWrap: isMobile ? 'nowrap' : 'wrap' }}>
<StyledButton
scale="sm"
onClick={() => {
setSlippageInput('')
setIsAutoSlippageEnabled(true)
}}
variant={isAutoSlippageEnabled ? 'subtle' : 'light'}
>
{t('Auto')}
</StyledButton>
<StyledButton
scale="sm"
onClick={() => {
setSlippageInput('')
setUserSlippageTolerance(10)
setIsAutoSlippageEnabled(false)
}}
variant={userSlippageTolerance === 10 ? 'subtle' : 'light'}
variant={userSlippageTolerance === 10 && !isAutoSlippageEnabled ? 'subtle' : 'light'}
>
0.1%
</StyledButton>
Expand All @@ -140,8 +169,9 @@ const SlippageTabs = () => {
onClick={() => {
setSlippageInput('')
setUserSlippageTolerance(50)
setIsAutoSlippageEnabled(false)
}}
variant={userSlippageTolerance === 50 ? 'subtle' : 'light'}
variant={userSlippageTolerance === 50 && !isAutoSlippageEnabled ? 'subtle' : 'light'}
>
0.5%
</StyledButton>
Expand All @@ -150,8 +180,9 @@ const SlippageTabs = () => {
onClick={() => {
setSlippageInput('')
setUserSlippageTolerance(100)
setIsAutoSlippageEnabled(false)
}}
variant={userSlippageTolerance === 100 ? 'subtle' : 'light'}
variant={userSlippageTolerance === 100 && !isAutoSlippageEnabled ? 'subtle' : 'light'}
>
1.0%
</StyledButton>
Expand All @@ -161,12 +192,15 @@ const SlippageTabs = () => {
scale="md"
inputMode="decimal"
pattern="^[0-9]*[.,]?[0-9]{0,2}$"
placeholder={(userSlippageTolerance / 100).toFixed(2)}
placeholder={isAutoSlippageEnabled ? 'Auto' : (userSlippageTolerance / 100).toFixed(2)}
value={slippageInput}
onBlur={() => {
parseCustomSlippage((userSlippageTolerance / 100).toFixed(2))
}}
onChange={(event) => {
if (isAutoSlippageEnabled) {
setIsAutoSlippageEnabled(false)
}
if (event.currentTarget.validity.valid) {
parseCustomSlippage(event.target.value.replace(/,/g, '.'))
}
Expand All @@ -184,7 +218,8 @@ const SlippageTabs = () => {
</Box>
</Flex>
</ButtonsContainer>
{!!slippageError && (

{!isAutoSlippageEnabled && !!slippageError && (
<Message
mt="8px"
variant={
Expand Down
Loading
Loading