Skip to content

Fix Moonpay buy tracking race condition#5947

Merged
j0ntz merged 2 commits intodevelopfrom
jon/fix/buy-tracking-race-condition
Feb 19, 2026
Merged

Fix Moonpay buy tracking race condition#5947
j0ntz merged 2 commits intodevelopfrom
jon/fix/buy-tracking-race-condition

Conversation

@j0ntz
Copy link
Contributor

@j0ntz j0ntz commented Feb 17, 2026

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes

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 RampDeeplinkManager using 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 listener field in RampDeeplinkManager with a token-keyed Map. Each register() call now returns a unique token for targeted cleanup, preventing one handler from overwriting another. handleDeeplink() matches the most recently registered listener for the given providerId + 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/:id API to verify the actual transaction amounts:

  • API succeeds: Log Buy_Success with API-verified values and include both closure + API values as diagnostic properties. If they differ, also log a Buy_Tracking_Mismatch event.
  • API fails: Skip Buy_Success entirely (unverifiable) and log Buy_Tracking_Mismatch with the closure values and failure reason.

If the deeplink manager fix works correctly, Buy_Tracking_Mismatch should never appear in PostHog. If it does, we know there's another issue — but the Buy_Success data stays clean.

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

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 RampDeeplinkManager listener with a tokenized Map, updating ramp plugins and webViewUtils to store per-quote tokens and reliably unregister on close/errors.

For Moonpay buys, adds a verification step that fetches GET /v1/transactions/:id and logs Buy_Success using API-verified fiat/crypto amounts (with diagnostic fields), otherwise emits a new Buy_Tracking_Mismatch event when verification fails or values differ. Updates CHANGELOG.md accordingly.

Written by Cursor Bugbot for commit 0dec727. This will update automatically on new commits. Configure here.


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.
@j0ntz j0ntz force-pushed the jon/fix/buy-tracking-race-condition branch from 19831a7 to 6d0ff5f Compare February 19, 2026 21:22
@j0ntz j0ntz merged commit 76ed3a0 into develop Feb 19, 2026
3 checks passed
@j0ntz j0ntz deleted the jon/fix/buy-tracking-race-condition branch February 19, 2026 22:27
@j0ntz j0ntz restored the jon/fix/buy-tracking-race-condition branch February 19, 2026 22:44
j0ntz pushed a commit that referenced this pull request Feb 19, 2026
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.

3 participants

Comments