Skip to content

Restore last connected wallet instead of first authorized one#1

Merged
realfishsam merged 1 commit into
mainfrom
fix/restore-last-connected-wallet
Jun 11, 2026
Merged

Restore last connected wallet instead of first authorized one#1
realfishsam merged 1 commit into
mainfrom
fix/restore-last-connected-wallet

Conversation

@realfishsam

Copy link
Copy Markdown
Contributor

Summary

The wallet panel's "Disconnect" looked broken: after disconnecting MetaMask and connecting Phantom, depositing would still pop MetaMask to sign.

Root cause is in the silent-restore effect in PmxtProvider. On mount it iterates detectWallets() in a hardcoded SUPPORTED_WALLETS order (metamask, phantom) and picks whichever is already authorized for the site. MetaMask's site authorization is not revoked when the widget "disconnects" (only the extension can do that), so on any reload or remount after switching to Phantom, MetaMask wins the restore race and connectedWallet is force-set back to metamask. The deposit flow then uses MetaMask's provider.

Fix: persist the last connected walletId in localStorage on connect, clear it on disconnect, and try it first during restore. Falls back to the old detection order when no preference is remembered (first visit, storage cleared, last wallet uninstalled).

Reproduction

  1. With both MetaMask and Phantom installed, connect MetaMask in the wallet panel.
  2. Click Disconnect.
  3. Click "Connect Phantom"; approve in Phantom.
  4. Reload the page.
  5. Click Deposit → expected: Phantom prompts. Actual (before fix): MetaMask prompts.

Test plan

  • Connect MM, disconnect, connect Phantom, reload, deposit → Phantom signs.
  • Connect MM, reload, deposit → MM signs (preference preserved).
  • Disconnect (any wallet), reload → still disconnected (DISCONNECTED_KEY behavior unchanged).
  • Uninstall last-used wallet between sessions → restore falls back to the other installed wallet.
  • SSR / privacy mode (localStorage throws) → does not crash; restore degrades to detection order.

The silent-restore effect iterated detectWallets() in a fixed
SUPPORTED_WALLETS order (metamask, phantom) and picked whichever was
already authorized for the site. After a user disconnected MetaMask
and then connected Phantom, a reload or navigation would silently snap
the connection back to MetaMask — because MetaMask's site
authorization is still active (only the extension can revoke it). The
deposit flow then opened MetaMask to sign, even though the UI showed
Phantom.

Persist the last connected walletId in localStorage on connect, clear
it on disconnect, and try it first during restore. Falls back to the
old detection order when no preference is remembered.
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
pmxt-widgets Ready Ready Preview, Comment Jun 11, 2026 10:30pm

Request Review

@realfishsam
realfishsam merged commit d09c793 into main Jun 11, 2026
2 checks passed
@realfishsam
realfishsam deleted the fix/restore-last-connected-wallet branch June 11, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant