Skip to content

feat: using websockets events for transaction polling#7822

Merged
jpuri merged 21 commits intomainfrom
transaction_polling_improvements
Feb 8, 2026
Merged

feat: using websockets events for transaction polling#7822
jpuri merged 21 commits intomainfrom
transaction_polling_improvements

Conversation

@jpuri
Copy link
Contributor

@jpuri jpuri commented Feb 3, 2026

Explanation

Using event AccountActivityService:transactionUpdated to improve transaction polling.

References

Fixes https://github.com/MetaMask/MetaMask-planning/issues/6948

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
Changes core transaction polling behavior by introducing a new event-driven trigger and additional filtering logic (chain/account/hash/status), which could affect how quickly transactions update or how often polling runs if the event stream is noisy or mismatched.

Overview
Adds event-driven pending transaction polling by having TransactionPoller subscribe to AccountActivityService:transactionUpdated and trigger an immediate poll when an update matches the current chainId, is a terminal status (confirmed/dropped/failed), is from the selected account, and corresponds to a currently pending tx hash.

Refactors CAIP-2 chain-id conversion into a shared caip2ToHex utility (used by both TransactionPoller and IncomingTransactionHelper) and adds unit coverage for the new websocket trigger behavior and CAIP parsing; changelog is updated to announce the new polling mode.

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

@jpuri jpuri requested a review from a team as a code owner February 3, 2026 15:00
@jpuri jpuri force-pushed the transaction_polling_improvements branch from 70ae62d to 41a0567 Compare February 3, 2026 15:22
@jpuri jpuri requested a review from a team as a code owner February 3, 2026 15:22
@jpuri jpuri enabled auto-merge February 3, 2026 15:25
@jpuri jpuri force-pushed the transaction_polling_improvements branch from e9cf4eb to 45493b2 Compare February 3, 2026 15:59
Copy link

@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.

@jpuri jpuri requested a review from matthewwalsh0 February 4, 2026 14:39
@jpuri jpuri requested a review from matthewwalsh0 February 6, 2026 08:35
}

if (
transaction.status !== 'confirmed' &&
Copy link
Member

Choose a reason for hiding this comment

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

Minor, could do a ![...].includes(transaction.status)?

return;
}

const isPendingTransaction = this.#pendingTransactions?.some(
Copy link
Member

@matthewwalsh0 matthewwalsh0 Feb 8, 2026

Choose a reason for hiding this comment

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

Minor, this is great, but does it negate the need for the selected account check above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is good point, I can update in a coming PR

@jpuri jpuri added this pull request to the merge queue Feb 8, 2026
Merged via the queue into main with commit e803934 Feb 8, 2026
302 checks passed
@jpuri jpuri deleted the transaction_polling_improvements branch February 8, 2026 14:48
@jpuri jpuri mentioned this pull request Feb 9, 2026
4 tasks
github-merge-queue bot pushed a commit that referenced this pull request Feb 9, 2026
## Explanation

Small transaction poller cleanup PR. Discussion here:
#7822 (comment)

## References
* Related to MetaMask/MetaMask-planning#6948

## Checklist

- [X] I've updated the test suite for new or updated code as appropriate
- [X] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [X] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [X] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes when websocket-driven polling is triggered, which could
increase polling or cause unintended refreshes if unrelated transaction
update events match pending hashes.
> 
> **Overview**
> `TransactionPoller` no longer filters
`AccountActivityService:transactionUpdated` events by chain ID (CAIP-2
conversion) or by the selected account address; it now triggers a poll
for any `confirmed`/`dropped`/`failed` event whose `transaction.id`
matches a pending transaction `hash`.
> 
> Tests were updated to reflect the relaxed filtering (simpler messenger
mock, removed non-matching chain/account cases, and adjusted
expectations/descriptions).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
cd0baa2. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments