Skip to content

Viem Migration - use short message when canceling transaction#7473

Open
brunota20 wants to merge 3 commits into
developfrom
bruno/cow-933-shorten-error-rejection-message-for-recover-funds
Open

Viem Migration - use short message when canceling transaction#7473
brunota20 wants to merge 3 commits into
developfrom
bruno/cow-933-shorten-error-rejection-message-for-recover-funds

Conversation

@brunota20
Copy link
Copy Markdown
Collaborator

@brunota20 brunota20 commented May 8, 2026

Summary

Shortens the error rejection message shown in the "Recover Funds" error modal. Previously, rejecting the wallet signature displayed the full verbose viem
error: "User rejected the request. Details: User rejected the request. Version: viem@2.47.1". Now it shows just "User rejected the request."

Uses isRejectRequestProviderError() from @cowprotocol/common-utils — the same pattern already used in TWAP and swap error handling. For non-rejection
errors, prefers viem's shortMessage over the full message.

https://www.notion.so/cownation/Shorten-error-rejection-message-for-recover-funds-35a8da5f04ca80edbbb9e346fd381cdd?v=2fc8da5f04ca81ada4ca000c320d51ef&source=copy_link

To Test

  1. Open CoW Swap and top up any of your proxy addresses
  2. Open the address details and start recovering funds
  3. Reject the order signing in the wallet
  • Error modal should show only "User rejected the request." without the redundant "Details: ..." and "Version: ..." suffix
  • Other (non-rejection) errors should still display a meaningful message

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messaging for rejected fund recovery requests to clearly distinguish user rejections from other errors. Users will now see a localized "User rejected the request" message when declining transaction confirmations, providing better clarity during the recovery funds process.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

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

Project Deployment Actions Updated (UTC)
cowfi Ready Ready Preview May 11, 2026 10:44am
explorer-dev Ready Ready Preview May 11, 2026 10:44am
storybook Error Error May 11, 2026 10:44am
swap-dev Ready Ready Preview May 11, 2026 10:44am
widget-configurator Ready Ready Preview May 11, 2026 10:44am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored May 11, 2026 10:44am
sdk-tools Ignored Ignored Preview May 11, 2026 10:44am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Walkthrough

The PR enhances error handling in useRecoverFundsCallback by detecting provider-rejection errors and displaying a localized user-facing message. An import for isRejectRequestProviderError enables error classification; catch-block logic now checks for rejections and falls back gracefully through multiple error-message properties; a translation entry provides the localized rejection message.

Changes

Provider Rejection Error Handling

Layer / File(s) Summary
Error Detection Import
apps/cowswap-frontend/src/modules/accountProxy/hooks/useRecoverFundsCallback.ts
isRejectRequestProviderError imported from @cowprotocol/common-utils.
Error Handler Update
apps/cowswap-frontend/src/modules/accountProxy/hooks/useRecoverFundsCallback.ts
Catch block distinguishes user-rejected requests via isRejectRequestProviderError(e) and sets a localized message; other errors use e.shortMessage with fallbacks to e.message then e.toString().
Translation Entry
apps/cowswap-frontend/src/locales/en-US.po
New .po entry for the English localization of "User rejected the request.".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through error flows,
With graceful fallbacks, how it goes—
Rejections now are caught with care,
Localized messages fill the air! 🐰✨

🚥 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
Title check ✅ Passed The title clearly describes the main change: using short message when canceling a transaction in the context of viem migration.
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.
Description check ✅ Passed The pull request description includes a summary, testing instructions with checkboxes, and a reference link. It aligns well with the template structure and provides clear context.

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

✨ 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 bruno/cow-933-shorten-error-rejection-message-for-recover-funds

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.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 8, 2026

Deploying swap-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 498b672
Status:🚫  Build failed.

View logs

Copy link
Copy Markdown
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

🤖 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.

Inline comments:
In
`@apps/cowswap-frontend/src/modules/accountProxy/hooks/useRecoverFundsCallback.ts`:
- Around line 35-39: In useRecoverFundsCallback's catch block, avoid directly
reading e.shortMessage/e.message because caught value may be non-object; update
the handler (around isRejectRequestProviderError, handleSetError) to first check
typeof e === 'object' && e !== null (and optionally 'in' checks for
shortMessage/message) and then extract message = (e && (e as any).shortMessage)
|| (e && (e as any).message) || String(e); keep the existing branch for
isRejectRequestProviderError(e) and call handleSetError(message) using this safe
extraction so non-object throws don't cause a secondary crash.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 210b6b9e-aee3-41db-bf04-e2fe96d8c83b

📥 Commits

Reviewing files that changed from the base of the PR and between d2d7dab and 498b672.

📒 Files selected for processing (2)
  • apps/cowswap-frontend/src/locales/en-US.po
  • apps/cowswap-frontend/src/modules/accountProxy/hooks/useRecoverFundsCallback.ts

