Skip to content

fix(trade): preserve URL recipient when chainId initializes#7465

Open
tenderdeve wants to merge 1 commit into
cowprotocol:developfrom
tenderdeve:fix/7323-prefill-recipient-from-url
Open

fix(trade): preserve URL recipient when chainId initializes#7465
tenderdeve wants to merge 1 commit into
cowprotocol:developfrom
tenderdeve:fix/7323-prefill-recipient-from-url

Conversation

@tenderdeve
Copy link
Copy Markdown
Contributor

When a URL contains a ?recipient= parameter (e.g. /#/1/swap/WETH/COW?recipient=vitalik.eth), the recipient field was cleared on page load before the user could interact with it.

The chain-change effect in useResetRecipient fires as the wallet's chainId initializes from undefined to its real value, unconditionally calling onChangeRecipient(null) and wiping the URL-provided recipient before it could stick.
Adding hasRecipientInUrl as a guard prevents the reset when recipient was provided via URL.

Fixes #7323

Summary

Fixes #7323

Added !hasRecipientInUrl condition to the chain-change reset effect in useResetRecipient so URL-provided recipients are preserved on page load.

To Test

  1. Open CoW Swap with a recipient in the URL: /#/1/swap/WETH/COW?recipient=vitalik.eth
  • Recipient field should be pre-filled with vitalik.eth on page load
  • Recipient field should not be cleared after wallet connects and chainId initializes
  1. Open CoW Swap without a recipient in the URL
  • Recipient field should remain empty on page load (existing behaviour unchanged)
  1. Switch chains while a recipient is set manually (not via URL)
  • Recipient field should still be cleared on chain switch (existing behaviour unchanged)

Background

useResetRecipient has a dedicated effect that resets the recipient whenever chainId changes. On initial page load, the wallet's chainId transitions from undefined to its real value, which triggers this effect. At that point hasRecipientInUrl is already true (parsed from the URL atom), but the effect had no guard for it — so onChangeRecipient(null) fired unconditionally, clearing the field.

The fix adds hasRecipientInUrl to both the condition and the dependency array of that specific effect. The initial-load effect already had this guard; only the chain-change effect was missing it

When a user navigates to a URL containing ?recipient=vitalik.eth,
the recipient was being cleared on page load because the chain
change effect in useResetRecipient fired as the wallet's chainId
went from undefined to its initial value.

Add hasRecipientInUrl as a guard so the chain change reset is skipped
when the recipient was explicitly provided in the URL.

Fixes cowprotocol#7323
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Warning

Rate limit exceeded

@tenderdeve has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 37 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2d40a9f1-1ba8-46f9-8411-c478a9aac0ef

📥 Commits

Reviewing files that changed from the base of the PR and between 5e55c4b and 618c26c.

📒 Files selected for processing (1)
  • apps/cowswap-frontend/src/modules/trade/hooks/useResetRecipient.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

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

Project Deployment Actions Updated (UTC)
swap-dev Ready Ready Preview May 7, 2026 9:06am

Request Review

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.

Hey @tenderdeve , thank you for the contribution!
Unfortunately, this does not fix the issue:

Image

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.

Custom link: recipient is not prefilled into the form

2 participants