Skip to content

Conversation

@Rustix69
Copy link

@Rustix69 Rustix69 commented Oct 24, 2025

Show Slippage Outside Accordion When Modified or Above Threshold

Fixes #6317

Summary

Slippage tolerance now displays outside the accordion when it requires user attention, making high slippage warnings and manual adjustments immediately visible.

Changes

  • Created useShouldShowSlippageProminent hook for smart visibility logic
  • Slippage shows outside accordion when manually modified OR exceeds thresholds
  • No duplication - displays in only ONE location at a time
  • Backward compatible - default behavior unchanged

When Slippage Shows Outside Accordion

Condition Threshold
User manually modified slippage Always shown
Regular ERC20 orders > 2%
ETH-flow orders (Mainnet) > 5%

Testing

  1. Default slippage (0.5%) → Hidden inside accordion ✅
  2. Set slippage to 1% → Shows outside accordion ✅
  3. Set slippage to 3% → Shows outside accordion with warning ✅
  4. Reset to Auto → Returns to accordion ✅

Snapshot

image

Files Modified

  • NEW: useShouldShowSlippageProminent.ts hook
  • tradeSlippage/index.tsx (exports)
  • TradeRateDetails/index.tsx (conditional rendering)

Before/After

Before: Slippage always hidden → users miss important warnings
After: Slippage prominent when needed → better transparency & safety


Summary by CodeRabbit

  • New Features
    • Slippage information now displays prominently outside the accordion when manually modified by users or when exceeding chain-specific thresholds, improving visibility for important trade parameters.

@vercel
Copy link

vercel bot commented Oct 24, 2025

@Rustix69 is attempting to deploy a commit to the cow Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2025

Walkthrough

Introduces a new hook useShouldShowSlippageProminent and exports it; integrates the hook into TradeRateDetails to conditionally render the slippage row outside the accordion when manually modified or when slippage exceeds chain- and flow-specific thresholds.

Changes

Cohort / File(s) Summary
New Hook: Slippage Prominence Logic
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts
Adds useShouldShowSlippageProminent hook that computes whether slippage should be shown prominently based on user modification flag, slippage (bps), ETH-flow vs ERC20 trade type, chainId and chain-specific thresholds; memoized.
Module Export
apps/cowswap-frontend/src/modules/tradeSlippage/index.tsx
Exports the new useShouldShowSlippageProminent hook.
UI Integration: Conditional Slippage Rendering
apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx
Imports and uses the hook to conditionally render RowSlippage outside the accordion when prominent; otherwise keeps slippage inside the accordion.

Sequence Diagram

sequenceDiagram
    participant TradeRateDetails
    participant Hook as useShouldShowSlippageProminent
    participant Wallet as useWalletInfo
    participant Slippage as useTradeSlippage
    participant Modified as useIsSlippageModified
    participant EthFlow as useIsEoaEthFlow

    TradeRateDetails->>Hook: ask shouldShowSlippageProminent
    Hook->>Modified: isSlippageModified?
    Modified-->>Hook: bool

    alt isSlippageModified = true
        Hook-->>TradeRateDetails: true
    else
        Hook->>Slippage: get slippage %
        Slippage-->>Hook: % value
        Hook->>EthFlow: isEoaEthFlow?
        EthFlow-->>Hook: bool
        Hook->>Wallet: get chainId
        Wallet-->>Hook: chainId
        Note over Hook: choose threshold (ERC20=200bps or ETH_FLOW per chain)
        alt slippage_bps > threshold
            Hook-->>TradeRateDetails: true
        else
            Hook-->>TradeRateDetails: false
        end
    end

    alt true
        TradeRateDetails->>TradeRateDetails: render slippageRow outside accordion
    else
        TradeRateDetails->>TradeRateDetails: render slippageRow inside accordion
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus areas: threshold logic in the hook, correct imports/use of ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD, and UI placement/duplication handling in TradeRateDetails.

Possibly related PRs

Suggested labels

preview-widget-cfg

Suggested reviewers

  • elena-zh
  • shoom3301
  • alfetopito

Poem

🐇 I hopped in code, a tiny twitch,
Slippage now jumps out of the niche,
When users tweak or thresholds cry,
I pop it open — no more shy.
A ribbon of bytes — a widget stitch ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "feat(slippage): show slippage outside accordion when modified or abov…" directly and clearly describes the main change—displaying slippage outside the accordion when user-modified or above threshold. The title is concise, uses conventional commit format, and accurately reflects the primary objective of the changeset without being vague or misleading.
Linked Issues Check ✅ Passed The pull request directly implements all coding requirements from linked issue #6317: it creates the useShouldShowSlippageProminent hook to determine visibility logic, conditionally displays slippage outside the accordion when manually modified, applies the correct thresholds (>2% for regular ERC20 orders, >5% for ETH-flow on Mainnet), prevents duplication by showing slippage in only one location, and maintains backward compatibility. The implementation fully addresses the stated objective of improving slippage visibility when user attention is required.
Out of Scope Changes Check ✅ Passed All code changes are directly within the scope of linked issue #6317. The new hook useShouldShowSlippageProminent implements the core visibility logic, the export in tradeSlippage/index.tsx makes the hook available, and the conditional rendering in TradeRateDetails/index.tsx applies this logic to display slippage outside the accordion when appropriate. No extraneous modifications, refactoring, or unrelated features are present in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Rustix69
Copy link
Author

@elena-zh Have a look on this PR and let me know if any changes required.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (1)

49-65: Threshold logic is correct and well-structured.

The logic correctly implements the different thresholds for regular orders (2%), ETH-flow on Mainnet (5%), and ETH-flow on other chains (uses ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD). While there's some redundancy since non-Mainnet ETH-flow currently uses the same 2% threshold as regular orders, keeping the logic explicit makes the intent clear and allows for future differentiation per chain.

The structure is clean, but if you want to simplify in the future, you could collapse cases with identical thresholds. For now, the explicit approach is fine and self-documenting.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 385b9c0 and 919038f.

📒 Files selected for processing (3)
  • apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (1 hunks)
  • apps/cowswap-frontend/src/modules/tradeSlippage/index.tsx (1 hunks)
  • apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (6)
libs/wallet/src/api/hooks.ts (1)
  • useWalletInfo (24-26)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useTradeSlippage.ts (1)
  • useTradeSlippage (36-40)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useIsSlippageModified.ts (1)
  • useIsSlippageModified (3-5)
apps/cowswap-frontend/src/modules/trade/hooks/useIsEoaEthFlow.ts (1)
  • useIsEoaEthFlow (5-7)
libs/common-utils/src/misc.ts (1)
  • percentToBps (193-195)
libs/common-const/src/common.ts (1)
  • ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD (86-88)
apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx (2)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (1)
  • useShouldShowSlippageProminent (37-70)
apps/cowswap-frontend/src/modules/trade/containers/TradeTotalCostsDetails/index.tsx (1)
  • TradeTotalCostsDetails (21-41)
🔇 Additional comments (7)
apps/cowswap-frontend/src/modules/tradeSlippage/index.tsx (1)

11-11: LGTM!

The export follows the existing pattern and correctly exposes the new hook.

apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx (3)

16-16: LGTM!

The import and hook usage are correct and follow React best practices.

Also applies to: 46-46


86-93: LGTM!

Extracting the slippage row into a variable improves readability and enables clean conditional rendering. The null check appropriately handles the case when slippage is not available.


103-104: LGTM!

The conditional rendering logic correctly ensures the slippage row appears in exactly one location—either prominently outside the accordion or inside when not prominent. The mutual exclusion logic is sound, and the padding wrapper is consistent with existing patterns.

Also applies to: 110-122

apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (3)

1-23: LGTM!

The imports and threshold constants are well-defined and clearly documented. The values correctly match the PR requirements (2% for regular orders, 5% for ETH-flow on Mainnet).


37-47: LGTM!

The hook correctly implements the requirement that manually modified slippage should always be shown prominently. The early return pattern is clean and efficient.


67-70: LGTM!

The final comparison and memoization are correctly implemented. The use of strict greater-than comparison aligns with the PR requirements, and all necessary dependencies are included in the useMemo array.

@elena-zh
Copy link
Contributor

@Rustix69 , thank you. will review. Until then, could you please sign the agreement #6427 (comment)?

@vercel
Copy link

vercel bot commented Oct 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
swap-dev Ready Ready Preview Oct 24, 2025 0:11am

@elena-zh elena-zh requested review from a team October 24, 2025 12:04
@Rustix69
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Rustix69 , thank you, great job!

3 issues I've found:

  1. It would be great to move the slippage field closer to the action button
to the borrom
  1. When setting ETH token on Ethereum, the slippage banner (when slippage is >2%) is displayed while the slippage field is not.
    A bit more background on this: now the slippage banner is displayed for ETH-flow orders when slippage is higher than 2%. Threshold of 5% was removed 3 weeks ago.
