feat: add support for accountChanged for Tron network
Description
After Solana, add the support for Tron account Change.
In parallel, a new PR is in progress to factorize this code and make it generic for all non-EVM chains: Solana, Tron, Bitcoin, etc.
Changelog
CHANGELOG entry: Add Tron Account Change detection support for multichain Api (#23639)
Related issues
Fixes:
Manual testing steps
You could try with our Tron test app here: https://metamask.github.io/test-dapp-tron/latest/
Feature: User connection
Scenario: User connection on Mainnet
Given the network Shasta Network is selected by default
When user user select mainnet network, and then select MetaMask Wallet
Then MetaMask connection screen popup
Scenario: User connection on Shasta (2 step connection)
Given the network Shasta Network is selected by default
When user user select MetaMask Wallet
Then MetaMask connection screen popup to connect. Once connected an other connection screen to accept to connect to Shasta.
Scenario: User reload the page
Given the user is already connected to a specific network and account
When user user reload the app
Then the app should re-connect to Metamask automatically with the right account and network.
Feature: Chain Change
Scenario: Ask permission for new chain
Given the network Shasta Network is the only one user accepted
When user user switch to mainnet
Then MetaMask connection screen popup to accept. Once connected the chain mainnet is selected.
Scenario: Do not ask permission for chain
Given the network Shasta Network AND mainnet are allowed
When user user switch to mainnet
Then the chain mainnet is selected.
Feature: Account Change
Scenario: User do not change if select a not allowed account
Given the user allow only one account
When user user switch to an other account
Then nothing happens in the app.
Scenario: User change if select an allowed account
Given the user allow only 2 accounts
When user user switch to the second account
Then nothing the selected address change in the app
Feature: Disconnect
Scenario: User disconnects from MM
Given the user is connected
When user remove the session from MM
Then the app disconnects
Screenshots/Recordings
Before
After
Pre-merge author checklist
- [ ] I’ve followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards.
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using JSDoc format if applicable
- [ ] I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
Pre-merge reviewer checklist
- [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
[!NOTE] Adds Tron
accountChangedsupport to the multichain provider and generalizes account-change notifications across non-EVM scopes.
- Core (BackgroundBridge)
- Add Tron support for
accountChangednotifications: subscribe to permission/selection changes, tracklastSelectedTronAccountAddress, and emit via_notifyMultichainAccountChange(app/core/BackgroundBridge/BackgroundBridge.js).- Send initial
accountChangedon connection for Tron and Solana when enabled.- Generalize notifier: replace
_notifySolanaAccountChangewith_notifyMultichainAccountChange(scope); renamegetNonEvmAccountFromSelectedAccountGrouptogetSolanaAccountFromSelectedAccountGroup.- Register/unregister Tron-related listeners alongside existing Solana ones.
- Tests
- Add comprehensive Tron unit tests for permission changes, selected account changes, and selected account group handling; prioritize selected-group account over scope accounts (
app/core/BackgroundBridge/BackgroundBridge.test.js).- Minor test expectation fixes (use
not.toHaveBeenCalled).- Dependencies
- Bump
@metamask/chain-agnostic-permissionto^1.3.0and update multichain packages:@metamask/multichain-api-client@^0.10.1,@metamask/[email protected](lockfile updated).Written by Cursor Bugbot for commit 346ca3ae8ade1ff4488f0013765a909390ff9182. This will update automatically on new commits. Configure here.
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.
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
| Diff | Package | Supply Chain Security |
Vulnerability | Quality | Maintenance | License |
|---|---|---|---|---|---|---|
| npm/@metamask/multichain-api-middleware@1.2.4 ⏵ 1.2.5 | ||||||
| npm/@metamask/chain-agnostic-permission@1.2.2 ⏵ 1.3.0 | ||||||
| npm/@metamask/multichain-api-client@0.7.0 ⏵ 0.10.1 |
All alerts resolved. Learn more about Socket for GitHub.
This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.
Ignoring alerts on:
npm/@metamask/[email protected]
@SocketSecurity ignore npm/@metamask/[email protected]
Hey @EdouardBougon, been trying to test this but I'm unable to select mainnet. I only see Tron in the wallet but when I try to connect to Shasta it seems to work. Is there any additional configuration required that I might be missing? Video below, using physical Android device.
https://github.com/user-attachments/assets/593f8b20-5c40-4213-b37b-4220c489ad7b
Can't seem to get the app to register the account change, as the address never changes. Again, not sure if I'm missing something here. Clip below:
https://github.com/user-attachments/assets/b021fc22-e216-499b-afbb-816203e16b30
🔍 Smart E2E Test Selection
- Selected E2E tags: SmokeCore, SmokeAccounts, SmokeMultiChainPermissions, SmokeNetworkExpansion, SmokeWalletPlatform, SmokeMultiChainAPI
- Risk Level: high
- AI Confidence: 85%
click to see 🤖 AI reasoning details
This PR introduces Tron blockchain support in the BackgroundBridge, which is a critical core component that handles communication between the app and dApps (browser, SDK, WalletConnect). The changes include:
-
BackgroundBridge.js (Critical - in app/core/): Adds Tron account change notification handlers mirroring existing Solana functionality. This affects how the app communicates account changes to connected dApps across multiple chains.
-
Package updates: Updates to @metamask/chain-agnostic-permission (1.2.2→1.3.0), @metamask/multichain-api-client (0.7.0→0.10.1), and @metamask/multichain-api-middleware (1.2.4→1.2.5). These packages are used extensively across permission-related components (AccountConnect, PermissionApproval, MultichainAccountConnect, etc.).
The BackgroundBridge is imported by 14 files including BrowserTab, SDKConnect, WalletConnect, and DeeplinkProtocol - all critical paths for dApp interactions.
Selected tags rationale:
- SmokeCore: BackgroundBridge is core infrastructure for app-dApp communication
- SmokeAccounts: Changes affect account selection and notification across chains
- SmokeMultiChainPermissions: Permission handling is directly affected by package updates and new Tron scope handling
- SmokeNetworkExpansion: Adding Tron support is network expansion functionality
- SmokeWalletPlatform: Core wallet functionality for account/network switching
- SmokeMultiChainAPI: Multichain API packages are updated and the changes add new multichain notification capabilities
The Tron code is feature-flagged (ONLY_INCLUDE_IF(tron)), but the package updates and refactoring of _notifySolanaAccountChange to _notifyMultichainAccountChange affect existing functionality.
Quality Gate passed
Issues
1 New issue
0 Accepted issues
Measures
0 Security Hotspots
89.0% Coverage on New Code
0.0% Duplication on New Code