Signed-in sponsor line shows the chain-bound sponsor for activated members (2026-11-02): Orlando (member 2, carried in with no sponsor field) saw whoever's referral link he last clicked because /api/me fell back to the iap.sponsor cookie; the cookie now only speaks for accounts not on chain yet

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-02 04:26:48 -06:00
parent e7a10f5478
commit f4351613a3
+14 -1
View File
@@ -954,6 +954,17 @@ async function resolveSponsorDetailed(tok) {
try { const id = await chain.memberIdByAccount(acct.address); return { id, reason: id ? 'ok' : 'notActivated', name: acct.username ? '@' + acct.username : t }; }
catch (e) { return { id: 0, reason: 'rpc', name: acct.username ? '@' + acct.username : t }; }
}
// The chain-bound sponsor of an activated member, as a resolveSponsorDetailed-shaped answer with a display name; null when the
// member is not on chain or the read fails (callers then fall back to the account's sponsor field).
async function sponsorByChain(memberId) {
const id = Number(memberId) || 0; if (id <= 0) return null;
try {
const me = await chain.member(id); const sid = Number(me && me.sponsorId) || 0; if (!sid) return null;
let name = 'member #' + sid;
try { const sp = await chain.member(sid); const a = sp && sp.account ? await accounts.byAddress(String(sp.account).toLowerCase()) : null; if (a && a.username) name = '@' + a.username; } catch (e) { /* name stays member #N */ }
return { id: sid, reason: 'ok', name, chain: true };
} catch (e) { return null; }
}
async function resolveSponsorToken(tok) { return (await resolveSponsorDetailed(tok)).id; }
const sponsorAlertLast = new Map(); // email -> ts (one alert per member per hour)
function sponsorBlockedAlert(who, r) {
@@ -1997,7 +2008,9 @@ const server = http.createServer(async (req, res) => {
if (!s) return json(res, 200, { signedIn: false });
const memberId = await auth.refreshMemberId(s);
let acct = (s.email && await accounts.byEmail(s.email)) || (s.address && await accounts.byAddress(s.address)) || null;
let spdMe = await resolveSponsorDetailed((acct && acct.sponsorRef) || parseCookies(req)['iap.sponsor']); let sponsorId = spdMe.id;
// Who the member sees as their sponsor (2026-11-02, Orlando saw a stranger): a member who is on the chain shows the sponsor the
// contract bound, never the referral cookie from the last link they clicked; the cookie only speaks for accounts not on chain yet.
let spdMe = await sponsorByChain(acct && acct.memberId); if (!spdMe) spdMe = await resolveSponsorDetailed((acct && acct.sponsorRef) || (!(acct && Number(acct.memberId) > 0) ? parseCookies(req)['iap.sponsor'] : '')); let sponsorId = spdMe.id;
// holding tank (2026-10-27): the network sponsor first; nobody known = tankHold (the Switch on payouts button waits
// for an adopter, 24 h at most). sponsorId keeps today's fallback so a purchase is never held.
let tankHold = null;