fix: improve swap UI when network costs round to 0#6846
fix: improve swap UI when network costs round to 0#6846Olaleye-Blessing wants to merge 1 commit intocowprotocol:developfrom
Conversation
|
@Olaleye-Blessing is attempting to deploy a commit to the cow Team on Vercel. A member of the Team first needs to authorize it. |
|
All contributors have signed the CLA ✍️ ✅ |
WalkthroughThe 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
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).
apps/cowswap-frontend/src/modules/trade/containers/TradeFeesAndCosts/index.tsx
Show resolved
Hide resolved
3d32ccc to
5833963
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
elena-zh
left a comment
There was a problem hiding this comment.
Hey @Olaleye-Blessing , thank you for addressing this issue.
I have 2 nitpicks to report:
- Styling: 'FREE' should be in capitals, and should be in green. See an example:
- 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.
Could you please address these issues?
Thanks
- show 'Free' when there is no network cost - Hide network field from the tooltip
c74ad31 to
c12c020
Compare
|
Hy @elena-zh I've addressed both issues. Thanks. |
| {hasNetworkFee && ( | ||
| <NetworkFeeItem discount={discount} networkFeeAmount={networkFeeAmount} isSell={isSell} hasFee={hasAnyFee} /> |
There was a problem hiding this comment.
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:
- The amount is negligible, < 1 atom of the opposite token, but it's not completely 0, so
FREEisn't accurate - Even here in the code, we use the
hasNetworkFeeto control the render of the component, but usehasAnyFee, which depends onhasPartnerFeeandhasProcotolFee
There was a problem hiding this comment.
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.

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
After
To Test
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.