Skip to content
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

fix(smart-slippage): fix smart slip tooltip and feature flag #5004

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading