Skip to content

feat: normalize bridge hardware type#8503

Open
GeorgeGkas wants to merge 3 commits intomainfrom
swaps-3894
Open

feat: normalize bridge hardware type#8503
GeorgeGkas wants to merge 3 commits intomainfrom
swaps-3894

Conversation

@GeorgeGkas
Copy link
Copy Markdown
Contributor

@GeorgeGkas GeorgeGkas commented Apr 17, 2026

Explanation

Previously, the bridge analytics pipeline tracked hardware wallet participation as a simple boolean (is_hardware_wallet: true/false). This was sufficient to answer "did a hardware wallet user complete this swap?" but not "which hardware wallet did they use?" — a signal needed for device-specific debugging and segmentation.

This PR adds an account_hardware_type field (typed as 'Ledger' | 'Trezor' | 'QR Hardware' | 'Lattice' | null) alongside the existing is_hardware_wallet boolean across all bridge/swap analytics events. The two fields are kept in sync: is_hardware_wallet is now always derived as accountHardwareType !== null, so they can never disagree.

Key implementation details:

  • getAccountHardwareType() — new helper in bridge-controller/src/utils/metrics/properties.ts that maps raw keyring type strings (e.g. 'Ledger Hardware') to the analytics enum values. isHardwareWallet is updated to delegate to it.
  • RequestMetadata gains account_hardware_type, and EventPropertiesFromControllerState[PageViewed] is widened to include the full request-metadata subset (hardware type, slippage, swap type) since that event was previously missing those fields.
  • BridgeController#getRequestMetadata now resolves account_hardware_type and is_hardware_wallet in one place and propagates them to all events that call it, replacing the scattered inline isHardwareWallet(this.#getMultichainSelectedAccount()) calls. The lookup is guarded by a walletAddress check to prevent #getMultichainSelectedAccount from throwing when the quote request hasn't been populated yet (which would silently suppress event tracking via the catch block).
  • getEVMTxPropertiesFromTransactionMeta gains an optional account parameter so the transactionFailed subscription can pass the resolved account for hardware-type enrichment.
  • #onTransactionFailed was extracted from the constructor into a private class field to comply with the no-messenger-calls-in-constructor lint rule. It also gains an upfront featureId guard so the AccountsController:getAccountByAddress call is never made for PERPS transactions (where tracking is intentionally skipped), and uses txParams?.from optional chaining to handle fixtures where txParams is absent.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Touches metrics payload construction and transactionFailed handling in BridgeController/BridgeStatusController, so mistakes could break analytics schema or suppress/alter event emission, but no funds movement logic is changed.

Overview
Adds normalized hardware-wallet attribution to unified swap/bridge analytics by introducing AccountHardwareType and emitting a new account_hardware_type field (Ledger/Trezor/QR Hardware/Lattice/null) across events, with is_hardware_wallet now derived from account_hardware_type !== null.

Centralizes hardware-type derivation via new getAccountHardwareType (and updates isHardwareWallet to use it), expands RequestMetadata and PageViewed controller-derived properties to include the hardware/slippage/swap-type metadata, and updates BridgeStatusController pre-confirmation and transaction-failure tracking to optionally look up the submitting account and include account_hardware_type (including refactoring the failure subscription into #onTransactionFailed with an early featureId skip). Test snapshots and unit tests are updated accordingly, and bridge-controller exports the new type/helper.

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

@GeorgeGkas GeorgeGkas requested a review from a team as a code owner April 17, 2026 10:14
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 193096f. Configure here.

Comment thread packages/bridge-controller/src/utils/metrics/types.ts
@GeorgeGkas GeorgeGkas requested a review from a team as a code owner April 17, 2026 10:28
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.

2 participants