Skip to content

refactor: timeouts and logging in wallet capabilities#7821

Open
kernelwhisperer wants to merge 1 commit into
developfrom
refactor/wallet-capabilities
Open

refactor: timeouts and logging in wallet capabilities#7821
kernelwhisperer wants to merge 1 commit into
developfrom
refactor/wallet-capabilities

Conversation

@kernelwhisperer

@kernelwhisperer kernelwhisperer commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  1. Improve logging
  2. Delete PromiseWithTimeout
  3. Refactor withTimeout which is used by the explorer

To Test

This PR doesn't really change any logic, just a refactor.

  1. Connect with a safe wallet
  • Batching works in swap
  • TWAP support is detected

Background

In the next PR (#7844) I will implement https://linear.app/cowswap/issue/FE-265/batch-support-for-eoas-and-eip7702-delegated-eoas

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Improved wallet capability detection with clearer timeout handling and legacy fallback.
  • Bug Fixes
    • Wallet capability fetch now returns null when providers fail or time out.
    • Improved timeout handling to avoid lingering timers.
  • Refactor
    • Standardized timeout handling to use a typed, options-based withTimeout API and TimeoutError.
    • Expanded environment-specific timeout messages for requests.
  • Chores
    • Removed the old PromiseWithTimeout utility export and updated related tests.

@kernelwhisperer kernelwhisperer requested a review from Danziger July 7, 2026 14:59
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
cowfi Ready Ready Preview Jul 13, 2026 9:46am
explorer-dev Ready Ready Preview Jul 13, 2026 9:46am
storybook Ready Ready Preview Jul 13, 2026 9:46am
swap-dev Ready Ready Preview Jul 13, 2026 9:46am
widget-configurator Ready Ready Preview Jul 13, 2026 9:46am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored Jul 13, 2026 9:46am
sdk-tools Ignored Ignored Preview Jul 13, 2026 9:46am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1f75e1fc-1964-4329-ab7d-13cc14e6f878

📥 Commits

Reviewing files that changed from the base of the PR and between d76cdd3 and 5a1c3f9.

📒 Files selected for processing (8)
  • apps/explorer/src/api/operator/operatorApi.ts
  • libs/common-utils/src/index.ts
  • libs/common-utils/src/misc.test.ts
  • libs/common-utils/src/misc.ts
  • libs/common-utils/src/promiseWithTimeout.test.ts
  • libs/common-utils/src/promiseWithTimeout.ts
  • libs/wallet/src/api/state/walletCapabilitiesAtom.test.ts
  • libs/wallet/src/api/state/walletCapabilitiesAtom.ts
💤 Files with no reviewable changes (3)
  • libs/common-utils/src/index.ts
  • libs/common-utils/src/promiseWithTimeout.test.ts
  • libs/common-utils/src/promiseWithTimeout.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • libs/common-utils/src/misc.test.ts
  • apps/explorer/src/api/operator/operatorApi.ts
  • libs/common-utils/src/misc.ts
  • libs/wallet/src/api/state/walletCapabilitiesAtom.ts
  • libs/wallet/src/api/state/walletCapabilitiesAtom.test.ts

Walkthrough

The PR replaces PromiseWithTimeout with an options-based withTimeout, adds typed timeout errors, updates wallet capability timeout and fallback handling, and changes operator timeout messages.

Changes

Timeout migration

Layer / File(s) Summary
Timeout utility contract
libs/common-utils/src/misc.ts, libs/common-utils/src/misc.test.ts, libs/common-utils/src/index.ts
withTimeout now accepts timeout options, raises TimeoutError, clears timers, removes the legacy barrel export, and covers resolution, timeout, and custom messages.
Wallet capability timeout flow
libs/wallet/src/api/state/walletCapabilitiesAtom.ts, libs/wallet/src/api/state/walletCapabilitiesAtom.test.ts
Capability and widget metadata requests use withTimeout; timeout and RPC failures return null, while legacy capability requests remain available as fallback.
Operator request timeout migration
apps/explorer/src/api/operator/operatorApi.ts
BARN and PROD wrappers use the options-based timeout API and expanded environment-specific messages.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant walletCapabilitiesAtom
  participant ViemProvider
  participant withTimeout
  participant LegacyRPC
  walletCapabilitiesAtom->>ViemProvider: getCapabilities()
  walletCapabilitiesAtom->>withTimeout: enforce REQUEST_TIMEOUT_MS
  withTimeout-->>walletCapabilitiesAtom: capabilities or TimeoutError
  walletCapabilitiesAtom->>LegacyRPC: wallet_getCapabilities request
  walletCapabilitiesAtom->>withTimeout: enforce REQUEST_TIMEOUT_MS
  withTimeout-->>walletCapabilitiesAtom: capabilities or TimeoutError
Loading

Possibly related PRs

Suggested reviewers: danziger, alfetopito, elena-zh, fairlighteth, shoom3301

Poem

A bunny hops where timers gleam,
WithTimeout guards each pending dream.
BARN and PROD now speak their time,
Wallet fallbacks work in rhyme.
TimeoutError wears ears so neat—
The code is crisp from tail to feet! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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
Title check ✅ Passed The title clearly reflects the main change: refactoring timeout handling and logging in wallet capabilities.
Description check ✅ Passed The description follows the template with Summary, To Test, and Background sections and is sufficiently specific.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/wallet-capabilities

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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploying explorer-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5a1c3f9
Status: ✅  Deploy successful!
Preview URL: https://dc9b8da7.explorer-dev-dxz.pages.dev
Branch Preview URL: https://refactor-wallet-capabilities.explorer-dev-dxz.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploying swap-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5a1c3f9
Status: ✅  Deploy successful!
Preview URL: https://eef8c655.swap-dev-5u6.pages.dev
Branch Preview URL: https://refactor-wallet-capabilities.swap-dev-5u6.pages.dev

View logs

Base automatically changed from refactor/COW-60-orders-table-joi-redux-sync to develop July 9, 2026 14:14
@kernelwhisperer kernelwhisperer force-pushed the refactor/wallet-capabilities branch from f858fc6 to 67a1a37 Compare July 10, 2026 07:27
@kernelwhisperer kernelwhisperer changed the title fix: skip wallet capabilities check on EOAs refactor: timeouts and logging in wallet capabilities Jul 10, 2026
@kernelwhisperer kernelwhisperer force-pushed the refactor/wallet-capabilities branch from 67a1a37 to d76cdd3 Compare July 10, 2026 07:31
@kernelwhisperer kernelwhisperer marked this pull request as ready for review July 10, 2026 10:19
@linear-code

linear-code Bot commented Jul 10, 2026

Copy link
Copy Markdown

FE-265

console.error('Cannot fetch wallet capabilities', getCapabilitiesError)
throw getCapabilitiesError
logWallet.error('Cannot fetch wallet capabilities via wagmi', { account, chainId }, wagmiError)
return null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the only breaking changes, instead of throw getCapabilitiesError we return null. It's what we do in other error cases and what the consumers expect.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
libs/wallet/src/api/state/walletCapabilitiesAtom.ts (1)

60-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Timeout message format inconsistency.

The widget meta-info timeout message uses ${REQUEST_TIMEOUT_MS}ms (→ "5000ms") while the capabilities timeout message at line 171 uses ${REQUEST_TIMEOUT_MS / 1000}s (→ "5s"). Both are correct but inconsistent — consider aligning the format for uniform log output.

♻️ Suggested alignment
-      timeoutMessage: `Widget provider meta info request timed out after ${REQUEST_TIMEOUT_MS}ms`,
+      timeoutMessage: `Widget provider meta info request timed out after ${REQUEST_TIMEOUT_MS / 1000}s`,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/wallet/src/api/state/walletCapabilitiesAtom.ts` around lines 60 - 62,
Align the timeout message formats in the widget meta-info request and
capabilities request. Update the timeout message near providerMetaInfo and the
corresponding capabilities timeout in the relevant function to use the same unit
and interpolation style, preferably seconds via REQUEST_TIMEOUT_MS / 1000, while
preserving the existing timeout behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@libs/wallet/src/api/state/walletCapabilitiesAtom.ts`:
- Around line 60-62: Align the timeout message formats in the widget meta-info
request and capabilities request. Update the timeout message near
providerMetaInfo and the corresponding capabilities timeout in the relevant
function to use the same unit and interpolation style, preferably seconds via
REQUEST_TIMEOUT_MS / 1000, while preserving the existing timeout behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7d57a21a-ce3d-4772-989a-499bcc67ea36

📥 Commits

Reviewing files that changed from the base of the PR and between 08e23be and d76cdd3.

📒 Files selected for processing (8)
  • apps/explorer/src/api/operator/operatorApi.ts
  • libs/common-utils/src/index.ts
  • libs/common-utils/src/misc.test.ts
  • libs/common-utils/src/misc.ts
  • libs/common-utils/src/promiseWithTimeout.test.ts
  • libs/common-utils/src/promiseWithTimeout.ts
  • libs/wallet/src/api/state/walletCapabilitiesAtom.test.ts
  • libs/wallet/src/api/state/walletCapabilitiesAtom.ts
💤 Files with no reviewable changes (3)
  • libs/common-utils/src/promiseWithTimeout.test.ts
  • libs/common-utils/src/promiseWithTimeout.ts
  • libs/common-utils/src/index.ts

@kernelwhisperer kernelwhisperer requested a review from a team July 10, 2026 12:17
@fairlighteth fairlighteth self-requested a review July 10, 2026 14:53

@fairlighteth fairlighteth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI Review follow-up: Safe-via-WalletConnect QA verified

Resolution: addressed. The requested browser QA evidence now covers the distinct Safe capability paths on PR head d76cdd3:

  • Safe App: detected the Safe and atomic batching support, then exposed TWAP onboarding. As expected, this path bypassed the changed capability fallback.
  • Safe via WalletConnect, ordinary flow: reached wallet-connected UI, invoked the direct wallet_getCapabilities fallback, resolved batching as supported, and exposed TWAP onboarding.
  • Safe via WalletConnect, timeout A/B: with only viem's capability request held pending, the PR timed out, invoked the real Safe provider's direct RPC fallback, resolved batching as supported, and opened the normal TWAP form. The pinned develop control did not invoke the fallback and showed Use Safe web app / Unsupported wallet.

Conclusion

The QA evidence gap is closed and no code change is requested from this finding. The run confirms the original technical observation: allowing a viem timeout to enter the direct RPC fallback is a behavior change, despite the PR description calling the refactor logic-neutral, and the changed behavior is desirable for Safe via WalletConnect.

The run did not submit a batch transaction, signature, or order. That remains outside this capability-detection verification.

Original review rationale and related context
  • Location: libs/wallet/src/api/state/walletCapabilitiesAtom.ts:176
  • Safe App returns early through isSafeAppAtom, so testing only “a Safe wallet” could pass without exercising the changed fallback.
  • The common-utils and wallet test suites passed, including the new timeout and fallback cases.
  • The PR's Cypress failures matched the same four missing-trade-button failures on the tested develop control, so they were not attributable to this diff.
  • The author's existing thread covered the separate null-vs-throw behavior change.
  • CodeRabbit covered the timeout-message unit inconsistency; it is not repeated here.

Generated using the pr-review and pr-qa skills from the CoW Protocol skills repo.

@fairlighteth

Copy link
Copy Markdown
Contributor
Browser QA passed: Safe App and Safe-via-WalletConnect timeout fallback

Outcome

  • Safe App: PR head and the pinned develop control both detected the Safe, resolved atomic batching support, and exposed TWAP onboarding.
  • Safe via WalletConnect, ordinary flow: both sources reached wallet-connected UI; the direct wallet_getCapabilities fallback was observed and atomic batching resolved as supported.
  • Timeout-specific A/B: with only viem's capability request held pending, the PR timed out, invoked the real Safe provider's direct RPC fallback, resolved batching as supported, and opened the normal TWAP form. The develop control did not invoke the fallback, resolved batching as unsupported, and showed Use Safe web app / Unsupported wallet.
  • Conclusion: the PR's timeout fallback fixes a reproducible runtime difference; this is not logic-neutral, but the changed behavior is the desired one for Safe via WalletConnect.
  • Not checked / follow-up: no batch transaction, signature, order submission, or fill was attempted. Coverage was Chromium on Gnosis Chain only.

Run details

  • Source: PR head d76cdd3b4224961efbebe508c7caaebdf8e9696b via local checkout; control develop at 8ab088d941de79d546aee3796a74c738d149b08a.
  • Environment: Linux; Chromium 140.0.7339.186.
  • Wallet: real Safe in wallet-connected-ui mode through both Safe App and WalletConnect; not signing-capable in this run.
  • AI assistance: Codex orchestrated the Playwright run and drafted this note from the observed browser and structured results.

Artifacts

  • Primary evidence: sanitized timeout A/B results

  • Supporting evidence:

    PR d76cdd3: direct fallback preserved batching support and opened the normal TWAP form.

    PR 7821 Safe WalletConnect timeout fallback opens the supported TWAP form

    Pinned develop control 8ab088d: the same timeout skipped the fallback and produced the unsupported-wallet state.

    Develop control Safe WalletConnect timeout produces the unsupported wallet state

    Real-wallet recordings were inspected locally but not published because they include transient WalletConnect pairing UI.

How to retest

  • Start CoW Swap and open the Gnosis Chain advanced-orders USDC/GNO route.
  • Check it once as a Safe App and once by pairing the same Safe through WalletConnect.
  • For the timeout branch, hold only viem's two-parameter wallet_getCapabilities request pending; leave the direct Safe provider request untouched.
  • Expected on this PR: after about five seconds, the direct fallback succeeds, batching remains supported, and TWAP does not show the unsupported-wallet state.

Generated using the pr-qa skill from the CoW Protocol skills repo.

@fairlighteth fairlighteth self-requested a review July 10, 2026 16:16
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.

2 participants