banner wo slippage Could you please add it like here? like here
  1. Could you please hide the slippage field (if is was changed) for swap and bridge orders when price/fee accordion is expanded? The field is duplicated in this case
duplicated
  1. In case of swap and bridge order. the field's name should be Max. swap slippage
  2. One more possible option to solve 3 and 4 cases is to hide Slippage tolerance field(if manually modified) for swap and bridge orders. :)

Thank you

github-actions bot added a commit that referenced this pull request Oct 26, 2025
@Rustix69
Copy link
Author

@elena-zh I had fixed the changes plz review once...

Show Slippage Prominently for Limit/TWAP Orders

Changes

  • Hide prominent slippage for Swap/Bridge orders - Slippage only shows inside accordion to avoid duplication
  • Show prominent slippage for Limit/TWAP/Yield - Displays below accordion when modified or >2% threshold
  • Fixed ETH-flow threshold - Now uses 2% threshold consistently (removed outdated 5% Mainnet special case)
  • Prevent duplication - Prominent slippage auto-hides when accordion is expanded

Behavior

Order Type Prominent Slippage
Swap ❌ Hidden (inside accordion only)
Bridge ❌ Hidden (inside accordion only)
Limit/TWAP/Yield ✅ Shows when modified or >2%
ETH-flow ✅ Shows at >2% threshold

Files Modified

  • useShouldShowSlippageProminent.ts - Order type detection logic
  • TradeRateDetails/index.tsx - Positioning below accordion

@Rustix69 Rustix69 requested a review from elena-zh October 26, 2025 17:24
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (1)

59-62: Clarify threshold variation in comment.

The comment states ">2%" but the actual threshold varies by order type (2% for regular, 5% for ETH-flow per requirements).

Apply this diff:

     // Show prominently when:
     // 1. User manually modified slippage, OR
-    // 2. Slippage exceeds threshold (>2%)
+    // 2. Slippage exceeds order-specific threshold (2% regular / 5% ETH-flow)
apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx (2)

103-104: Clarify comment about conditional slippage rendering.

The comment "Always show slippage inside accordion" is misleading—it suggests unconditional rendering, but the actual intent is that slippage is available inside the accordion (visible when expanded) and may also appear outside when prominent.

Apply this diff:

-      {/* Always show slippage inside accordion */}
+      {/* Slippage inside accordion (visible when expanded) */}
       {slippageRow}

121-122: Consider optimization: avoid rendering slippageRow twice.

Currently, slippageRow is rendered both inside the accordion (line 104) and outside (line 122) when prominent. Although only one is visible at a time due to accordion state, this creates unnecessary DOM nodes and component instances.

Refactor to render in only one location:

       <TradeFeesAndCosts
         receiveAmountInfo={receiveAmountInfo}
         networkCostsSuffix={shouldPayGas ? <NetworkCostsSuffix /> : null}
         networkCostsTooltipSuffix={<NetworkCostsTooltipSuffix />}
       />
-      {/* Slippage inside accordion (visible when expanded) */}
-      {slippageRow}
+      {/* Show slippage inside only when not shown prominently outside, or when accordion is open */}
+      {(!shouldShowSlippageProminent || isFeeDetailsOpen) && slippageRow}
       <RowDeadline deadline={deadline} />

This ensures slippageRow renders in exactly one location:

  • Inside when !shouldShowSlippageProminent (any accordion state)
  • Inside when shouldShowSlippageProminent && isFeeDetailsOpen (open accordion)
  • Outside when shouldShowSlippageProminent && !isFeeDetailsOpen (closed accordion, line 122)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 919038f and 6c293df.

📒 Files selected for processing (2)
  • apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (1 hunks)
  • apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-10T20:28:16.565Z
Learnt from: fairlighteth
PR: cowprotocol/cowswap#6347
File: apps/cowswap-frontend/src/modules/trade/pure/TradeConfirmation/index.tsx:49-49
Timestamp: 2025-10-10T20:28:16.565Z
Learning: In apps/cowswap-frontend/src/modules/trade, TradeConfirmation follows a two-layer architecture: TradeConfirmationView (pure/stateless) in pure/TradeConfirmation/index.tsx renders the UI, while TradeConfirmation (container) in containers/TradeConfirmation/index.tsx wraps it to freeze props during pending trades (via useStableTradeConfirmationProps), wire in signing state (useSigningStep), and inject trade confirmation state (useTradeConfirmState). Consuming modules should import the container TradeConfirmation from 'modules/trade' to preserve this stateful behavior.
<!-- [add_learning]
When reviewing component refactoring in apps/cowswap-frontend/src/modules/trade, recognize the pattern where a pure view component (e.g., TradeConfirmationView) is separated from a stateful container (e.g., TradeConfirmation) that wraps it. The container adds runtime state management (prop stabilization, signing state, etc.) while the view remains testable and composable. Do not flag usages that import th...

