diff --git a/chatbot.js b/chatbot.js index a83cecd..98734bb 100644 --- a/chatbot.js +++ b/chatbot.js @@ -25,7 +25,7 @@ let DATA_DIR = null; let chain = null; const MODEL = process.env.OPENROUTER_MODEL || 'deepseek/deepseek-v4-flash:nitro'; const CONTRACT = '0x26Bdc556b94399bEdd69ae3ACA5aA6c54D946e8b'; -const KNOWLEDGE_DATE = '2026-11-05'; // the day the CANNED answers and FACTS below were last checked against the site +const KNOWLEDGE_DATE = '2026-11-07'; // the day the CANNED answers and FACTS below were last checked against the site function init(opts) { if (opts && typeof opts.refuelOn === 'function') REFUEL_ON = opts.refuelOn; DATA_DIR = opts.dataDir; chain = opts.chain; return kb.init({ dataDir: DATA_DIR, seeds: seeds() }); } @@ -142,12 +142,15 @@ const CANNED = [ { id: 'control-room', title: 'The Control Room screens', q: ['Where do I find my links?', 'What is on the dashboard?', 'Which screen has my campaigns?'], tags: ['control room', 'dashboard', 'menu', 'tools'], re: /(control room|dashboard|where (do|can) i (find|see)|which screen|menu|navigation|more tools|\/tools)/i, a: 'Your Control Room has these screens: Links (spin links), Pages (the page builder), Zones (ad slots on your site plus Audiences), Ads (your campaigns and the daily ad set), Credits (buy packages, link your wallet, switch on payouts), Reports (every link in one view), Team (your line, three levels) and Wallet (what was paid to you). More, at ' + SITE_URL + '/tools, holds Promo tools, Training, the Pipeline follow-up board, My line and your Profile.' }, + { id: 'who-invited', title: 'Who invited you? (naming your sponsor)', q: ['How do I add the person who invited me?', 'I joined without a link, can I name my sponsor?', 'What is the Who invited you box?'], tags: ['who invited you', 'invited', 'holding tank', 'no sponsor', 'sponsor link'], + re: /(who invited|invited (me|by)|joined without a (link|sponsor)|forgot (the|my|to use).{0,12}(link|sponsor)|(add|name|set|enter|pick|choose) (my |a )?sponsor|nobody invited)/i, + a: 'If you joined without a sponsor link, a Who invited you? box shows at the top of your Control Room screens. Type the username of the person who invited you, confirm it, and they become your sponsor, here and on InstantAdPay, and they get a notice. If your wallet is already linked, your payouts switch on under them right away, and that locks them in on the contract, so check the name first. It has to be a real member: not you, not someone in your own line, and not someone who has not switched on payouts with nobody above them who has (ask them to switch on first). Once you have a sponsor or a member number the box goes away. Nobody invited you? Tap Nobody invited me and stay in the holding tank; a small link under More brings the box back while you are still there. Nothing on the site waits for your answer. New sign-ups cannot be adopted by hand for their first 24 hours, so you have a day to tell us before a member can pick you up.' }, { id: 'tank-hold', title: 'Matched with a sponsor (payouts on hold)', q: ['Why can I not switch on payouts?', 'It says I am being matched with a sponsor'], tags: ['holding tank', 'switch on payouts', 'matched with a sponsor', 'ready to activate'], re: /(being matched|matched with a sponsor|(can.?t|cannot|unable to) (i )?(switch on|turn on|activate) (my )?payouts|activate (button|payouts) (is )?(gone|missing|hidden)|ready to activate)/i, - a: 'You joined without a sponsor, so you are in the holding tank. The contract locks your sponsor for good the moment your payouts are switched on, so the site waits for a real member to pick you up instead of placing you under the company. First it checks the network: if InstantAdPay already has a sponsor for your email or wallet, you are placed under them right away. Otherwise members see you at the top of their holding tank with a Ready to activate badge once your wallet is linked, and if nobody adopts you within 24 hours the site assigns you to the next eligible member in turn (someone active with their own $25 package). As soon as you have a sponsor, the site switches your payouts on under them for you (no cost to you) and tells you, with the transaction link. Buying is never held: you can buy a package at any time, but a purchase made before you have a sponsor places you under the platform position for good.' }, + a: 'You joined without a sponsor, so you are in the holding tank. If someone invited you, type their username in the Who invited you? box and this ends right away. The contract locks your sponsor for good the moment your payouts are switched on, so the site waits for a real member to pick you up instead of placing you under the company. First it checks the network: if InstantAdPay already has a sponsor for your email or wallet, you are placed under them right away. Otherwise members see you at the top of their holding tank with a Ready to activate badge once your wallet is linked, and if nobody adopts you within 24 hours the site assigns you to the next eligible member in turn (someone active with their own $25 package). As soon as you have a sponsor, the site switches your payouts on under them for you (no cost to you) and tells you, with the transaction link. Buying is never held: you can buy a package at any time, but a purchase made before you have a sponsor places you under the platform position for good.' }, { id: 'holding-tank', title: 'Holding tank and adoptions', q: ['What is the holding tank?', 'How do I adopt a member?'], tags: ['holding tank', 'adopt', 'no sponsor'], re: /(holding tank|adopt|no sponsor|without a sponsor|orphan)/i, - a: 'Members who join from the public site with no sponsor wait in the holding tank under More, My line, unless the network already knows their sponsor (the same email or wallet on InstantAdPay), in which case they are placed under that sponsor. A member who has switched on payouts and bought their own qualifying package can adopt one, first come, with a 7-day window for the new member to link a wallet or buy; otherwise they return to the tank. Adopting sets the sponsor, and their first purchase then binds to the adopter on the contract. Members who have linked a wallet show a Ready to activate badge with the hours left and sit at the top of the list; adopting one switches their payouts on under you right away. If nobody adopts them within 24 hours, the site assigns them to the next eligible adopter in turn (own $25 package, fewer than 2 open adoptions, signed in within the last 7 days); the one assigned least recently goes first. Someone waiting in the InstantAdPay tank as well is assigned there, and the adoption carries over to LinkSpin.' }, + a: 'Members who join from the public site with no sponsor wait in the holding tank under More, My line, unless the network already knows their sponsor (the same email or wallet on InstantAdPay), in which case they are placed under that sponsor. A new sign-up shows an Opens in badge with no Adopt button for their first 24 hours, so they have a day to tell us who invited them (the 24-hour safety net for wallet-linked members still runs on its own clock). After that, a member who has switched on payouts and bought their own qualifying package can adopt one, first come, with a 7-day window for the new member to link a wallet or buy; otherwise they return to the tank. Adopting sets the sponsor, and their first purchase then binds to the adopter on the contract. Members who have linked a wallet show a Ready to activate badge with the hours left and sit at the top of the list; adopting one switches their payouts on under you right away. If nobody adopts them within 24 hours, the site assigns them to the next eligible adopter in turn (own $25 package, fewer than 2 open adoptions, signed in within the last 7 days); the one assigned least recently goes first. Someone waiting in the InstantAdPay tank as well is assigned there, and the adoption carries over to LinkSpin.' }, { id: 'team', title: 'My line: the Team screen', q: ['How do I see my downline?', 'Who is in my team?'], tags: ['team', 'my line', 'downline', 'levels'], re: /(my line|downline|my team|who (is|are) (in|on) my|three levels|level 1\b)/i, a: 'Team shows your line as a working table, three levels deep: who joined through your link, who has switched on payouts, who has bought, and how many qualifying buyers each person has. The chip count is what opens your levels: two qualifying buyers ($25 or larger) open level 2, five open level 3.' }, @@ -202,6 +205,8 @@ ${refuelFact()}${synFact()}- PRODUCT, all free with an email account: SPIN LINKS - ACCOUNT: join at ${SITE_URL}/join with email only, a six-digit code, no password. Wallet linking happens inside the Control Room (Credits screen): one signature to link, then payouts switch on by activating (one transaction, gas only) or by buying any package. SafePal is the recommended wallet; MetaMask, Phantom (turn Polygon on first) and any WalletConnect wallet work; Trust Wallet blocks a buy that spends most of its POL. No card button on the site: members buy POL with a card on any major exchange or on-ramp, then send it to their own wallet on the Polygon network (guide at ${SITE_URL}/wallets); never name a specific exchange or on-ramp brand. - SPONSOR: the invite link opened most recently sets the sponsor (30-day cookie), shown on the join page, locked when the account is created; the contract binds the buyer to that sponsor at the first purchase. CARRY-OVER: Crypto Team Build Network members who sign in with the email they use on InstantAdPay get their InstantAdPay sponsor from the network registry automatically when no invite link was used. Wrong sponsor before the first purchase: the admin can move the account. Members should switch on payouts before their people buy. - CONTROL ROOM screens: Links, Pages, Zones (with Audiences), Ads, Credits, Reports, Team (three levels, who has payouts on, who bought, qualifying-buyer counts), Wallet (what was paid to this wallet, payout history). More at ${SITE_URL}/tools: Promo tools, Training, Pipeline (a follow-up board for prospects and directs), My line (including the holding tank: members who joined with no sponsor wait there and can be adopted by a member with payouts on and their own qualifying package), Profile. +- WHO INVITED YOU (2026-11-07, Marty approved): a member with no sponsor and no member number sees a Who invited you? box at the top of their Control Room screens. They type a username, confirm in an in-page box, and that member becomes their sponsor (it follows to InstantAdPay, lifts the hold, and the sponsor gets a new-referral email and notice); with a wallet already linked the site switches their payouts on under that sponsor right away. Refused: themselves, a username that does not exist, someone in their own line, a member who cannot take new members, a member with no payouts on and nobody above them on the contract, and anyone who already has a sponsor or a member number. Nobody invited me hides the box (a small link under More brings it back while they are in the tank) and changes nothing else. It never blocks the site. It is not an adoption: no 7-day window and it does not count toward the two. +- SIGN-UP GRACE (2026-11-07): for 24 hours from sign-up nobody can adopt a member by hand. The 24-hour auto-assign is unchanged and runs from the wallet link, so a member who links a wallet in their first hour is matched about 24 hours after linking, with at most a short hand-adoption window first. Members back in the tank later have no grace. - HOLDING TANK ACTIVATION HOLD (2026-10-27): a member with no sponsor is first matched to their network sponsor (the same email or wallet with a sponsor on InstantAdPay). Nobody known: the free Switch on payouts waits for an adopter and the Credits screen says "You're being matched with a sponsor. Payouts switch on as soon as someone picks you up (within 24 hours)." with the time left; they show at the top of every holding tank with a green Ready to activate badge and the hours left, and the shared payments topic on Telegram is told. Nobody adopts in 24 hours: the site assigns them to the next eligible adopter in rotation (own $25+ package, fewer than 2 open adoptions, signed in within 7 days; least recently auto-assigned first), and the pickup is posted marked (auto-assigned). The moment they have a sponsor (adopted, assigned or matched), the site switches their payouts on under that sponsor (engine-paid) and sends them the transaction link. A PURCHASE IS NEVER HELD: a tank member can buy at any time; with no sponsor yet that purchase places them under the platform position for good. Someone who arrived through a sponsor link is never held. ${launchFact()} - SUPPORT (LIVE 2026-10-16): members open Help in the Control Room (${SITE_URL}/help) to send Marty a ticket (pick a category, a subject, the message), see each ticket's status (Open, Waiting on you, Closed), and read and answer his replies; a badge on the Help item shows when he has replied, and replies also arrive by email. Anyone signed out or locked out uses the public form at ${SITE_URL}/support, gets a private link to follow the ticket without signing in, and can reply there. The chat can also pass a conversation to support ("Send this to support"). Marty answers every ticket himself; there is no support email address, point people to ${SITE_URL}/support instead. Tickets share one desk with the rest of the Crypto Team Build Network. diff --git a/coach.js b/coach.js index a97c45a..c2975e1 100644 --- a/coach.js +++ b/coach.js @@ -242,7 +242,7 @@ async function nudgeTick() { // weekly member email (Marty, 2026-09-14, modelled on the mailer.gold weekly): credits sitting unspent, // the streak, the contest standings with the member's own rank, the tank, and the line for sponsors let lbWeek = null; try { lbWeek = X.lb ? await X.lb().view('week') : null; } catch (e) {} - let tankN = 0; try { tankN = X.tank ? (await X.tank.waiting()).length : 0; } catch (e) {} + let tankN = 0; try { tankN = X.tank ? (await X.tank.adoptable()).length : 0; } catch (e) {} for (const acct of all) { if (!acct.email || !acct.lastSeen) continue; // weekly mail only to people who have actually signed in here const lastD = await impl().lastDigest(acct.email); diff --git a/public/admin.html b/public/admin.html index 45d40c6..f712ffe 100644 --- a/public/admin.html +++ b/public/admin.html @@ -548,8 +548,8 @@ - + - + diff --git a/public/ads.html b/public/ads.html index 7732515..96a79fb 100644 --- a/public/ads.html +++ b/public/ads.html @@ -75,7 +75,7 @@ - + diff --git a/public/assets/admin-sponsorcheck.js b/public/assets/admin-sponsorcheck.js index aa1ffab..24d536b 100644 --- a/public/assets/admin-sponsorcheck.js +++ b/public/assets/admin-sponsorcheck.js @@ -8,7 +8,7 @@ const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); const day = ts => ts ? new Date(Number(ts)).toLocaleString([], { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) : ''; const say = (m, k) => { try { IAP.status(m, k); } catch (e) {} }; - const HOW = { adopt: 'adopted from the tank', rescue: 'rescued to the tank', release: 'released to the tank', expire: 'adoption window ended', admin: 'admin edit' }; + const HOW = { adopt: 'adopted from the tank', rescue: 'rescued to the tank', release: 'released to the tank', expire: 'adoption window ended', admin: 'admin edit', invited: 'the member named who invited them' }; const NAME = { instantadpay: 'InstantAdPay', linkspin: 'LinkSpin' }; function side(f) { if (!f) return 'no account'; diff --git a/public/assets/admin.js b/public/assets/admin.js index 0553cd4..0000dce 100644 --- a/public/assets/admin.js +++ b/public/assets/admin.js @@ -300,10 +300,10 @@ $('tankAdmSub').textContent = r.waiting.length + ' waiting' + (nReady ? ' (' + nReady + ' ready to activate)' : '') + ' · cap ' + r.cap + ' open per adopter · ' + r.ttlDays + '-day window · ready members: the free activation is held ' + (r.holdHours || 24) + ' h (a purchase never is), then auto-assigned in rotation'; // ready = wallet linked: the plain activation is held (never the company) until someone adopts them or the 24-hour safety net assigns them (2026-10-27) const left = w => { const ms = (w.holdUntil || 0) - Date.now(); if (ms <= 0) return 'assigning now'; const m = Math.round(ms / 60000); return (m >= 60 ? Math.floor(m / 60) + ' h ' + (m % 60) + ' min' : m + ' min') + ' left'; }; - const rb = w => w.ready ? ' Ready to activate · ' + left(w) + '' : ''; + const rb = w => (w.opensAt > Date.now() ? ' Opens ' + when(w.opensAt) + '' : '') + (w.ready ? ' Ready to activate · ' + left(w) + '' : ''); $('tankWait').innerHTML = 'WaitingEmailJoinedLast sign-in' + (r.waiting.length ? r.waiting.map(w => '' + esc(w.name) + rb(w) + '' + esc(w.email) + '' + when(w.joined) + '' + (w.lastSeen ? when(w.lastSeen) : 'never') + '').join('') : 'empty') + ((r.aligned || []).length ? 'Aligned to their network sponsor (InstantAdPay) instead of the tank' + r.aligned.slice(0, 15).map(x => '' + esc(x.email) + '' + esc(x.toName || x.to) + '' + when(x.at) + '' + esc(x.via || '') + '').join('') : ''); - $('tankAdopt').innerHTML = 'MemberAdopted byWhenWindow endsStatus' + (r.adoptions.length ? r.adoptions.map(a => '' + esc(a.adopteeName) + '' + esc(a.adopterName) + '' + when(a.ts) + '' + (a.status === 'released' ? '' : when(a.expires)) + '' + esc(a.status) + '').join('') : 'none yet'); + $('tankAdopt').innerHTML = 'MemberAdopted byWhenWindow endsStatus' + (r.adoptions.length ? r.adoptions.map(a => '' + esc(a.adopteeName) + '' + esc(a.adopterName) + '' + when(a.ts) + '' + (a.status === 'released' || a.status === 'invited' ? '' : when(a.expires)) + '' + esc(a.status) + '').join('') : 'none yet'); } catch (e) {} } async function loadMembers() { diff --git a/public/assets/common.js b/public/assets/common.js index 24de09a..694588a 100644 --- a/public/assets/common.js +++ b/public/assets/common.js @@ -199,7 +199,7 @@ window.IAP = (function () { how: 'Wallet tab, Connect, sign the free message. MetaMask recommended. Never held crypto? The wallet guide in Training walks through buying POL with a card.', why: 'Payouts go to this address. No wallet, nowhere to pay you.' }, { key: 'payouts', title: 'Payouts switched on', done: !!m.memberId, href: '/wallet', cta: 'Wallet', - how: 'Happens by itself once your wallet is linked and you have a sponsor: LinkSpin registers your address on the contract and pays the gas. Joined with no sponsor? You wait in the holding tank while one is matched (up to 24 hours).', + how: 'Happens by itself once your wallet is linked and you have a sponsor: LinkSpin registers your address on the contract and pays the gas. Joined with no sponsor? Tell us who invited you, or you wait in the holding tank while one is matched (up to 24 hours after you link your wallet).', why: 'The contract binds each buyer to their sponsor at their first purchase. If payouts are off when your first person buys, that commission is not yours.' }, { key: 'level2', title: 'Qualify: open level 2', done: bc >= 2, href: '/credits', cta: 'Buy packages', how: 'Two of your people buy a $25 or more package. Or use Qualified Start: add two positions from extra wallets in your own MetaMask and buy a $25 package from each (about $23 of POL in each wallet).', diff --git a/public/assets/cr-shell.js b/public/assets/cr-shell.js index bb5b0c9..a29b1de 100644 --- a/public/assets/cr-shell.js +++ b/public/assets/cr-shell.js @@ -221,7 +221,38 @@ window.CR = (function () { if (!b) { b = document.createElement('b'); b.className = 'rbadge'; a.appendChild(b); } b.textContent = n > 9 ? '9+' : String(n); a.title = 'Help: ' + n + ' new repl' + (n === 1 ? 'y' : 'ies'); return n; } - async function requireSession(onReady) { let m = await me(); whoPaint(m); themeSync(m); if (m && m.signedIn) { strip(); helpBadge(); m = await ensureUsername(m); await loginAd(); return onReady(m); } signInFlow(async r => { whoPaint(r); themeSync(r); strip(); helpBadge(); await loginAd(); onReady(r); }); } + // "Who invited you?" (Marty approved 2026-11-07): a member with no sponsor and no member number can name who invited them. + // LinkSpin members land on the Control Room, not on the /tools Overview, so it sits at the top of every screen, /tools included. + // Soft: nothing waits for it. "Nobody invited me" hides it everywhere; a small link on /tools brings it back. + function inviteCard(m) { + if ($('crInvite')) $('crInvite').remove(); + const ask = m && m.signedIn && !m.memberId && m.inviteAsk; const body = $('crBody'); if (!ask || !body) return; + if (ask.dismissed && location.pathname !== '/tools') return; + if (!$('crInviteCss')) { const st = document.createElement('style'); st.id = 'crInviteCss'; st.textContent = '.invite{margin:12px 24px;padding:12px 14px;border:1px solid var(--line);background:var(--panel)}.invite h2{font:700 16px Manrope,system-ui;margin:0 0 4px}.invite .row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px;align-items:center}.invite .field{flex:1 1 180px;max-width:280px;margin:0}.invite .bad{color:var(--bad,#c0392b)}@media(max-width:640px){.invite{margin:10px 16px}}'; document.head.appendChild(st); } + const box = document.createElement('div'); box.id = 'crInvite'; box.className = 'invite'; body.insertBefore(box, body.firstChild); + const full = () => { + box.innerHTML = '

