Fix Moonpay buy tracking race condition#5947
Merged
Conversation
swansontec
approved these changes
Feb 19, 2026
Replace single-listener deeplink handler with a token-keyed Map so concurrent ramp quotes no longer clobber each other's callbacks. register() now returns a token; all callers (banxa, simplex, revolut, paybis, moonpay) capture it and pass it to unregister() in closeQuote. openExternalWebView returns the token and cleans up on launch failure. openWebView tracks and unregisters by token on dismiss/error.
After a successful buy deeplink callback, fetch the Moonpay transaction from /v1/transactions/:id and compute the total fiat charge as baseCurrencyAmount + feeAmount + networkFeeAmount + extraFeeAmount. Log Buy_Success with API-verified amounts. If the closure-captured values differ from the API values, also log Buy_Tracking_Mismatch with both sets for diagnostics. If the API query itself fails, log Buy_Tracking_Mismatch instead of Buy_Success.
19831a7 to
6d0ff5f
Compare
j0ntz
pushed a commit
that referenced
this pull request
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.