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 <noreply@anthropic.com>
This commit is contained in:
+12
-2
@@ -129,7 +129,17 @@
|
|||||||
$('connectBtn').addEventListener('click',connect);
|
$('connectBtn').addEventListener('click',connect);
|
||||||
$('registerBtn').addEventListener('click',doRegister);
|
$('registerBtn').addEventListener('click',doRegister);
|
||||||
var ub=$('upgradeBtn'); if(ub) ub.addEventListener('click',doUpgrade);
|
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();}); }
|
// Update in place on wallet events — do NOT location.reload() here: some wallets
|
||||||
if(!eth) log('No wallet detected in this browser. Use MetaMask (desktop extension) or the MetaMask in-app browser on mobile.','err');
|
// (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');
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user