Who invited you?

You joined without a sponsor. If someone told you about LinkSpin, type their username and they become your sponsor. Do it before your payouts switch on or you buy: your sponsor locks on the contract at that point.
' + + '
'; + const say = (t, bad) => { const x = $('inviteMsg'); x.textContent = t || ''; x.classList.toggle('bad', !!bad); }; + const go = async () => { + say(''); + try { + const who = $('inviteWho').value; + const chk = await api('/api/my/tank/invited', { who, check: true }); + const yes = await dialog({ title: 'Who invited you?', text: chk.name + ' becomes your sponsor. ' + (m.address ? 'Your wallet is linked, so your payouts switch on under them right away, and that locks them in for good on the contract.' : 'Your sponsor locks on the contract when your payouts switch on or you buy, so check this is the right person.'), ok: 'Yes, ' + chk.name, no: 'Not them' }); + if (!yes) return; + const r = await api('/api/my/tank/invited', { who }); + box.remove(); toast(r.name + ' is now your sponsor.'); setTimeout(() => location.reload(), 1400); + } catch (e) { say(e.message, true); } + }; + $('inviteGo').addEventListener('click', go); + $('inviteWho').addEventListener('keydown', e => { if (e.key === 'Enter') { e.preventDefault(); go(); } }); + $('inviteNo').addEventListener('click', async () => { try { await api('/api/my/tank/invited/dismiss', {}); } catch (e) {} if (location.pathname === '/tools') small(); else box.remove(); }); + }; + const small = () => { box.innerHTML = 'Remembered who invited you? Tell us'; $('inviteBack').addEventListener('click', e => { e.preventDefault(); full(); $('inviteWho').focus(); }); }; + if (ask.dismissed) small(); else full(); + } + async function requireSession(onReady) { let m = await me(); whoPaint(m); themeSync(m); if (m && m.signedIn) { strip(); helpBadge(); m = await ensureUsername(m); await loginAd(); inviteCard(m); return onReady(m); } signInFlow(async r => { whoPaint(r); themeSync(r); strip(); helpBadge(); await loginAd(); me(true).then(inviteCard); onReady(r); }); } // tiles with a sparkline and a delta chip (Instrument scheme, 2026-09-29): series = numbers oldest first function sparkline(series) { const s = (series || []).map(Number); if (s.length < 2 || !s.some(Boolean)) return ''; diff --git a/public/assets/credits-screen.js b/public/assets/credits-screen.js index bb7cf81..522b2b2 100644 --- a/public/assets/credits-screen.js +++ b/public/assets/credits-screen.js @@ -152,7 +152,7 @@ function tankHoldText(h) { let t = "You're being matched with a sponsor. Payouts switch on as soon as someone picks you up (within 24 hours)."; if (h && h.until) { const ms = h.until - Date.now(); t += ms > 0 ? ' Time left: ' + holdLeft(ms) + '.' : ' Any minute now.'; } - return t; + return t + ' Did someone invite you? Tell us in the Who invited you box.'; } // a named sponsor that cannot be paid right now: hold the transaction and say why (never credit the company by default) function holdText(sp) { diff --git a/public/assets/my.js b/public/assets/my.js index b379cec..e5cad6c 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -32,7 +32,7 @@ function tankHoldText(h) { let t = "You're being matched with a sponsor. Payouts switch on as soon as someone picks you up (within 24 hours)."; if (h && h.until) { const ms = h.until - Date.now(); t += ms > 0 ? ' Time left: ' + holdLeft(ms) + '.' : ' Any minute now.'; } - return t; + return t + ' Did someone invite you? Tell us in the Who invited you box.'; } let TANK_HOLD = null; function nextMove(d) { @@ -1287,11 +1287,13 @@ $('tankMine').querySelectorAll('[data-tchat]').forEach(b => b.addEventListener('click', () => openConvo(b.dataset.tchat, b.dataset.tname))); $('tankMine').querySelectorAll('[data-pif]').forEach(b => b.addEventListener('click', () => pif(b.dataset.pif, b.dataset.pname, b.dataset.paddr))); if (!r.waiting.length) { el.innerHTML = '