Applied to files:

  • apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx
🧬 Code graph analysis (2)
apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx (2)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (1)
  • useShouldShowSlippageProminent (31-66)
apps/cowswap-frontend/src/modules/trade/containers/TradeTotalCostsDetails/index.tsx (1)
  • TradeTotalCostsDetails (21-41)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (8)
libs/wallet/src/api/hooks.ts (1)
  • useWalletInfo (24-26)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useTradeSlippage.ts (1)
  • useTradeSlippage (36-40)
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useIsSlippageModified.ts (1)
  • useIsSlippageModified (3-5)
apps/cowswap-frontend/src/modules/trade/hooks/useIsEoaEthFlow.ts (1)
  • useIsEoaEthFlow (5-7)
apps/cowswap-frontend/src/modules/trade/hooks/useTradeTypeInfo.ts (1)
  • useTradeTypeInfo (6-8)
apps/cowswap-frontend/src/modules/trade/hooks/useIsCurrentTradeBridging.ts (1)
  • useIsCurrentTradeBridging (5-9)
libs/common-utils/src/misc.ts (1)
  • percentToBps (193-195)
libs/common-const/src/common.ts (1)
  • ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD (86-88)
🔇 Additional comments (2)
apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TradeRateDetails/index.tsx (1)

86-93: Nice refactor for reusability.

Extracting slippageRow as a constant eliminates duplication and makes the conditional rendering logic cleaner.

apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts (1)

39-44: Verify the exclusion of SWAP orders from prominent slippage display with the PR author or design documentation.

The code explicitly excludes TradeType.SWAP and bridge orders with a comment ("Never show prominently for Swap or Bridge orders"), indicating intentional design. However, I could not locate supporting rationale in the codebase or public resources. Confirm with the PR author or linked issue whether this exclusion aligns with the stated objectives and is properly documented in the broader architecture or design specs.

Comment on lines +18 to +30
/**
* 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% for all orders)
*
* EXCEPT: Never show prominently for Swap or Bridge orders (to avoid duplication)
*
* Note: When accordion is expanded, prominent slippage is hidden to avoid duplication
*
* @returns {boolean} true if slippage should be shown outside the accordion
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Documentation contradicts stated requirements.

The JSDoc on line 23 states slippage should exceed ">2% for all orders," but the PR objectives clearly specify different thresholds: ">2% for regular orders" and ">5% for ETH-flow orders on Mainnet."

Apply this diff to correct the documentation:

  * Slippage should be prominent when:
  * 1. User has manually modified the slippage value, OR
- * 2. Slippage exceeds warning thresholds (>2% for all orders)
+ * 2. Slippage exceeds warning thresholds (>2% for regular ERC20 orders, >5% for ETH-flow orders)
🤖 Prompt for AI Agents
In
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts
around lines 18 to 30, the JSDoc incorrectly states a single ">2% for all
orders" threshold; update the documentation to reflect the PR objectives:
slippage should be prominent when the user manually modified it OR when slippage
exceeds >2% for regular orders and >5% for ETH-flow orders on Mainnet; retain
the exceptions noting never show prominently for Swap or Bridge orders and hide
prominent slippage when the accordion is expanded.

Comment on lines +51 to +57
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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_THRESHOLD is 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:

export const ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD: Record<SupportedChainId, number> = mapSupportedNetworks(
  500, // 5%
)

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
In
apps/cowswap-frontend/src/modules/tradeSlippage/hooks/useShouldShowSlippageProminent.ts
around lines 51–57, the ETH-flow threshold is set to 2% but requirements require
>5% on Mainnet; update the constant definition in
libs/common-const/src/common.ts to set ETH_FLOW_SLIPPAGE_WARNING_THRESHOLD to
500 (bps) via mapSupportedNetworks(500) so chains use 5% instead of 2%, and then
update the inline comment at line ~52 in useShouldShowSlippageProminent.ts to
reflect that ETH-flow orders use a 5% threshold on Mainnet (e.g., “For ETH-flow
orders, use 5% threshold”) ensuring types still match SupportedChainId mapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conditionally show Slippage field on the Swap UI

2 participants