-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat(core-backend): add AccountActivity and Websocket for TokenBalancesController #36819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
971905c
to
f27a63e
Compare
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Warning MetaMask internal reviewing guidelines:
|
0492257
to
7cf06e9
Compare
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [7cf06e9]
UI Startup Metrics (1208 ± 69 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
7cf06e9
to
db89d40
Compare
❌ test-e2e-chrome-api-specs failed. View the html report here. |
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [db89d40]
UI Startup Metrics (1239 ± 81 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
db89d40
to
8652c12
Compare
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [8652c12]
UI Startup Metrics (1277 ± 89 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
8652c12
to
d964c60
Compare
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [d964c60]
UI Startup Metrics (1235 ± 65 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
d964c60
to
fc523c2
Compare
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [fc523c2]
UI Startup Metrics (1230 ± 57 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
f912185
to
c4f1f2d
Compare
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
✨ Files requiring CODEOWNER review ✨🧩 @MetaMask/extension-devs (5 files, +60 -0)
📜 @MetaMask/policy-reviewers (5 files, +60 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 🔗 @MetaMask/supply-chain (5 files, +60 -0)
|
02b6ca7
to
495360b
Compare
This PR is unrelated to updateStakedBalances, the updateStakedBalances will work as it is today. I will let the ongoing work about moving AccountTracker to core to normalize all balances |
✨ Files requiring CODEOWNER review ✨🧩 @MetaMask/extension-devs (5 files, +60 -0)
📜 @MetaMask/policy-reviewers (5 files, +60 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 🔗 @MetaMask/supply-chain (5 files, +60 -0)
|
495360b
to
a93caf4
Compare
✨ Files requiring CODEOWNER review ✨🧩 @MetaMask/extension-devs (5 files, +60 -0)
📜 @MetaMask/policy-reviewers (5 files, +60 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 🔗 @MetaMask/supply-chain (5 files, +60 -0)
|
a93caf4
to
8d19837
Compare
✨ Files requiring CODEOWNER review ✨🧩 @MetaMask/extension-devs (5 files, +60 -0)
📜 @MetaMask/policy-reviewers (5 files, +60 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 🔗 @MetaMask/supply-chain (5 files, +60 -0)
|
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [8d19837]
UI Startup Metrics (1240 ± 78 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a comment about the cursor review you should check out.,
if (balance) { | ||
state.accountsByChainId[chainId][address].balance = toHex(balance); | ||
state.accountsByChainId[chainId][lowercaseAddress].balance = | ||
toHex(balance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this something you need to fix?
this.controllerMessenger.call('BackendWebSocketService:connect'); | ||
} else { | ||
this.controllerMessenger.call('BackendWebSocketService:disconnect'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems fine
|
✨ Files requiring CODEOWNER review ✨🧩 @MetaMask/extension-devs (5 files, +60 -0)
📜 @MetaMask/policy-reviewers (5 files, +60 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 🔗 @MetaMask/supply-chain (5 files, +60 -0)
|
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [c66db6b]
UI Startup Metrics (1267 ± 66 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
For @MetaMask/policy-reviewers, apparently this PR requires approval from policy reviewers again. Both packages are internal metamask packages and added permission are required for the functionality. Policy changes looks good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added packages are internal metamask packages and added permission are required for the functionality. Policy changes looks good to me.
Description
This PR integrates the Backend WebSocket Service and Account Activity Service from
@metamask/core-backend
into MetaMask Extension. These services enable real-time account activity monitoring and balance updates via WebSocket connections.backendWebSocketConnection
remote feature flag is enabled. Without the feature flag, the WebSocket service will not connect, and the extension will continue to work exactly as before.What is the reason for the change?
To prepare the extension for real-time account activity updates from the MetaMask backend platform, reducing reliance on polling and enabling faster balance updates and transaction notifications.
What is the improvement/solution?
Integrated BackendWebSocketService: Provides authenticated WebSocket connectivity to the MetaMask backend with automatic reconnection, authentication flow integration, and feature flag control.
Integrated AccountActivityService: Subscribes to account activity channels and receives real-time transaction and balance updates.
TokenBalancesController Integration: The controller automatically adjusts polling intervals based on WebSocket availability:
Package Updates: Updated to use local
@metamask/core-backend
and@metamask/assets-controllers
packages from the core monorepo for development.Architecture
BackendWebSocketService (Transport Layer)
↓
AccountActivityService (Data Layer)
↓
TokenBalancesController & AccountTrackerController, TokenDetectionController (Business Logic, and internal state Management)
References
For detailed architecture, implementation details, and API documentation, see:
Changelog
CHANGELOG entry: Integrated Backend WebSocket Service and Account Activity Service for real-time balance updates (feature-flagged)
Related issues
Fixes: [Add issue number]
Manual testing steps
Since this feature is behind a feature flag, testing requires enabling the flag:
Testing with Feature Flag Disabled (Default)
Testing with Feature Flag Enabled (Development)
.metamaskrc
:[BackendWebSocketService]
Screenshots/Recordings
Before
N/A - This is a new feature integration
After
Pre-merge author checklist
Pre-merge reviewer checklist
Technical Details
Files Added
app/scripts/controller-init/core-backend/backend-websocket-service-init.ts
- Service initialization with feature flag and auth integrationapp/scripts/controller-init/core-backend/account-activity-service-init.ts
- Account activity service setupapp/scripts/controller-init/messengers/core-backend/backend-websocket-service-messenger.ts
- Messenger with auth actions/eventsapp/scripts/controller-init/messengers/core-backend/account-activity-service-messenger.ts
- Account activity messengerFiles Modified
package.json
- Added@metamask/core-backend
and switched@metamask/assets-controllers
to local file referencebuilds.yml
- Environment variables for WebSocket URL (already present)controller-list.ts
- Added service typesmessengers/index.ts
- Registered service messengersmetamask-controller.js
- Integrated services into controller initializationmessengers/token-balances-controller-messenger.ts
- Added actions/events for WebSocket integrationyarn.lock
- Updated dependenciesIntegration Points
TokenBalancesController (in core) automatically:
AccountActivityService:statusChanged
for dynamic polling adjustmentAccountActivityService:balanceUpdated
for real-time balance updatesTokenDetectionController:addDetectedTokensViaWs
to auto-import new tokensBackendWebSocketService handles:
backendWebSocketConnection
remote feature flag)AuthenticationController:getBearerToken
AccountActivityService provides: