Skip to content

Add input currency mode to Unified SwapBridge metrics#8909

Open
bfullam wants to merge 3 commits into
mainfrom
swaps-add-input-currency-mode-metrics
Open

Add input currency mode to Unified SwapBridge metrics#8909
bfullam wants to merge 3 commits into
mainfrom
swaps-add-input-currency-mode-metrics

Conversation

@bfullam
Copy link
Copy Markdown
Contributor

@bfullam bfullam commented May 27, 2026

Summary

  • Added input_currency_mode to Unified SwapBridge quote, submit, and completion metrics.
  • Introduced shared InputCurrencyMode enum in @metamask/bridge-controller with fiat and crypto values.
  • Threaded the mode through existing quote/submit context, persisted it on bridge history, and defaulted missing values to crypto for backward compatibility.
  • Expanded event types so clients can pass input_currency_mode without local casts.

Testing

  • Updated existing snapshots for bridge-controller and bridge-status-controller metrics payloads.
  • Ran targeted lint checks for the touched controller and metrics files.
  • Ran focused Jest suites for @metamask/bridge-controller and @metamask/bridge-status-controller with coverage disabled.

Note

Low Risk
Analytics-only field additions with safe defaults; no changes to swap/bridge execution or auth.

Overview
Adds input_currency_mode (fiat | crypto) to Unified SwapBridge analytics so clients can report whether the user entered the source amount in fiat or crypto.

@metamask/bridge-controller introduces shared InputCurrencyMode, exports it, and extends metrics types (including InputChanged with input_currency_mode). BridgeController reads the mode from client event context and attaches it to Quotes Requested and Quotes Received, defaulting to crypto when omitted.

@metamask/bridge-status-controller threads the mode from quote context through submit/intent flows, persists it on bridge history, includes it on pre-submit metrics via getPreConfirmationPropertiesFromQuote, and emits it on Completed from stored history (again defaulting to crypto).

Test snapshots and changelogs are updated for the new payload field.

Reviewed by Cursor Bugbot for commit b3fdad6. Bugbot is set up for automated code reviews on this repo. Configure here.

@bfullam bfullam requested a review from a team as a code owner May 27, 2026 13:28
@bfullam bfullam temporarily deployed to default-branch May 27, 2026 13:28 — with GitHub Actions Inactive
@bfullam
Copy link
Copy Markdown
Contributor Author

bfullam commented May 27, 2026

@metamaskbot publish-preview

@bfullam bfullam requested a review from a team as a code owner May 27, 2026 13:35
@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.4.0-preview-781882851
@metamask-previews/accounts-controller@38.1.1-preview-781882851
@metamask-previews/address-book-controller@7.1.2-preview-781882851
@metamask-previews/ai-controllers@0.6.3-preview-781882851
@metamask-previews/analytics-controller@1.1.0-preview-781882851
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-781882851
@metamask-previews/announcement-controller@8.1.0-preview-781882851
@metamask-previews/app-metadata-controller@2.0.1-preview-781882851
@metamask-previews/approval-controller@9.0.1-preview-781882851
@metamask-previews/assets-controller@8.0.1-preview-781882851
@metamask-previews/assets-controllers@108.1.0-preview-781882851
@metamask-previews/authenticated-user-storage@2.0.0-preview-781882851
@metamask-previews/base-controller@9.1.0-preview-781882851
@metamask-previews/base-data-service@0.1.3-preview-781882851
@metamask-previews/bridge-controller@73.0.1-preview-781882851
@metamask-previews/bridge-status-controller@71.2.0-preview-781882851
@metamask-previews/build-utils@3.0.4-preview-781882851
@metamask-previews/chain-agnostic-permission@1.6.1-preview-781882851
@metamask-previews/chomp-api-service@3.1.0-preview-781882851
@metamask-previews/claims-controller@0.5.1-preview-781882851
@metamask-previews/client-controller@1.0.1-preview-781882851
@metamask-previews/compliance-controller@2.1.1-preview-781882851
@metamask-previews/composable-controller@12.0.1-preview-781882851
@metamask-previews/config-registry-controller@0.3.1-preview-781882851
@metamask-previews/connectivity-controller@0.2.0-preview-781882851
@metamask-previews/controller-utils@12.1.0-preview-781882851
@metamask-previews/core-backend@6.3.0-preview-781882851
@metamask-previews/delegation-controller@3.0.0-preview-781882851
@metamask-previews/earn-controller@12.2.0-preview-781882851
@metamask-previews/eip-5792-middleware@3.0.4-preview-781882851
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-781882851
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-781882851
@metamask-previews/ens-controller@19.1.3-preview-781882851
@metamask-previews/eth-block-tracker@15.0.1-preview-781882851
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-781882851
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-781882851
@metamask-previews/foundryup@1.0.1-preview-781882851
@metamask-previews/gas-fee-controller@26.2.2-preview-781882851
@metamask-previews/gator-permissions-controller@4.2.0-preview-781882851
@metamask-previews/geolocation-controller@0.1.3-preview-781882851
@metamask-previews/json-rpc-engine@10.5.0-preview-781882851
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-781882851
@metamask-previews/keyring-controller@25.5.0-preview-781882851
@metamask-previews/logging-controller@8.0.2-preview-781882851
@metamask-previews/message-manager@14.1.2-preview-781882851
@metamask-previews/messenger@1.2.0-preview-781882851
@metamask-previews/messenger-cli@0.2.0-preview-781882851
@metamask-previews/money-account-balance-service@1.0.2-preview-781882851
@metamask-previews/money-account-controller@0.3.0-preview-781882851
@metamask-previews/money-account-upgrade-controller@2.0.2-preview-781882851
@metamask-previews/multichain-account-service@10.0.0-preview-781882851
@metamask-previews/multichain-api-middleware@3.1.2-preview-781882851
@metamask-previews/multichain-network-controller@3.1.2-preview-781882851
@metamask-previews/multichain-transactions-controller@7.1.0-preview-781882851
@metamask-previews/name-controller@9.1.2-preview-781882851
@metamask-previews/network-controller@32.0.0-preview-781882851
@metamask-previews/network-enablement-controller@5.2.0-preview-781882851
@metamask-previews/notification-services-controller@24.1.1-preview-781882851
@metamask-previews/passkey-controller@2.0.1-preview-781882851
@metamask-previews/permission-controller@13.1.1-preview-781882851
@metamask-previews/permission-log-controller@5.1.0-preview-781882851
@metamask-previews/perps-controller@6.3.0-preview-781882851
@metamask-previews/phishing-controller@17.2.0-preview-781882851
@metamask-previews/polling-controller@16.0.6-preview-781882851
@metamask-previews/preferences-controller@23.1.0-preview-781882851
@metamask-previews/profile-metrics-controller@3.1.4-preview-781882851
@metamask-previews/profile-sync-controller@28.1.0-preview-781882851
@metamask-previews/ramps-controller@14.0.0-preview-781882851
@metamask-previews/rate-limit-controller@7.0.1-preview-781882851
@metamask-previews/react-data-query@0.2.1-preview-781882851
@metamask-previews/remote-feature-flag-controller@4.2.1-preview-781882851
@metamask-previews/sample-controllers@5.0.1-preview-781882851
@metamask-previews/seedless-onboarding-controller@9.1.0-preview-781882851
@metamask-previews/selected-network-controller@26.1.3-preview-781882851
@metamask-previews/shield-controller@5.1.2-preview-781882851
@metamask-previews/signature-controller@39.2.2-preview-781882851
@metamask-previews/snap-account-service@0.2.0-preview-781882851
@metamask-previews/social-controllers@2.2.1-preview-781882851
@metamask-previews/storage-service@1.0.1-preview-781882851
@metamask-previews/subscription-controller@6.1.3-preview-781882851
@metamask-previews/transaction-controller@66.0.0-preview-781882851
@metamask-previews/transaction-pay-controller@22.7.0-preview-781882851
@metamask-previews/user-operation-controller@41.2.2-preview-781882851
@metamask-previews/wallet@0.0.0-preview-781882851

Copy link
Copy Markdown

@cursor cursor Bot left a 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.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a3d4476. Configure here.

...(eventName === UnifiedSwapBridgeEventName.Completed && {
input_currency_mode:
historyItem.inputCurrencyMode ?? InputCurrencyMode.CRYPTO,
}),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-submission Failed events inconsistently omit input_currency_mode

Medium Severity

The input_currency_mode field is read from the history item only when eventName === Completed, but not when it's Failed. Pre-submission Failed events receive it via preConfirmationProperties, but post-submission Failed events (from polling status checks or #onTransactionFailed) go through #trackUnifiedSwapBridgeEvent without it. This creates inconsistent analytics data for the same event type — some Failed events include input_currency_mode and others don't, depending on when the failure occurred, even though inputCurrencyMode is persisted on the history item and available.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a3d4476. Configure here.

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.

1 participant