metamask-mobile icon indicating copy to clipboard operation
metamask-mobile copied to clipboard

feat: add support for accountChanged for Tron network

Open EdouardBougon opened this issue 3 weeks ago • 6 comments

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

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 accountChanged support to the multichain provider and generalizes account-change notifications across non-EVM scopes.

  • Core (BackgroundBridge)
    • Add Tron support for accountChanged notifications: subscribe to permission/selection changes, track lastSelectedTronAccountAddress, and emit via _notifyMultichainAccountChange (app/core/BackgroundBridge/BackgroundBridge.js).
    • Send initial accountChanged on connection for Tron and Solana when enabled.
    • Generalize notifier: replace _notifySolanaAccountChange with _notifyMultichainAccountChange(scope); rename getNonEvmAccountFromSelectedAccountGroup to getSolanaAccountFromSelectedAccountGroup.
    • 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-permission to ^1.3.0 and 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.

EdouardBougon avatar Dec 03 '25 22:12 EdouardBougon

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.

github-actions[bot] avatar Dec 03 '25 22:12 github-actions[bot]

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​metamask/​multichain-api-middleware@​1.2.4 ⏵ 1.2.5991007695100
Updatednpm/​@​metamask/​chain-agnostic-permission@​1.2.2 ⏵ 1.3.0100 +11007895 +1100
Updatednpm/​@​metamask/​multichain-api-client@​0.7.0 ⏵ 0.10.110010010096 -4100

View full report

socket-security[bot] avatar Dec 05 '25 17:12 socket-security[bot]

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:

View full report

socket-security[bot] avatar Dec 05 '25 17:12 socket-security[bot]

@SocketSecurity ignore npm/@metamask/[email protected]

baptiste-marchand avatar Dec 10 '25 08:12 baptiste-marchand

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

wenfix avatar Dec 15 '25 14:12 wenfix

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

wenfix avatar Dec 15 '25 17:12 wenfix

🔍 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:

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

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

View GitHub Actions results

github-actions[bot] avatar Dec 16 '25 14:12 github-actions[bot]