From 379a5352ea3929408d04e5aeba7323675eab6745 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 8 Sep 2026 09:21:42 -0500 Subject: [PATCH] Add "Disconnect wallet" button (clears stuck WC session / switch wallets) A stuck WalletConnect request or wrong-wallet choice could trap testers. New IAPWallet.disconnect() drops the WC session, forgets the chosen provider, and clears WC localStorage so the next connect re-offers the picker. Surfaced as a "Disconnect wallet" button on the Wallet pane. Co-Authored-By: Claude Opus 4.8 --- public/assets/my.js | 5 +++++ public/assets/wallet.js | 9 ++++++++- public/index.html | 2 +- public/my.html | 10 ++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/public/assets/my.js b/public/assets/my.js index 899dede..b7e594d 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -1425,6 +1425,11 @@ + (copied ? ' is copied' : '') + '. On the faucet, choose Polygon Amoy, paste your address, and request POL. Then come back and buy.'; IAP.status('Faucet opened in a new tab. Choose Polygon Amoy, paste your address, and request test POL.', 'ok'); })); + if ($('wcDisconnect')) $('wcDisconnect').addEventListener('click', busy($('wcDisconnect'), async () => { + try { await IAPWallet.disconnect(); } catch (e) {} + $('wcDisconnectInfo').textContent = 'Disconnected. Tap Connect or Get test POL to pick a wallet again.'; + IAP.status('Wallet disconnected. You can connect a different wallet now.', 'ok'); + })); $('activateBtn').addEventListener('click', busy($('activateBtn'), async () => { const me = await (await fetch('/api/me')).json(); IAP.status('Confirm the free activation in your wallet…'); diff --git a/public/assets/wallet.js b/public/assets/wallet.js index 03dddeb..f93e2ff 100644 --- a/public/assets/wallet.js +++ b/public/assets/wallet.js @@ -192,5 +192,12 @@ window.IAPWallet = (function () { const hash = await sendTx(data, null); return { hash, receipt: await waitTx(hash) }; } - return { connect, signIn, buy, activate, waitTx }; + // Drop the WalletConnect session + any stuck pending request, and forget the + // chosen provider so the next connect re-offers the wallet picker. + async function disconnect() { + try { if (wcProvider && wcProvider.disconnect) await wcProvider.disconnect(); } catch (e) {} + wcProvider = null; CHOSEN = null; wcSdkPromise = null; + try { Object.keys(localStorage).forEach(k => { if (/^wc@2|walletconnect|w3m|wcm_/i.test(k)) localStorage.removeItem(k); }); } catch (e) {} + } + return { connect, signIn, buy, activate, waitTx, disconnect }; })(); diff --git a/public/index.html b/public/index.html index 6f96108..7918f16 100644 --- a/public/index.html +++ b/public/index.html @@ -439,7 +439,7 @@ - + diff --git a/public/my.html b/public/my.html index bf646e7..98fcdf7 100644 --- a/public/my.html +++ b/public/my.html @@ -645,6 +645,12 @@

+
+

Wallet connection

+

Connected the wrong wallet, or stuck on a transaction prompt? Disconnect to clear the session, then reconnect or pick a different wallet.

+

+

+

Your account

…

@@ -690,8 +696,8 @@
- - + +