Sponsor fallback never names a position the contract does not have yet: on a fresh contract the first member joins with sponsor 0 and becomes #1 (Marty's activate(1) reverted 'Unknown sponsor')
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -135,6 +135,7 @@ async function ensureOnChain(acct, depth) {
|
||||
if (sp && sp.address) sponsorId = await ensureOnChain(sp, depth + 1);
|
||||
}
|
||||
if (!sponsorId) sponsorId = Number((X.siteConfig && X.siteConfig().defaultSponsorId) || 1) || 1;
|
||||
try { if (sponsorId > await X.chain.memberCount()) sponsorId = 0; } catch (e) {} // first member on a fresh contract: no catch position exists yet
|
||||
try {
|
||||
const w = signer(); const ctr = new ethers.Contract(X.chain.getConfig().contract, ABI, w);
|
||||
const tx = await ctr.activateFor(acct.address, sponsorId, { gasLimit: 160000n });
|
||||
|
||||
@@ -1106,6 +1106,9 @@ const server = http.createServer(async (req, res) => {
|
||||
// orphan fallback: an unresolvable/absent sponsor (dead link, no link) lands
|
||||
// the new member under the configured catch position (#1) instead of root
|
||||
if (!sponsorId && (!acct || acct.memberId !== (Number(siteConfig().defaultSponsorId) || 1))) sponsorId = Number(siteConfig().defaultSponsorId) || 1;
|
||||
// a brand-new contract has no catch position yet: the first member joins with sponsor 0 and BECOMES #1 (Marty's reverted
|
||||
// activate(1) on 2026-10-08: 'Unknown sponsor' because memberCount was 0)
|
||||
if (sponsorId) { try { if (sponsorId > await chain.memberCount()) { console.log('sponsor', sponsorId, 'not on chain yet, using 0'); sponsorId = 0; } } catch (e) {} }
|
||||
let name = null, avatarUrl = null, own = false;
|
||||
// the join page names the owner of the LINK it was opened with (?ref=token), not the visitor's own
|
||||
// sponsor: a member previewing their own invite page was seeing their upline's name (Jim, 2026-09-13)
|
||||
|
||||
Reference in New Issue
Block a user