Skip to content

fix(widget): enhance error type processing#7114

Merged
shoom3301 merged 4 commits intodevelopfrom
fix/widget-types
Mar 10, 2026
Merged

fix(widget): enhance error type processing#7114
shoom3301 merged 4 commits intodevelopfrom
fix/widget-types

Conversation

@shoom3301
Copy link
Collaborator

@shoom3301 shoom3301 commented Mar 6, 2026

Summary

Fixes #7113

  1. Got rid of @web3-react/types dependency in types lib (commit)
  2. Enhanced error catching process in WidgetEthereumProvider and CowSwapWidget. error argument of catch is unknown and must be validated in runtime. (commit)

To Test

  1. Basic flows of widget

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling to ensure consistent, informative error objects across widget failures.
  • Refactor

    • Consolidated and clarified provider/event typings for the transport layer and protocol compatibility.
  • UI

    • Added a CSS hook to trade orders containers so visibility rules apply correctly to the orders table.
  • Chores

    • Removed an unused development dependency.

@shoom3301 shoom3301 self-assigned this Mar 6, 2026
@vercel
Copy link

vercel bot commented Mar 6, 2026

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

Project Deployment Actions Updated (UTC)
cowfi Ready Ready Preview Mar 10, 2026 6:49am
explorer-dev Ready Ready Preview Mar 10, 2026 6:49am
swap-dev Ready Ready Preview Mar 10, 2026 6:49am
widget-configurator Ready Ready Preview Mar 10, 2026 6:49am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored Mar 10, 2026 6:49am
sdk-tools Ignored Ignored Preview Mar 10, 2026 6:49am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Walkthrough

Consolidates and exposes typed Ethereum provider events and ProviderMessage, strengthens error handling (using robust stringification and unknown-typed callbacks), removes an unused dev dependency, and restructures EIP-6963 type definitions to avoid external dev-only imports. Several UI wrappers receive a CSS class for targeting.

Changes

Cohort / File(s) Summary
Ethereum provider (events & messaging)
libs/iframe-transport/src/iframeRpcProvider/WidgetEthereumProvider.ts
Added ProviderMessage type, exported IFrameEthereumProviderEvents and IFrameEthereumProviderEventTypes, consolidated event typings, updated sendAsync callback types to use unknown, and added stringifyError() and getUniqueId() helpers.
Type definitions (EIP-6963)
libs/types/src/eip6963-types.ts, libs/types/package.json
Removed reliance on external @web3-react/types (devDependency removed from package.json), introduced local RequestArguments and EIP6963ProviderInfo, removed EIP1193Provider alias and EIP6963AnnounceProviderEvent.
Widget error handling
libs/widget-react/src/lib/CowSwapWidget.tsx
Catch clause adjusted: caught value renamed and normalized into an Error instance when necessary before logging / setError.
UI class hook additions
apps/cowswap-frontend/src/pages/AdvancedOrders/AdvancedOrders.page.tsx, apps/cowswap-frontend/src/pages/LimitOrders/RegularLimitOrders.page.tsx, apps/cowswap-frontend/src/modules/trade/pure/TradePageLayout/index.tsx
Added className="trade-orders-table" to wrappers and updated selector usage to target .trade-orders-table for conditional visibility.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I nibble on types and tidy the trace,
Events lined up in a neat little place,
Errors turned friendly with strings in embrace,
A hop, a patch, and a cleaner code-space! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The CSS class additions to TradePageLayout and order pages appear unrelated to error type processing and issue #7113, suggesting scope creep. Clarify or remove CSS class changes (trade-orders-table) if not part of the error handling fix, as they appear to be UI improvements unrelated to #7113.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main focus of the changes: enhancing error type processing in the widget, which is the central theme across multiple files.
Description check ✅ Passed The description covers the main objectives with issue reference and commit links, but lacks detailed testing steps and expected outcomes as specified in the template.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #7113: validates caught errors before use, removes @web3-react/types dependency, and applies fixes to all specified files.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/widget-types

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

