8000 fix(eth-flow): fix refund tx detection by shoom3301 · Pull Request #5904 · cowprotocol/cowswap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(eth-flow): fix refund tx detection #5904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2025
Merged

fix(eth-flow): fix refund tx detection #5904

merged 2 commits into from
Jul 1, 2025

Conversation

shoom3301
Copy link
Collaborator
@shoom3301 shoom3301 commented Jun 30, 2025

Summary

Fixes #5883

I couldn't reproduce this case:
image

But I fixed it blindly, please review this commit carefuly: e0b0f54

Other cases are fixed:

image

To Test

  1. Create ETH-flow order with extremely low sell amount, set deadline to 10 minutes and minimum slippage
  2. Wait till the order gets expired
  • AR: displays "Replaced" state
  • ER: displays "ETH refunded" state with a link to transaction

See Fixes #5883

Summary by CodeRabbit

  • Refactor

    • Improved clarity and modularity of the EthFlow stepper component by reorganizing transaction state logic and simplifying control flow.
    • Enhanced type declarations for better code maintainability and explicitness.
  • Style

    • Updated function signatures to explicitly declare return types for improved code consistency.
  • Bug Fixes

    • Refined logic for handling expired orders to ensure correct status is shown only when orders are not filled.

Copy link
vercel bot commented Jun 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
cosmos ❌ Failed (Inspect) Jun 30, 2025 1:16pm
cowfi ✅ Ready (Inspect) Visit Preview Jun 30, 2025 1:16pm
explorer-dev ✅ Ready (Inspect) Visit Preview Jun 30, 2025 1:16pm
sdk-tools ✅ Ready (Inspect) Visit Preview Jun 30, 2025 1:16pm
swap-dev ✅ Ready (Inspect) Visit Preview Jun 30, 2025 1:16pm
widget-configurator ✅ Ready (Inspect) Visit Preview Jun 30, 2025 1:16pm

Copy link
Contributor
coderabbitai bot commented Jun 30, 2025

Walkthrough

The updates refactor and clarify ETH-flow order status handling in the frontend. They modularize transaction state logic, refine refund and expiration checks, and make type exports explicit. The changes aim to ensure ETH-flow orders display accurate statuses, particularly for refund and expiration scenarios, without altering core logic elsewhere.

Changes

