-
Notifications
You must be signed in to change notification settings - Fork 151
feat(slippage): show slippage outside accordion when modified or abov… #6427
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
Open
Rustix69
wants to merge
8
commits into
cowprotocol:develop
Choose a base branch
from
Rustix69:fix/slippage-accordian
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
919038f
feat(slippage): show slippage outside accordion when modified or abov…
Rustix69 648f336
Merge branch 'develop' into fix/slippage-accordian
Rustix69 6c293df
feat(slippage): show prominently for limit/TWAP orders, hide for swap…
Rustix69 b5092d8
Merge branch 'develop' into fix/slippage-accordian
Rustix69 7c45009
feat(slippage): show prominently for swap orders, hide for bridge
Rustix69 4dcc4fc
Merge branch 'develop' into fix/slippage-accordian
Rustix69 fc45f08
style(slippage): adjust spacing for better alignment with rate info
Rustix69 0340046
Merge branch 'develop' into fix/slippage-accordian
Rustix69 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { useMemo } from 'react' | ||
|
|
||
| import { ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD } from '@cowprotocol/common-const' | ||
| import { percentToBps } from '@cowprotocol/common-utils' | ||
| import { useWalletInfo } from '@cowprotocol/wallet' | ||
|
|
||
| import { useIsCurrentTradeBridging, useIsEoaEthFlow } from 'modules/trade' | ||
|
|
||
| import { useIsSlippageModified } from './useIsSlippageModified' | ||
| import { useTradeSlippage } from './useTradeSlippage' | ||
|
|
||
| /** | ||
| * Slippage warning threshold for regular ERC20 orders | ||
| * Show slippage prominently when > 2% | ||
| */ | ||
| const REGULAR_ORDER_SLIPPAGE_WARNING_BPS = 200 // 2% | ||
|
|
||
| /** | ||
| * Hook to determine if slippage should be displayed prominently (outside the accordion) | ||
| * | ||
| * Slippage should be prominent when: | ||
| * 1. User has manually modified the slippage value, OR | ||
| * 2. Slippage exceeds warning thresholds (>2%) | ||
| * | ||
| * EXCEPT: Never show prominently for Bridge orders | ||
| * | ||
| * Note: When accordion is expanded, prominent slippage is hidden to avoid duplication | ||
| * | ||
| * @returns {boolean} true if slippage should be shown outside the accordion | ||
| */ | ||
| export function useShouldShowSlippageProminent(): boolean { | ||
| const { chainId } = useWalletInfo() | ||
| const slippage = useTradeSlippage() | ||
| const isSlippageModified = useIsSlippageModified() | ||
| const isEoaEthFlow = useIsEoaEthFlow() | ||
| const isCurrentTradeBridging = useIsCurrentTradeBridging() | ||
|
|
||
| return useMemo(() => { | ||
| // Never show prominently for Bridge orders | ||
| if (isCurrentTradeBridging) { | ||
| return false | ||
| } | ||
|
|
||
| const slippageBps = percentToBps(slippage) | ||
|
|
||
| // Determine the warning threshold based on order type | ||
| let warningThresholdBps: number | ||
|
|
||
| if (isEoaEthFlow) { | ||
| // For ETH-flow orders, use 2% threshold | ||
| warningThresholdBps = ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD[chainId] | ||
| } else { | ||
| // For regular ERC20 orders, use 2% threshold | ||
| warningThresholdBps = REGULAR_ORDER_SLIPPAGE_WARNING_BPS | ||
| } | ||
|
|
||
| // Show prominently when: | ||
| // 1. User manually modified slippage, OR | ||
| // 2. Slippage exceeds threshold (>2%) | ||
| const shouldShowDueToHighSlippage = slippageBps > warningThresholdBps | ||
|
|
||
| return isSlippageModified || shouldShowDueToHighSlippage | ||
| }, [chainId, slippage, isSlippageModified, isEoaEthFlow, isCurrentTradeBridging]) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: ETH-flow threshold implementation contradicts requirements.
The implementation uses 2% for ETH-flow orders (line 53), but the PR objectives and linked issue #6317 explicitly state the threshold should be ">5% for ETH-flow orders on Mainnet."
Looking at
libs/common-const/src/common.ts,ETH_FLOW_SLIPPAGE_WARNING_THRESHOLDis hardcoded to 200 bps (2%) for all chains. This constant needs to be updated to 500 bps (5%) to match requirements.You'll need to update the constant definition in
libs/common-const/src/common.ts:Then update the comment on line 52:
if (isEoaEthFlow) { - // For ETH-flow orders, use 2% threshold + // For ETH-flow orders, use 5% threshold warningThresholdBps = ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD[chainId]🤖 Prompt for AI Agents