Skip to content

Commit

Permalink
fix(smart-slippage): fix smart slip tooltip and feature flag (#5004)
Browse files Browse the repository at this point in the history
* fix: remove hard coded smart slippage value

* fix: handle case when multiplier percentage in falsy

* feat: use different tooltip when feature flag is off

* fix: pass dynamic slippage settings to row slippage content

* chore: fix lint
  • Loading branch information
alfetopito authored Oct 17, 2024
1 parent 0c1e9b9 commit c6ea5af
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export function TransactionSettings() {
// <Trans>Your transaction will revert if the price changes unfavorably by more than this percentage.</Trans>
isEoaEthFlow
? getNativeSlippageTooltip(chainId, [nativeCurrency.symbol, getWrappedToken(nativeCurrency).symbol])
: getNonNativeSlippageTooltip(true)
: getNonNativeSlippageTooltip({ isDynamic: !!smartSlippage, isSettingsModal: true })
}
/>
</RowFixed>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { useIsEoaEthFlow } from '../../hooks/useIsEoaEthFlow'
import { useNavigateToNewOrderCallback } from '../../hooks/useNavigateToNewOrderCallback'
import { useShouldPayGas } from '../../hooks/useShouldPayGas'
import { useSwapConfirmButtonText } from '../../hooks/useSwapConfirmButtonText'
import { useSmartSwapSlippage } from '../../hooks/useSwapSlippage'
import { useSwapState } from '../../hooks/useSwapState'
import { NetworkCostsTooltipSuffix } from '../../pure/NetworkCostsTooltipSuffix'
import { getNativeSlippageTooltip, getNonNativeSlippageTooltip } from '../../pure/Row/RowSlippageContent'
Expand Down Expand Up @@ -87,6 +88,7 @@ export function ConfirmSwapModalSetup(props: ConfirmSwapModalSetupProps) {
const buttonText = useSwapConfirmButtonText(slippageAdjustedSellAmount)

const isSmartSlippageApplied = useIsSmartSlippageApplied()
const smartSlippage = useSmartSwapSlippage()

const labelsAndTooltips = useMemo(
() => ({
Expand All @@ -96,7 +98,7 @@ export function ConfirmSwapModalSetup(props: ConfirmSwapModalSetupProps) {
: undefined,
slippageTooltip: isEoaEthFlow
? getNativeSlippageTooltip(chainId, [nativeCurrency.symbol])
: getNonNativeSlippageTooltip(),
: getNonNativeSlippageTooltip({ isDynamic: !!smartSlippage }),
expectReceiveLabel: isExactIn ? 'Expected to receive' : 'Expected to sell',
minReceivedLabel: isExactIn ? 'Minimum receive' : 'Maximum sent',
minReceivedTooltip: getMinimumReceivedTooltip(allowedSlippage, isExactIn),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,30 @@ export const getNativeSlippageTooltip = (chainId: SupportedChainId, symbols: (st
robust MEV protection, consider wrapping your {symbols?.[0] || 'native currency'} before trading.
</Trans>
)
export const getNonNativeSlippageTooltip = (isSettingsModal?: boolean) => (

export const getNonNativeSlippageTooltip = (params?: { isDynamic?: boolean; isSettingsModal?: boolean }) => (
<Trans>
CoW Swap dynamically adjusts your slippage tolerance to ensure your trade executes quickly while still getting the
best price.{' '}
{isSettingsModal ? (
{params?.isDynamic ? (
<>
To override this, enter your desired slippage amount.
<br />
<br />
Either way, your slippage is protected from MEV!
CoW Swap dynamically adjusts your slippage tolerance to ensure your trade executes quickly while still getting
the best price.{' '}
{params?.isSettingsModal ? (
<>
To override this, enter your desired slippage amount.
<br />
<br />
Either way, your slippage is protected from MEV!
</>
) : (
<>
<br />
<br />
Trades are protected from MEV, so your slippage can't be exploited!
</>
)}
</>
) : (
"Trades are protected from MEV, so your slippage can't be exploited!"
<>CoW Swap trades are protected from MEV, so your slippage can't be exploited!</>
)}
</Trans>
)
Expand Down Expand Up @@ -113,7 +124,10 @@ export function RowSlippageContent(props: RowSlippageContentProps) {
} = props

const tooltipContent =
slippageTooltip || (isEoaEthFlow ? getNativeSlippageTooltip(chainId, symbols) : getNonNativeSlippageTooltip())
slippageTooltip ||
(isEoaEthFlow
? getNativeSlippageTooltip(chainId, symbols)
: getNonNativeSlippageTooltip({ isDynamic: !!smartSlippage }))

// In case the user happened to set the same slippage as the suggestion, do not show the suggestion
const suggestedEqualToUserSlippage = smartSlippage && smartSlippage === displaySlippage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function calculateBpsFromFeeMultiplier(
isSell: boolean | undefined,
multiplierPercentage: number,
): number | undefined {
if (!sellAmount || !feeAmount || isSell === undefined || multiplierPercentage <= 0) {
if (!sellAmount || !feeAmount || isSell === undefined || !multiplierPercentage || multiplierPercentage <= 0) {
return undefined
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useReceiveAmountInfo } from 'modules/trade'

import { calculateBpsFromFeeMultiplier } from './calculateBpsFromFeeMultiplier'


/**
* Calculates smart slippage in bps, based on quoted fee
*
Expand All @@ -19,7 +18,7 @@ export function useSmartSlippageFromFeeMultiplier(): number | undefined {
const sellAmount = isSell ? afterNetworkCosts?.sellAmount : beforeNetworkCosts?.sellAmount
const feeAmount = costs?.networkFee?.amountInSellCurrency

const { smartSlippageFeeMultiplierPercentage = 50 } = useFeatureFlags()
const { smartSlippageFeeMultiplierPercentage } = useFeatureFlags()

return useMemo(
() => calculateBpsFromFeeMultiplier(sellAmount, feeAmount, isSell, smartSlippageFeeMultiplierPercentage),
Expand Down

0 comments on commit c6ea5af

Please sign in to comment.