The tank is empty. Anyone who joins from the public site without a sponsor lands here.

'; return; } + const opens = w => w.opensAt > Date.now(); // new sign-up: they have 24 hours to say who invited them + const opensBadge = w => ' Opens in ' + holdLeft(w.opensAt - Date.now()) + ''; const readyBadge = w => w.ready ? ' Ready to activate \u00b7 ' + (w.holdUntil > Date.now() ? holdLeft(w.holdUntil - Date.now()) + ' left' : 'assigning now') + '' : ''; - el.innerHTML = r.waiting.slice().sort((a, b) => (b.ready ? 1 : 0) - (a.ready ? 1 : 0)).map(w => '
' + esc(w.name) + readyBadge(w) + '' + el.innerHTML = r.waiting.slice().sort((a, b) => (opens(a) ? 1 : 0) - (opens(b) ? 1 : 0) || (b.ready ? 1 : 0) - (a.ready ? 1 : 0)).map(w => '
' + esc(w.name) + (opens(w) ? opensBadge(w) : readyBadge(w)) + '' + 'joined ' + ago(w.joined) + '' + 'last sign-in: ' + ago(w.lastSeen) + '' - + (r.eligible ? '' : '') + '
').join(''); + + (r.eligible && !opens(w) ? '' : '') + '
').join(''); el.querySelectorAll('[data-adopt]').forEach(b => b.addEventListener('click', async () => { const note = await IAP.ask({ title: 'Adopt ' + b.dataset.aname, text: 'Your first message to ' + b.dataset.aname + ' (sent as a chat and an email):', type: 'textarea', ok: 'Adopt and send', value: 'Hi, I picked you up from the LinkSpin holding tank so you have a sponsor who will actually help. Reply here and I will walk you through the first three steps.' }); if (note === null) return; diff --git a/public/conversions.html b/public/conversions.html index c37451a..b3bac83 100644 --- a/public/conversions.html +++ b/public/conversions.html @@ -69,7 +69,7 @@
- + diff --git a/public/credits.html b/public/credits.html index a157cba..2fd25f0 100644 --- a/public/credits.html +++ b/public/credits.html @@ -81,10 +81,10 @@ - + - - + + diff --git a/public/earning.html b/public/earning.html index a72073a..8954adb 100644 --- a/public/earning.html +++ b/public/earning.html @@ -69,6 +69,6 @@
Advertising services with a performance referral program. Not an investment product; no income guarantees.
- + diff --git a/public/help.html b/public/help.html index f121d55..f0fdcdd 100644 --- a/public/help.html +++ b/public/help.html @@ -30,7 +30,7 @@
loading
- + diff --git a/public/join.html b/public/join.html index 3dc642a..e24e590 100644 --- a/public/join.html +++ b/public/join.html @@ -106,7 +106,7 @@ body.squeeze .card{position:sticky;top:16px} a Crypto Team Build Network property - + diff --git a/public/launch.html b/public/launch.html index 8d9ff4e..3b32564 100644 --- a/public/launch.html +++ b/public/launch.html @@ -102,7 +102,7 @@
Advertising services with a performance referral program. Not an investment product; no income guarantees.
- + diff --git a/public/ledger.html b/public/ledger.html index b490cb4..f7d0776 100644 --- a/public/ledger.html +++ b/public/ledger.html @@ -65,7 +65,7 @@ a Crypto Team Build Network property - + diff --git a/public/links.html b/public/links.html index 4289829..18f7555 100644 --- a/public/links.html +++ b/public/links.html @@ -270,7 +270,7 @@ - + diff --git a/public/my.html b/public/my.html index e15781d..d522556 100644 --- a/public/my.html +++ b/public/my.html @@ -280,7 +280,7 @@

Holding tank

members who arrived with no sponsor
-

People who joined without a sponsor wait here. Adopt one and you become their sponsor: a chat opens, they get an email with your message, and their first purchase binds to you on the contract. First come. At most 2 open adoptions at a time, and an adoption goes back to the tank after 7 days if they have not linked a wallet or bought.

+

People who joined without a sponsor wait here. New sign-ups open for adoption 24 hours after they join, so they have time to tell us who invited them. Adopt one and you become their sponsor: a chat opens, they get an email with your message, and their first purchase binds to you on the contract. First come. At most 2 open adoptions at a time, and an adoption goes back to the tank after 7 days if they have not linked a wallet or bought.

Loading…

