Skip to content

fix: improve swap UI when network costs round to 0#6846

Open
Olaleye-Blessing wants to merge 1 commit intocowprotocol:developfrom
Olaleye-Blessing:fix/show-network-costs-field
Open

fix: improve swap UI when network costs round to 0#6846
Olaleye-Blessing wants to merge 1 commit intocowprotocol:developfrom
Olaleye-Blessing:fix/show-network-costs-field

Conversation

@Olaleye-Blessing
Copy link

@Olaleye-Blessing Olaleye-Blessing commented Jan 18, 2026

Summary

Fixes #6826

Sometimes, there is no "network costs" field on the swap order estimation. This PR makes sure the field is present everytime even if the cost is zero. The word, "free", is shown when the cost is zero.

Screenshots

Before

Screenshot 2026-01-18 at 17 04 13

After

Screenshot 2026-01-18 at 17 09 51

To Test

  1. Go to the swap page
  2. Switch to any L2 chain with a general low gas fee (Gnosis, Plasma)
  3. Swap tokens
  4. Check the network costs field (present with the "free" word if the cost is zero)

Summary by CodeRabbit

  • New Features

    • Added a "Free" label to indicate when network costs are absent.
  • Improvements

    • Network cost row now appears whenever a network fee amount exists, clarifying when costs apply.
    • Fee labeling and propagation across review screens improved for clearer, more consistent fee breakdowns.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Jan 18, 2026

@Olaleye-Blessing 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 Jan 18, 2026

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

Walkthrough

The PR surfaces a new showFreeLabel prop through trade fee components and relaxes NetworkCostsRow rendering to depend on networkFeeAmount, allowing the UI to show a "Free" label when network costs are effectively zero while keeping the row visible.

Changes

Cohort / File(s) Summary
Container
apps/cowswap-frontend/src/modules/trade/containers/TradeFeesAndCosts/index.tsx
Render NetworkCostsRow when networkFeeAmount exists and pass showFreeLabel={ !hasNetworkCosts }.
Network costs row
apps/cowswap-frontend/src/modules/trade/pure/NetworkCostsRow/index.tsx
Added optional showFreeLabel?: boolean (default false) to props and forwarded it to ReviewOrderModalAmountRow.
Amount row rendering
apps/cowswap-frontend/src/modules/trade/pure/ReviewOrderModalAmountRow/index.tsx
Added showFreeLabel?: boolean; when true renders localized Trans("FREE") in green instead of numeric amount/fiat.
Receive amount info
apps/cowswap-frontend/src/common/pure/ReceiveAmountInfo/index.tsx
Adjusted fee presence logic: removed internal hasFee calc, render NetworkFeeItem only when hasNetworkFee, and use hasAnyFee for fee flagging.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant TradeFeesAndCosts as "TradeFeesAndCosts\n(container)"
    participant NetworkCostsRow as "NetworkCostsRow"
    participant ReviewAmountRow as "ReviewOrderModalAmountRow"

    User->>TradeFeesAndCosts: trigger render (trade/fees)
    TradeFeesAndCosts->>NetworkCostsRow: render(networkFeeAmount, hasNetworkCosts)
    Note right of NetworkCostsRow: computes showFreeLabel = !hasNetworkCosts
    NetworkCostsRow->>ReviewAmountRow: render(amount?, showFreeLabel)
    alt showFreeLabel == true
        ReviewAmountRow->>ReviewAmountRow: render "FREE" (Trans, green)
    else showFreeLabel == false
        ReviewAmountRow->>ReviewAmountRow: render numeric TokenAmount + optional fiat
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Design

Suggested reviewers

  • elena-zh
  • limitofzero
  • shoom3301

Poem

🐰 I hopped from prop to prop today,
If tiny fees would slip away,
I plant a "Free" where numbers hide,
Keep the costs row standing by your side,
A carrot cheer for clarity! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main change: improving swap UI when network costs round to 0 by displaying 'Free' instead of hiding the field.
Linked Issues check ✅ Passed All code changes align with issue #6826: the PR ensures the network costs field always renders with a 'Free' label when costs round to zero instead of being hidden.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the network costs display issue. No unrelated modifications detected across the four modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

@Olaleye-Blessing
Copy link
Author

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

github-actions bot added a commit that referenced this pull request Jan 18, 2026
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: 1

🤖 Fix all issues with AI agents
In
`@apps/cowswap-frontend/src/modules/trade/containers/TradeFeesAndCosts/index.tsx`:
- Around line 64-73: The isLast prop for the NetworkCostsRow is incorrectly tied
to hasNetworkCosts (isLast={!hasNetworkCosts}) so when networkFeeAmount exists
the row is marked not-last; change the prop to always pass true when rendering
NetworkCostsRow (e.g., isLast={true}) so that NetworkCostsRow is consistently
treated as the final timeline row regardless of hasNetworkCosts; locate this in
the TradeFeesAndCosts component around the NetworkCostsRow render and update the
isLast prop only (leave showFreeLabel logic as-is).

@vercel
Copy link

vercel bot commented Jan 19, 2026

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

Project Deployment Review Updated (UTC)
swap-dev Ready Ready Preview Jan 19, 2026 1:40pm

Request Review

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 @Olaleye-Blessing , thank you for addressing this issue.
I have 2 nitpicks to report:

  1. Styling: 'FREE' should be in capitals, and should be in green. See an example:
free
  1. When we say that it is 'free', then, the 'receive'/'from' tooptips should not show '-0' for fee. The line should be removed from there.
image

Example:
no fee

Could you please address these issues?

Thanks

- show 'Free' when there is no network cost
- Hide network field from the tooltip
@Olaleye-Blessing Olaleye-Blessing force-pushed the fix/show-network-costs-field branch from c74ad31 to c12c020 Compare January 19, 2026 12:57
@Olaleye-Blessing Olaleye-Blessing changed the title fix: show 'Free' when network costs round to zero fix: improve swap UI when network costs round to 0 Jan 19, 2026
@Olaleye-Blessing
Copy link
Author

Hy @elena-zh

I've addressed both issues. Thanks.

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.

LGTM, thank you!

@elena-zh elena-zh requested a review from a team January 19, 2026 14:14
Comment on lines +74 to +75
{hasNetworkFee && (
<NetworkFeeItem discount={discount} networkFeeAmount={networkFeeAmount} isSell={isSell} hasFee={hasAnyFee} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

While this does fix a problem, of showing something when the amounts are too small, I don't think it solves the main issue because:

  1. The amount is negligible, < 1 atom of the opposite token, but it's not completely 0, so FREE isn't accurate
  2. Even here in the code, we use the hasNetworkFee to control the render of the component, but use hasAnyFee, which depends on hasPartnerFee and hasProcotolFee

Copy link
Author

Choose a reason for hiding this comment

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

I think the <NetworkFeeItem /> is a little misleading. If there's a protocol/partner fee but the network fee is zero, the component will always display 0. I don't think the hasFee prop is really effective if <NetworkFeeItem /> always renders only the network fee.

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.

[plasma] No Network costs field for some orders

3 participants