8645b471ae
TANK_MODE=iap (or hub) + IAP_URL + DRAFT_PARTNER_SECRET: pool / adopt / release / status as HMAC-signed POSTs ('draft.v1.' + ts +
newline + body, X-Draft-Ts / X-Draft-Sig). The stub stays the default and keeps every existing test. adopt carries the coach claim
(wallet, hubId, username, positions = store.positionsOf) and a request id; one retry with the same rid on a network failure, so a
retry never makes two adoptions. release sends why 'coach' | 'return' + the pick's iap ref and takes InstantAdPay's outcome
(returned / kept / done). league.sweep follows a pick InstantAdPay closed first (its own 3-day sweep, a release there, a LinkSpin
follow). Surfing arrives as ad credits (surfCredits, shown "N ad credits" to coaches, +10 scouting like surf POL); games stay
"not tracked yet" (InstantAdPay has no per-member game record).
Fix found by the cross test: a tank refusal about the COACH (no InstantAdPay account, full, not vested, hub off) used to mark the
person unavailable and let the same coach choose again, which would burn the whole pool; now the slot passes (skip 'tank: <code>')
and a silent tank pauses the draft (nothing recorded, the next tick retries the same slot). Manual picks record nothing on either.
Tests: unit 62/62 (2 new: skip + wait), smoke 156/156 (ports 3561-3564), qa/iap-tank.test.cjs 23/23 (this client + league against
InstantAdPay's REAL draftpartner.js + tank.js from the sibling checkout behind a signed server on 3565, then a dead port 3566).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
8.8 KiB
JavaScript
82 lines
8.8 KiB
JavaScript
// My Team (the coach's dashboard): stat tiles, instant picks left, the focused pick card (scouting stats, the getting-started
|
|
// steps, one-tap messages, the message composer and thread, release), the rest of the team, who to help first, the draft queue.
|
|
// Someone who is a pick sees their coach here instead (steps, the thread, the coach's builder links). Messages go through the
|
|
// site only; no contact details are ever shown. Every figure comes from /api/my.
|
|
(async function () {
|
|
FX.renderNav('/team'); FX.renderFooter();
|
|
const $ = FX.$, esc = FX.esc;
|
|
const c = await FX.getConfig().catch(() => ({}));
|
|
const me = await FX.getJSON('/api/me');
|
|
if (!me.signedIn) {
|
|
if (await FX.silentSso('/team')) return;
|
|
$('signin').hidden = false; $('signinBox').innerHTML = FX.signInBlock('/team'); FX.wireSignIn($('signinBox')); return;
|
|
}
|
|
$('signout').hidden = false; $('signout').onclick = async () => { await FX.post('/api/auth/logout'); location.reload(); };
|
|
const pol = w => w == null ? 'not tracked yet' : FX.polOf(w) + ' POL';
|
|
let D = null, focus = null;
|
|
const stat = (k, v, note) => '<div class="stat"><span>' + k + '</span><b>' + v + '</b>' + (note ? '<em>' + note + '</em>' : '') + '</div>';
|
|
const stepsHtml = steps => '<div class="steps">' + steps.map(s => '<div class="' + (s.done ? 'done' : s.next ? 'next' : '') + '">' + esc(s.label) + (s.next ? ' (next)' : '') + '</div>').join('') + '</div>';
|
|
const thread = items => items.length ? items.map(x => '<div class="msg' + (x.mine ? ' mine' : '') + '">' + esc(x.text) + '<em>' + esc(FX.when(x.at)) + '</em></div>').join('') : '<p class="small" style="color:#4a587e">No messages yet. Say hello: they see it in their member area.</p>';
|
|
|
|
async function load() {
|
|
const d = await FX.getJSON('/api/my'); if (d.error) { FX.status(d.error, 'err'); return; }
|
|
D = d; $('dash').hidden = false;
|
|
$('hello').textContent = d.username ? '@' + d.username : FX.short(d.address);
|
|
// a pick: their coach
|
|
if (d.myCoach) {
|
|
const mc = d.myCoach; $('myCoach').hidden = false;
|
|
$('mcName').textContent = '@' + mc.coach; $('mcTier').textContent = mc.tierName + ' · on the team since ' + FX.when(mc.since);
|
|
$('mcSteps').innerHTML = stepsHtml(mc.steps);
|
|
$('mcThread').innerHTML = thread(mc.messages.map(x => ({ mine: x.dir === 'out', text: x.text, at: x.at })));
|
|
$('mcSend').onclick = async () => { const t = $('mcText').value.trim(); if (!t) return; const r = await FX.post('/api/my/message', { pick: mc.pickId, text: t }); if (r.error) return FX.status(r.error, 'err'); $('mcText').value = ''; load(); };
|
|
$('mcBuilder').innerHTML = mc.builder.slice(0, 8).map(p => '<a class="btn small" href="' + esc(p.url) + '" target="_blank" rel="noopener nofollow">' + esc(p.name) + '</a>').join(' ') || '<span class="small">No builder links yet.</span>';
|
|
}
|
|
if (!d.coach && !d.picks.length) { $('noCoach').hidden = false; if (!d.myCoach) $('coachTools').hidden = true; return; }
|
|
$('coachTools').hidden = false;
|
|
const s = d.stats;
|
|
$('stats').innerHTML = stat('On my team', s.onTeam, s.open + ' open of ' + s.maxOpen) + stat('Started this week', s.startedThisWeek, 'payouts on or a first purchase')
|
|
+ stat('Next draft spot', s.nextSpot ? '#' + s.nextSpot : '-', 'earned by this week\'s starts') + stat('Back to pool soon', s.backSoon, 'within 24 hours');
|
|
$('credits').hidden = !(d.credits > 0);
|
|
$('creditsN').textContent = d.credits + ' instant pick' + (d.credits === 1 ? '' : 's');
|
|
if (d.page) { $('myPage').hidden = false; $('myPageLink').href = d.page; $('myPageLink').textContent = d.page.replace(/^https:\/\//, ''); }
|
|
const team = d.picks.filter(p => ['open', 'done', 'kept'].includes(p.status));
|
|
if (!focus || !team.some(p => p.id === focus)) focus = (d.help[0] && d.help[0].pickId) || (team[0] && team[0].id) || null;
|
|
paintFocus(team.find(p => p.id === focus));
|
|
const rest = team.filter(p => p.id !== focus);
|
|
$('team').innerHTML = rest.length ? rest.map(p => '<button type="button" class="mini' + (p.id === focus ? ' on' : '') + '" data-f="' + p.id + '"><b>@' + esc(p.username || 'player') + '</b><span class="t">' + esc(p.tierName) + (p.status === 'open' ? '' : ' · on the team') + '</span><span class="s">'
|
|
+ esc(p.status === 'open' ? (p.daysLeft <= 1 ? 'Back to the pool in ' + (p.daysLeft ? '1 day' : 'under a day') : (d.help.find(h => h.pickId === p.id) || {}).why || '') : 'Started: stays on your team') + (p.unread ? ' · ' + p.unread + ' new' : '') + '</span></button>').join('')
|
|
: '<p class="muted">' + (team.length ? 'Nobody else on the team yet. ' : 'No picks yet. ') + (d.credits ? 'Use your instant picks on the Draft Board.' : 'Your next picks come in the Monday draft.') + '</p>';
|
|
document.querySelectorAll('[data-f]').forEach(b => b.onclick = () => { focus = Number(b.dataset.f); load(); });
|
|
$('help').innerHTML = d.help.length ? d.help.slice(0, 8).map(h => '<div class="h"><div><b>@' + esc(h.username || 'player') + '</b><div class="small">' + esc(h.why) + '</div></div><button type="button" class="btn small" data-f2="' + h.pickId + '">Coach them</button></div>').join('')
|
|
: '<p class="muted small">Nobody needs a nudge right now.</p>';
|
|
document.querySelectorAll('[data-f2]').forEach(b => b.onclick = () => { focus = Number(b.dataset.f2); load().then(() => $('focus').scrollIntoView({ behavior: 'smooth' })); });
|
|
const past = d.picks.filter(p => p.status === 'returned');
|
|
$('pastWrap').hidden = !past.length;
|
|
$('past').innerHTML = past.slice(0, 12).map(p => '<span class="btn-ghost">@' + esc(p.username || 'player') + '</span>').join(' ');
|
|
$('queue').innerHTML = d.queue.length ? '<p class="small">' + d.queue.length + ' player' + (d.queue.length === 1 ? '' : 's') + ' on your queue. If you are away when your pick comes up, the first one still available is drafted for you. Edit it on the <a href="/">Draft Board</a>.</p>' : '<p class="small">Your queue is empty: if you are away when your pick comes up, the best available player by scouting score is drafted for you. Add players from the <a href="/">Draft Board</a>.</p>';
|
|
}
|
|
async function paintFocus(p) {
|
|
const el = $('focus'); if (!p) { el.hidden = true; return; } el.hidden = false;
|
|
const label = p.kind === 'instant' ? 'INSTANT PICK' : 'ROUND ' + (p.round || '?') + ' PICK';
|
|
$('fKick').textContent = label + ' · ' + p.tierName.toUpperCase();
|
|
$('fName').textContent = '@' + (p.username || 'player');
|
|
$('fWhen').textContent = 'Picked ' + FX.when(p.at) + (p.status === 'open' ? ' · ' + (p.daysLeft ? p.daysLeft + ' day' + (p.daysLeft === 1 ? '' : 's') + ' left to start' : 'goes back to the pool today') : ' · started, stays on your team');
|
|
$('fStats').innerHTML = [['Game plays', p.plays == null ? 'not tracked yet' : FX.n(p.plays) + (p.game ? ' (' + p.game + ')' : '')], ['Earned in games', pol(p.gameWei)], ['Earned surfing', p.surfWei == null && p.surfCredits != null ? FX.n(p.surfCredits) + ' ad credits' : pol(p.surfWei)], ['Came from', p.door || 'not tracked yet'], ['Last seen', FX.ago(p.lastSeen)]]
|
|
.map(r => '<div class="kvr"><span>' + r[0] + '</span><b>' + esc(r[1]) + '</b></div>').join('');
|
|
$('fSteps').innerHTML = stepsHtml(p.steps);
|
|
const h = D.help.find(x => x.pickId === p.id);
|
|
const taps = [h ? h.say : 'Great work so far. Anything I can help with?', 'Any questions so far? Reply here and I will walk you through it.', p.game ? 'Nice run in ' + p.game + '!' : 'Welcome to the team! I am here to help.'];
|
|
$('fTaps').innerHTML = taps.map((t, i) => '<button type="button" data-tap="' + i + '">"' + esc(t) + '"</button>').join('');
|
|
document.querySelectorAll('[data-tap]').forEach(b => b.onclick = () => { $('fText').value = taps[Number(b.dataset.tap)]; $('fText').focus(); });
|
|
$('fSend').onclick = async () => { const t = $('fText').value.trim(); if (!t) return; const r = await FX.post('/api/my/message', { pick: p.id, text: t }); if (r.error) return FX.status(r.error, 'err'); $('fText').value = ''; FX.status('Sent. They see it in their member area.', 'ok'); thr(); };
|
|
$('fRelease').hidden = p.status !== 'open';
|
|
$('fRelease').onclick = async () => { if (!confirmBox()) return; const r = await FX.post('/api/my/release', { pick: p.id }); FX.status(r.error || 'Released back to the pool.', r.error ? 'err' : 'ok'); load(); };
|
|
async function thr() { const t = await FX.getJSON('/api/my/messages?pick=' + p.id); $('fThread').innerHTML = thread(t.items || []); }
|
|
thr();
|
|
}
|
|
// releasing is a commitment decision: ask in the page (no browser dialogs)
|
|
let armed = 0; function confirmBox() { if (Date.now() - armed < 6000) { armed = 0; return true; } armed = Date.now(); FX.status('Tap "Release to the pool" again within 6 seconds to confirm. They go back to the pool for another coach, and it still counts as one of their two adoptions.', ''); return false; }
|
|
await load();
|
|
setInterval(() => { load().catch(() => {}); }, 30000);
|
|
})();
|