// Admin > Members > Sponsor check (2026-10-22). The SAME file ships in InstantAdPay and LinkSpin.
// Lists members on both sites whose sponsor differs (or is set on one side only), with when and how each side's sponsor
// was set and whether each side is bound on its contract. "Use X's sponsor" applies X's sponsor on the OTHER site; the
// server refuses when the member is already bound there. Nothing runs until the admin presses "Run the check".
(function () {
const $ = id => document.getElementById(id);
if (!$('scRun')) return;
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', invited: 'the member named who invited them' };
const NAME = { instantadpay: 'InstantAdPay', linkspin: 'LinkSpin' };
function side(f) {
if (!f) return 'no account';
const sp = f.sponsorEmail ? esc(f.sponsorName || f.sponsorEmail) + '
' + esc(f.sponsorEmail) + '' : f.deadLink ? 'dead link: ' + esc(f.sponsorRef) + '' : 'none (in the tank)';
const how = [];
if (f.prov) how.push('' + esc(HOW[f.prov.by] || f.prov.by) + ' ' + esc(day(f.prov.at)) + (f.prov.origin ? ' on ' + esc(NAME[f.prov.origin] || f.prov.origin) : '') + (f.prov.prevEmail ? ', before: ' + esc(f.prov.prevEmail) : ''));
else how.push('no deliberate change on record; account made ' + esc(day(f.created)) + (f.joinedVia ? ' via ' + esc(f.joinedVia) : '') + (f.joinedRef ? ' (' + esc(f.joinedRef) + ')' : ''));
for (const a of (f.adoptions || []).slice(-3)) how.push('tank: ' + esc(a.status) + ' by ' + esc(a.adopter) + ' ' + esc(day(a.ts)));
if (f.remoteTank && f.remoteTank.open) how.push('adopted on the other site by ' + esc(f.remoteTank.adopterEmail));
if (f.pending) how.push('follow waiting: ' + esc(f.pending.why || '') + '');
for (const l of (f.log || []).filter(x => x.conflict).slice(0, 2)) how.push('' + esc(l.action) + ' ' + esc(l.reason || '') + ' ' + esc(day(l.ts)));
const bound = f.bound ? 'bound on chain' + (f.memberId ? ': member #' + f.memberId : '') + (f.activation ? ', on-chain sponsor #' + f.activation.sponsorId + ', block ' + f.activation.block : '') + '' : 'not bound on chain' + (f.wallet ? ' (wallet linked)' : '') + '';
return sp + '
' + how.join('
') + '
' + bound + '
';
}
let last = null;
async function run() {
$('scRun').disabled = true; $('scSub').textContent = 'checking both sites...';
try {
const r = await (await fetch('/api/admin/sponsor-check', { cache: 'no-store' })).json();
if (r.error) throw new Error(r.error === 'auth' ? 'Session expired. Sign in again.' : r.error);
last = r;
if (r.peerError) { $('scSub').textContent = 'could not read the other site: ' + r.peerError; $('scTable').innerHTML = ''; return; }
const differ = r.rows.filter(x => x.kind === 'differ').length;
$('scSub').textContent = r.shared + ' on both sites, ' + r.same + ' match, ' + differ + ' differ, ' + (r.rows.length - differ) + ' set on one side only (' + day(r.at) + ')';
$('scTable').innerHTML = '| Member | InstantAdPay sponsor | LinkSpin sponsor | Settle it |
' + (r.rows.length ? r.rows.map(x => {
const iapBound = !!(x.iap && x.iap.bound), lsBound = !!(x.ls && x.ls.bound);
return '' + esc(x.username ? '@' + x.username : '') + ' ' + esc(x.email) + ' ' + esc(x.kind === 'differ' ? 'different sponsors' : x.kind === 'iap-only' ? 'sponsor on InstantAdPay only' : 'sponsor on LinkSpin only') + ' | '
+ '' + side(x.iap) + ' | ' + side(x.ls) + ' | '
+ ' '
+ ' |
';
}).join('') : '| Every shared member has the same sponsor on both sites. |
');
const logs = [].concat((r.follow && r.follow.recent) || []).map(l => Object.assign({ where: r.here }, l)).concat(((r.peerFollow && r.peerFollow.recent) || []).map(l => Object.assign({ where: r.here === 'linkspin' ? 'instantadpay' : 'linkspin' }, l))).sort((a, b) => b.ts - a.ts).slice(0, 60);
$('scLog').innerHTML = '| When | Site | Member | What | From | To | Why |
' + (logs.length ? logs.map(l => '| ' + esc(day(l.ts)) + ' | ' + esc(NAME[l.where] || l.where) + ' | ' + esc(l.email || '') + ' | ' + (l.conflict ? '' + esc(l.action) + '' : esc(l.action)) + (l.by ? ' ' + esc(HOW[l.by] || l.by) + '' : '') + ' | ' + esc(l.from || '-') + ' | ' + esc(l.to || '(tank)') + ' | ' + esc(l.reason || '') + ' |
').join('') : '| nothing yet |
');
} catch (e) { $('scSub').textContent = e.message; say(e.message, 'bad'); }
finally { $('scRun').disabled = false; }
}
$('scRun').addEventListener('click', run);
document.addEventListener('click', async e => {
const b = e.target.closest('[data-scuse]'); if (!b || b.disabled) return;
const use = b.dataset.scuse, email = b.dataset.email; const row = last && last.rows.find(x => x.email === email); if (!row) return;
const from = use === 'instantadpay' ? row.iap : row.ls; const target = use === 'instantadpay' ? 'LinkSpin' : 'InstantAdPay';
const who = from && from.sponsorEmail ? (from.sponsorName || from.sponsorEmail) : 'no sponsor (back to the holding tank)';
let ok = false;
try { ok = await IAP.confirmBox('Set ' + email + "'s sponsor on " + target + ' to ' + who + '? The other site keeps what it has. This is refused if the member is already bound on the ' + target + ' contract.', { title: 'Use ' + NAME[use] + "'s sponsor", ok: 'Apply on ' + target, cancel: 'Cancel' }); } catch (err) { ok = false; }
if (!ok) return;
b.disabled = true;
try {
const r = await (await fetch('/api/admin/sponsor-check/resolve', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, use }) })).json();
if (r.error) throw new Error(r.error === 'auth' ? 'Session expired. Sign in again.' : r.error);
say('Done: ' + email + ' now has ' + who + ' on ' + target + '.', 'ok'); await run();
} catch (err) { say(err.message, 'bad'); b.disabled = false; }
});
})();