File(s) Change Summary
.../src/common/updaters/orders/ExpiredOrdersUpdater.ts Added a trailing comma in a dependency array; no logic change.
.../src/modules/ethFlow/containers/EthFlowStepper/index.tsx Refactored ETH-flow stepper: extracted transaction state logic, clarified refund checks, improved control flow.
.../src/modules/ethFlow/pure/EthFlowStepper/index.tsx Made TxState type exportable.
.../src/modules/ethFlow/pure/EthFlowStepper/steps/Step2.tsx,
.../steps/Step3.tsx
Explicitly set return types to ReactNode, refined expiration logic to check for unfilled orders.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EthFlowStepper
    participant Order
    participant TxStore

    User->>EthFlowStepper: View ETH-flow order status
    EthFlowStepper->>Order: Fetch order details
    EthFlowStepper->>TxStore: Fetch related transactions
    EthFlowStepper->>EthFlowStepper: getCreationTxState(order, allTxs)
    EthFlowStepper->>Order: Check refundHash and status
    EthFlowStepper-->>User: Display accurate order status (Created, Refunded, Expired, etc.)
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure ETH-flow orders show correct statuses (created, executed, refunded, expired, replaced, etc.) [#5883]
Fix ETH-flow refund TX fetching and accurate status display [#5883]

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested labels

RELEASE

Suggested reviewers

  • elena-zh
  • fairlighteth

Poem

🐇
In the meadow of code, a flow refined,
Orders now show the status aligned.
Refunds and expiries, clear as day,
No more confusion along the way.
With types exported and logic neat,
ETH-flow's journey is now complete!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
(node:20770) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for url.parse() vulnerabilities.
(Use node --trace-deprecation ... to show where the warning was created)
[2/4] Fetching packages...
error nx@21.0.3: The engine "node" is incompatible with this module. Expected version "^20.19.0 || ^22.12.0". Got "24.3.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 272cebc and e0b0f54.

📒 Files selected for processing (5)
  • apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts (1 hunks)
  • apps/cowswap-frontend/src/modules/ethFlow/containers/EthFlowStepper/index.tsx (4 hunks)
  • apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/index.tsx (1 hunks)
  • apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/steps/Step2.tsx (4 hunks)
  • apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/steps/Step3.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: shoom3301
PR: cowprotocol/cowswap#5443
File: apps/cowswap-frontend/src/modules/swap/containers/ConfirmSwapModalSetup/index.tsx:71-71
Timestamp: 2025-02-20T15:59:33.749Z
Learning: The swap module in apps/cowswap-frontend/src/modules/swap/ is marked for deletion in PR #5444 as part of the swap widget unification effort.
Learnt from: shoom3301
PR: cowprotocol/cowswap#5549
File: apps/cowswap-frontend/src/modules/tradeFlow/services/safeBundleFlow/safeBundleEthFlow.ts:152-152
Timestamp: 2025-04-02T09:58:29.374Z
Learning: In the `safeBundleEthFlow` function, `account` is guaranteed to be truthy based on the type system (`PostOrderParams` defines it as a required string) and the context in which the function is called, so additional runtime checks are unnecessary.
apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts (1)
Learnt from: shoom3301
PR: cowprotocol/cowswap#5859
File: apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuotePolling.ts:76-82
Timestamp: 2025-06-23T07:03:50.760Z
Learning: In the useTradeQuotePolling hook, there are two useLayoutEffect hooks that work together: one resets the counter to 0 when the confirmation modal closes, and another automatically triggers pollQuote(false, true) whenever the counter reaches 0. This creates an intentional chain reaction for immediate quote updates.
apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/steps/Step3.tsx (3)
Learnt from: alfetopito
PR: cowprotocol/cowswap#5830
File: apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/index.tsx:1-2
Timestamp: 2025-06-16T15:58:00.268Z
Learning: JSX can be imported as a named export from React in modern React versions (React 17+). The import `import { JSX } from 'react'` is valid and does not cause compilation errors.
Learnt from: alfetopito
PR: cowprotocol/cowswap#5831
File: apps/cowswap-frontend/src/modules/application/containers/AppMenu/index.tsx:7-9
Timestamp: 2025-06-16T16:01:46.729Z
Learning: React Router v7 restructured packages - NavLink and other core routing components should be imported from 'react-router' (not 'react-router-dom'). In v7, 'react-router-dom' mainly re-exports for backward compatibility, while 'react-router' is the new preferred import path for most components.
Learnt from: fairlighteth
PR: cowprotocol/cowswap#5780
File: CONTRIBUTING.md:121-121
Timestamp: 2025-06-02T12:52:34.606Z
Learning: React 19.0.0 was released on December 5, 2024, introducing new features like Actions, Server Components, and hooks such as useActionState and useOptimistic.
apps/cowswap-frontend/src/modules/ethFlow/containers/EthFlowStepper/index.tsx (3)
Learnt from: shoom3301
PR: cowprotocol/cowswap#5549
File: apps/cowswap-frontend/src/modules/tradeFlow/services/safeBundleFlow/safeBundleEthFlow.ts:152-152
Timestamp: 2025-04-02T09:58:29.374Z
Learning: In the `safeBundleEthFlow` function, `account` is guaranteed to be truthy based on the type system (`PostOrderParams` defines it as a required string) and the context in which the function is called, so additional runtime checks are unnecessary.
Learnt from: alfetopito
PR: cowprotocol/cowswap#5830
File: apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/index.tsx:1-2
Timestamp: 2025-06-16T15:58:00.268Z
Learning: JSX can be imported as a named export from React in modern React versions (React 17+). The import `import { JSX } from 'react'` is valid and does not cause compilation errors.
Learnt from: fairlighteth
PR: cowprotocol/cowswap#5780
File: CONTRIBUTING.md:121-121
Timestamp: 2025-06-02T12:52:34.606Z
Learning: React 19.0.0 was released on December 5, 2024, introducing new features like Actions, Server Components, and hooks such as useActionState and useOptimistic.
apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/steps/Step2.tsx (4)
Learnt from: shoom3301
PR: cowprotocol/cowswap#5549
File: apps/cowswap-frontend/src/modules/tradeFlow/services/safeBundleFlow/safeBundleEthFlow.ts:152-152
Timestamp: 2025-04-02T09:58:29.374Z
Learning: In the `safeBundleEthFlow` function, `account` is guaranteed to be truthy based on the type system (`PostOrderParams` defines it as a required string) and the context in which the function is called, so additional runtime checks are unnecessary.
Learnt from: alfetopito
PR: cowprotocol/cowswap#5830
File: apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/index.tsx:1-2
Timestamp: 2025-06-16T15:58:00.268Z
Learning: JSX can be imported as a named export from React in modern React versions (React 17+). The import `import { JSX } from 'react'` is valid and does not cause compilation errors.
Learnt from: alfetopito
PR: cowprotocol/cowswap#5831
File: apps/cowswap-frontend/src/modules/application/containers/AppMenu/index.tsx:7-9
Timestamp: 2025-06-16T16:01:46.729Z
Learning: React Router v7 restructured packages - NavLink and other core routing components should be imported from 'react-router' (not 'react-router-dom'). In v7, 'react-router-dom' mainly re-exports for backward compatibility, while 'react-router' is the new preferred import path for most components.
Learnt from: alfetopito
PR: cowprotocol/cowswap#5831
File: apps/cowswap-frontend/src/modules/application/containers/AppMenu/index.tsx:7-9
Timestamp: 2025-06-16T16:01:46.729Z
Learning: In React Router v6+, NavLink can be imported directly from 'react-router' package, not just 'react-router-dom'. The package structure has evolved and the import from 'react-router' is valid for the latest versions.
🧬 Code Graph Analysis (2)
apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts (1)
apps/cowswap-frontend/src/legacy/state/orders/actions.ts (1)
  • setIsOrderRefundedBatch (237-237)
apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/steps/Step2.tsx (1)
apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/index.tsx (1)
  • EthFlowStepperProps (36-69)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Setup
  • GitHub Check: Cypress
🔇 Additional comments (18)
apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts (1)

70-70: LGTM! Good formatting practice.

Adding the trailing comma in the dependency array is a good practice that improves consistency and makes future additions easier.

apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/index.tsx (1)

19-34: LGTM! Good modularization of types.

Exporting the TxState type enables better type sharing across the ethFlow module and supports the refactoring in the container component.

apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/steps/Step3.tsx (3)

1-1: LGTM! Improved type imports.

Adding ReactNode import is necessary for the explicit return type annotation.


24-31: LGTM! Better type safety with explicit return type.

Explicitly declaring the return type as ReactNode improves type safety and makes the component contract clearer.


41-41: LGTM! Fixed logic for expired before creation detection.

The addition of !isFilled condition correctly prevents filled orders from being considered as expired before creation. This aligns with the business logic that filled orders should not be treated as failed due to expiration.

apps/cowswap-frontend/src/modules/ethFlow/pure/EthFlowStepper/steps/Step2.tsx (3)

1-1: LGTM! Improved type imports.

Adding ReactNode import is necessary for the explicit return type annotation.


13-13: LGTM! Better type safety with explicit return type.

Explicitly declaring the return type as ReactNode improves type safety and makes the component contract clearer.


40-40: LGTM! Fixed logic for expired before creation detection.

The addition of !isFilled condition correctly prevents filled orders from being considered as expired before creation. This change is consistent with the same fix in Step3.tsx and aligns with the business logic.

apps/cowswap-frontend/src/modules/ethFlow/containers/EthFlowStepper/index.tsx (10)

1-1: LGTM! Improved type imports.

Adding ReactNode import is necessary for the explicit return type annotation.


12-17: LGTM! Better type organization.

Importing TxState from the pure component and organizing the imports improves type sharing and modularity.


19-23: LGTM! Well-defined interface for creation state.

The CreationState interface provides clear typing for the extracted creation state logic, improving code organization and type safety.


30-30: LGTM! Explicit return type annotation.

Adding the explicit ReactNode return type improves type safety and makes the component contract clearer.


41-48: LGTM! Improved early return pattern.

The early return pattern makes the code more readable and reduces nesting. The logic is clear and correct.


45-46: LGTM! Clean extraction of creation state logic.

Using the extracted getCreationTxState function improves code organization and makes the main function more readable.


52-53: LGTM! Improved refund hash detection.

The refund hash computation now considers multiple sources (order.refundHash, order.apiAdditionalInfo?.ethflowData?.refundTxHash), which should improve the detection of refund transactions as mentioned in the PR objectives.


65-69: LGTM! Cleaner refund state logic.

Using the computed refundHash and setting failed: !refundHash simplifies the refund state logic. The presence of a refund hash indicates the refund was successful.


86-103: LGTM! Improved function readability with early returns.

The refactored mapOrderToEthFlowStepperState function uses early returns and cleaner control flow, making it much more readable. The logic is correct and well-structured.


105-122: LGTM! Well-structured extraction of creation state logic.

The getCreationTxState function properly extracts the complex creation transaction state logic, including handling of linked transactions and replacement types. This improves code organization and makes the logic more testable.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again 8000 .
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

hash: order.refundHash,
failed: didRefundFail(order),
hash: refundHash,
failed: !refundHash,
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 actual fix, other changes in this file is just a refactoring

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.

Thanks for addressing this issue!

@shoom3301 shoom3301 merged commit 76285e2 into develop Jul 1, 2025
13 of 15 checks passed
@shoom3301 shoom3301 deleted the fix/5883 branch July 1, 2025 09:49
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2025
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.

ETH-flow: Refunded TXs fetching is not working
3 participants
0