callback(null, result)
} catch (error) {
callback(error, null)
callback(stringifyError(error), null)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only actual change in this file, other changes are just eslint fix result

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.

🧹 Nitpick comments (3)
libs/types/src/eip6963-types.ts (2)

27-30: Consider exporting RequestArguments for public API consumers.

RequestArguments is used in the public EIP1193Provider type (line 6), but the interface itself is not exported. Consumers who need to construct or type-check request arguments won't have access to this type.

Proposed fix
-interface RequestArguments {
+export interface RequestArguments {
   readonly method: string
   readonly params?: readonly unknown[] | object
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/types/src/eip6963-types.ts` around lines 27 - 30, RequestArguments is
referenced by the public EIP1193Provider type but is not exported; update the
declaration of the RequestArguments interface to be exported so downstream
consumers can import and use it (i.e., change the interface declaration to
export the RequestArguments symbol so EIP1193Provider and callers have access to
the type).

20-25: Note: EIP6963ProviderInfo is duplicated in libs/iframe-transport/src/types.ts.

This interface has an identical definition in libs/iframe-transport/src/types.ts (lines 70-75). Consider consolidating these definitions to avoid drift, either by having iframe-transport import from @cowprotocol/types or by extracting to a shared location.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/types/src/eip6963-types.ts` around lines 20 - 25, The
EIP6963ProviderInfo interface is duplicated; remove the duplicate by choosing a
single source of truth: keep the definition in the types package
(EIP6963ProviderInfo in libs/types) and update the other location to
import/re-export it (replace the inline interface in iframe-transport with an
import of EIP6963ProviderInfo), or move the interface to a shared module and
have both packages import that module; ensure you update exports so consumers
still get EIP6963ProviderInfo and run type checks to confirm no breaking
changes.
libs/iframe-transport/src/iframeRpcProvider/WidgetEthereumProvider.ts (1)

489-501: Simplify stringifyError to avoid redundant type assertion.

Line 493 uses (error as Error).message which violates the coding guideline against using type casts when stronger typing is available. The logic can be streamlined using optional chaining.

Proposed simplification
 function stringifyError(error: unknown): string | null {
   if (!error) return null
   if (typeof error === 'string') return error
   if (error instanceof Error) return error.message
-  if ((error as Error).message) return (error as Error).message
+
+  // Handle duck-typed error objects with a message property
+  if (typeof error === 'object' && 'message' in error && typeof (error as { message: unknown }).message === 'string') {
+    return (error as { message: string }).message
+  }

   try {
     return JSON.stringify(error)
   } catch {
     const errorMessage = 'Unknown WidgetEthereumProvider error'
     console.error(errorMessage, error)
     return errorMessage
   }
 }

Alternatively, a simpler approach using optional chaining with a type guard:

Alternative using type narrowing
 function stringifyError(error: unknown): string | null {
   if (!error) return null
   if (typeof error === 'string') return error
   if (error instanceof Error) return error.message
-  if ((error as Error).message) return (error as Error).message
+
+  // Handle duck-typed error objects
+  const maybeMessage = (error as Record<string, unknown>)?.message
+  if (typeof maybeMessage === 'string') return maybeMessage

   try {
     return JSON.stringify(error)
   } catch {
     const errorMessage = 'Unknown WidgetEthereumProvider error'
     console.error(errorMessage, error)
     return errorMessage
   }
 }

As per coding guidelines: "Use NEVER with any type in TypeScript; prefer unknown or stronger types."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/iframe-transport/src/iframeRpcProvider/WidgetEthereumProvider.ts` around
lines 489 - 501, The stringifyError function currently uses a redundant type
assertion "(error as Error).message"; replace that with an optional-chained
access to message (e.g., error?.message) or a proper typeof/type guard so you
avoid casting unknown to Error, keep the existing checks for falsy and string,
and retain the JSON.stringify fallback and catch block; update the function
implementation around stringifyError to use optional chaining or a
type-narrowing check instead of the explicit cast.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@libs/iframe-transport/src/iframeRpcProvider/WidgetEthereumProvider.ts`:
- Around line 489-501: The stringifyError function currently uses a redundant
type assertion "(error as Error).message"; replace that with an optional-chained
access to message (e.g., error?.message) or a proper typeof/type guard so you
avoid casting unknown to Error, keep the existing checks for falsy and string,
and retain the JSON.stringify fallback and catch block; update the function
implementation around stringifyError to use optional chaining or a
type-narrowing check instead of the explicit cast.

In `@libs/types/src/eip6963-types.ts`:
- Around line 27-30: RequestArguments is referenced by the public
EIP1193Provider type but is not exported; update the declaration of the
RequestArguments interface to be exported so downstream consumers can import and
use it (i.e., change the interface declaration to export the RequestArguments
symbol so EIP1193Provider and callers have access to the type).
- Around line 20-25: The EIP6963ProviderInfo interface is duplicated; remove the
duplicate by choosing a single source of truth: keep the definition in the types
package (EIP6963ProviderInfo in libs/types) and update the other location to
import/re-export it (replace the inline interface in iframe-transport with an
import of EIP6963ProviderInfo), or move the interface to a shared module and
have both packages import that module; ensure you update exports so consumers
still get EIP6963ProviderInfo and run type checks to confirm no breaking
changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bc1d8ec9-734a-4fab-8c30-498931f8c191

📥 Commits

Reviewing files that changed from the base of the PR and between 043d67b and e8cab53.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • libs/iframe-transport/src/iframeRpcProvider/WidgetEthereumProvider.ts
  • libs/types/package.json
  • libs/types/src/eip6963-types.ts
  • libs/widget-react/src/lib/CowSwapWidget.tsx
💤 Files with no reviewable changes (1)
  • libs/types/package.json

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 @shoom3301 , idk why, but TWAP widget is not displayed when I hide orders table. Could you please check why?

Image

it is working fine on develop

Image

Copy link
Contributor

@limitofzero limitofzero left a comment

Choose a reason for hiding this comment

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

work as expected

@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​rebass@​4.0.151001007080100
Added@​types/​react@​19.1.31001008094100

View full report

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.

🧹 Nitpick comments (1)
apps/cowswap-frontend/src/modules/trade/pure/TradePageLayout/index.tsx (1)

35-37: Hoist the shared class name into a constant.

trade-orders-table is now a contract between this selector and multiple pages. Exporting a single constant for it would remove the typo risk and keep future renames atomic.

♻️ Proposed refactor
+export const TRADE_ORDERS_TABLE_CLASS = 'trade-orders-table' as const
+
 export const PageWrapper = styled.div<{
   isUnlocked: boolean
   secondaryOnLeft?: boolean
   maxWidth?: string
   hideOrdersTable?: boolean
 }>`
@@
-  > .trade-orders-table {
+  > .${TRADE_ORDERS_TABLE_CLASS} {
     display: ${({ isUnlocked }) => (!isUnlocked ? 'none' : '')};
   }
 `

Then reuse TRADE_ORDERS_TABLE_CLASS from the pages instead of repeating the literal. As per coding guidelines, "Hoist repeating strings/tooltips into constants colocated with the feature".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/cowswap-frontend/src/modules/trade/pure/TradePageLayout/index.tsx`
around lines 35 - 37, Create and export a single constant like
TRADE_ORDERS_TABLE_CLASS to hold the shared classname (replace the literal
".trade-orders-table" in the styled selector within TradePageLayout/index.tsx),
update the styled selector to reference that constant (ensuring it still renders
as a class selector where needed), and then import and use
TRADE_ORDERS_TABLE_CLASS from the other pages/components that currently repeat
the literal so renames are atomic and typo-prone strings are eliminated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/cowswap-frontend/src/modules/trade/pure/TradePageLayout/index.tsx`:
- Around line 35-37: Create and export a single constant like
TRADE_ORDERS_TABLE_CLASS to hold the shared classname (replace the literal
".trade-orders-table" in the styled selector within TradePageLayout/index.tsx),
update the styled selector to reference that constant (ensuring it still renders
as a class selector where needed), and then import and use
TRADE_ORDERS_TABLE_CLASS from the other pages/components that currently repeat
the literal so renames are atomic and typo-prone strings are eliminated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 24d5df43-97d7-4b84-8f3e-5b4f0d801483

📥 Commits

Reviewing files that changed from the base of the PR and between e8cab53 and 65a4b8b.

📒 Files selected for processing (3)
  • apps/cowswap-frontend/src/modules/trade/pure/TradePageLayout/index.tsx
  • apps/cowswap-frontend/src/pages/AdvancedOrders/AdvancedOrders.page.tsx
  • apps/cowswap-frontend/src/pages/LimitOrders/RegularLimitOrders.page.tsx

@shoom3301
Copy link
Collaborator Author

@elena-zh thanks! Fixed.
p.s. the issue is not from this PR, you can see it on prod in incognito mode (the issue is related to unlock screen displaying)

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.

thank you!

@shoom3301 shoom3301 merged commit 8ebb7cd into develop Mar 10, 2026
16 checks passed
@shoom3301 shoom3301 deleted the fix/widget-types branch March 10, 2026 13:03
@github-actions github-actions bot locked and limited conversation to collaborators Mar 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple type errors in shipped code

3 participants