fix(trade): preserve URL recipient when chainId initializes#7465
fix(trade): preserve URL recipient when chainId initializes#7465tenderdeve wants to merge 1 commit into
Conversation
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
|
@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
elena-zh
left a comment
There was a problem hiding this comment.
Hey @tenderdeve , thank you for the contribution!
Unfortunately, this does not fix the issue:
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
useResetRecipientfires as the wallet'schainIdinitializes fromundefinedto its real value, unconditionally callingonChangeRecipient(null)and wiping the URL-provided recipient before it could stick.Adding
hasRecipientInUrlas a guard prevents the reset when recipient was provided via URL.Fixes #7323
Summary
Fixes #7323
Added
!hasRecipientInUrlcondition to the chain-change reset effect inuseResetRecipientso URL-provided recipients are preserved on page load.To Test
/#/1/swap/WETH/COW?recipient=vitalik.ethvitalik.ethon page loadchainIdinitializesBackground
useResetRecipienthas a dedicated effect that resets the recipient wheneverchainIdchanges. On initial page load, the wallet'schainIdtransitions fromundefinedto its real value, which triggers this effect. At that pointhasRecipientInUrlis alreadytrue(parsed from the URL atom), but the effect had no guard for it — soonChangeRecipient(null)fired unconditionally, clearing the field.The fix adds
hasRecipientInUrlto 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