0254f933be
One box: member ID or wallet address -> member ID, wallet (short, full on hover + Copy), level and tier, join date, sponsor ID (clickable), direct referral count, Polygonscan link, public dashboard link. Chain facts only, never names or emails. RM Circle only; nothing from any other site. - chain.lookupPublic: served from the indexed state (zero RPC); only a position or wallet the index has not seen yet falls back to one eth_call (memberId(address) 0x39106821, verified live: 0x7c7D...d3c2 -> 7230) - /api/public/lookup: own 12/min per-IP limiter, 3-minute answer cache (negative answers too), global budget of 60 RPC fallbacks per minute - page lookup.html + lookup.js (no inline script), ?q= deep links, /find alias - "Find a Member" in every site footer; chat.js?v=20261114a - chatbot: canned answer in chat.js + FACT line and Site pages entry in the AI system prompt - tests: qa/lookup-unit.mjs (25), qa/lookup-e2e.mjs (51, desktop + phone, CSP, no-email, rate limit) against qa/harness-server.js LOOKUP_SEED Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
4.3 KiB
JavaScript
84 lines
4.3 KiB
JavaScript
// Find a member (/lookup): one box, member ID or wallet address -> public chain facts.
|
|
// Talks only to /api/public/lookup (same origin; CSP connect-src 'self').
|
|
(function(){
|
|
'use strict';
|
|
var $=function(id){return document.getElementById(id)};
|
|
var form=$('lkForm'),input=$('lkQ'),msg=$('lkMsg'),res=$('lkRes'),go=$('lkGo');
|
|
var busy=false,current=null;
|
|
|
|
function setMsg(t,err){msg.textContent=t||'';msg.className='lk-msg'+(err?' err':'');}
|
|
function short(a){return a.slice(0,6)+'...'+a.slice(-4);}
|
|
function fmtDate(ts){
|
|
if(!ts)return 'Unknown';
|
|
try{return new Date(ts*1000).toLocaleDateString(undefined,{year:'numeric',month:'short',day:'numeric'});}
|
|
catch(e){return new Date(ts*1000).toISOString().slice(0,10);}
|
|
}
|
|
function clean(v){
|
|
v=String(v||'').trim().replace(/\s+/g,'');
|
|
if(/^#\d+$/.test(v))v=v.slice(1);
|
|
return v;
|
|
}
|
|
function valid(v){return /^\d{1,15}$/.test(v)&&Number(v)>=1||/^0x[0-9a-fA-F]{40}$/.test(v);}
|
|
|
|
function show(d){
|
|
current=d;
|
|
$('rId').textContent='#'+d.id;
|
|
var q=(d.directCount||0)>=2;
|
|
var b=$('rQual');b.textContent=q?'Qualified':'Building ('+(d.directCount||0)+'/2)';b.className='lk-badge '+(q?'q':'w');
|
|
var w=$('rWallet');w.textContent=short(d.account);w.title=d.account;
|
|
$('rLevel').textContent=d.levelName+' (Level '+d.level+' of 8)';
|
|
$('rTier').textContent=d.tierName;
|
|
$('rJoined').textContent=fmtDate(d.joinedAt);
|
|
var s=$('rSponsor');s.textContent='';
|
|
if(d.sponsorId){
|
|
var a=document.createElement('button');a.type='button';a.className='lk-link';a.textContent='#'+d.sponsorId;
|
|
a.title='Look up member #'+d.sponsorId;
|
|
a.addEventListener('click',function(){input.value=String(d.sponsorId);lookup(String(d.sponsorId),true);});
|
|
s.appendChild(a);
|
|
}else s.textContent='None (contract root)';
|
|
$('rDirects').textContent=String(d.directCount||0);
|
|
$('rScan').href='https://polygonscan.com/address/'+d.account;
|
|
$('rDash').href='/my/'+d.id;
|
|
$('rCopy').textContent='Copy';
|
|
res.classList.remove('hidden');
|
|
}
|
|
|
|
function lookup(v,push){
|
|
v=clean(v);
|
|
if(!v){setMsg('Type a member ID or paste a wallet address.',true);return;}
|
|
if(!valid(v)){setMsg('That does not look right. Use a member ID (like 21) or a full wallet address (0x followed by 40 characters).',true);return;}
|
|
if(busy)return;
|
|
busy=true;go.disabled=true;setMsg('Looking it up on the blockchain...');
|
|
fetch('/api/public/lookup?q='+encodeURIComponent(v),{headers:{Accept:'application/json'}})
|
|
.then(function(r){return r.json().catch(function(){return {error:'Lookup failed. Try again.'};}).then(function(j){return {status:r.status,j:j};});})
|
|
.then(function(x){
|
|
var j=x.j||{};
|
|
if(x.status!==200){res.classList.add('hidden');setMsg(j.error||'Lookup failed. Try again.',true);return;}
|
|
if(!j.found){
|
|
res.classList.add('hidden');
|
|
setMsg(/^0x/i.test(v)?'No RM Circle position is registered to that wallet.':'There is no member #'+v+' yet.',true);
|
|
return;
|
|
}
|
|
setMsg('');show(j);
|
|
if(push){try{history.pushState({q:v},'','/lookup?q='+encodeURIComponent(v));}catch(e){}}
|
|
})
|
|
.catch(function(){res.classList.add('hidden');setMsg('Could not reach the site. Check your connection and try again.',true);})
|
|
.then(function(){busy=false;go.disabled=false;});
|
|
}
|
|
|
|
form.addEventListener('submit',function(e){e.preventDefault();lookup(input.value,true);});
|
|
$('rCopy').addEventListener('click',function(){
|
|
if(!current)return;
|
|
var btn=this,done=function(){btn.textContent='Copied';setTimeout(function(){btn.textContent='Copy';},1500);};
|
|
var legacy=function(){var t=document.createElement('textarea');t.value=current.account;document.body.appendChild(t);t.select();try{document.execCommand('copy');}catch(e){}t.remove();done();};
|
|
if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(current.account).then(done,legacy);}
|
|
else legacy();
|
|
});
|
|
window.addEventListener('popstate',function(){
|
|
var q=new URLSearchParams(location.search).get('q');
|
|
if(q){input.value=q;lookup(q,false);}else{res.classList.add('hidden');setMsg('');input.value='';}
|
|
});
|
|
var q0=new URLSearchParams(location.search).get('q');
|
|
if(q0){input.value=q0;lookup(q0,false);}
|
|
})();
|