Skip to content

Conversation

@kernelwhisperer
Copy link
Contributor

@kernelwhisperer kernelwhisperer commented Dec 30, 2025

Summary

Fixes #4127

The issue was that the form validation was not taking into account the isBalancesLoading state.

To Test

As per the issue:

Connect to a wallet (using WC or open the app inside Safe --> most likely you will immediately reproduce the issue)

AR: each time when app is loading after changing a network/connection, 'Couldn't load balances' message appears and is displayed up to 20 seconds

Summary by CodeRabbit

  • New Features

    • Trade form now shows a "Fetching balances" message with a subtle loading indicator while token balances load.
  • Bug Fixes

    • Validation updated to suppress premature balance errors while balance data is still loading, preventing incorrect error states during fetch.

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

@vercel
Copy link

vercel bot commented Dec 30, 2025

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

Project Deployment Review Updated (UTC)
cowfi Ready Ready Preview Jan 8, 2026 5:32pm
explorer-dev Ready Ready Preview Jan 8, 2026 5:32pm
swap-dev Ready Ready Preview Jan 8, 2026 5:32pm
widget-configurator Ready Ready Preview Jan 8, 2026 5:32pm
2 Skipped Deployments
Project Deployment Review Updated (UTC)
cosmos Ignored Ignored Jan 8, 2026 5:32pm
sdk-tools Ignored Ignored Preview Jan 8, 2026 5:32pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds a balances-loading flag to trade form validation: exposes isBalancesLoading from the balances hook, extends validation context and types, updates validation logic to show a "balances loading" state instead of a "balances not loaded" error while balances are being fetched, and adds UI for the loading state.

Changes

Cohort / File(s) Summary
Hook / Context
apps/cowswap-frontend/src/modules/tradeFormValidation/hooks/useTradeFormValidationContext.ts
Import useTokensBalances, derive isBalancesLoading, expose it on the returned validation context, and add it to memo deps.
Types
apps/cowswap-frontend/src/modules/tradeFormValidation/types.ts
Added TradeFormValidation.BalancesLoading enum member and isBalancesLoading: boolean to TradeFormValidationCommonContext.
Validation Logic
apps/cowswap-frontend/src/modules/tradeFormValidation/services/validateTradeForm.ts
Updated balance-related checks: return BalancesLoading when isBalancesLoading is true; only return BalancesNotLoaded when balances are not loading and no balance exists; retain BalanceInsufficient checks once balance is present.
UI / i18n
apps/cowswap-frontend/src/modules/tradeFormValidation/pure/TradeFormButtons/tradeButtonsMap.tsx, apps/cowswap-frontend/src/locales/en-US.po
Added BalancesLoading entry in tradeButtonsMap rendering a "Fetching balances" message with CenteredDots; added corresponding i18n string in en-US.po.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant UI as TradeForm UI
participant Hook as useTradeFormValidationContext
participant Balances as useTokensBalances
participant Validator as validateTradeForm
UI->>Hook: request validation context (user input)
Hook->>Balances: subscribe / read balances state
Balances-->>Hook: isBalancesLoading / balances data
Hook-->>UI: context includes isBalancesLoading
UI->>Validator: validateTradeForm(context)
alt balances loading
Validator-->>UI: TradeFormValidation.BalancesLoading
UI-->>UI: show "Fetching balances" + CenteredDots
else balances loaded / available
Validator-->>UI: other validations (ok / BalancesNotLoaded / BalanceInsufficient / ...)
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • elena-zh
  • shoom3301
  • alfetopito

Poem

🐰 Fetching balances, hop by hop,

I nibble bugs until they stop,
Dots a-dancing, soft and light,
No false warnings through the night,
Hooray — the numbers now feel right! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: hiding the 'couldn't load balances' message when balances are loading, which directly addresses the PR's primary objective.
Description check ✅ Passed The PR description includes the issue number, a clear explanation of the problem, and testing steps. It follows the template with the main sections populated, though testing steps are somewhat brief.
Linked Issues check ✅ Passed The code changes directly address issue #4127 by adding isBalancesLoading state to validation logic, introducing a BalancesLoading enum state, and updating UI to show 'Fetching balances' during loading, preventing premature error display.
Out of Scope Changes check ✅ Passed All code changes are directly related to fixing the balance loading state issue. The modifications to validation context, validation logic, types, UI rendering, and localization are all scoped to resolving issue #4127.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

@kernelwhisperer kernelwhisperer self-assigned this Dec 30, 2025
@kernelwhisperer kernelwhisperer requested review from a team December 30, 2025 15:58
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 @kernelwhisperer , thank you!
However, I still can see this message ('could not load balances') when I connect to a wallet (to Safe with WC, or to MM).
image

To reproduce:

  1. open the PR preview link
  2. connect to Safe wallet using WC

Then, sometimes. when I switch between networks using network selector (connected to MM), I can see 'fetching balances' message flashing on a quote load, but then I get 'could not load balances' error again.

See the video: the issue happened when I switched to Base: https://www.loom.com/share/e896d51a2d314e0aaba185ada0ebb465

@kernelwhisperer kernelwhisperer force-pushed the fix/couldnt-load-balances branch from 98f40f0 to 397c499 Compare January 8, 2026 17:23
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.

'Couldn't load balances' message is displayed after a wallet connection

6 participants