@@ -1015,12 +1015,12 @@
- - + + - + diff --git a/public/pages.html b/public/pages.html index 4b9269c..00c342b 100644 --- a/public/pages.html +++ b/public/pages.html @@ -73,7 +73,7 @@ - + diff --git a/public/partners.html b/public/partners.html index 26c2b48..3bd0a77 100644 --- a/public/partners.html +++ b/public/partners.html @@ -131,7 +131,7 @@
Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford to lose.
- + diff --git a/public/plays.html b/public/plays.html index b945d1b..9479ff8 100644 --- a/public/plays.html +++ b/public/plays.html @@ -193,7 +193,7 @@
Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford.
- + diff --git a/public/reports.html b/public/reports.html index 124f283..3aae5be 100644 --- a/public/reports.html +++ b/public/reports.html @@ -90,7 +90,7 @@ - + diff --git a/public/sources.html b/public/sources.html index fa752db..9787e51 100644 --- a/public/sources.html +++ b/public/sources.html @@ -128,7 +128,7 @@ - + diff --git a/public/support.html b/public/support.html index b5342e9..dbff747 100644 --- a/public/support.html +++ b/public/support.html @@ -67,7 +67,7 @@ a Crypto Team Build Network property - + diff --git a/public/team.html b/public/team.html index 2173c49..10d30ed 100644 --- a/public/team.html +++ b/public/team.html @@ -38,7 +38,7 @@ - + diff --git a/public/traffic-guide.html b/public/traffic-guide.html index c4e810c..7cf653b 100644 --- a/public/traffic-guide.html +++ b/public/traffic-guide.html @@ -64,7 +64,7 @@
- + diff --git a/public/tx.html b/public/tx.html index 74c0ac2..6c917cc 100644 --- a/public/tx.html +++ b/public/tx.html @@ -35,7 +35,7 @@

← Back to the live ledger · Read the contract review

