diff --git a/server.js b/server.js index 05f22a6..6af9471 100644 --- a/server.js +++ b/server.js @@ -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;