-
Notifications
You must be signed in to change notification settings - Fork 279
Fix Moonpay buy tracking race condition #5930
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba11f8e5ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ba11f8e to
4a1d17d
Compare
4a1d17d to
b8494fe
Compare
b8494fe to
d905ce7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Replace the single-listener slot in RampDeeplinkManager with a token-keyed Map. Previously, each register() call silently overwrote the previous handler, causing stale closure-captured values to be used when a delayed deeplink arrived after the user initiated a new quote. Now each registration returns a unique token for targeted cleanup, and handleDeeplink matches the most recently registered listener for the given providerId + direction. Update all callers (webViewUtils, moonpay, revolut, paybis) to capture and pass the token for unregistration.
When the Moonpay buy deeplink handler fires, query the Moonpay transactions API to fetch the actual transaction amounts and use those as the source of truth for Buy_Success tracking. If the API query succeeds, log Buy_Success with API values and include both closure and API values as diagnostic properties. If closure values differ from API values, also log a separate Buy_Tracking_Mismatch event. If the API query fails, skip Buy_Success entirely (values are unverifiable) and log Buy_Tracking_Mismatch with the closure values and the failure reason. This serves as both a correctness guarantee for PostHog data and a diagnostic signal — if Buy_Tracking_Mismatch events appear after the deeplink manager fix, it indicates an additional unknown issue.
d905ce7 to
0dec727
Compare
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
None
Description
Fixes the P1 Moonpay Buy_Success PostHog tracking bug where incorrect values were intermittently reported. The root cause was identified as the
RampDeeplinkManagerusing a single-listener slot that got silently overwritten when a new quote was initiated before the previous transaction's deeplink arrived. This root cause is not confirmed, these changes are a theory, with handling and canary reporting to ensure we at least don't further pollute our tracking with inflated buy volume and report if the regression persists.Commit 1: Fix deeplink handler overwrite race condition
Replace the single
listenerfield inRampDeeplinkManagerwith a token-keyedMap. Eachregister()call now returns a unique token for targeted cleanup, preventing one handler from overwriting another.handleDeeplink()matches the most recently registered listener for the givenproviderId+direction.Updates all callers (
webViewUtils,moonpayRampPlugin,revolutRampPlugin,paybisRampPlugin) to use the token-based API.Commit 2: Add Moonpay buy tracking verification via transactions API
When the Moonpay buy deeplink fires, query Moonpay's
GET /v1/transactions/:idAPI to verify the actual transaction amounts:Buy_Successwith API-verified values and include both closure + API values as diagnostic properties. If they differ, also log aBuy_Tracking_Mismatchevent.Buy_Successentirely (unverifiable) and logBuy_Tracking_Mismatchwith the closure values and failure reason.If the deeplink manager fix works correctly,
Buy_Tracking_Mismatchshould never appear in PostHog. If it does, we know there's another issue — but theBuy_Successdata stays clean.Requirements
If you have made any visual changes to the GUI. Make sure you have:
No visual changes in this PR.
Note
Medium Risk
Touches shared deeplink/webview flow across multiple ramp providers and changes analytics emission behavior for Moonpay, so regressions could impact ramp completion handling or tracking accuracy.
Overview
Prevents ramp deeplink callbacks from being silently overwritten by replacing the single
RampDeeplinkManagerlistener with a tokenizedMap, updating ramp plugins andwebViewUtilsto store per-quote tokens and reliably unregister on close/errors.For Moonpay buys, adds a verification step that fetches
GET /v1/transactions/:idand logsBuy_Successusing API-verified fiat/crypto amounts (with diagnostic fields), otherwise emits a newBuy_Tracking_Mismatchevent when verification fails or values differ. UpdatesCHANGELOG.mdaccordingly.Written by Cursor Bugbot for commit 0dec727. This will update automatically on new commits. Configure here.