Comment on lines +35 to +39
if (isRejectRequestProviderError(e)) {
handleSetError(t`User rejected the request.`)
} else {
const message = e.shortMessage || e.message || e.toString()
handleSetError(message)
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether catch variables are treated strictly and locate similar unsafe patterns.

echo "== tsconfig useUnknownInCatchVariables =="
fd -i '^tsconfig.*\.json$' | xargs -I{} sh -c 'echo "--- {} ---"; cat "{}" | jq -r ".compilerOptions.useUnknownInCatchVariables // \"not-set\""' 2>/dev/null

echo
echo "== Potentially unsafe property reads in catch blocks =="
rg -nP --type=ts --type=tsx -C2 'catch\s*\(([^)]*)\)\s*\{[\s\S]{0,300}\b\1\.(shortMessage|message)\b'

Repository: cowprotocol/cowswap

Length of output: 4384


🏁 Script executed:

cat -n apps/cowswap-frontend/src/modules/accountProxy/hooks/useRecoverFundsCallback.ts | head -50

Repository: cowprotocol/cowswap

Length of output: 1779


🏁 Script executed:

# Search for catch blocks that access .message or .shortMessage without narrowing
rg --type=ts --type=ts -C3 'catch\s*\([^)]*\)' | grep -A3 -E '\.(shortMessage|message|toString)\(' | head -60

Repository: cowprotocol/cowswap

Length of output: 2376


🏁 Script executed:

# Look for how .message is accessed in catch blocks across the repo
rg -C2 'catch\s*\(\s*(\w+)\s*\)' --type=ts --type=ts | rg -B2 -A2 '\1\.(message|shortMessage)' | head -80

Repository: cowprotocol/cowswap

Length of output: 257


🏁 Script executed:

# Search for patterns accessing error.message or error.shortMessage in catch blocks
rg 'catch\s*\([^)]*\)' -A5 --type=ts --type=ts | rg -B3 '\.(message|shortMessage)' | head -100

Repository: cowprotocol/cowswap

Length of output: 5958


🏁 Script executed:

# Check how isRejectRequestProviderError is defined to understand what it does
fd -i 'isRejectRequestProviderError' -t f | head -5 | xargs -I {} sh -c 'echo "=== {} ==="; head -30 "{}"'

Repository: cowprotocol/cowswap

Length of output: 45


🏁 Script executed:

# Search for isRejectRequestProviderError definition
rg 'isRejectRequestProviderError' --type=ts --type=ts -B2 -A10 | head -80

Repository: cowprotocol/cowswap

Length of output: 8233


🏁 Script executed:

# Find where getProviderErrorMessage is defined
rg 'export.*getProviderErrorMessage' --type=ts --type=ts -A10 | head -50

Repository: cowprotocol/cowswap

Length of output: 790


🏁 Script executed:

# Check if getProviderErrorMessage is imported/available in the useRecoverFundsCallback file
head -50 apps/cowswap-frontend/src/modules/accountProxy/hooks/useRecoverFundsCallback.ts | grep -i provider

Repository: cowprotocol/cowswap

Length of output: 181


Guard catch error before reading shortMessage/message to avoid secondary crash.

Line 38 accesses e.shortMessage || e.message without narrowing the catch variable, which will crash if a non-object value is thrown (since useUnknownInCatchVariables is not enabled in tsconfig). This breaks error handling itself.

Suggested fix
+type ErrorWithMessages = {
+  shortMessage?: string
+  message?: string
+}
+
+function getReadableErrorMessage(error: unknown): string {
+  if (typeof error === 'object' && error !== null) {
+    const candidate = error as ErrorWithMessages
+    if (candidate.shortMessage) return candidate.shortMessage
+    if (candidate.message) return candidate.message
+  }
+  return String(error)
+}
+
       if (isRejectRequestProviderError(e)) {
         handleSetError(t`User rejected the request.`)
       } else {
-        const message = e.shortMessage || e.message || e.toString()
+        const message = getReadableErrorMessage(e)
         handleSetError(message)
       }
🤖 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
`@apps/cowswap-frontend/src/modules/accountProxy/hooks/useRecoverFundsCallback.ts`
around lines 35 - 39, In useRecoverFundsCallback's catch block, avoid directly
reading e.shortMessage/e.message because caught value may be non-object; update
the handler (around isRejectRequestProviderError, handleSetError) to first check
typeof e === 'object' && e !== null (and optionally 'in' checks for
shortMessage/message) and then extract message = (e && (e as any).shortMessage)
|| (e && (e as any).message) || String(e); keep the existing branch for
isRejectRequestProviderError(e) and call handleSetError(message) using this safe
extraction so non-object throws don't cause a secondary crash.

@lgahdl
Copy link
Copy Markdown
Collaborator

lgahdl commented May 8, 2026

something broke on the cowfi vercel deployment

@elena-zh
Copy link
Copy Markdown
Contributor

Hey @brunota20 , could you please link a notion task of the issue you're fixing to the PR?

Copy link
Copy Markdown
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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants