Skip to content

fix: ensure wallet switching after disconnect works for TON/TRON - #5547

Merged
0xmkh merged 3 commits into
mainfrom
fix/tron-ton-disconnect-switching
Feb 18, 2026
Merged

fix: ensure wallet switching after disconnect works for TON/TRON#5547
0xmkh merged 3 commits into
mainfrom
fix/tron-ton-disconnect-switching

Conversation

@enesozturk

@enesozturk enesozturk commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the disconnect issue for TON and TRON adapters when multi-account feature is enabled. After disconnecting an active wallet, the UI now explicitly switches to the first available remaining wallet, ensuring consistent behavior across all adapters.

Problem

When a user disconnects an active wallet with other wallets connected:

  • EVM, Solana, Bitcoin: Works correctly - automatically switches to another wallet
  • TON, TRON: UI doesn't update - the disconnected wallet remains shown as active

Root Cause

All adapters (Solana, Bitcoin, TON, TRON) call emitFirstAvailableConnection() after disconnect, which emits an accountChanged event. However, for TON/TRON adapters, this event doesn't consistently trigger the UI state update in the profile wallets view.

Solution

Added explicit wallet switching logic in handleDisconnect that:

  1. Captures the list of connections before disconnecting
  2. Disconnects the wallet normally
  3. If the disconnected wallet was active AND other wallets exist:
    • Filters remaining connections (excluding the disconnected one)
    • Explicitly calls handleSwitchWallet with the first remaining wallet
    • Ensures UI reflects the correct active wallet

This approach works for all adapters (EVM, Solana, Bitcoin, TON, TRON) and provides consistent behavior.

Changes

  • packages/scaffold-ui/src/views/w3m-profile-wallets-view/index.ts: Updated handleDisconnect method to explicitly switch wallets after disconnecting an active wallet

Test Plan

  1. Connect multiple TRON wallets (e.g., TronLink + another wallet)
  2. Disconnect the active wallet
  3. Verify that the UI automatically switches to show the next available wallet
  4. Repeat for TON adapter
  5. Verify EVM, Solana, and Bitcoin adapters still work correctly

🤖 Generated with Claude Code

Closes APKT-4457

When disconnecting an active wallet with multi-account feature enabled,
explicitly switch to the first available remaining wallet. This ensures
consistent behavior across all adapters (EVM, Solana, Bitcoin, TON, TRON).

The issue was that while adapters emit 'accountChanged' after disconnect,
the event doesn't always trigger the UI update properly for TON/TRON.
By explicitly calling handleSwitchWallet, we ensure the active wallet
is updated correctly in all cases.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Feb 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
appkit-demo Ready Ready Preview, Comment Feb 17, 2026 3:10pm
appkit-gallery Ready Ready Preview, Comment Feb 17, 2026 3:10pm
appkit-headless-sample-app Ready Ready Preview, Comment Feb 17, 2026 3:10pm
appkit-laboratory Ready Ready Preview, Comment Feb 17, 2026 3:10pm
9 Skipped Deployments
Project Deployment Actions Updated (UTC)
appkit-basic-example Ignored Ignored Feb 17, 2026 3:10pm
appkit-basic-sign-client-example Ignored Ignored Feb 17, 2026 3:10pm
appkit-basic-up-example Ignored Ignored Feb 17, 2026 3:10pm
appkit-ethers5-bera Ignored Ignored Feb 17, 2026 3:10pm
appkit-nansen-demo Ignored Ignored Feb 17, 2026 3:10pm
appkit-wagmi-cdn-example Ignored Ignored Feb 17, 2026 3:10pm
ethereum-provider-wagmi-example Ignored Ignored Feb 17, 2026 3:10pm
next-wagmi-solana-bitcoin-example Ignored Ignored Feb 17, 2026 3:10pm
vue-wagmi-example Ignored Ignored Feb 17, 2026 3:10pm

Request Review

@changeset-bot

changeset-bot Bot commented Feb 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d32a92a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Visual Regression Test Results ✅ Passed

⚠️ 15 visual change(s) detected

Chromatic Build: https://www.chromatic.com/build?appId=6493191bf4b10fed8ca7353f&number=775
Storybook Preview: https://6493191bf4b10fed8ca7353f-aawnqccart.chromatic.com/

👉 Please review the visual changes in Chromatic and accept or reject them.

…hing

Root cause: TON/TRON connectors didn't expose a 'provider' property, causing
the AppKit client's accountChanged handler to skip syncConnectedWalletInfo().

When emitFirstAvailableConnection() emits accountChanged after disconnect,
the handler checks 'if (connector?.provider)' before calling:
  - syncProvider()
  - syncConnectedWalletInfo()  // Updates UI with wallet info!

Since TON/TRON connectors had no provider property, this block never ran,
leaving the UI with stale wallet info after disconnect.

Solution: Add provider getter that returns self, allowing the connectors
to satisfy the optional provider property in the Connector type definition.

This fix eliminates the need for explicit wallet switching workarounds in
the UI layer, as the proper events now trigger the correct state updates.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Size Check

