Skip to content

feat: normalize bridge hardware type#8503

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

feat: normalize bridge hardware type#8503
GeorgeGkas wants to merge 6 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 analytics event schemas and the bridge/swap event construction paths, so downstream consumers and tracking validation could break if any property expectations diverge. Runtime risk is limited but includes account lookup/metadata edge cases in failure tracking.

Overview
Adds normalized hardware wallet branding to unified bridge/swap analytics by introducing AccountHardwareType and emitting account_hardware_type (Ledger/Trezor/QR Hardware/Lattice/null) alongside a derived is_hardware_wallet across events.

Refactors metrics property building to centralize this derivation in BridgeController/metrics utils (including widening PageViewed controller-derived properties), updates BridgeStatusController failure handling to optionally look up the submitting account (without calling getAccountByAddress when from is missing), and adjusts exports, types, and snapshots/tests accordingly.

Reviewed by Cursor Bugbot for commit 2f5ed17. 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
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
SteP-n-s
SteP-n-s previously approved these changes Apr 17, 2026
Comment thread packages/bridge-status-controller/src/bridge-status-controller.ts
SteP-n-s
SteP-n-s previously approved these changes Apr 20, 2026
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 1af1228. Configure here.

Comment thread packages/bridge-controller/src/utils/metrics/properties.ts
SteP-n-s
SteP-n-s previously approved these changes Apr 20, 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.

2 participants