- + diff --git a/public/wall.html b/public/wall.html index e30aef8..3573fbe 100644 --- a/public/wall.html +++ b/public/wall.html @@ -49,7 +49,7 @@ - + diff --git a/public/wallet.html b/public/wallet.html index 338e41d..3376a87 100644 --- a/public/wallet.html +++ b/public/wallet.html @@ -32,7 +32,7 @@ - + diff --git a/public/wallets.html b/public/wallets.html index ace8acc..e0ea3bc 100644 --- a/public/wallets.html +++ b/public/wallets.html @@ -120,7 +120,7 @@
Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never share your recovery phrase.
- + diff --git a/public/zones.html b/public/zones.html index 7dd0355..15f9841 100644 --- a/public/zones.html +++ b/public/zones.html @@ -42,7 +42,7 @@ - + diff --git a/qa/run.sh b/qa/run.sh index 4d98372..45c255a 100644 --- a/qa/run.sh +++ b/qa/run.sh @@ -65,6 +65,7 @@ elif [ "$MODE" = "launchweek" ]; then node qa/launchweek.test.cjs || status=1 elif [ "$MODE" = "member" ]; then start_local 8796 && { LOCAL=http://127.0.0.1:8796 node qa/walk.mjs member || status=1; }; stop_local 8796 + node qa/tank-hold.test.mjs || status=1 node qa/profile-policy.test.cjs || status=1 elif [ "$MODE" = "policy" ]; then node qa/profile-policy.test.cjs || status=1 diff --git a/qa/sponsorfollow.test.cjs b/qa/sponsorfollow.test.cjs index 707323a..5bb8d96 100644 --- a/qa/sponsorfollow.test.cjs +++ b/qa/sponsorfollow.test.cjs @@ -173,6 +173,31 @@ async function network() { assert.strictEqual(P.chats.length, 1); assert.strictEqual(Q.chats.length, 0, 'no chat on the quiet side'); const qr = await Q.tank.adopt('other@x.co', 'lead'); assert.ok(qr.error, 'cannot be adopted twice across the network'); }); + await t('Who invited you: the member names a sponsor on one platform, the other follows and agrees (2026-11-07)', async () => { + const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q); + const r = await P.tank.nameSponsor('lead@x.co', 'adopter'); assert.ok(r.ok, JSON.stringify(r)); + assert.strictEqual(P.store.get('lead@x.co').by, 'invited'); + const s = await settle(P, Q, ['lead@x.co', 'adopter@x.co']); + assert.strictEqual(s.moves, 1); assert.strictEqual(await spOf(Q, 'lead@x.co'), 'adopter@x.co'); + assert.ok(!(await Q.tank.waiting()).some(w => w.email === 'lead@x.co'), 'gone from the other waiting list'); + assert.strictEqual(Q.store.get('lead@x.co').by, 'invited'); assert.strictEqual(Q.store.get('lead@x.co').origin, 'instantadpay'); + assert.ok((await Q.tank.adopt('other@x.co', 'lead')).error, 'nobody adopts them on the other side'); + assert.ok((await Q.tank.nameSponsor('lead@x.co', 'otheradopter')).error, 'the other side refuses a second name'); + }); + await t('Who invited you: a bound member on the other platform keeps that sponsor; reported, not moved', async () => { + const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q); + Q.bound.add('lead@x.co'); + const r = await P.tank.nameSponsor('lead@x.co', 'adopter'); assert.ok(r.ok, JSON.stringify(r)); + const { d } = await deliver(P, Q, 'lead@x.co'); + assert.strictEqual(d.action, 'bound'); assert.strictEqual(await spOf(Q, 'lead@x.co'), null); + }); + await t('sign-up grace holds on both platforms', async () => { + const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q); + for (const X of [P, Q]) X.accounts.add('fresh@x.co', { username: 'fresh', created: Date.now() }); + for (const X of [P, Q]) assert.ok(/less than 24 hours/.test((await X.tank.adopt('adopter@x.co', 'fresh')).error || ''), X.name); + assert.strictEqual(await spOf(P, 'fresh@x.co'), null); assert.strictEqual(await spOf(Q, 'fresh@x.co'), null); + }); + await t('ping-pong guard: the applied change comes back as "same" and settles in one round trip', async () => { const P = platform('instantadpay', 'linkspin'), Q = platform('linkspin', 'instantadpay'); people(P, Q); await P.tank.adopt('adopter@x.co', 'lead'); diff --git a/qa/tank-hold.test.mjs b/qa/tank-hold.test.mjs index ce4dfc7..d73aa53 100644 --- a/qa/tank-hold.test.mjs +++ b/qa/tank-hold.test.mjs @@ -190,12 +190,157 @@ async function partA() { } // ---------------- Part B ---------------- +// ---------------- Sign-up grace + "Who invited you?" (Marty approved 2026-11-07) ---------------- +async function partGrace() { + console.log('-- Sign-up grace + Who invited you: tank.js with a mocked clock'); + const M = 60000; + { // hand adoption: blocked for 24 hours from created, open after, old members untouched + const B = bench(); const { tank, accounts, env } = B; const t0 = env.now; + B.buyer('ad@x.co', 11); + accounts.add('new@x.co', { created: t0 - H }); accounts.add('old@x.co'); + const w = await tank.waiting(); const row = w.find(x => x.email === 'new@x.co'); + ok(row && row.opensAt === t0 + 23 * H, 'waiting(): new sign-up carries opensAt = created + 24 h', JSON.stringify(row)); + ok(w.find(x => x.email === 'old@x.co').opensAt === 0, 'waiting(): an old account is open now'); + ok(w[w.length - 1].email === 'new@x.co', 'waiting(): grace members sort after the open ones'); + ok((await tank.adoptable()).every(x => x.email !== 'new@x.co'), 'adoptable() leaves out grace members (Overview note, weekly email)'); + const r = await tank.adopt('ad@x.co', 'new', 'hi'); + ok(r.error && /less than 24 hours/.test(r.error) && /23 h 0 min/.test(r.error), 'grace blocks a hand adoption with a plain message', JSON.stringify(r)); + ok(!(await accounts.byEmail('new@x.co')).sponsorRef, '...and writes no sponsor'); + ok(!B.mails.length && !B.chats.length, '...and tells nobody'); + env.now = t0 + 23 * H - M; + ok((await tank.adopt('ad@x.co', 'new', 'hi')).error, 'still blocked one minute before it opens'); + env.now = t0 + 23 * H + M; + const r2 = await tank.adopt('ad@x.co', 'new', 'hi'); + ok(r2.ok, 'opens after 24 hours', JSON.stringify(r2)); + const r3 = await tank.adopt('ad@x.co', 'old', 'hi'); + ok(r3.ok, 'an old account is adoptable at once (back in the tank later = no grace)', JSON.stringify(r3)); + } + { // wallet in the first hour: hand adoption opens at 24 h, the safety net keeps its own clock + const B = bench(); const { tank, accounts, env } = B; const t0 = env.now; + B.buyer('ad@x.co', 11); B.buyer('ad2@x.co', 12); + accounts.add('w@x.co', { created: t0 }); + env.now = t0 + H; accounts._by.get('w@x.co').address = addr(); accounts._by.get('w@x.co').lastSeen = env.now; + const t1 = await tank.readyTick(); + ok(t1.fresh.length === 0, 'wallet in the first hour: no "adopt them" notice during the grace', JSON.stringify(t1.fresh)); + const h = await tank.holdFor(await accounts.byEmail('w@x.co')); + ok(h.hold.since === t0 + H && h.hold.until === t0 + 25 * H, 'the hold clock runs from the wallet link, not stretched by the grace', JSON.stringify(h.hold)); + env.now = t0 + 23 * H; ok((await tank.readyTick()).fresh.length === 0, 'still no notice at 23 hours'); + ok((await tank.adopt('ad@x.co', 'w', 'hi')).error, 'hand adoption refused at 23 hours'); + env.now = t0 + 24 * H + M; for (const em of ['ad@x.co', 'ad2@x.co']) accounts._by.get(em).lastSeen = env.now; + const t2 = await tank.readyTick(); + ok(t2.fresh.length === 1 && t2.fresh[0].until === t0 + 25 * H && !t2.assigned.length, 'grace over: notice once, with the real end of the hold', JSON.stringify(t2.fresh)); + ok(tank.leftText(t2.fresh[0].until - env.now) === '59 min', 'the notice text can say the time really left', tank.leftText(t2.fresh[0].until - env.now)); + ok((await tank.readyTick()).fresh.length === 0, '...and not twice'); + env.now = t0 + 25 * H - 10 * M; + const t3 = await tank.readyTick(); + ok(t3.assigned.length === 1 && t3.assigned[0].adoptee === 'w@x.co', 'the rotation takes them inside 24 hours of the wallet link', JSON.stringify(t3.assigned)); + } + { // wallet in the first minutes: the rotation fires just before the grace ends, no notice ever goes out + const B = bench(); const { tank, accounts, env } = B; const t0 = env.now; + B.buyer('ad@x.co', 11); + accounts.add('fast@x.co', { created: t0, address: addr() }); + env.now = t0 + 5 * M; ok((await tank.readyTick()).fresh.length === 0, 'wallet in minute 5: no notice'); + env.now = t0 + 24 * H - 5 * M; accounts._by.get('ad@x.co').lastSeen = env.now; + const t = await tank.readyTick(); + ok(t.assigned.length === 1 && t.fresh.length === 0, 'auto path unaffected: assigned inside the grace (24 h from the wallet link), no adopt notice', JSON.stringify({ a: t.assigned, f: t.fresh })); + ok((await accounts.byEmail('fast@x.co')).sponsorRef === 'ad', 'the safety net wrote the sponsor'); + } + { // grace ends in the last tick of the hold: the safety net takes them, nobody is told to adopt someone already gone + const B = bench(); const { tank, accounts, env } = B; const t0 = env.now; + B.buyer('ad@x.co', 11); + accounts.add('mid@x.co', { created: t0 }); + env.now = t0 + 10 * M; accounts._by.get('mid@x.co').address = addr(); await tank.readyTick(); + env.now = t0 + 24 * H + M; accounts._by.get('ad@x.co').lastSeen = env.now; // 9 minutes of hold left: inside the last tick + const t = await tank.readyTick(); + ok(t.assigned.length === 1 && t.fresh.length === 0, 'no notice for someone the rotation takes in the same tick', JSON.stringify({ a: t.assigned, f: t.fresh })); + } + { // the arrivals post: announced when the grace ends + const B = bench(); const { tank, env } = B; const t0 = env.now; + const list = [{ email: 'a', joined: t0 - 24 * H - 5 * M }, { email: 'b', joined: t0 - 24 * H - 20 * M }, { email: 'c', joined: t0 - H }]; + ok(tank.openedSince(list, t0 - 15 * M).map(x => x.email).join() === 'a', 'openedSince: only people whose grace ended since the last check'); + } + { // Who invited you: every refusal, nothing written + const B = bench(); const { tank, accounts, env } = B; const t0 = env.now; + B.buyer('boss@x.co', 21); + accounts.add('m@x.co', { username: 'mm1', created: t0 }); + accounts.add('kid@x.co', { username: 'kid', sponsorRef: 'mm1' }); // joined under m: a loop + accounts.add('free@x.co', { username: 'free' }); // no payouts, nobody above them + accounts.add('under@x.co', { username: 'under', sponsorRef: 'boss' }); // no payouts, but boss above them + accounts.add('has@x.co', { username: 'hassp', sponsorRef: 'boss' }); + accounts.add('bound@x.co', { username: 'bound1', memberId: 55 }); + const say = async (e, who) => { const r = await tank.nameSponsor(e, who); return r.error || ''; }; + ok(/Type the username/.test(await say('m@x.co', ' ')), 'refused: empty'); + ok(/That is you/.test(await say('m@x.co', '@MM1')), 'refused: self (any case, leading @)'); + ok(/No member here/.test(await say('m@x.co', 'nosuchname')), 'refused: unknown username'); + ok(/No member here/.test(await say('m@x.co', 'bad name!')), 'refused: not a username'); + ok(/already have a sponsor/.test(await say('has@x.co', 'boss')), 'refused: already sponsored'); + ok(/locked on the contract/.test(await say('bound@x.co', 'boss')), 'refused: member id'); + ok(/in your own line/.test(await say('m@x.co', 'kid')), 'refused: chain loop (inDownlineOf)'); + ok(/nobody above them/.test(await say('m@x.co', 'free')), 'refused: nobody on the contract in that line (would fall to the company)'); + B.blocked.add(21); + ok(/cannot take new members/.test(await say('m@x.co', 'boss')), 'refused: no-payout chain'); + B.blocked.delete(21); + ok(!(await accounts.byEmail('m@x.co')).sponsorRef && !B.mails.length, 'no refusal wrote a sponsor or sent a notice'); + const c = await tank.nameSponsor('m@x.co', 'boss', { check: true }); + ok(c.ok && c.name === '@boss' && !(await accounts.byEmail('m@x.co')).sponsorRef && !B.mails.length, 'check mode validates and writes nothing', JSON.stringify(c)); + ok((await tank.nameSponsor('m@x.co', 'under', { check: true })).ok, 'a sponsor with no payouts but someone above them on the contract is allowed'); + B.net['m2@x.co'] = { sponsorEmail: 'boss@x.co', via: 'email' }; + accounts.add('m2@x.co', { username: 'mm2' }); + const al = await tank.nameSponsor('m2@x.co', 'under'); + ok(al.error && al.aligned && (await accounts.byEmail('m2@x.co')).sponsorRef === 'boss', 'the sponsor the network already knows comes first', JSON.stringify(al)); + } + { // Who invited you: success + const B = bench(); const { tank, accounts, env } = B; const t0 = env.now; + B.buyer('boss@x.co', 21); B.buyer('ad@x.co', 22); + accounts.add('m@x.co', { username: 'mm1', created: t0 }); + const m0 = await accounts.byEmail('m@x.co'); + ok(tank.inviteAsk(m0) && tank.inviteAsk(m0).dismissed === false, 'inviteAsk: the card shows for a tank member'); + ok(tank.inviteAsk(await accounts.byEmail('boss@x.co')) === null, 'inviteAsk: no card for a member with a sponsor line / member id'); + tank.dismissInvite('m@x.co'); + ok(tank.inviteAsk(m0).dismissed === true, 'Nobody invited me: card dismissed'); + ok(!(await accounts.byEmail('m@x.co')).sponsorRef && (await tank.waiting()).some(w => w.email === 'm@x.co'), '...nothing else changes: still in the tank'); + const r = await tank.nameSponsor('m@x.co', '@Boss'); + ok(r.ok && r.name === '@boss', 'prompt success', JSON.stringify(r)); + const a = await accounts.byEmail('m@x.co'); + ok(a.sponsorRef === 'boss', 'sponsor written'); + ok((await tank.holdFor(a)) === null && tank.inviteAsk(a) === null, 'hold gone, card gone'); + ok(!(await tank.waiting()).some(w => w.email === 'm@x.co'), 'out of the waiting list'); + ok(B.mails.length === 1 && B.mails[0].to === 'boss@x.co' && /new referral/.test(B.mails[0].subject), 'the named sponsor gets the notice, nobody else', JSON.stringify(B.mails.map(x => x.to))); + ok(!B.chats.length, 'no chat written in the sponsor\'s name'); + const v = await tank.adminView(); const rec = v.adoptions.find(x => x.adoptee === 'm@x.co'); + ok(rec && rec.status === 'invited' && rec.adopter === 'boss@x.co', 'admin record: status invited'); + ok((await tank.summaryFor('m@x.co')) === null, 'not an adoption: nothing counts toward the two, nothing open on the other site'); + const again = await tank.nameSponsor('m@x.co', 'ad'); + ok(/already have a sponsor/.test(again.error || '') && (await accounts.byEmail('m@x.co')).sponsorRef === 'boss', 'a second name is refused'); + env.now = t0 + 8 * 86400000; await tank.sweep(); + ok((await accounts.byEmail('m@x.co')).sponsorRef === 'boss', 'no 7-day window: still theirs after a week'); + } + { // a ready member names someone: the hold record clears the way an adoption does, no auto-assign + const B = bench(); const { tank, accounts, env } = B; const t0 = env.now; + B.buyer('boss@x.co', 21); B.buyer('ad@x.co', 22); + accounts.add('r@x.co', { username: 'rr1', created: t0, address: addr() }); + await tank.readyTick(); + ok(tank.readyRec('r@x.co'), 'setup: on the 24-hour clock'); + const r = await tank.nameSponsor('r@x.co', 'boss'); + ok(r.ok && !tank.readyRec('r@x.co'), 'the hold record clears', JSON.stringify(r)); + env.now = t0 + 24 * H; + for (const em of ['boss@x.co', 'ad@x.co']) accounts._by.get(em).lastSeen = env.now; + ok(!(await tank.readyTick()).assigned.length && (await accounts.byEmail('r@x.co')).sponsorRef === 'boss', 'the rotation leaves them alone'); + await sleep(40); + ok(B.sends.length === 1 && B.sends[0].sponsorId === 21, 'wallet linked: the engine switches payouts on under the named sponsor, same as an adoption', JSON.stringify(B.sends)); + const B2 = bench(); B2.buyer('boss@x.co', 21); const w = addr(); B2.accounts.add('c@x.co', { username: 'cc1', address: w }); B2.onchain.set(w, 77); + ok(/locked on the contract/.test((await B2.tank.nameSponsor('c@x.co', 'boss')).error || ''), 'refused: wallet already on the contract, member number not saved yet'); + } +} + async function partB() { console.log('-- Part B: local copy + mock InstantAdPay'); const PORT = Number(process.env.TANKHOLD_PORT || 8803), IAPPORT = PORT + 1; const BASE = 'http://127.0.0.1:' + PORT; const ADMIN_PW = 'localtest-th'; const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'ls-tankhold-srv-')); fs.mkdirSync(path.join(DATA, 'uploads')); const SECRET = crypto.randomBytes(24).toString('hex'); // throwaway + { const a = { email: 'qa-sponsor@example.com', pass: null, sponsorRef: '', code: 'cqasp1', username: 'qasponsor', address: null, created: Date.now() - 30 * 86400000, lastSeen: Date.now() - H, memberId: 42 }; // a member with a contract position, for the Who invited you checks + fs.writeFileSync(path.join(DATA, 'accounts.json'), JSON.stringify({ v: 2, byEmail: { [a.email]: a }, byAddress: {}, byCode: { [a.code]: a.email }, joins: 0, positions: {} })); } const iapRows = {}; let factsCalls = 0; const mock = http.createServer((req, res) => { let d = ''; req.on('data', c => d += c); req.on('end', () => { const sig = crypto.createHmac('sha256', SECRET).update(String(req.headers['x-ls-ts'] || '') + '\n' + d).digest('hex'); @@ -281,6 +426,48 @@ async function partB() { ok(!st.act && st.buy && !st.hold, 'Credits: no Switch on payouts button, Buy still there, no hold box on the buy side', JSON.stringify(st)); try { fs.mkdirSync(path.join(SITE, 'qa/out'), { recursive: true }); await page.screenshot({ path: path.join(SITE, 'qa/out/tank-hold-credits.png'), fullPage: true }); } catch (e) {} ok(!errs.length, 'no page errors', errs.join(' | ').slice(0, 200)); + { // Who invited you + the sign-up grace, on the real pages (2026-11-07) + const nc = await signIn('qa-new@example.com'); await req('POST', '/api/my/profile', { cookie: nc, body: { username: 'qanewone' } }); + const m0 = (await req('GET', '/api/me', { cookie: nc })).json; + ok(m0 && m0.inviteAsk && m0.inviteAsk.dismissed === false, '/api/me: inviteAsk for a tank member', JSON.stringify(m0 && m0.inviteAsk)); + const sc = await signIn('qa-sponsor@example.com'); + const tv = (await req('GET', '/api/my/tank', { cookie: sc })).json; const row6 = tv && tv.waiting.find(w => w.email === 'qa-new@example.com'); + ok(row6 && row6.opensAt > Date.now(), '/api/my/tank: a new sign-up is listed with opensAt', JSON.stringify(row6)); + const bad = await req('POST', '/api/my/tank/invited', { cookie: nc, body: { who: 'nosuchname' } }); + ok(bad.status === 400 && /No member here/.test(bad.json.error), 'POST invited: unknown username refused', JSON.stringify(bad.json)); + const self = await req('POST', '/api/my/tank/invited', { cookie: nc, body: { who: 'qanewone' } }); + ok(self.status === 400 && /That is you/.test(self.json.error), 'POST invited: self refused', JSON.stringify(self.json)); + ok((await req('POST', '/api/my/tank/invited', { body: { who: 'qasponsor' } })).status === 401, 'POST invited: signed out refused'); + const c2 = await browser.newContext({ viewport: { width: 390, height: 900 } }); + await c2.addInitScript(() => { try { sessionStorage.setItem('ls.la', '1'); } catch (e) {} }); + await c2.addCookies(nc.split('; ').filter(Boolean).map(kv => { const i = kv.indexOf('='); return { name: kv.slice(0, i), value: kv.slice(i + 1), domain: '127.0.0.1', path: '/' }; })); + const pg = await c2.newPage(); pg.on('pageerror', e => errs.push(e.message)); + await pg.goto(BASE + '/links', { waitUntil: 'load' }); await pg.waitForSelector('#crInvite', { timeout: 15000 }).catch(() => {}); + const has = sel => pg.evaluate(s => !!document.querySelector(s), sel); + ok(await has('#inviteWho'), 'Control Room (/links): Who invited you box shows'); + const over = await pg.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + ok(over <= 0, 'no sideways scroll at phone width', String(over)); + await pg.screenshot({ path: path.join(SITE, 'qa/out/tank-invite-card.png') }).catch(() => {}); + await pg.fill('#inviteWho', 'nosuchname'); await pg.click('#inviteGo'); await pg.waitForTimeout(700); + ok(/No member here/.test(await pg.textContent('#inviteMsg')), 'box: the refusal shows in the box'); + await pg.click('#inviteNo'); await pg.waitForTimeout(500); + ok(!(await has('#crInvite')), 'Nobody invited me: gone from the screen'); + await pg.goto(BASE + '/links', { waitUntil: 'load' }); await pg.waitForTimeout(2500); + ok(!(await has('#crInvite')), 'stays gone on the next screen'); + await pg.goto(BASE + '/tools', { waitUntil: 'load' }); await pg.waitForSelector('#inviteBack', { timeout: 15000 }).catch(() => {}); + ok(await has('#inviteBack'), '/tools: the small link is there'); + await pg.click('#inviteBack'); await pg.fill('#inviteWho', '@qasponsor'); await pg.click('#inviteGo'); await pg.waitForSelector('#dlgNo', { timeout: 5000 }); + await pg.click('#dlgNo'); await pg.waitForTimeout(400); + ok(!(await req('GET', '/api/me', { cookie: nc })).json.sponsorName, 'box: Not them writes nothing'); + await pg.click('#inviteGo'); await pg.waitForSelector('#dlgOk', { timeout: 5000 }); await pg.click('#dlgOk'); await pg.waitForTimeout(3000); + const m1 = (await req('GET', '/api/me', { cookie: nc })).json; + ok(m1 && m1.sponsorName === '@qasponsor' && !m1.inviteAsk, 'box: yes sets the sponsor, the box is gone', JSON.stringify({ n: m1 && m1.sponsorName, a: m1 && m1.inviteAsk })); + ok(!(await has('#crInvite')), 'box: gone after the reload'); + const adm6 = (await req('GET', '/api/admin/tank', { headers: ADMIN })).json; + ok(adm6.adoptions.some(a => a.adoptee === 'qa-new@example.com' && a.status === 'invited'), 'admin tank: the invited record shows'); + await c2.close(); + ok(!errs.length, 'no page errors (Who invited you)', errs.join(' | ').slice(0, 200)); + } } } finally { if (browser) await browser.close().catch(() => {}); @@ -291,6 +478,7 @@ async function partB() { } await partA(); +await partGrace(); if (process.argv[2] !== 'unit') await partB(); console.log(fails ? '\n' + fails + ' FAILED' : '\nall passed'); process.exit(fails ? 1 : 0); diff --git a/server.js b/server.js index fc5737e..6d88d28 100644 --- a/server.js +++ b/server.js @@ -733,6 +733,7 @@ async function boot() { hooks: { network: (email, address) => networkSponsor(email, address), prefetch: emails => iapFacts(emails, { timeout: 20000 }), iapOwns: (email, o) => iapOwnsTank(email, o), bound: async a => { const id = Number(await chain.memberIdByAccount(a.address)) || 0; if (id) await accounts.setMemberId(a.email, id).catch(() => {}); return id; }, payoutBlocked: id => payoutChainBlocked(id, 2), companyId: () => Number(siteConfig().defaultSponsorId) || 1, + notify: (email, subject, text) => messages.deliver(1, ADMIN_EMAIL || 'house@' + SITE_HOST, [email], subject, '

' + String(text).replace(/&/g, '&').replace(//g, '>').replace(/(https:\/\/[^\s)]+)/g, '$1') + '

'), lifted: email => tankLifted(email), claim: k => marks.claim(k), assigned: r => { tankPickupPost(r.adopterName, r.adopteeName, true); }, adminAlert: text => tankAdminAlert(text) } }); legacy.init({ dataDir: DATA_DIR }); traffic.init({ dataDir: DATA_DIR }); @@ -1170,7 +1171,11 @@ async function tankNotifyTick() { const f = path.join(DATA_DIR, 'tank-notify.json'); let st = { last: 0 }; try { st = JSON.parse(fs.readFileSync(f, 'utf8')); } catch (e) {} const since = st.last || (Date.now() - 24 * 3600 * 1000); - const fresh = (await tank.waiting()).filter(w => (w.joined || 0) > since); + // sign-up grace (2026-11-07): announced when they can be adopted, 24 hours after sign-up, not when they arrive. graceFrom = + // the first run of this rule: anyone who joined before it was already announced at sign-up. + const graceFrom = st.graceFrom || (st.graceFrom = st.last || Date.now()); + const fresh = []; + for (const w of tank.openedSince(await tank.waiting(), since)) if ((w.joined || 0) > graceFrom && await marks.claim('tankopen:' + w.email + ':' + (w.joined || 0))) fresh.push(w); st.last = Date.now(); fs.writeFileSync(f, JSON.stringify(st)); if (!fresh.length) return; const named = fresh.filter(w => w.username).map(w => '@' + w.username); @@ -1265,10 +1270,10 @@ async function tankReadyTick() { const clean = t => String(t || '').replace(/[<>&]/g, ''); const link = SITE_URL + '/tools#line'; if (r.fresh.length <= 3) { - for (const w of r.fresh) await telegramSend(sc.telegramEchoChatId, '\u{1F7E2} LinkSpin \u00b7 ' + (w.username ? '@' + clean(w.username) : 'A new member') + ' linked a wallet and is ready to switch on payouts. Adopt them from the holding tank in the next 24 hours: ' + link, sc.telegramEchoTopicId).catch(() => {}); + for (const w of r.fresh) await telegramSend(sc.telegramEchoChatId, '\u{1F7E2} LinkSpin \u00b7 ' + (w.username ? '@' + clean(w.username) : 'A new member') + ' linked a wallet and is ready to switch on payouts. Adopt them from the holding tank in the next ' + tank.leftText(w.until - Date.now()) + ': ' + link, sc.telegramEchoTopicId).catch(() => {}); } else { // first run after deploy (the members already linked) or a busy quarter hour: one digest, not a wall of posts const named = r.fresh.filter(w => w.username).map(w => '@' + clean(w.username)); - await telegramSend(sc.telegramEchoChatId, '\u{1F7E2} LinkSpin \u00b7 ' + r.fresh.length + ' members linked a wallet and are ready to switch on payouts' + (named.length ? ': ' + named.slice(0, 12).join(', ') + (named.length > 12 ? ' and ' + (named.length - 12) + ' more' : '') : '') + '. Adopt them from the holding tank in the next 24 hours: ' + link, sc.telegramEchoTopicId).catch(() => {}); + await telegramSend(sc.telegramEchoChatId, '\u{1F7E2} LinkSpin \u00b7 ' + r.fresh.length + ' members linked a wallet and are ready to switch on payouts' + (named.length ? ': ' + named.slice(0, 12).join(', ') + (named.length > 12 ? ' and ' + (named.length - 12) + ' more' : '') : '') + '. Adopt them from the holding tank in the next ' + tank.leftText(Math.min(...r.fresh.map(w => w.until)) - Date.now()) + ': ' + link, sc.telegramEchoTopicId).catch(() => {}); } return r; } @@ -2042,6 +2047,7 @@ const server = http.createServer(async (req, res) => { const out = { signedIn: true, sponsorBlocked, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null, address: s.address || (acct && acct.address) || null, memberId, username: (acct && acct.username) || null, theme: (acct && acct.theme) || null, + inviteAsk: !memberId && acct ? tank.inviteAsk(acct) : null, // the Who invited you card (2026-11-07) refCode: (acct && acct.code) || null, sponsorId, tankHold, // profile + line-banner fields so the Profile pane repopulates on reload (were being saved but not returned) avatarUrl: (acct && acct.avatarUrl) || null, bio: (acct && acct.bio) || null, @@ -2069,7 +2075,7 @@ const server = http.createServer(async (req, res) => { let tankWaiting = null; // top of every Overview: people waiting for a sponsor (Marty, 2026-09-12) try { if (!tankWaitCache || Date.now() - tankWaitCache.ts > 60000) tankWaitCache = { ts: Date.now(), list: await tank.waiting() }; - const tw = tankWaitCache.list; + const tw = tank.adoptableOf(tankWaitCache.list); // only people who can be adopted right now (sign-up grace, 2026-11-07) tankWaiting = { count: tw.length, names: tw.slice(0, 6).map(w => w.name), eligible: !!(await tank.eligibility(s.email)).ok, ready: tw.filter(w => w.ready).length }; } catch (e) {} const sc0 = siteConfig(); @@ -2530,6 +2536,19 @@ const server = http.createServer(async (req, res) => { if (r.ok) tankPickupPost(r.adopterName, r.adopteeName, false); // tell the payments topic who picked whom up (Marty, 2026-09-12) return json(res, r.error ? 400 : 200, r); } + // "Who invited you?" (Marty approved 2026-11-07): the signed-in member names their own sponsor. check: validate only. + if (p === '/api/my/tank/invited' && req.method === 'POST') { + const s = await auth.fromRequest(req); + if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); + const b = await readBody(req); + const r = await tank.nameSponsor(s.email, b.who, { check: !!b.check }); + return json(res, r.error ? 400 : 200, r); + } + if (p === '/api/my/tank/invited/dismiss' && req.method === 'POST') { // "Nobody invited me": hides the card, nothing else changes + const s = await auth.fromRequest(req); + if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); + return json(res, 200, tank.dismissInvite(s.email)); + } if (p === '/api/my/tank/release' && req.method === 'POST') { const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); diff --git a/sponsorfollow.js b/sponsorfollow.js index 3e5613a..c330946 100644 --- a/sponsorfollow.js +++ b/sponsorfollow.js @@ -30,7 +30,7 @@ const fs = require('fs'); const path = require('path'); const crypto = require('crypto'); -const DELIBERATE = ['adopt', 'rescue', 'release', 'expire', 'admin']; +const DELIBERATE = ['adopt', 'rescue', 'release', 'expire', 'admin', 'invited']; // invited = the member named who invited them (tank.js nameSponsor, 2026-11-07) const WINDOW_MS = 15 * 60 * 1000; const PROTO = 2; // wire version: 2 = rows may carry sponsorSet* + tank, peers answer { proto: 2 } const n = v => String(v == null ? '' : v).trim().toLowerCase(); diff --git a/tank.js b/tank.js index 12bdedf..ec747a9 100644 --- a/tank.js +++ b/tank.js @@ -17,11 +17,15 @@ const TTL_MS = 7 * 86400000; // an adoption's window to convert const MAX_ADOPTIONS = 2; // per adoptee, lifetime (dropped adoptions count too, since 2026-09-13) const HOLD_MS = 3 * 24 * 3600 * 1000; // an adoption is a commitment: no releasing someone you picked up less than 3 days ago (Marty, 2026-09-13) // statuses that do not count toward a person's two adoptions: a release record, and the later side of a network race -// (both sites adopted the same person within minutes; the earlier adoption won on both, sponsorfollow.js) -const NOT_COUNTED = ['released', 'conflict']; +// (both sites adopted the same person within minutes; the earlier adoption won on both, sponsorfollow.js), and a record of a +// member naming who invited them (nobody adopted them; nameSponsor below) +const NOT_COUNTED = ['released', 'conflict', 'invited']; const MIN_OWN_BUY_CENTS = 2500; // adopter must have bought a qualifying ($25+) package themselves const WARN_DAYS = 10; // dormant lead: sponsor warned after this many days without contact const RESCUE_DAYS = 14; // ...and the lead moves to the tank after this many (warning at least 4 days old) +const GRACE_MS = 24 * 3600 * 1000; // nobody adopts a new sign-up by hand for this long after `created`, so they can say who invited them (Marty 2026-11-07) +const BRAND = 'LinkSpin'; +const LINE_URL = () => siteUrl + '/tools#line'; let DATA_DIR = '.', accounts, chain, messages, mailer, siteUrl = SITE_URL; @@ -49,10 +53,10 @@ const D = { const rows = adopter ? await db.q("SELECT * FROM adoptions WHERE status='open' AND adopter=?", [adopter]) : await db.q("SELECT * FROM adoptions WHERE status='open'"); return rows.map(rowA); }, - async countFor(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict')", [adoptee]); return Number(r[0].n); }, + async countFor(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict','invited')", [adoptee]); return Number(r[0].n); }, async setStatus(id, status) { await db.q('UPDATE adoptions SET status=?, closed=? WHERE id=?', [status, Date.now(), Number(id)]); }, async recent(n) { return (await db.q('SELECT * FROM adoptions ORDER BY id DESC LIMIT ?', [Number(n) || 100])).map(rowA); }, - async hasRecord(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict')", [adoptee]); return Number(r[0].n) > 0; }, + async hasRecord(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict','invited')", [adoptee]); return Number(r[0].n) > 0; }, async all() { return (await db.q('SELECT * FROM adoptions ORDER BY id')).map(rowA); }, async mark(lead) { const r = await db.q('SELECT * FROM lead_marks WHERE `lead`=?', [lead]); return r[0] ? { sponsor: r[0].sponsor, contacted: Number(r[0].contacted_ts || 0), warned: Number(r[0].warned_ts || 0) } : null; }, async setMark(lead, f) { @@ -83,9 +87,10 @@ async function waiting() { const all = await accounts.listAll(2000); return all.filter(a => inTank(a) && !remoteOpen(a.email)).map(a => ({ email: a.email, name: nameOf(a), username: a.username || null, joined: a.created, lastSeen: a.lastSeen || 0, wallet: !!a.address, // wallet linked = ready to switch on payouts, the plain activation held for an adopter (24-hour clock, autoAssign after that) + opensAt: inGrace(a) ? graceEnd(a) : 0, // new sign-up: nobody can adopt them by hand before this (0 = open now) ...(() => { const r = a.address ? readyRec(a.email) : null; return r ? { ready: true, readyAt: r.readyAt, holdUntil: r.readyAt + READY_MS } : { ready: false }; })() })) - // ready members first (least time left first), then newest sign-in - .sort((a, b) => (b.ready ? 1 : 0) - (a.ready ? 1 : 0) || (a.ready && b.ready ? a.readyAt - b.readyAt : 0) || (b.lastSeen || b.joined) - (a.lastSeen || a.joined)); + // open before the sign-up grace ones, ready members first (least time left first), then newest sign-in + .sort((a, b) => (a.opensAt ? 1 : 0) - (b.opensAt ? 1 : 0) || (b.ready ? 1 : 0) - (a.ready ? 1 : 0) || (a.ready && b.ready ? a.readyAt - b.readyAt : 0) || (b.lastSeen || b.joined) - (a.lastSeen || a.joined)); } // has this member bought a $25 or larger package themselves? (the qualifying-for-yourself buy) @@ -112,7 +117,7 @@ async function view(email) { const a = await accounts.byEmail(ad.adoptee); mine.push({ id: ad.id, name: a ? nameOf(a) : mask(ad.adoptee), email: ad.adoptee, ts: ad.ts, expires: ad.expires, lastSeen: a ? (a.lastSeen || 0) : 0, wallet: !!(a && a.address), address: (a && a.address) || null, bought: !!(a && a.memberId) }); } - return { eligible: el.ok, reason: el.ok ? '' : el.reason, cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, waiting: await waiting(), mine }; + return { eligible: el.ok, reason: el.ok ? '' : el.reason, cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, graceHours: GRACE_MS / 3600000, waiting: await waiting(), mine }; } async function adopt(adopterEmail, who, note, opts) { @@ -126,6 +131,7 @@ async function adopt(adopterEmail, who, note, opts) { const target = list.find(w => (w.username && w.username.toLowerCase() === key) || w.email === key); if (!target) return { error: 'That member is no longer in the tank.' }; if (target.email === e) return { error: 'That is you.' }; + if (!auto && target.opensAt > clock()) return { error: 'That member joined less than 24 hours ago, so they still have time to tell us who invited them. You can adopt them in ' + leftText(target.opensAt - clock()) + '.' }; // the safety net is not held by this: it keeps its 24-hour clock from the wallet link if (remoteOpen(target.email)) return { error: 'That member was just picked up on ' + OTHER + ', so they are no longer in the tank.' }; if (!auto && await countAll(target.email) >= MAX_ADOPTIONS) return { error: 'That member has been adopted twice already and stays where they are.' }; // the safety net never leaves anyone to the company const token = me.username || me.code || String(me.memberId); @@ -510,9 +516,11 @@ async function readyTick() { if (await alignToNetwork(a).catch(() => null)) { aligned++; continue; } if (remoteOpen(a.email)) continue; const rec = markReady(a); - if (rec && !rec.notified) { + // Sign-up grace (2026-11-07): no "adopt them" post for someone who cannot be adopted yet; announced when the grace ends, + // and not at all when the safety net takes them in this same tick (nothing left for anyone to do) + if (rec && !rec.notified && !inGrace(a)) { rec.notified = clock(); - const iap = hooks.iapOwns ? await Promise.resolve(hooks.iapOwns(a.email)).catch(() => false) : false; + const iap = clock() < rec.readyAt + READY_MS - TICK_MS ? (hooks.iapOwns ? await Promise.resolve(hooks.iapOwns(a.email)).catch(() => false) : false) : true; if (!iap && await claimOnce('tankready:' + a.email + ':' + rec.readyAt)) fresh.push({ email: a.email, name: nameOf(a), username: a.username || null, until: rec.readyAt + READY_MS }); } } @@ -567,6 +575,85 @@ async function liftPendingRun() { } function alignedRecent(n) { return RS.load().aligned.slice(-(n || 50)).reverse(); } +// ── sign-up grace + "Who invited you?" (Marty approved 2026-11-07: "24-hour grace plus the prompt") ── +// Nov 2: @santoridaviss signed up with no referral at 10:35 PM, was adoptable at 2:24 AM and adopted at 3:36 AM, before he +// could say who invited him. So: +// GRACE: for 24 hours from the account's `created`, nobody can adopt the person BY HAND. They stay on the waiting list with +// opensAt set (the card shows "Opens in ...", no Adopt button). The dates are each site's own account dates. Only sign-up +// counts: someone back in the tank later (released, rescued, window ended) is past it. +// The safety net does not wait for the grace (opts.auto skips it): Marty's rule is a wallet-linked member is held for no +// longer than 24 hours, so autoAssign keeps its clock from the wallet link. Wallet linked in the first 15 minutes: the +// rotation can fire up to 15 minutes before the grace ends, and hand adoption never opens for them. Wallet linked in the +// first hour: hand adoption opens at 24 hours and the rotation takes them about an hour after that. +// Notices: readyTick announces a ready member only once they can be adopted, and only when time is left (adoptableOf and +// openedSince keep the Overview note, the arrivals post and the weekly email to people who are open too). +// PROMPT: a tank member can name who invited them. nameSponsor() goes through setSponsor like adopt(), so it follows to the +// other site and clears the hold the same way, but it is the member's own choice: only ever for the signed-in member, +// never an open adoption (no 7-day window, no fall-back, no count toward the two), recorded as status 'invited'. +function graceEnd(a) { return (Number(a && a.created) || 0) + GRACE_MS; } +function inGrace(a) { return graceEnd(a) > clock(); } +function leftText(ms) { const m = Math.max(1, Math.ceil(Number(ms) / 60000) || 1); const h = Math.floor(m / 60); return h ? h + ' h ' + (m % 60) + ' min' : m + ' min'; } +const adoptableOf = list => (list || []).filter(w => !(w.opensAt > clock())); +async function adoptable() { return adoptableOf(await waiting()); } +// people whose grace ended after `since` (the arrivals post: announced when they can be adopted, not when they sign up) +function openedSince(list, since) { const now = clock(); return (list || []).filter(w => { const t = (Number(w.joined) || 0) + GRACE_MS; return t > since && t <= now; }); } +// what the dashboard needs: null = no card. dismissed = they tapped "Nobody invited me" (a small link brings the card back). +function inviteAsk(a) { + if (!a || !inTank(a) || remoteOpen(a.email)) return null; + return { dismissed: !!(RS.load().noInvite || {})[String(a.email || '').toLowerCase()] }; +} +function dismissInvite(email) { const st = RS.load(); st.noInvite = st.noInvite || {}; st.noInvite[String(email || '').toLowerCase()] = clock(); RS.save(); return { ok: true }; } +// someone in the named person's line (them first) already has a contract position? Otherwise the member would be walked up to +// the company at their first activation, the one thing the tank exists to stop +async function firstOnContract(sp) { + let cur = sp; const seen = new Set(); + for (let i = 0; cur && i < 60; i++) { if (Number(cur.memberId) > 0) return cur; if (seen.has(cur.email)) return null; seen.add(cur.email); cur = await accounts.sponsorOf(cur.email); } + return null; +} +// opts.check: every refusal, nothing written (the card asks "is this them?" before the real call) +async function nameSponsor(email, who, opts) { + const e = String(email || '').toLowerCase(); const check = !!(opts && opts.check); + const LOCKED = 'Your payouts are already on, so your sponsor is locked on the contract.'; + let a = await accounts.byEmail(e); + if (!a) return { error: 'Sign in first.' }; + if (Number(a.memberId) > 0) return { error: LOCKED }; + if (a.sponsorRef) return { error: 'You already have a sponsor.' }; + if (a.address) { // wallet on the contract already, member number not saved yet + if (hooks.bound) { const id = await Promise.resolve(hooks.bound(a)).catch(() => -1); if (id < 0) return { error: 'Could not check the contract just now. Try again in a minute.' }; if (id > 0) return { error: LOCKED }; } + else if (hooks.activated && await Promise.resolve(hooks.activated(a)).catch(() => false)) return { error: LOCKED }; + } + if (remoteOpen(e)) return { error: 'You were just picked up on ' + OTHER + ', so you already have a sponsor.' }; + const al = await alignToNetwork(a).catch(() => null); // one identity: the sponsor the network already knows comes first + if (al) return { error: 'You already have a sponsor on the network: ' + al.toName + '.', aligned: true }; + const key = String(who || '').trim().toLowerCase().replace(/^@+/, ''); + if (!key) return { error: 'Type the username of the person who invited you.' }; + const sp = /^[a-z0-9_]{3,20}$/.test(key) ? await accounts.byUsername(key) : null; + if (!sp || (accounts.isUnclaimedShell && accounts.isUnclaimedShell(sp))) return { error: 'No member here has the username ' + key + '. Check the spelling with the person who invited you.' }; + if (String(sp.email).toLowerCase() === e) return { error: 'That is you. Type the username of the person who invited you.' }; + const bar = hooks.excluded || hooks.isSuspended; + if (bar && bar(sp.email)) return { error: nameOf(sp) + ' cannot take new members right now.' }; + if (await inDownlineOf(e, sp)) return { error: nameOf(sp) + ' is in your own line, so they cannot be your sponsor.' }; + const payee = await firstOnContract(sp); + if (!payee) return { error: nameOf(sp) + ' has not switched on payouts yet, and nobody above them has either, so you cannot go under them yet. Ask them to switch on payouts, then come back here.' }; + if (hooks.payoutBlocked && await Promise.resolve(hooks.payoutBlocked(Number(payee.memberId))).catch(() => true)) return { error: nameOf(sp) + ' cannot take new members right now.' }; + if (check) return { ok: true, check: true, name: nameOf(sp) }; + a = await accounts.byEmail(e); + if (!a || !inTank(a)) return { error: 'You already have a sponsor.' }; + const token = sp.username || sp.code || String(sp.memberId); + const r = await setSponsor(e, token, 'invited', 'named by the member on the Who invited you card'); + if (r && r.error) return r; + const now = clock(); + const ad = await impl().add({ adoptee: e, adopter: String(sp.email).toLowerCase(), ts: now, expires: now, status: 'invited', note: 'named by the member on the Who invited you card' }); + { const rr = RS.load().ready[e]; if (rr && !rr.done) { rr.done = now; rr.namedSponsor = sp.email; RS.save(); } } // the hold lifts: their sponsor resolves now + const name = nameOf(a); + { const tg = await accounts.byEmail(e); if (tg && tg.address && !(Number(tg.memberId) > 0) && hooks.lifted) { markLift(e); liftRun(e).catch(err => console.error('tank lift', err.message)); } } // wallet already linked: the engine switches payouts on under them, same as an adoption + const subject = 'You have a new referral on ' + BRAND; + const text = name + ' joined ' + BRAND + ' without a sponsor link and told us you invited them, so they are on your team from today. Say hello and help them with their first steps: ' + LINE_URL(); + if (mailer && mailer.hasKey()) { try { await mailer.send(sp.email, subject, text + '\n\n' + BRAND); } catch (err) {} } + if (hooks.notify) { try { await hooks.notify(sp.email, subject, text); } catch (err) {} } + return { ok: true, name: nameOf(sp), sponsorEmail: sp.email, member: name }; +} + async function adminView() { const recent = await impl().recent(200); const names = {}; @@ -574,4 +661,4 @@ async function adminView() { return { waiting: await waiting(), adoptions: recent.map(ad => Object.assign({}, ad, { adopteeName: names[ad.adoptee], adopterName: names[ad.adopter] })), cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, aligned: alignedRecent(30) }; } -module.exports = { init, view, adopt, holdFor, gate, markReady, readyRec, readyTick, autoAssign, alignToNetwork, alignedRecent, setClock, eligibility, inTank, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS }; +module.exports = { init, view, adopt, holdFor, gate, markReady, readyRec, readyTick, autoAssign, alignToNetwork, alignedRecent, setClock, eligibility, inTank, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, adoptable, adoptableOf, openedSince, leftText, inviteAsk, dismissInvite, nameSponsor, GRACE_MS, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };