From c5b5ef7f8689e73137b9df7a3e8f21e25bc794d9 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 18 Aug 2026 06:12:32 -0500 Subject: [PATCH] Fix infinite refresh loop on /direct-join with Trust Wallet/Brave chainChanged handler called location.reload(); wallets that fire chainChanged on page load turned that into an endless refresh that blocked Connect. Handle accountsChanged/chainChanged in place instead of reloading. Co-Authored-By: Claude Opus 4.8 --- public/direct-join.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/public/direct-join.js b/public/direct-join.js index 4ed3663..a374549 100644 --- a/public/direct-join.js +++ b/public/direct-join.js @@ -129,7 +129,17 @@ $('connectBtn').addEventListener('click',connect); $('registerBtn').addEventListener('click',doRegister); var ub=$('upgradeBtn'); if(ub) ub.addEventListener('click',doUpgrade); - if(eth && eth.on){ eth.on('accountsChanged',function(){location.reload();}); eth.on('chainChanged',function(){location.reload();}); } - if(!eth) log('No wallet detected in this browser. Use MetaMask (desktop extension) or the MetaMask in-app browser on mobile.','err'); + // Update in place on wallet events — do NOT location.reload() here: some wallets + // (Trust Wallet in Brave) fire chainChanged on load, and reloading re-arms the + // handler → infinite refresh loop that blocks the Connect button. + if(eth && eth.on){ + eth.on('accountsChanged',function(accs){ + account=(accs&&accs[0])||null; + if(!account){ $('connected').style.display='none'; $('connectBtn').style.display=''; log('Wallet disconnected.','err'); } + else { $('wallet').textContent=account.slice(0,6)+'…'+account.slice(-4); refreshBalance(); } + }); + eth.on('chainChanged',function(){ if(account) refreshBalance(); }); + } + if(!eth) log('No wallet detected in this browser. Use MetaMask or Trust Wallet (extension, or the wallet app’s in-app browser).','err'); }); })();