From 33f3b9d337f9d1f8dcb65a6fde8187b99b41fa6e Mon Sep 17 00:00:00 2001 From: martbost Date: Wed, 21 Oct 2026 06:25:23 -0500 Subject: [PATCH] Wallet: EIP-6963 discovery; with more than one wallet installed the account picker and disconnect no longer assume window.ethereum (Phantom held it in Michael's Chrome, so every pick went to Phantom and was rejected): the named wallet list opens instead; cache tag bumped Co-Authored-By: Claude Opus 5.5 --- public/assets/wallet.js | 14 ++++++++++++-- public/credits.html | 2 +- public/my.html | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/public/assets/wallet.js b/public/assets/wallet.js index b2b4c18..4e43323 100644 --- a/public/assets/wallet.js +++ b/public/assets/wallet.js @@ -18,6 +18,16 @@ window.IAPWallet = (function () { const APPKIT_URL = 'https://cdn.jsdelivr.net/npm/@reown/appkit-cdn@1.8.23/dist/appkit.js'; let modal = null, akPromise = null, provider = null; + // EIP-6963 discovery (2026-10-21, Michael's Chrome: Phantom held window.ethereum, so every "pick an account" prompt went + // to Phantom and failed). Every installed wallet announces itself here; with more than one, never assume the default + // slot is the wallet the member means: send them through the wallet list, where each one is named. + const announced = []; + try { + window.addEventListener('eip6963:announceProvider', e => { const d = e && e.detail; if (d && d.provider && !announced.some(x => x.provider === d.provider)) announced.push(d); }); + window.dispatchEvent(new Event('eip6963:requestProvider')); + } catch (e) {} + // the default-slot wallet, only when it is the ONLY wallet installed (older wallets that never announce count as one) + const soleInjected = () => (window.ethereum && window.ethereum.request && announced.length <= 1) ? window.ethereum : null; async function initAppKit(c) { if (modal) return modal; @@ -108,7 +118,7 @@ window.IAPWallet = (function () { async function pickAccount() { const c = await IAP.getConfig(); await initAppKit(c); - const inj = window.ethereum; + const inj = soleInjected(); // several wallets installed: go straight to the named wallet list below if (inj && inj.request) { try { await inj.request({ method: 'wallet_requestPermissions', params: [{ eth_accounts: {} }] }); @@ -293,7 +303,7 @@ window.IAPWallet = (function () { // (wallets without it just ignore the call), and the pick flag makes the next connect open the picker. async function disconnect() { try { localStorage.setItem(PICK_KEY, '1'); } catch (e) {} - const inj = window.ethereum; + const inj = (provider && provider.request && isInjected()) ? provider : soleInjected(); // revoke on the wallet actually in use if (inj && inj.request) { try { await Promise.race([inj.request({ method: 'wallet_revokePermissions', params: [{ eth_accounts: {} }] }), new Promise(r => setTimeout(r, 1000))]); } catch (e) {} } await dropSession(); } diff --git a/public/credits.html b/public/credits.html index e789113..2741da9 100644 --- a/public/credits.html +++ b/public/credits.html @@ -81,7 +81,7 @@ - + diff --git a/public/my.html b/public/my.html index da937a9..1994a06 100644 --- a/public/my.html +++ b/public/my.html @@ -1010,7 +1010,7 @@ - +