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'); }); })();