fix: should show slippage/deadline on LP flow settings (#7367)

* fix: should show slippage/deadline on LP flow settings

* write unit tests & update

---------

Co-authored-by: Kristie Huang <kristie.huang@uniswap.org>
This commit is contained in:
Kristie Huang 2023-09-22 13:12:32 -04:00 committed by GitHub
parent beef7f2d86
commit 4f8956f79a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 14 deletions

@ -1,4 +1,7 @@
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Percent } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import SettingsTab from 'components/Settings'
import { ReactNode } from 'react' import { ReactNode } from 'react'
import { ArrowLeft } from 'react-feather' import { ArrowLeft } from 'react-feather'
import { Link, useLocation } from 'react-router-dom' import { Link, useLocation } from 'react-router-dom'
@ -63,15 +66,18 @@ const AddRemoveTitleText = styled(ThemedText.SubHeaderLarge)`
export function AddRemoveTabs({ export function AddRemoveTabs({
adding, adding,
creating, creating,
autoSlippage,
positionID, positionID,
children, children,
}: { }: {
adding: boolean adding: boolean
creating: boolean creating: boolean
autoSlippage: Percent
positionID?: string positionID?: string
showBackLink?: boolean showBackLink?: boolean
children?: ReactNode children?: ReactNode
}) { }) {
const { chainId } = useWeb3React()
const theme = useTheme() const theme = useTheme()
// reset states on back // reset states on back
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
@ -108,6 +114,7 @@ export function AddRemoveTabs({
)} )}
</AddRemoveTitleText> </AddRemoveTitleText>
{children && <Box style={{ marginRight: '.5rem' }}>{children}</Box>} {children && <Box style={{ marginRight: '.5rem' }}>{children}</Box>}
<SettingsTab autoSlippage={autoSlippage} chainId={chainId} showRoutingSettings={false} />
</RowBetween> </RowBetween>
</Tabs> </Tabs>
) )

@ -0,0 +1,39 @@
import { Percent } from '@uniswap/sdk-core'
import { isSupportedChain } from 'constants/chains'
import { mocked } from 'test-utils/mocked'
import { fireEvent, render, screen, waitFor } from 'test-utils/render'
import SettingsTab from './index'
const slippage = new Percent(75, 10_000)
jest.mock('constants/chains')
describe('Settings Tab', () => {
describe('showRoutingSettings', () => {
beforeEach(() => {
mocked(isSupportedChain).mockReturnValue(true)
})
it('renders routing settings when showRoutingSettings is true', async () => {
render(<SettingsTab showRoutingSettings={true} chainId={1} autoSlippage={slippage} />)
const settingsButton = screen.getByTestId('open-settings-dialog-button')
fireEvent.click(settingsButton)
await waitFor(() => {
expect(screen.getByTestId('toggle-local-routing-button')).toBeInTheDocument()
})
})
it('does not render routing settings when showRoutingSettings is false', async () => {
render(<SettingsTab showRoutingSettings={false} chainId={1} autoSlippage={slippage} />)
const settingsButton = screen.getByTestId('open-settings-dialog-button')
fireEvent.click(settingsButton)
await waitFor(() => {
expect(screen.queryByTestId('toggle-local-routing-button')).not.toBeInTheDocument()
})
})
})
})

@ -59,9 +59,9 @@ const MenuFlyout = styled(AutoColumn)`
padding: 16px; padding: 16px;
` `
const ExpandColumn = styled(AutoColumn)` const ExpandColumn = styled(AutoColumn)<{ $padTop: boolean }>`
gap: 16px; gap: 16px;
padding-top: 16px; padding-top: ${({ $padTop }) => ($padTop ? '16px' : '0')};
` `
const MobileMenuContainer = styled(Row)` const MobileMenuContainer = styled(Row)`
@ -101,10 +101,12 @@ export default function SettingsTab({
autoSlippage, autoSlippage,
chainId, chainId,
trade, trade,
showRoutingSettings = true,
}: { }: {
autoSlippage: Percent autoSlippage: Percent
chainId?: number chainId?: number
trade?: InterfaceTrade trade?: InterfaceTrade
showRoutingSettings?: boolean
}) { }) {
const { chainId: connectedChainId } = useWeb3React() const { chainId: connectedChainId } = useWeb3React()
const showDeadlineSettings = Boolean(chainId && !L2_CHAIN_IDS.includes(chainId)) const showDeadlineSettings = Boolean(chainId && !L2_CHAIN_IDS.includes(chainId))
@ -123,16 +125,17 @@ export default function SettingsTab({
useDisableScrolling(isOpen) useDisableScrolling(isOpen)
const isChainSupported = isSupportedChain(chainId) const isChainSupported = isSupportedChain(chainId)
const Settings = useMemo( const Settings = useMemo(
() => ( () => (
<> <>
{showRoutingSettings && (
<AutoColumn gap="16px"> <AutoColumn gap="16px">
<RouterPreferenceSettings /> <RouterPreferenceSettings />
</AutoColumn> </AutoColumn>
)}
<AnimatedDropdown open={!isUniswapXTrade(trade)}> <AnimatedDropdown open={!isUniswapXTrade(trade)}>
<ExpandColumn> <ExpandColumn $padTop={showRoutingSettings}>
<Divider /> {showRoutingSettings && <Divider />}
<MaxSlippageSettings autoSlippage={autoSlippage} /> <MaxSlippageSettings autoSlippage={autoSlippage} />
{showDeadlineSettings && ( {showDeadlineSettings && (
<> <>
@ -144,7 +147,7 @@ export default function SettingsTab({
</AnimatedDropdown> </AnimatedDropdown>
</> </>
), ),
[autoSlippage, showDeadlineSettings, trade] [autoSlippage, showDeadlineSettings, showRoutingSettings, trade]
) )
return ( return (

@ -599,7 +599,13 @@ function AddLiquidity() {
pendingText={pendingText} pendingText={pendingText}
/> />
<StyledBodyWrapper $hasExistingPosition={hasExistingPosition}> <StyledBodyWrapper $hasExistingPosition={hasExistingPosition}>
<AddRemoveTabs creating={false} adding={true} positionID={tokenId} showBackLink={!hasExistingPosition}> <AddRemoveTabs
creating={false}
adding={true}
positionID={tokenId}
autoSlippage={DEFAULT_ADD_IN_RANGE_SLIPPAGE_TOLERANCE}
showBackLink={!hasExistingPosition}
>
{!hasExistingPosition && ( {!hasExistingPosition && (
<Row justifyContent="flex-end" style={{ width: 'fit-content', minWidth: 'fit-content' }}> <Row justifyContent="flex-end" style={{ width: 'fit-content', minWidth: 'fit-content' }}>
<MediumOnly> <MediumOnly>

@ -335,7 +335,7 @@ export default function AddLiquidity() {
return ( return (
<> <>
<AppBody> <AppBody>
<AddRemoveTabs creating={isCreate} adding={true} /> <AddRemoveTabs creating={isCreate} adding={true} autoSlippage={DEFAULT_ADD_V2_SLIPPAGE_TOLERANCE} />
<Wrapper> <Wrapper>
<TransactionConfirmationModal <TransactionConfirmationModal
isOpen={showConfirm} isOpen={showConfirm}

@ -739,7 +739,11 @@ export default function MigrateV2Pair() {
<ThemedText.DeprecatedMediumHeader> <ThemedText.DeprecatedMediumHeader>
<Trans>Migrate V2 Liquidity</Trans> <Trans>Migrate V2 Liquidity</Trans>
</ThemedText.DeprecatedMediumHeader> </ThemedText.DeprecatedMediumHeader>
<SettingsTab autoSlippage={DEFAULT_MIGRATE_SLIPPAGE_TOLERANCE} chainId={chainId} /> <SettingsTab
autoSlippage={DEFAULT_MIGRATE_SLIPPAGE_TOLERANCE}
chainId={chainId}
showRoutingSettings={false}
/>
</AutoRow> </AutoRow>
{!account ? ( {!account ? (

@ -300,7 +300,12 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
pendingText={pendingText} pendingText={pendingText}
/> />
<AppBody $maxWidth="unset"> <AppBody $maxWidth="unset">
<AddRemoveTabs creating={false} adding={false} positionID={tokenId.toString()} /> <AddRemoveTabs
creating={false}
adding={false}
positionID={tokenId.toString()}
autoSlippage={DEFAULT_REMOVE_V3_LIQUIDITY_SLIPPAGE_TOLERANCE}
/>
<Wrapper> <Wrapper>
{position ? ( {position ? (
<AutoColumn gap="lg"> <AutoColumn gap="lg">

@ -451,7 +451,7 @@ function RemoveLiquidity() {
return ( return (
<> <>
<AppBody> <AppBody>
<AddRemoveTabs creating={false} adding={false} /> <AddRemoveTabs creating={false} adding={false} autoSlippage={DEFAULT_REMOVE_LIQUIDITY_SLIPPAGE_TOLERANCE} />
<Wrapper> <Wrapper>
<TransactionConfirmationModal <TransactionConfirmationModal
isOpen={showConfirm} isOpen={showConfirm}