Repository navigation
fix: hide captcha if BE is down - #7812
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Deploying swap-dev with
|
| Latest commit: |
302ed98
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3044f8b9.swap-dev-5u6.pages.dev |
| Branch Preview URL: | https://fix-hide-captcha-if-be-is-do.swap-dev-5u6.pages.dev |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Walkthrough
ChangesCaptcha Error State Handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
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/captcha/containers/CaptchaWidget.container.tsx`:
- Line 20: The CaptchaWidget.container component leaves captchaError stuck after
a failed JWT exchange, preventing Turnstile from mounting again. Update the
retry/reset flow in CaptchaWidget.container so captchaError is cleared whenever
captchaJwt is reset or a new challenge is allowed, and also ensure the
success/error handlers that trigger another attempt can reset this state. Use
the existing useState-managed captchaError and related captchaJwt reset logic as
the place to fix it.
🪄 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: 385459c7-5f0f-4216-b009-b713a32f13ee
📒 Files selected for processing (1)
apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsx
elena-zh
left a comment
There was a problem hiding this comment.
Hey @kernelwhisperer , but it still shows 'success' state when token is failed
For me it is weird. Moreover, then the question comes: why it reappears again and again on the form switching/page refresh/qupte update?
fairlighteth
left a comment
There was a problem hiding this comment.
⚠️ AI Review (Codex GPT-5, worked 5m): add rejected captcha exchange coverage
Finding: [NON-BLOCKING] Cover rejected JWT exchange behavior
- Location:
apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsx:109 - This PR changes the linked failure path by latching
captchaErrorafterexchangeTurnstileToken()rejects, hiding Turnstile and leaving no JWT. The existingCaptchaWidget.container.test.tsxcases cover disabled/enabled/stored-JWT paths, but none callonSuccessor assert the rejected exchange path. - Without a focused test, a future change can reintroduce the stale success UI from #7801 or accidentally change the intentional hide behavior while unit CI still passes.
Suggested fix
- Add a component test that mocks Turnstile enough to trigger
onSuccess, makesexchangeTurnstileTokenreject, and asserts the widget is hidden after the rejection andcaptchaJwtAtomremainsnull. - If the permanent per-mount hide is the intended product behavior, encode that in the test name so the CodeRabbit thread decision is documented in code.
Review scope and related context
- I’m not repeating the existing CodeRabbit thread about
captchaErrornever resetting; current code still behaves that way, but the author marked it intentional and CodeRabbit withdrew. - Lint, unit test, typecheck, and Agent Harness checks are green on the PR. Cypress is currently red in
swap.test.ts/swapMod.test.tswaiting for#do-trade-button; I didn’t tie that failure to this captcha diff, but it still needs resolution or rerun before merge.
🤖 Prompt for AI agents
Verify the missing test against current PR code. Add only focused coverage for the CaptchaWidget JWT-exchange rejection path.
Context:
- apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsx:109
- onSuccess awaits exchangeTurnstileToken(token); on rejection it normalizes the error, sets captchaError, logs it, and sets captchaJwtAtom to null.
- Existing apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.test.tsx tests do not invoke onSuccess or the rejected exchange path.
Expected coverage:
- Mock Turnstile so the test can trigger onSuccess.
- Mock exchangeTurnstileToken to reject.
- Assert the widget is hidden after the rejection and captchaJwtAtom remains null.
Generated using the pr-review skill from the CoW Protocol skills repo.
Deploying explorer-dev with
|
| Latest commit: |
302ed98
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6b425161.explorer-dev-dxz.pages.dev |
| Branch Preview URL: | https://fix-hide-captcha-if-be-is-do.explorer-dev-dxz.pages.dev |
There was a problem hiding this comment.
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/captcha/state/captchaErrorAtom.ts`:
- Line 3: Add a reset path for captchaErrorAtom so the Turnstile can reappear
after a retry. Update the captcha module around captchaErrorAtom and the
CaptchaWidget flow to expose a way to clear the stored Error before
re-attempting the JWT exchange, and make sure the retry path invokes that reset
instead of leaving the atom set indefinitely.
🪄 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: 3ccbe980-2f3e-4227-8d3e-aa2a22f9e975
📒 Files selected for processing (2)
apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsxapps/cowswap-frontend/src/modules/captcha/state/captchaErrorAtom.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsx
Not much we can do there, because that captcha component is controlled by cloudflare from their POV the challenge succeeded. It's the second step on our side that is failing.
|
|
Hey @kernelwhisperer , thank you, now it looks better. However, 'success' state still confuses me a bit. |
azebuado
left a comment
There was a problem hiding this comment.
After reviewing the proposal and the issues raised by Elena, I think this is a good enough compromise.
- We don't expect it to be down very often, making it an unlikely edge case. We were seeing this because backend was not properly setup.
- Hiding it should be ok when it fails because as Anuj confirmed, when it's down it just not block anything, so the fact that the captcha shows success kind of is true in either case (if I understood it correctly).
302ed98 to
ee81458
Compare
ee81458 to
6079f64
Compare

Summary
Fixes #7801 and #7768
If the our BE endpoint is down, it will simply hide the CF turnstile widget.
To Test
It's difficult to test, you need to bring the endpoint down or try it in an environment where it's not been deployed like prod.
Background
Why not a retry button?
Instead of a retry button we can do exponential backoff, why should the user click a button for us to retry.
Still, I think it's premature to optimize for this edge case. When this failure happens it will be caught by Sentry and we should react quickly to bring the endpoint back up.
Summary by CodeRabbit