All bundles are within size limits

📊 View detailed bundle sizes

> @reown/appkit-monorepo@1.7.1 size /home/runner/work/appkit/appkit


> size-limit

@reown/appkit - Main Entry
Size limit:   80 kB
Size:         75.61 kB with all dependencies, minified and gzipped
Loading time: 1.5 s    on slow 3G
Running time: 3.4 s    on Snapdragon 410
Total time:   4.9 s
@reown/appkit/react
Size limit:   235 kB
Size:         233.81 kB with all dependencies, minified and gzipped
Loading time: 4.6 s     on slow 3G
Running time: 7.6 s     on Snapdragon 410
Total time:   12.1 s
@reown/appkit/vue
Size limit:   80 kB
Size:         75.61 kB with all dependencies, minified and gzipped
Loading time: 1.5 s    on slow 3G
Running time: 2 s      on Snapdragon 410
Total time:   3.4 s
@reown/appkit-scaffold-ui
Size limit:   220 kB
Size:         213.71 kB with all dependencies, minified and gzipped
Loading time: 4.2 s     on slow 3G
Running time: 3.4 s     on Snapdragon 410
Total time:   7.5 s
@reown/appkit-ui
Size limit:   500 kB
Size:         13.16 kB with all dependencies, minified and gzipped
Loading time: 258 ms   on slow 3G
Running time: 265 ms   on Snapdragon 410
Total time:   522 ms

@enesozturk

Copy link
Copy Markdown
Contributor Author

Root Cause Analysis Update

I've identified and fixed the actual root cause! The issue is that TON/TRON connectors don't expose a provider property.

The Issue Chain:

  1. Connector Type includes optional provider:
export type Connector = {
  provider?: Provider | W3mFrameProvider | UniversalProvider
}
  1. TON/TRON Connectors were missing this property ❌

  2. AppKit accountChanged Handler checks for provider:

if (connector?.provider) {  // FALSE for TON/TRON\!
  this.syncProvider({...})
  this.syncConnectedWalletInfo(chainNamespace)  // NEVER CALLED\!
}
  1. syncConnectedWalletInfo updates UI with wallet info - it was never called for TON/TRON!

The Fix:

Added provider getter to TON/TRON connectors:

public get provider(): TronConnector {
  return this
}

This ensures the accountChanged event handler properly updates the UI when switching wallets after disconnect, just like EVM/Solana/Bitcoin adapters.

@github-actions

github-actions Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 78.65% 39601 / 50345
🔵 Statements 78.65% 39601 / 50345
🔵 Functions 76.34% 4251 / 5568
🔵 Branches 86.69% 9623 / 11100
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/adapters/ton/src/connectors/TonConnectConnector.ts 52.48% 65% 46.15% 52.48% 31-32, 43-44, 51-52, 55-69, 77-86, 90-147, 151-152, 155-156, 182-183, 185-186, 211-214, 243-244, 249-250, 256-257, 261-262
Generated in workflow #16900 for commit d32a92a by the Vitest Coverage Report Action

Comment thread packages/scaffold-ui/src/views/w3m-profile-wallets-view/index.ts Outdated

@enesozturk enesozturk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the explicit wallet switching logic from handleDisconnect as it's
now redundant. The root cause fix (adding provider property to TON/TRON
connectors) ensures that adapters properly emit accountChanged events,
which trigger syncConnectedWalletInfo() and update the UI automatically.

This follows the proper architectural pattern:
  Adapter → emit('accountChanged') → syncConnectedWalletInfo() → UI update

Addresses feedback from @0xmkh: switching should be handled at the adapter
level via event emission, not manually in the UI layer.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@enesozturk

Copy link
Copy Markdown
Contributor Author

✅ Agreed and fixed! Removed the manual switching logic in commit d32a92a.

Now relying entirely on adapter-level event handling:

  • Adapters emit accountChanged with proper provider property
  • AppKit client calls syncConnectedWalletInfo() automatically
  • UI updates through the event flow, not manual switching

The handleDisconnect method is now back to its simple form - just disconnect and show success message. All wallet switching is handled by the adapter layer via events. 🎯

@enesozturk
enesozturk added this pull request to the merge queue Feb 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 17, 2026
@enesozturk
enesozturk added this pull request to the merge queue Feb 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 17, 2026
@enesozturk
enesozturk added this pull request to the merge queue Feb 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 17, 2026
@enesozturk
enesozturk added this pull request to the merge queue Feb 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 17, 2026
@enesozturk
enesozturk added this pull request to the merge queue Feb 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 17, 2026
@enesozturk
enesozturk added this pull request to the merge queue Feb 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 17, 2026
@enesozturk
enesozturk added this pull request to the merge queue Feb 18, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Feb 18, 2026
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 18, 2026
@enesozturk
enesozturk added this pull request to the merge queue Feb 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 18, 2026
@0xmkh
0xmkh merged commit 4fe0a64 into main Feb 18, 2026
97 of 102 checks passed
@0xmkh
0xmkh deleted the fix/tron-ton-disconnect-switching branch February 18, 2026 14:21
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants