diff --git a/public/join-now.js b/public/join-now.js
index 0569885..7e50b27 100644
--- a/public/join-now.js
+++ b/public/join-now.js
@@ -78,6 +78,16 @@
}catch(e){ log('Could not open MoonPay: '+(e.message||e),'err'); }
}
+ async function finishConnect(){
+ await loadCosts();
+ $('wallet').textContent=account.slice(0,6)+'…'+account.slice(-4);
+ $('connected').style.display='block'; $('connectBtn').style.display='none';
+ await refreshBalance();
+ $('joinCost').textContent=polStr(regValue())+' POL';
+ var pos=await readPosition(account);
+ if(pos){ $('already').style.display='block'; $('already').innerHTML='This wallet already holds position — open your dashboard. To create a new position, connect a different wallet.'; $('joinBtn').disabled=true; }
+ $('joinBox').style.display='block';
+ }
async function connect(){
try{
eth=await window.RMCWallet.pick();
@@ -85,17 +95,35 @@
attachWalletEvents();
log('Requesting wallet connection…');
var accs=await req('eth_requestAccounts'); account=accs[0];
- await ensurePolygon(); await loadCosts();
- $('wallet').textContent=account.slice(0,6)+'…'+account.slice(-4);
- $('connected').style.display='block'; $('connectBtn').style.display='none';
- await refreshBalance();
- $('joinCost').textContent=polStr(regValue())+' POL';
- var pos=await readPosition(account);
- if(pos){ $('already').style.display='block'; $('already').innerHTML='This wallet already holds position — open your dashboard. To create a new position, connect a different wallet.'; $('joinBtn').disabled=true; }
- $('joinBox').style.display='block';
+ await ensurePolygon();
+ await finishConnect();
log('Connected. Review the amount, then Join.','ok');
}catch(e){ log('Connect failed: '+(e.message||e),'err'); }
}
+ // Inside a wallet's in-app browser the wallet is often ALREADY connected —
+ // recognize it silently on load (eth_accounts never prompts) instead of
+ // greeting a connected user like a stranger. Skipped when multiple wallets
+ // are injected (desktop) so no picker UI ever pops uninvited.
+ async function autoDetect(){
+ try{
+ var list=window.RMCWallet.list();
+ var p=list.length===1?list[0].provider:(list.length===0?window.ethereum:null);
+ if(!p) return;
+ eth=p; attachWalletEvents();
+ var accs=await req('eth_accounts',[]);
+ if(!accs||!accs.length){ log('✅ Wallet detected in this browser — tap "Connect wallet" to continue.','ok'); return; }
+ account=accs[0];
+ var cid=await req('eth_chainId');
+ if(cid===POLYGON_HEX){
+ await finishConnect();
+ log('✅ Already connected as '+account.slice(0,6)+'…'+account.slice(-4)+'. Review the amount, then Join.','ok');
+ }else{
+ $('wallet').textContent=account.slice(0,6)+'…'+account.slice(-4);
+ $('connected').style.display='block';
+ log('Wallet connected ('+account.slice(0,6)+'…'+account.slice(-4)+') but on another network — tap "Connect wallet" to switch to Polygon and continue.','ok');
+ }
+ }catch(e){}
+ }
async function doJoin(){
try{
@@ -150,7 +178,7 @@
var box=$('walletHelp'); if(!box) return;
var here=location.host+location.pathname+location.search;
var mm=$('mmDeep'); if(mm) mm.href='https://metamask.app.link/dapp/'+here;
- var tw=$('twDeep'); if(tw) tw.href='https://link.trustwallet.com/open_url?url='+encodeURIComponent(location.href);
+ var tw=$('twDeep'); if(tw) tw.href='https://link.trustwallet.com/open_url?coin_id=966&url='+encodeURIComponent(location.href);
box.style.display='block';
}
@@ -165,5 +193,6 @@
$('joinBtn').addEventListener('click',doJoin);
var fb=$('fundBtn'); if(fb)fb.addEventListener('click',openMoonpay);
var fr=$('fundRefresh'); if(fr)fr.addEventListener('click',function(){ log('Checking your balance…'); refreshBalance(); });
+ setTimeout(autoDetect,350); // let EIP-6963 announcements land first
});
})();