5xYourTeam The Draft v1 (phase 1, local only): weekly earned-order draft of holding-tank people, picks as adoptions (stub tank), coaching tools, cards, boards, trust pack

$10 one-time DraftPosition purchases (sponsor 25%, L2-5 5%, 10% Best Coach pot, 45% company) with keeper-signed hub-line
vouchers; pure draft engine with a mocked clock; no contact data anywhere; Telegram to an outbox unless TG_LIVE=1.
Unit 60/60, smoke 156/156 (Playwright 1280/390). Not deployed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 06:16:10 -06:00
commit f26ac15712
110 changed files with 6177 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
// The Draft Board (front page): who is on the clock, this week's pool as scouting cards, the draft tracker, Best Coach standings,
// Rookie of the Week and the Best Coach pot. Every figure comes from /api/board; a missing stat says "not tracked yet".
(async function () {
FX.renderNav('/'); FX.renderFooter();
const $ = FX.$, esc = FX.esc;
const c = await FX.getConfig().catch(() => ({}));
const me = await FX.getJSON('/api/me').catch(() => ({}));
let B = null, busy = false, showAll = false;
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const hourLabel = h => (h % 12 || 12) + ' ' + (h < 12 ? 'AM' : 'PM');
const pol = w => w == null ? 'not tracked yet' : FX.polOf(w) + ' POL';
function hero(b) {
const d = b.draft; const cur = d && d.onClock;
const when = days[(c.draft || {}).dow == null ? 1 : c.draft.dow] + ' ' + hourLabel(b.draftHour) + ' Central';
if (d && d.status === 'live' && cur) {
$('heroKick').textContent = cur.me ? 'YOU\'RE ON THE CLOCK' : 'THE DRAFT IS LIVE';
$('heroTitle').textContent = cur.me ? 'Pick ' + cur.n + ' of Round ' + cur.round + '. Make it count.' : 'Pick ' + cur.n + ' of Round ' + cur.round + ': @' + cur.coach + ' is on the clock.';
$('heroClock').hidden = false; $('heroClock').dataset.until = cur.until;
} else if (d && d.status === 'done' && b.now < b.nextDraftAt) {
$('heroKick').textContent = 'NEXT DRAFT: ' + when.toUpperCase();
$('heroTitle').textContent = d.made ? d.made + ' players drafted this week. Get your picks started.' : 'Next draft ' + FX.when(b.nextDraftAt) + '.';
$('heroClock').hidden = false; $('heroClock').dataset.until = b.nextDraftAt;
} else {
$('heroKick').textContent = 'DRAFT DAY: ' + when.toUpperCase();
$('heroTitle').textContent = b.rounds + ' rounds. Draft order is earned.';
$('heroClock').hidden = false; $('heroClock').dataset.until = b.now < b.draftAt ? b.draftAt : b.nextDraftAt;
}
}
function clock() { const el = $('heroClock'); if (!el || el.hidden) return; const u = Number(el.dataset.until || 0); const live = B && B.draft && B.draft.status === 'live';
el.textContent = live ? 'Clock: ' + FX.left(u - Date.now() - (B.now - B.fetched)) : 'Starts in ' + FX.left(u - Date.now() - (B.now - B.fetched)); }
function scout(p, b) {
const coach = b.me && b.me.coach; const live = b.draft && b.draft.status === 'live'; const onClock = live && b.draft.onClock && b.draft.onClock.me;
const queued = b.me && (b.me.queue || []).includes(p.id);
let act = '';
if (onClock) act = '<button type="button" class="btn" data-draft="' + esc(p.id) + '">DRAFT</button>';
else if (coach && !live && b.me.credits > 0) act = '<button type="button" class="btn" data-instant="' + esc(p.id) + '">DRAFT NOW</button>';
else if (coach) act = '<button type="button" class="btn" data-queue="' + esc(p.id) + '">' + (queued ? 'ON MY QUEUE' : 'ADD TO QUEUE') + '</button>';
else act = '<a class="btn" href="/join">GET A POSITION</a>';
const rows = [['Game plays', p.plays == null ? 'not tracked yet' : FX.n(p.plays)], ['Plays', p.game || (p.plays === 0 ? 'none yet' : p.plays == null ? 'not tracked yet' : 'none yet')]];
if (coach) rows.push(['Earned in games', pol(p.gameWei)], ['Earned surfing', pol(p.surfWei)]);
rows.push(['Last seen', FX.ago(p.lastSeen, b.now)], ['Came from', p.door || 'not tracked yet'], ['Wallet', p.wallet ? 'linked' : 'not yet']);
return '<article class="scout"><div class="hd"><b>@' + esc(p.username || 'player') + '</b>' + (p.hot ? '<span class="tag">HOT</span>' : '') + '</div><div class="bd">'
+ rows.map(r => '<div class="kvr"><span>' + r[0] + '</span><b>' + esc(r[1]) + '</b></div>').join('') + '</div><div class="ft">' + act + '</div></article>';
}
function paint(b) {
B = b; B.fetched = Date.now(); FX.setWeek(b.week); hero(b);
$('potWei').textContent = FX.polOf(b.pot.wei) + ' POL';
$('potRank').innerHTML = b.me && b.me.coach ? '<span>Your draft spot next Monday</span><b>#' + esc(b.me.nextSpot || '?') + '</b>' : '<span>Coaches this week</span><b>' + FX.n(b.coaches) + '</b>';
const coach = b.me && b.me.coach;
$('poolNote').textContent = (b.poolSize ? FX.n(b.poolSize) + ' people waiting for a sponsor. ' : '') + (coach ? (b.me.credits > 0 && !(b.draft && b.draft.status === 'live') ? 'You have ' + b.me.credits + ' instant pick' + (b.me.credits === 1 ? '' : 's') + ': draft now, or queue players for Monday.' : 'Queue the players you want; an away coach is auto-picked from their queue.') : 'Usernames only, never contact details. Coaches see earnings where they are tracked.');
const shown = showAll ? b.pool : b.pool.slice(0, 8);
$('poolMore').hidden = showAll || b.pool.length <= 8; $('poolMore').textContent = 'Show all ' + b.pool.length + ' players';
$('pool').innerHTML = b.pool.length ? shown.map(p => scout(p, b)).join('') : '<p class="muted">The pool is empty right now. People who join the network without a sponsor show up here after their first 24 hours.</p>';
// tracker
const d = b.draft;
if (d && d.status === 'live') {
$('trackTitle').textContent = 'DRAFT TRACKER: ROUND ' + (d.onClock ? d.onClock.round : '');
const rows = d.rows.slice(0, 6).reverse().map(x => '<tr' + (x.me ? ' class="me"' : '') + '><td>' + esc(x.slot) + '</td><td>@' + esc(x.coach) + '</td><td>' + (x.person ? '@' + esc(x.person) : '<span class="muted">' + esc(x.skipped === 'team full' ? 'skipped: team full' : 'skipped') + '</span>') + '</td><td>' + esc(x.tierName || '') + '</td></tr>')
.concat(d.room.map((r, i) => '<tr' + (r.me ? ' class="me"' : '') + '><td>' + esc(r.slot) + '</td><td class="c">' + (i === 0 ? (r.me ? 'You are on the clock' : '@' + esc(r.coach) + ' is on the clock') : '@' + esc(r.coach)) + '</td><td>' + (i === 0 ? '...' : '') + '</td><td></td></tr>'));
$('track').innerHTML = rows.join('');
} else if (d && d.rows.length) {
$('trackTitle').textContent = 'DRAFT RESULTS: WEEK OF ' + b.week;
$('track').innerHTML = d.rows.filter(x => x.person).slice(0, 15).map(x => '<tr' + (x.me ? ' class="me"' : '') + '><td>' + esc(x.slot) + '</td><td>@' + esc(x.coach) + '</td><td>@' + esc(x.person) + '</td><td>' + esc(x.tierName || '') + '</td></tr>').join('');
} else { $('trackTitle').textContent = 'DRAFT TRACKER'; $('track').innerHTML = '<tr><td colspan="4" class="muted">The draft starts ' + esc(FX.when(b.now < b.draftAt ? b.draftAt : b.nextDraftAt)) + '. Every coach gets a spot every week.</td></tr>'; }
$('best').innerHTML = b.best.length ? b.best.map(x => '<div class="r' + (x.me ? ' me' : '') + '"><span>' + x.rank + '. @' + esc(x.coach) + '</span><b>' + x.started + ' started</b></div>').join('')
: '<p class="muted small">No picks started yet this week. The first coach to get one going leads the board.</p>';
$('potRule').textContent = '"Started" = a pick switched on payouts or made a first purchase. The pot is 10% of every position sold this week' + (b.pot.split && b.pot.split.length ? ', shared ' + b.pot.split.join('/') + ' by the top ' + b.pot.split.length + ' coaches after the week.' : '.');
$('rookie').innerHTML = b.rookie ? FX.card(b.rookie) : '<p class="muted small">The first pick this week to link a wallet takes it.</p>';
$('lastBest').innerHTML = b.lastWeekBest.length ? b.lastWeekBest.map(x => '<div class="r"><span>' + x.rank + '. @' + esc(x.coach) + '</span><b>' + x.started + ' started</b></div>').join('') : '<p class="muted small">No results from last week yet.</p>';
wire();
}
function wire() {
document.querySelectorAll('[data-draft]').forEach(el => el.onclick = () => act('/api/draft/pick', { person: el.dataset.draft }, 'Drafted. They show on My Team now.'));
document.querySelectorAll('[data-instant]').forEach(el => el.onclick = () => act('/api/my/instant', { person: el.dataset.instant }, 'Drafted. They show on My Team now.'));
document.querySelectorAll('[data-queue]').forEach(el => el.onclick = async () => {
const q = (B.me.queue || []).slice(); const id = el.dataset.queue; const i = q.indexOf(id); if (i >= 0) q.splice(i, 1); else q.push(id);
const r = await FX.post('/api/my/queue', { ids: q }); if (r.error) return FX.status(r.error, 'err'); B.me.queue = r.queue; paint(B);
});
}
async function act(url, body, okMsg) {
if (busy) return; busy = true;
try { const r = await FX.post(url, body); if (r.error) FX.status(r.error, 'err'); else FX.status(okMsg, 'ok'); await load(); } finally { busy = false; }
}
async function load() { const b = await FX.getJSON('/api/board'); if (!b.error) paint(b); return b; }
$('poolMore').onclick = () => { showAll = true; paint(B); };
await load();
setInterval(clock, 1000); clock();
setInterval(() => { load().catch(() => {}); }, 6000);
if (me.signedIn) { const ping = () => FX.post('/api/presence', {}).catch(() => {}); ping(); setInterval(ping, 30000); }
})();
+18
View File
@@ -0,0 +1,18 @@
// Card Collection: trading cards that level up as the picks do (Rookie, Starter, Pro, All-Star, Hall of Fame). Public cards show
// milestones, never earnings. ?u=<coach> shows that coach's team; signed in, your own team; otherwise the five tiers explained.
(async function () {
FX.renderNav('/cards'); FX.renderFooter();
const $ = FX.$, esc = FX.esc;
const TIERS = [['rookie', 'Rookie', 'Drafted'], ['starter', 'Starter', 'Wallet linked'], ['pro', 'Pro', 'Payouts switched on'], ['allstar', 'All-Star', 'First purchase'], ['hof', 'Hall of Fame', 'Built a team of their own']];
$('tiers').innerHTML = TIERS.map(t => FX.card({ tier: t[0], tierName: t[1], username: t[1].toLowerCase().replace(/[^a-z]/g, ''), coach: 'your team', milestone: t[2], plays: null, kind: 'draft', round: null })).join('');
let u = new URLSearchParams(location.search).get('u') || '';
let title = '', list = [];
if (!/^[A-Za-z0-9_.-]{2,40}$/.test(u)) {
const me = await FX.getJSON('/api/me').catch(() => ({}));
if (me.signedIn) { const d = await FX.getJSON('/api/my'); if (!d.error) { list = (d.picks || []).filter(p => p.status !== 'returned').map(p => ({ tier: p.tier, tierName: p.tierName, username: p.username, coach: d.username || 'me', round: p.round, kind: p.kind, milestone: TIERS.find(t => t[0] === p.tier)[2], plays: p.plays, status: p.status })); title = 'My team'; } }
} else {
const d = await FX.getJSON('/api/coach?u=' + encodeURIComponent(u));
if (!d.error) { list = d.team; title = '@' + d.username + '\'s team'; }
}
if (title) { $('mine').hidden = false; $('mineTitle').textContent = title; $('mineCards').innerHTML = list.length ? list.map(x => FX.card(x)).join('') : '<p class="muted">No cards yet: they appear with the first pick.</p>'; }
})();
+14
View File
@@ -0,0 +1,14 @@
// A coach page, 5xyourteam.com/<username>: the coach card (since, positions, picks started) and the team as trading cards. Public:
// milestones only, never earnings or contact details.
(async function () {
FX.renderNav(''); FX.renderFooter();
const $ = FX.$, esc = FX.esc;
const u = decodeURIComponent(location.pathname.replace(/^\/|\/$/g, ''));
const d = await FX.getJSON('/api/coach?u=' + encodeURIComponent(u));
if (d.error) { $('cName').textContent = 'No coach by that name yet'; return; }
$('cName').textContent = '@' + d.username;
$('cSince').textContent = 'Coach since ' + FX.when(d.since);
$('cStats').innerHTML = '<div class="kvr"><span>Positions</span><b>' + FX.n(d.positions) + '</b></div><div class="kvr"><span>On the team</span><b>' + FX.n(d.team.length) + '</b></div><div class="kvr"><span>Picks started</span><b>' + FX.n(d.started) + '</b></div>';
$('cTeam').innerHTML = d.team.length ? d.team.map(x => FX.card(x)).join('') : '<p class="muted">Their first picks show here.</p>';
$('cJoin').href = d.joinUrl; $('cJoin').textContent = 'Join the network free under @' + d.username;
})();
+97
View File
@@ -0,0 +1,97 @@
// Shared page helpers (FX namespace, modelled on the ViralAdBlitz / VBB common.js): nav, footer (legal links, the company line, the
// network line from the hub), toasts of real events, and small formatters. Every number on a page comes from the API.
window.FX = (function () {
let cfgP = null;
const $ = id => document.getElementById(id);
const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
const getConfig = () => cfgP || (cfgP = fetch('/api/config').then(r => r.json()));
const short = a => a ? a.slice(0, 6) + '...' + a.slice(-4) : '';
const n = x => Number(x || 0).toLocaleString('en-US');
function status(msg, cls, id) { const el = $(id || 'status'); if (!el) return; el.hidden = !msg; el.className = 'note ' + (cls || ''); el.textContent = msg || ''; }
async function getJSON(url, opts) { const r = await fetch(url, opts); let j = {}; try { j = await r.json(); } catch (e) {} if (!r.ok && !j.error) j.error = 'Request failed (' + r.status + ')'; j._status = r.status; return j; }
const post = (url, body) => getJSON(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) });
const polOf = (w, d) => { try { const k = BigInt(w || 0); if (k === 0n) return '0'; const v = Number(k / 10n ** 12n) / 1e6; return v.toFixed(d != null ? d : (v >= 100 ? 2 : v >= 1 ? 2 : 4)); } catch (e) { return '0'; } };
const when = t => t ? new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago', weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : '';
// "today", "yesterday", "3 days ago" (Central days) or "not seen yet"
function ago(t, nowMs) {
if (!t) return 'not seen yet';
const day = x => new Date(x).toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
const now = nowMs || Date.now(); const dd = Math.round((Date.parse(day(now)) - Date.parse(day(t))) / 86400000);
return dd <= 0 ? 'today' : dd === 1 ? 'yesterday' : dd + ' days ago';
}
function left(ms) { if (ms <= 0) return 'now'; const m = Math.ceil(ms / 60000); if (m < 60) return m + ' min'; const h = Math.floor(m / 60); if (h < 48) return h + ' h ' + (m % 60) + ' min'; return Math.round(h / 24) + ' days'; }
const initials = s => String(s || '?').replace(/[^A-Za-z0-9]/g, '').slice(0, 2).toUpperCase() || '?';
let weekLabel = '';
function renderNav(active, week) {
const nav = document.createElement('nav'); nav.className = 'top';
const links = [['/', 'Draft Board'], ['/team', 'My Team'], ['/cards', 'Card Collection'], ['/join', 'Get a Position'], ['/ledger', 'Ledger'], ['/contract', 'Contract']];
nav.innerHTML = '<div class="wrap"><a class="brand" href="/" aria-label="5xYourTeam, the draft board"><span class="wm">5X<b>YOUR</b>TEAM</span><span class="wk" id="navWeek" hidden></span></a><div class="links">'
+ links.map(l => '<a href="' + l[0] + '"' + (l[0] === active ? ' class="on" aria-current="page"' : '') + '>' + l[1] + '</a>').join('') + '</div></div>';
document.body.prepend(nav);
if (week) setWeek(week);
}
// ISO-ish week number of a Monday date (the mockup's "DRAFT WEEK 46")
function weekNo(monday) { const d = new Date(monday + 'T12:00:00Z'); const t = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + 3)); const y = new Date(Date.UTC(t.getUTCFullYear(), 0, 4)); return 1 + Math.round(((t - y) / 86400000 - 3 + ((y.getUTCDay() + 6) % 7)) / 7); }
function setWeek(monday) { const el = $('navWeek'); if (!el || !monday) return; weekLabel = 'DRAFT WEEK ' + weekNo(monday); el.textContent = weekLabel; el.hidden = false; }
const NET = [['iap', 'InstantAdPay', 'https://instantadpay.com'], ['linkspin', 'LinkSpin', 'https://linkspin.app'], ['dlb', 'Downline Banners', 'https://downlinebanners.com'],
['vbb', 'Viral Banner Blitz', 'https://viralbannerblitz.com'], ['viraladblitz', 'ViralAdBlitz', 'https://viraladblitz.com'], ['fivex', '5xYourTeam', 'https://5xyourteam.com'], ['stackpol', 'Stack POL', 'https://stackpol.com'], ['earnerscorner', 'Earners Corner', 'https://earnerscorner.com']].map(a => ({ id: a[0], name: a[1], url: a[2] }));
function netLine(el) {
if (!el) return;
const paint = list => { el.innerHTML = '<b>Part of the network</b> &middot; One account across the network: ' + list.map(s => (s.id === 'fivex' || /5xyourteam\.com/.test(s.url))
? '<span class="here" aria-current="page">' + esc(s.name) + '</span>' : '<a href="' + esc(s.go || s.url) + '" target="_blank" rel="noopener nofollow">' + esc(s.name) + '</a>').join(' &middot; '); };
paint(NET);
fetch('/api/network-sites').then(r => r.json()).then(l => { if (Array.isArray(l) && l.length) paint(l.some(s => s.id === 'fivex') ? l : l.concat([NET[5]])); }).catch(() => {});
}
function renderFooter() {
const f = document.createElement('footer'); f.className = 'foot';
f.innerHTML = '<div class="wrap"><p><b>5xYourTeam</b>, the weekly draft for people who need a sponsor</p>'
+ '<p>A position buys a draft spot and coaching tools, not income. Nothing is promised.</p>'
+ '<p><a href="/">Draft Board</a> &middot; <a href="/team">My Team</a> &middot; <a href="/cards">Cards</a> &middot; <a href="/join">Get a Position</a> &middot; <a href="/promote">Promote</a></p>'
+ '<p class="legal-links"><a href="/terms">Terms</a> &middot; <a href="/disclaimer">Earnings Disclaimer</a> &middot; <a href="/privacy">Privacy</a> &middot; <a href="/contract">Contract</a> &middot; <a href="/ledger">Ledger</a> &middot; <a href="https://instantadpay.com/support" target="_blank" rel="noopener">Support</a></p>'
+ '<p class="co">TrustClickz &middot; 615 Green Valley Drive, Moody, AL 35004</p><p class="netline"></p></div>';
document.body.appendChild(f);
netLine(f.querySelector('.netline'));
toasts();
}
// live toasts: real new positions, picks and level-ups only, bottom-right, never older than 30 minutes
let toastsOn = false;
function toasts() {
if (toastsOn) return; toastsOn = true;
const seen = new Set(); let first = true;
const box = document.createElement('div'); box.className = 'toasts'; box.setAttribute('aria-live', 'polite'); document.body.appendChild(box);
const show = c => {
const el = document.createElement('a'); el.className = 'toast' + (c.kind === 'position' ? ' red' : '');
if (c.kind === 'position') { el.href = '/ledger'; el.innerHTML = '<b>' + (c.name ? '@' + esc(c.name) : 'A new coach') + ' joined The Draft</b><br><span>Paid on-chain, split by the contract in the same transaction</span>'; }
else if (c.kind === 'level') { el.href = '/cards'; el.innerHTML = '<b>@' + esc(c.person || 'a pick') + ' just made ' + esc(c.tierName) + (c.name ? ' on @' + esc(c.name) + '\'s team' : '') + '</b><br><span>' + (c.tierName === 'Starter' ? 'Wallet linked. One step from Pro.' : c.tierName === 'Pro' ? 'Payouts switched on.' : 'Leveling up.') + '</span>'; }
else { el.href = '/'; el.innerHTML = '<b>' + (c.name ? '@' + esc(c.name) : 'A coach') + ' drafted @' + esc(c.person || 'a player') + '</b><br><span>' + (c.slot ? 'Pick ' + esc(c.slot) : 'An instant pick') + '</span>'; }
box.appendChild(el); requestAnimationFrame(() => el.classList.add('in'));
setTimeout(() => { el.classList.remove('in'); setTimeout(() => el.remove(), 400); }, 7000);
};
const tick = async () => {
const d = await getJSON('/api/recent').catch(() => null); const all = (d && d.items) || [];
const fresh = all.filter(c => !seen.has(c.key)); all.forEach(c => seen.add(c.key));
const list = first ? fresh.slice(0, 1) : fresh.reverse(); first = false;
list.slice(0, 3).forEach((c, i) => setTimeout(() => show(c), 1500 + i * 8000));
};
tick(); setInterval(tick, 25000);
}
// a trading card (milestones only, never earnings)
function card(c, opts) {
const o = opts || {};
return '<article class="tc ' + esc(c.tier) + (c.status === 'returned' ? ' faded' : '') + '"><div class="tier">' + esc(c.tierName) + '</div><div class="face">' + esc(initials(c.username)) + '</div>'
+ '<div class="info"><b>@' + esc(c.username || 'player') + '</b><span>Team @' + esc(c.coach) + (c.round ? ' · Round ' + esc(c.round) : c.kind === 'instant' ? ' · Instant pick' : '') + '</span><span>' + esc(c.milestone) + '</span>'
+ '<span>Games played: ' + (c.plays == null ? 'not tracked yet' : n(c.plays)) + '</span>' + (c.status === 'returned' ? '<span class="dim">Back in the pool</span>' : '') + (o.extra || '') + '</div></article>';
}
// signed in on InstantAdPay already? one quick hop there and back signs you in here too
async function silentSso(to) { try { const ss = await getJSON('/api/sso/status'); if (ss && ss.check) { location.replace('/sso/start?mode=check&via=iap&to=' + encodeURIComponent(to)); return true; } } catch (e) {} return false; }
function signInBlock(to) {
const t = encodeURIComponent(to);
return '<div class="signin"><a class="btn-gold" href="/sso/start?mode=go&amp;via=iap&amp;to=' + t + '">Sign in with InstantAdPay</a><a class="btn-gold" href="/sso/start?mode=go&amp;via=linkspin&amp;to=' + t + '">Sign in with LinkSpin</a><button class="btn-line" type="button" data-wallet-signin>Sign in with your wallet</button></div>'
+ '<p class="small">Your wallet: SafePal or any other crypto wallet. Signing in is free and cannot move funds.</p>';
}
function wireSignIn(root) {
(root || document).querySelectorAll('[data-wallet-signin]').forEach(b => { b.onclick = async () => {
try { status('Check your wallet for the sign-in message.'); await FXWallet.signIn(); location.reload(); } catch (e) { status(String(e && e.message || e).slice(0, 300), 'err'); } }; });
}
return { $, esc, getConfig, short, status, getJSON, post, n, polOf, when, ago, left, initials, renderNav, renderFooter, setWeek, weekNo, card, silentSso, signInBlock, wireSignIn };
})();
+24
View File
@@ -0,0 +1,24 @@
// Contract proof page (trust pack): live facts from /api/contract (read from Polygon, cached 5 minutes on the server).
(async function () {
FX.renderNav('/contract'); FX.renderFooter();
const el = document.getElementById('facts'); const esc = FX.esc;
let d; try { d = await FX.getJSON('/api/contract'); } catch (e) { d = {}; }
const ex = d.explorer || 'https://polygonscan.com';
const addr = (a, note) => a ? '<a href="' + esc(ex) + '/address/' + esc(a) + '" target="_blank" rel="noopener">' + esc(a) + '</a>' + (note ? '<br><span class="small">' + note + '</span>' : '') : '<span class="muted">not read yet</span>';
const sp = d.split || { sponsorPct: 25, levelPct: 5, potPct: 10, companyPct: 45, maxDepth: 20 };
const splitRow = ['The split', 'Sponsor ' + sp.sponsorPct + '%, levels 2 to 5 ' + sp.levelPct + '% each, Best Coach pot ' + sp.potPct + '%, 5xYourTeam ' + sp.companyPct + '%. Someone in the line with no position is passed over and the share goes up to the next person who holds one, up to ' + sp.maxDepth + ' places. Fixed in the code: no setter can change it.'];
if (!d.address) { el.innerHTML = '<tbody><tr><th>Status</th><td class="muted">The contract is not live yet. Its address, owner, prize pot wallet and every position will show here, read straight from Polygon.</td></tr><tr><th>' + splitRow[0] + '</th><td>' + splitRow[1] + '</td></tr></tbody>'; return; }
const rows = [
['Contract', addr(d.address, 'DraftPosition on ' + (d.chainId === 137 ? 'Polygon' : 'chain ' + d.chainId))],
['Source code', 'Verified source on Polygonscan and Sourcify: ' + esc(d.verified && d.verified.polygonscan === 'pending' ? 'pending' : 'done')],
['Owner', addr(d.owner, 'A Tangem hardware wallet. It can pause new sales, set the price of future positions and change the keeper. It cannot move anyone\'s money or change the split.')],
['Company', addr(d.company, '5xYourTeam. Fixed in the contract when it was deployed.')],
['Best Coach pot', addr(d.prizeWallet, 'Receives 10% of every position in the same transaction. Fixed in the contract when it was deployed. Each payout from it is listed on the ledger.')],
['Keeper', addr(d.keeper, 'The site\'s signing key. It only signs a buyer\'s sponsor line from the network hub, once, on their first position.')],
splitRow,
['Position', '$' + esc(d.position && d.position.usd) + ' one-time, paid in POL at the live Chainlink price' + (d.priceCents ? ' (contract price: $' + (d.priceCents / 100).toFixed(2) + ')' : '')],
['Sales', d.live ? (d.paused ? '<b>Paused</b>' : 'Open') + ' · ' + FX.n(d.orderCount) + ' orders so far' : '<span class="muted">' + esc(d.error || 'not read yet') + '</span>'],
['Held by the contract', d.live ? FX.polOf(d.balanceWei) + ' POL' + (BigInt(d.totalOwedWei || 0) > 0n ? ' (all of it owed to wallets whose payment bounced, waiting for them to claim)' : ' (nothing is kept: every position is paid out in the same transaction)') : '<span class="muted">not read yet</span>']
];
el.innerHTML = '<tbody>' + rows.map(r => '<tr><th>' + r[0] + '</th><td>' + r[1] + '</td></tr>').join('') + '</tbody>';
})();
+175
View File
@@ -0,0 +1,175 @@
/* 5xYourTeam: the approved "draft night" look (mockup 2026-11-14): stadium navy, gold, a red tag; white trading cards with a navy
header; Oswald headlines + Inter text. Distinct from the other network sites (IAP mint, DLB ultraviolet, VBB pop-art,
ViralAdBlitz daylight royal, DownlineHydra parchment). One stylesheet, variables up top. */
:root{
--bg:#0b1530;--bar:#07102a;--panel:#13214a;--panel2:#1b2c5e;--line:#2a3a6e;--ink:#eef2fb;--muted:#b8c4e0;--dim:#8f9cc0;
--gold:#ffc93c;--gold2:#ffe08a;--red:#ff4d4d;--paper:#fff;--paperInk:#0b1530;--paperMuted:#4a587e;
--rookie:#9aa6c4;--starter:#1f8a5b;--pro:#2f5be0;--allstar:#ffc93c;--hof:#ff4d4d;
--disp:Oswald,Impact,'Arial Narrow',sans-serif;--text:Inter,system-ui,-apple-system,'Segoe UI',sans-serif;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--text);font-size:16px;line-height:1.5;overflow-x:hidden}
a{color:var(--gold)}a:hover{color:var(--gold2)}
img{max-width:100%}
h1,h2,h3{font-family:var(--disp);font-weight:700;letter-spacing:.5px;line-height:1.05;margin:0}
h2{font-size:30px;text-transform:uppercase}
h3{font-size:20px;text-transform:uppercase}
.wrap{max-width:1200px;margin:0 auto;padding:0 24px}
main.wrap{padding-top:32px;padding-bottom:40px;display:flex;flex-direction:column;gap:32px}
.kicker{margin:0;font-family:var(--disp);font-size:14px;letter-spacing:3px;color:var(--gold);text-transform:uppercase}
.muted{color:var(--muted)}.dim{color:var(--dim)}
.note{margin:0;padding:10px 14px;background:var(--panel2);border-left:4px solid var(--gold);font-size:14px}
.note.err{border-color:var(--red)}.note.ok{border-color:var(--starter)}
.hidden,[hidden]{display:none!important}
/* header */
nav.top{background:var(--bar);border-bottom:4px solid var(--gold);position:relative;z-index:5}
nav.top .wrap{display:flex;align-items:center;gap:20px;flex-wrap:wrap;padding-top:14px;padding-bottom:14px}
.brand{display:flex;align-items:center;gap:10px;margin-right:auto;text-decoration:none}
.wm{font-family:var(--disp);font-weight:700;font-size:30px;letter-spacing:1px;color:#fff;white-space:nowrap}.wm b{color:var(--gold);font-weight:700}
.wk{font-family:var(--disp);font-size:12px;background:var(--red);color:#fff;padding:3px 8px;letter-spacing:2px;white-space:nowrap}
nav.top .links{display:flex;gap:18px;flex-wrap:wrap;font-size:14px;font-weight:600}
nav.top .links a{color:var(--muted);text-decoration:none;padding-bottom:2px;border-bottom:2px solid transparent}
nav.top .links a.on,nav.top .links a:hover{color:#fff;border-bottom-color:var(--gold)}
/* buttons */
.btn,.btn-gold,.btn-line,.btn-ghost{display:inline-flex;align-items:center;justify-content:center;gap:8px;border:0;cursor:pointer;text-decoration:none;font-family:var(--disp);letter-spacing:1px;text-transform:uppercase;font-size:16px;padding:12px 18px;line-height:1.1}
.btn{background:var(--paperInk);color:var(--gold)}.btn:hover{background:#13214a;color:var(--gold2)}
.btn-gold{background:var(--gold);color:var(--paperInk)}.btn-gold:hover{background:var(--gold2);color:var(--paperInk)}
.btn-line{background:transparent;color:#fff;border:2px solid var(--gold);padding:10px 16px}.btn-line:hover{background:var(--panel2);color:#fff}
.btn-ghost{background:transparent;color:var(--muted);border:2px solid var(--line);padding:10px 16px;font-family:var(--text);text-transform:none;letter-spacing:0;font-weight:600;font-size:14px}
button:disabled{opacity:.5;cursor:not-allowed}
.row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}
/* hero */
.hero{display:flex;flex-wrap:wrap;gap:16px;align-items:stretch}
.hero .copy{flex:999 1 520px;min-width:0;display:flex;flex-direction:column;gap:10px}
.hero h1{font-size:58px;color:#fff}
.hero .lead{margin:0;font-size:17px;color:var(--muted);max-width:640px}
.potbox{flex:1 1 280px;background:var(--panel);border:2px solid var(--gold);padding:18px;display:flex;flex-direction:column;gap:10px}
.potbox .lab{font-family:var(--disp);letter-spacing:2px;color:var(--gold);font-size:13px;text-transform:uppercase}
.potbox b.big{font-family:var(--disp);font-size:44px;color:#fff;line-height:1}
.potbox .kv{display:flex;justify-content:space-between;border-top:1px solid var(--line);padding-top:10px;font-size:14px}.potbox .kv b{color:var(--gold)}
.clock{font-family:var(--disp);font-size:22px;color:var(--gold);letter-spacing:1px}
/* section heads */
.sh{display:flex;align-items:baseline;justify-content:space-between;flex-wrap:wrap;gap:8px}
.sh p{margin:0;color:var(--muted);font-size:14px}
/* scouting cards (the pool) */
.pool{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:14px}
.scout{background:var(--paper);color:var(--paperInk);display:flex;flex-direction:column}
.scout .hd{background:var(--panel);color:#fff;padding:12px 14px;display:flex;justify-content:space-between;align-items:center;gap:8px}
.scout .hd b{font-family:var(--disp);font-size:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.tag{font-family:var(--disp);font-size:12px;background:var(--gold);color:var(--paperInk);padding:2px 6px;letter-spacing:1px;white-space:nowrap}
.tag.red{background:var(--red);color:#fff}
.scout .bd{padding:14px;display:flex;flex-direction:column;gap:6px;font-size:14px;flex:1}
.kvr{display:flex;justify-content:space-between;gap:10px}.kvr span{color:var(--paperMuted)}.kvr b{text-align:right}
.scout .ft{margin:0 14px 14px;display:flex;gap:6px}
.scout .ft .btn{flex:1;font-size:15px;padding:11px 8px}
.scout .ft .q{flex:0 0 auto;background:#e5e9f4;color:var(--paperInk);border:0;font-family:var(--disp);padding:0 12px;cursor:pointer;letter-spacing:1px}
.scout .ft .q.on{background:var(--gold)}
.scout.mine .hd{background:var(--starter)}
/* panels, tables */
.panel{background:var(--panel);padding:20px;display:flex;flex-direction:column;gap:10px;min-width:0}
.split{display:flex;flex-wrap:wrap;gap:20px}
.split>.wide{flex:999 1 560px}.split>.side{flex:1 1 300px}
.tbl{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:14px}
th{color:var(--gold);text-align:left;font-family:var(--disp);letter-spacing:1px;font-weight:500;padding:8px;border-bottom:1px solid var(--line);white-space:nowrap}
td{padding:8px;border-bottom:1px solid var(--line);vertical-align:top}
tr.me td{background:var(--panel2)}tr.me td.c{color:var(--gold);font-weight:700}
.board{display:flex;flex-direction:column;gap:6px}
.board .r{display:flex;justify-content:space-between;font-size:15px;border-bottom:1px solid var(--line);padding-bottom:6px;gap:10px}
.board .r b{color:var(--gold);white-space:nowrap}.board .r.me span{color:var(--gold);font-weight:700}
.small{font-size:13px;color:var(--muted)}
/* stat tiles */
.stats{display:flex;flex-wrap:wrap;gap:14px}
.stat{flex:1 1 200px;background:var(--panel);padding:16px;display:flex;flex-direction:column;gap:4px}
.stat span{font-family:var(--disp);letter-spacing:2px;font-size:12px;color:var(--gold);text-transform:uppercase}
.stat b{font-family:var(--disp);font-size:36px;line-height:1}
.stat em{font-style:normal;font-size:13px;color:var(--muted)}
/* the focused pick */
.focus{background:var(--paper);color:var(--paperInk);display:flex;flex-wrap:wrap}
.focus .who{flex:1 1 280px;background:var(--panel);color:#fff;padding:22px;display:flex;flex-direction:column;gap:8px}
.focus .who .k{font-family:var(--disp);letter-spacing:2px;color:var(--gold);font-size:13px;text-transform:uppercase}
.focus .who b.n{font-family:var(--disp);font-size:30px;word-break:break-all}
.focus .who .kvr span{color:var(--muted)}
.focus .act{flex:999 1 520px;min-width:0;padding:22px;display:flex;flex-direction:column;gap:14px}
.focus h3{font-size:22px}
.steps{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:8px;font-size:13px;text-align:center}
.steps div{background:#e5e9f4;color:var(--paperMuted);padding:10px 6px}
.steps .done{background:var(--starter);color:#fff}.steps .next{background:var(--gold);color:var(--paperInk);font-weight:700}
.taps{display:flex;flex-wrap:wrap;gap:8px}
.taps button{background:var(--paperInk);color:#fff;border:0;padding:12px 14px;font-size:14px;cursor:pointer;text-align:left;font-family:var(--text)}
.taps button:hover{background:var(--panel2)}
textarea,input,select{font:inherit;font-size:15px;padding:10px 12px;border:2px solid #c6cde0;background:#fff;color:var(--paperInk);width:100%;border-radius:0}
.dark textarea,.dark input,.dark select{background:var(--bar);color:var(--ink);border-color:var(--line)}
textarea{min-height:84px;resize:vertical}
.thread{display:flex;flex-direction:column;gap:8px;max-height:260px;overflow:auto;padding:4px 0}
.msg{padding:10px 12px;background:#eef1f8;font-size:14px;max-width:85%;white-space:pre-wrap;word-break:break-word}
.msg.mine{background:var(--paperInk);color:#fff;align-self:flex-end}
.msg em{display:block;font-style:normal;font-size:11px;opacity:.7;margin-top:4px}
/* team grid */
.team{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px}
.mini{background:var(--panel);padding:14px;display:flex;flex-direction:column;gap:6px;cursor:pointer;border:2px solid transparent;text-align:left;color:var(--ink);font:inherit}
.mini:hover,.mini.on{border-color:var(--gold)}
.mini b{font-family:var(--disp);font-size:18px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.mini .t{color:var(--gold);font-size:13px;text-transform:uppercase;letter-spacing:1px}
.mini .s{color:var(--muted);font-size:13px}
.help{display:flex;flex-direction:column;gap:8px}
.help .h{display:flex;gap:12px;align-items:center;justify-content:space-between;background:var(--panel2);padding:10px 12px;flex-wrap:wrap}
.help .h b{font-family:var(--disp);font-size:17px}
/* trading cards */
.cards{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:20px}
.tc{border:6px solid var(--rookie);background:#e5e9f4;color:var(--paperInk);min-height:380px;display:flex;flex-direction:column}
.tc .tier{font-family:var(--disp);letter-spacing:3px;text-align:center;padding:6px;background:var(--rookie);color:var(--paperInk);text-transform:uppercase}
.tc .face{height:150px;display:flex;align-items:center;justify-content:center;font-family:var(--disp);font-size:48px;background:#c6cde0;color:var(--paperMuted)}
.tc .info{padding:12px;display:flex;flex-direction:column;gap:4px;font-size:13px}
.tc .info b{font-family:var(--disp);font-size:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tc.starter{border-color:var(--starter);background:#eaf6ef}.tc.starter .tier{background:var(--starter);color:#fff}.tc.starter .face{background:#bfe3cf;color:#1f5c40}
.tc.pro{border-color:var(--pro);background:#e8eefc}.tc.pro .tier{background:var(--pro);color:#fff}.tc.pro .face{background:#c3d2fa;color:#1d3a96}
.tc.allstar{border-color:var(--allstar);background:#fff7df;box-shadow:0 0 0 3px var(--paperInk),0 0 24px rgba(255,201,60,.6)}.tc.allstar .tier{background:var(--allstar)}.tc.allstar .face{background:#ffe8a3;color:#7a5a00}
.tc.hof{border-color:var(--gold);background:#1a1030;color:#fff;box-shadow:0 0 0 3px var(--red)}.tc.hof .tier{background:linear-gradient(90deg,var(--gold),var(--red))}.tc.hof .face{background:#2a1a4a;color:var(--gold)}
.tc.faded{opacity:.55}
/* coach card */
.ccard{display:flex;flex-wrap:wrap;gap:0;background:var(--paper);color:var(--paperInk)}
.ccard .l{flex:1 1 260px;background:var(--panel);color:#fff;padding:22px;display:flex;flex-direction:column;gap:8px;border-left:8px solid var(--gold)}
.ccard .l b{font-family:var(--disp);font-size:36px;word-break:break-all}
.ccard .r{flex:999 1 400px;padding:22px;display:flex;flex-direction:column;gap:12px}
/* steps strip on the front page */
.how{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}
.how .s{background:var(--panel);padding:18px;display:flex;flex-direction:column;gap:6px;border-top:4px solid var(--gold)}
.how .s b{font-family:var(--disp);font-size:40px;color:var(--gold);line-height:1}
.splitbar{display:flex;height:34px;font-size:12px;font-weight:700}
.splitbar div{display:flex;align-items:center;justify-content:center;color:var(--paperInk);overflow:hidden;white-space:nowrap}
.legal .card{background:var(--panel);padding:20px}.legal .card h2{font-size:22px;margin-bottom:8px}.legal .card p,.legal .card li{color:var(--muted)}
.signin{display:flex;flex-wrap:wrap;gap:10px}
/* footer */
footer.foot{border-top:1px solid var(--line);padding:24px 0;text-align:center;color:var(--dim);font-size:13px}
footer.foot p{margin:4px 0}footer.foot a{color:var(--gold)}footer.foot .here{color:#fff;font-weight:700}
/* toasts */
.toasts{position:fixed;right:24px;bottom:24px;z-index:50;display:flex;flex-direction:column;gap:8px;max-width:320px;pointer-events:none}
.toast{background:#fff;color:var(--paperInk);border-left:6px solid var(--gold);padding:12px 16px;font-size:14px;box-shadow:0 8px 24px rgba(0,0,0,.45);text-decoration:none;opacity:0;transform:translateY(10px);transition:all .35s;pointer-events:auto}
.toast.in{opacity:1;transform:none}.toast span{color:var(--paperMuted)}.toast.red{border-color:var(--red)}
.net-zone{text-align:center;margin:12px auto}.net-zone-label{font-size:11px;color:var(--dim)}
/* phones */
@media (max-width:1000px){.pool,.team{grid-template-columns:repeat(2,minmax(0,1fr))}.cards{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media (max-width:640px){
.wrap{padding:0 16px}main.wrap{padding-top:20px;gap:24px}
.wm{font-size:24px}nav.top .links{gap:12px;font-size:13px}
.hero h1{font-size:38px}h2{font-size:24px}
.pool{grid-template-columns:minmax(0,1fr)}.team{grid-template-columns:repeat(2,minmax(0,1fr))}.cards{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
.tc{min-height:300px}.tc .face{height:100px;font-size:36px}
.steps{grid-template-columns:repeat(2,minmax(0,1fr))}.how{grid-template-columns:minmax(0,1fr)}
.toasts{left:16px;right:16px;bottom:16px;max-width:none}
}
/* promo kit (kitpage.js) */
.card{background:var(--panel);padding:20px;display:flex;flex-direction:column;gap:10px}
.btn.small{font-size:13px;padding:8px 12px}.btn.sec{background:var(--panel2);color:#fff}
.kit-row{display:flex;gap:10px;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line);padding:8px 0;flex-wrap:wrap}
.kit-l{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1}.kit-lab{font-size:12px;color:var(--gold);font-family:var(--disp);letter-spacing:1px;text-transform:uppercase;display:block}
.kit-url{font-size:13px;color:var(--muted);word-break:break-all}.kit-txt{margin:0;flex:1;min-width:0;color:var(--ink)}
.kit-tabs{display:flex;flex-wrap:wrap;gap:6px}.kit-tab{background:var(--panel2);color:var(--muted);border:0;padding:8px 12px;cursor:pointer;font:inherit;font-size:14px}.kit-tab.on{background:var(--gold);color:var(--paperInk)}
.kit-set{display:flex;flex-wrap:wrap;gap:16px;align-items:flex-start}.kit-fig{margin:0;display:flex;flex-direction:column;gap:6px;max-width:100%}
.kit-fig img{height:auto;max-width:100%;display:block}.kit-social img,.kit-square img{width:360px}
.kit-fig figcaption{font-size:13px;display:flex;flex-wrap:wrap;gap:6px;align-items:center}.kit-acts{display:flex;gap:6px;flex-wrap:wrap}
.kit-pre{white-space:pre-wrap;font:inherit;font-size:14px;color:var(--muted);margin:0;background:var(--bar);padding:12px}
.ccard .l .kvr{color:var(--muted)}.ccard .l .kvr span{color:var(--muted)}.ccard .l .kvr b{font-family:var(--text);font-size:15px;color:#fff;word-break:normal}
.splitbar div{font-size:11px;padding:0 4px}
+44
View File
@@ -0,0 +1,44 @@
// Get a Position: $10 one-time through DraftPosition. The server builds the buy() call for the signed-in member (POST /api/my/order,
// with a fresh line voucher when the member's sponsor line is not on the contract yet); the member's own wallet sends it. After the
// transaction confirms, the page waits for the watcher to record it (then the 5 instant picks show on My Team).
(async function () {
FX.renderNav('/join'); FX.renderFooter();
const $ = FX.$, esc = FX.esc;
const c = await FX.getConfig().catch(() => ({}));
const P = c.position || { usd: 10, picksOnBuy: 5, maxQty: 10 }, S = c.split || {};
$('jPrice').textContent = '$' + P.usd; $('jPicks').textContent = P.picksOnBuy;
$('splitbar').innerHTML = [['Sponsor ' + S.sponsorPct + '%', S.sponsorPct, '#ffc93c'], ['L2-5 ' + S.levelPct + '% each', S.levelPct * 4, '#ffe08a'], ['Pot ' + S.potPct + '%', S.potPct, '#1f8a5b'], ['5xYourTeam ' + S.companyPct + '%', S.companyPct, '#c6cde0']]
.map(x => '<div style="flex:' + x[1] + ';background:' + x[2] + '" title="' + esc(x[0]) + '">' + esc(x[0]) + '</div>').join('');
$('jQty').innerHTML = Array.from({ length: P.maxQty }, (_, i) => '<option value="' + (i + 1) + '">' + (i + 1) + ' position' + (i ? 's' : '') + ' ($' + P.usd * (i + 1) + ', ' + P.picksOnBuy * (i + 1) + ' instant picks)</option>').join('');
const fmtPol = (wei, d) => { const k = d || 4; const s = (BigInt(wei) * 10n ** BigInt(k) / 10n ** 18n).toString().padStart(k + 1, '0'); return s.slice(0, -k) + '.' + s.slice(-k); };
const me = await FX.getJSON('/api/me').catch(() => ({}));
if (!me.signedIn) { $('jSign').hidden = false; $('jSignBox').innerHTML = FX.signInBlock('/join'); FX.wireSignIn($('jSignBox')); }
async function quote() {
if (!c.shop || !c.shop.live) { $('jPol').textContent = 'Positions open when the contract goes live.'; $('jBuy').disabled = true; return; }
const q = await FX.getJSON('/api/quote?qty=' + $('jQty').value);
$('jPol').textContent = q.error ? q.error : 'about ' + fmtPol(q.wei, 2) + ' POL at today\'s Chainlink price';
$('jBuy').disabled = !!q.error || !me.signedIn;
}
$('jQty').onchange = quote; quote();
$('jBuy').onclick = async () => {
const say = (m, cls) => FX.status(m, cls);
try {
$('jBuy').disabled = true;
say('Connecting your wallet...');
const addr = String(await FXWallet.activeAddress(await FXWallet.connect()) || '').toLowerCase();
if (!addr) throw new Error('No wallet connected. Tap the button again and pick SafePal or any other crypto wallet.');
if (addr !== me.address) throw new Error('Your wallet is connected as ' + FX.short(addr) + ', but you are signed in here as ' + FX.short(me.address) + '. A position goes to the wallet that pays, so switch your wallet app to ' + FX.short(me.address) + ', or sign out and sign in with ' + FX.short(addr) + '.');
const od = await FX.post('/api/my/order', { qty: Number($('jQty').value) }); if (od.error) throw new Error(od.error);
const value = BigInt(od.value);
try { const bal = await FXWallet.balance(addr); if (bal < value) throw new Error('This wallet holds ' + fmtPol(bal) + ' POL. The position needs about ' + fmtPol(value) + ' POL plus a little gas. Add POL on Polygon and try again.'); } catch (e) { if (/holds/.test(e.message)) throw e; }
say('Confirm the payment in your wallet: about ' + fmtPol(value) + ' POL ($' + od.usd + '). Anything above the exact price comes straight back in the same transaction.');
const hash = await FXWallet.sendTx(od.to, od.data, od.value);
say('Payment sent. Waiting for Polygon to confirm it...');
const r = await FXWallet.waitTx(hash);
if (r.status !== '0x1') throw new Error('The transaction did not go through, so nothing was charged except gas.');
FX.post('/api/my/paid', {}).catch(() => {});
say('Confirmed on Polygon. Your instant picks show on My Team within about a minute.', 'ok');
for (let i = 0; i < 72; i++) { await new Promise(res => setTimeout(res, 5000)); if (i % 4 === 3) FX.post('/api/my/paid', {}).catch(() => {}); const d = await FX.getJSON('/api/my'); if (d.coach) { location.href = '/team'; return; } }
} catch (e) { say(String(e && e.message || e).slice(0, 400), 'err'); $('jBuy').disabled = false; }
};
})();
+51
View File
@@ -0,0 +1,51 @@
// Promote page renderer (2026-11-14). Draws a promo kit (GET /api/promo-kit) into a container: links, creatives grouped by angle,
// swipe lines, headlines, an email and social posts, each with a copy button. Same file on Downline Banners, Viral Banner Blitz, ViralAdBlitz and 5xYourTeam;
// the page script decides the username and the look comes from the site's own CSS (.card, .btn, .kit-*).
window.KitPage = (function () {
const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
async function copy(text, btn) {
try { await navigator.clipboard.writeText(text); } catch (e) {
const t = document.createElement('textarea'); t.value = text; document.body.appendChild(t); t.select(); try { document.execCommand('copy'); } catch (e2) {} t.remove();
}
if (btn) { const o = btn.textContent; btn.textContent = 'Copied'; setTimeout(() => { btn.textContent = o; }, 1400); }
}
const TXT = [];
const cb = (text, label, cls) => { TXT.push(text); return '<button type="button" class="btn small ' + (cls || 'sec') + '" data-kc="' + (TXT.length - 1) + '">' + esc(label || 'Copy') + '</button>'; };
// on the kit's own site, show creatives from this origin (same files; the copied URL stays absolute)
function local(url, k) { try { const u = new URL(url); return u.hostname === k.site && location.hostname !== k.site ? u.pathname : url; } catch (e) { return url; } }
const row = (label, url, cls) => '<div class="kit-row"><div class="kit-l"><span class="kit-lab">' + esc(label) + '</span><code class="kit-url">' + esc(url) + '</code></div>' + cb(url, 'Copy link', cls) + '</div>';
function render(root, k) {
TXT.length = 0;
const angles = []; const by = {};
(k.creatives || []).forEach(c => { if (!by[c.angle]) { by[c.angle] = []; angles.push(c); } by[c.angle].push(c); });
let h = '';
h += '<div class="card"><h3>Your links</h3>' + (k.username ? '<p class="muted small">Every link, creative and line below carries <b>' + esc(k.username) + '</b>.</p>' : '<p class="muted small">Add your network username above so these links carry it.</p>')
+ k.links.map(l => row(l.label, l.url, '') + (l.tracked ? row(l.label + ', tracked', l.tracked, 'sec') : '')).join('')
+ (k.links.some(l => l.tracked) ? '<p class="muted small">A tracked link goes through LinkSpin first, so the network can see which site sent the visit, then opens the same page with your username. Use either one.</p>' : '') + '</div>';
h += '<div class="card"><h3>Creatives</h3><p class="muted small">Download them, or copy the HTML: it already links to you.</p><div class="kit-tabs" role="tablist">'
+ angles.map((c, i) => '<button type="button" class="kit-tab' + (i ? '' : ' on') + '" data-ka="' + esc(c.angle) + '">' + esc(c.angleLabel) + '</button>').join('') + '</div>';
angles.forEach((a, i) => {
h += '<div class="kit-set" data-ks="' + esc(a.angle) + '"' + (i ? ' hidden' : '') + '>' + by[a.angle].map(c =>
'<figure class="kit-fig kit-' + esc(c.shape) + '"><a href="' + esc(c.url) + '" target="_blank" rel="noopener"><img src="' + esc(local(c.url, k)) + '" alt="' + esc(k.name + ', ' + c.label) + '" width="' + c.w + '" height="' + c.h + '" loading="lazy"></a>'
+ '<figcaption><b>' + esc(c.label) + '</b> <span class="muted">' + c.w + 'x' + c.h + '</span><span class="kit-acts"><a class="btn small sec" href="' + esc(c.url) + '" download>Download</a>' + cb(c.url, 'Copy URL') + cb(c.html, 'Copy HTML') + '</span></figcaption></figure>').join('') + '</div>';
});
h += '</div>';
h += '<div class="card"><h3>Short lines</h3><p class="muted small">For chats, comments, text ads and signatures.</p>' + k.lines.map(t => '<div class="kit-row"><p class="kit-txt">' + esc(t) + '</p>' + cb(t) + '</div>').join('') + '</div>';
h += '<div class="card"><h3>Headlines</h3>' + k.headlines.map(t => '<div class="kit-row"><p class="kit-txt"><b>' + esc(t) + '</b></p>' + cb(t) + '</div>').join('') + '</div>';
h += '<div class="card"><h3>Email</h3><div class="kit-row"><p class="kit-txt"><span class="kit-lab">Subject</span>' + esc(k.email.subject) + '</p>' + cb(k.email.subject, 'Copy subject') + '</div>'
+ '<pre class="kit-pre">' + esc(k.email.body) + '</pre><div class="kit-row" style="justify-content:flex-end">' + cb(k.email.body, 'Copy email') + '</div></div>';
h += '<div class="card"><h3>Social posts</h3>' + k.posts.map(t => '<div class="kit-post"><pre class="kit-pre">' + esc(t) + '</pre><div class="kit-row" style="justify-content:flex-end">' + cb(t, 'Copy post') + '</div></div>').join('') + '</div>';
if (k.note) h += '<p class="muted small kit-note">' + esc(k.note) + '</p>';
root.innerHTML = h;
root.querySelectorAll('[data-kc]').forEach(b => b.addEventListener('click', () => copy(TXT[Number(b.dataset.kc)], b)));
root.querySelectorAll('[data-ka]').forEach(b => b.addEventListener('click', () => {
root.querySelectorAll('[data-ka]').forEach(x => x.classList.toggle('on', x === b));
root.querySelectorAll('[data-ks]').forEach(s => { s.hidden = s.dataset.ks !== b.dataset.ka; });
}));
}
async function load(root, u) {
const r = await fetch('/api/promo-kit' + (u ? '?u=' + encodeURIComponent(u) : ''), { cache: 'no-store' });
const k = await r.json(); render(root, k); return k;
}
return { render, load, copy };
})();
+31
View File
@@ -0,0 +1,31 @@
// Live ledger (trust pack): every position with every share paid in the same transaction (sponsor 25%, levels 2-5 5%, with each
// person's place in the buyer's line), who was passed over, the Best Coach pot and the company, plus every Best Coach payout, from
// /api/ledger, refreshed every 30 seconds.
(function () {
FX.renderNav('/ledger'); FX.renderFooter();
const esc = FX.esc;
const pol = w => FX.polOf(w) + ' POL';
const usd = c => '$' + (Number(c || 0) / 100).toFixed(2);
const who = (a, nm) => nm ? '@' + esc(nm) : '<span class="small">' + esc(FX.short(a || '')) + '</span>';
async function load() {
let d; try { d = await FX.getJSON('/api/ledger?n=100'); } catch (e) { return; } if (!d || !d.items) return;
const ex = d.explorer || 'https://polygonscan.com'; const t = d.totals || {};
document.getElementById('totals').innerHTML = '<div class="stat"><span>Positions on-chain</span><b>' + FX.n(t.positions) + '</b></div>'
+ '<div class="stat"><span>To the Best Coach pot</span><b>' + pol(t.potWei) + '</b><em>10% of every position</em></div>'
+ '<div class="stat"><span>In positions</span><b>' + usd(t.usdCents) + '</b><em>at the price when bought</em></div>'
+ '<div class="stat"><span>Withdrawals needed</span><b>0</b><em>every share is paid in the same transaction</em></div>';
const body = document.querySelector('#rows tbody');
if (!d.items.length) body.innerHTML = '<tr><td colspan="4" class="muted">No positions yet. The first one shows here within a minute of its transaction.</td></tr>';
else body.innerHTML = d.items.map(r => {
const link = '<a href="' + esc(ex) + '/tx/' + esc(r.tx) + '" target="_blank" rel="noopener">verify</a>';
const pays = (r.pays || []).map(p => p.level === 0 ? '5xYourTeam: ' + pol(p.wei) : p.level === 6 ? 'Best Coach pot: ' + pol(p.wei)
: (p.level === 1 ? 'Sponsor 25%' : 'Level ' + p.level + ' 5%') + ': ' + pol(p.wei) + ' to ' + (p.to ? who(p.to, p.name) : 'sponsor') + (p.depth && p.depth !== p.level ? ' <span class="small">(place ' + p.depth + ')</span>' : '') + (p.failed ? ' <span class="small">(bounced, waiting in the contract for them to claim)</span>' : '')).join('<br>');
const over = (r.passedOver || []).length ? '<br><span class="small">Passed over (no position yet): ' + r.passedOver.map(o => (o.name ? '@' + esc(o.name) : esc(FX.short(o.who))) + ' at place ' + o.depth).join(', ') + '</span>' : '';
return '<tr><td class="small">' + FX.when(r.at) + '</td><td>' + who(r.buyer, r.buyerName) + ' bought ' + esc(r.what) + ' for ' + usd(r.usdCents) + '</td><td class="small">' + pays + over + '</td><td>' + link + '</td></tr>';
}).join('');
const pb = document.querySelector('#payouts tbody');
pb.innerHTML = (d.payouts || []).length ? d.payouts.map(p => '<tr><td>' + esc(p.week) + '</td><td>#' + esc(p.rank) + ' ' + who(p.coach, p.username) + '</td><td>' + pol(p.wei) + '</td><td><a href="' + esc(ex) + '/tx/' + esc(p.tx) + '" target="_blank" rel="noopener">verify</a></td></tr>').join('')
: '<tr><td colspan="4" class="muted">No Best Coach payouts yet. Each one is listed here with its transaction.</td></tr>';
}
load(); setInterval(load, 30000);
})();
+46
View File
@@ -0,0 +1,46 @@
// Small pages: promote (the kit), builder (my CryptoTeamBuild builder IDs), admin, legal. One file, chosen by data-page on <body>.
(async function () {
const page = document.body.dataset.page; const $ = FX.$, esc = FX.esc;
if (page === 'legal') { FX.renderNav(''); FX.renderFooter(); return; }
if (page === 'promote') {
FX.renderNav(''); FX.renderFooter();
const RE = /^(?:[A-Za-z0-9_.-]{2,40}|0x[0-9a-fA-F]{40})$/;
let u = new URLSearchParams(location.search).get('u') || '';
if (!RE.test(u)) { u = ''; try { const me = await FX.getJSON('/api/me'); if (me.signedIn) u = me.username || me.address || ''; } catch (e) {} }
if (!u) { try { u = localStorage.getItem('kit.u') || ''; } catch (e) {} if (!RE.test(u)) u = ''; }
$('whoIn').value = u;
const show = async name => { try { await KitPage.load($('kit'), name); FX.status(''); } catch (e) { FX.status('Could not load the kit. Try again in a moment.', 'err'); } };
$('whoForm').addEventListener('submit', e => { e.preventDefault(); const v = $('whoIn').value.trim().replace(/^@/, ''); if (v && !RE.test(v)) return FX.status('That does not look like a username.', 'err'); try { localStorage.setItem('kit.u', v); } catch (e2) {} show(v); });
return show(u);
}
if (page === 'builder') {
FX.renderNav(''); FX.renderFooter();
const me = await FX.getJSON('/api/me');
if (!me.signedIn) { $('bSign').hidden = false; $('bSignBox').innerHTML = FX.signInBlock('/builder'); FX.wireSignIn($('bSignBox')); return; }
const d = await FX.getJSON('/api/my/builder'); if (d.error) return FX.status(d.error, 'err');
$('bList').innerHTML = d.programs.map(p => '<div class="kit-row"><div class="kit-l"><span class="kit-lab">' + esc(p.name) + '</span><code class="kit-url">' + esc(p.example) + '</code></div><div class="row dark" style="flex:0 1 320px"><input data-p="' + esc(p.id) + '" value="' + esc(p.myId) + '" placeholder="your referral ID" aria-label="Your referral ID for ' + esc(p.name) + '"><button type="button" class="btn small" data-s="' + esc(p.id) + '">Save</button></div></div>').join('');
document.querySelectorAll('[data-s]').forEach(b => b.onclick = async () => { const inp = document.querySelector('[data-p="' + b.dataset.s + '"]'); const r = await FX.post('/api/my/builder', { program: b.dataset.s, refId: inp.value }); FX.status(r.error || 'Saved. Your picks see this link when they open your builder links.', r.error ? 'err' : 'ok'); if (!r.error) inp.value = r.refId; });
return;
}
if (page === 'admin') {
FX.renderNav(''); FX.renderFooter();
let tok = ''; try { tok = sessionStorage.getItem('fx.admin') || ''; } catch (e) {}
const H = () => ({ 'x-admin-token': tok, 'Content-Type': 'application/json' });
const show = (el, o) => { el.textContent = JSON.stringify(o, null, 2); };
const load = async () => { if (!tok) return; show($('statusOut'), await FX.getJSON('/api/admin/status', { headers: H() })); show($('potOut'), await FX.getJSON('/api/admin/pot', { headers: H() })); };
$('tokForm').addEventListener('submit', e => { e.preventDefault(); tok = $('tok').value.trim(); try { sessionStorage.setItem('fx.admin', tok); } catch (x) {} load(); });
$('tickBtn').onclick = async () => { show($('statusOut'), await FX.getJSON('/api/admin/tick', { method: 'POST', headers: H(), body: '{}' })); };
$('oldFile').addEventListener('change', async e => { const f = e.target.files[0]; if (!f) return; const r = await fetch('/api/admin/oldrefs', { method: 'POST', headers: H(), body: await f.text() }); show($('oldOut'), await r.json()); });
return load();
}
if (page === 'draftday') {
// the 1080 x 1080 Draft Day results card (tools/art.mjs renders it to PNG for Telegram); no nav, no footer
const wk = location.pathname.split('/').pop();
const d = await FX.getJSON('/api/draftday?week=' + encodeURIComponent(wk));
$('ddWeek').textContent = 'WEEK ' + FX.weekNo(wk);
$('ddRows').innerHTML = (d.rows || []).slice(0, 6).map(r => '<div class="dd-r"><span class="s">' + esc(r.slot) + '</span><span>@' + esc(r.coach) + ' takes @' + esc(r.person) + '</span></div>').join('') || '<div class="dd-r"><span>No picks yet</span></div>';
$('ddStats').textContent = FX.n(d.players || 0) + ' players drafted · ' + FX.n(d.coaches || 0) + ' coaches';
$('ddPot').textContent = 'Best Coach pot: ' + FX.polOf(d.potWei || 0) + ' POL';
document.body.dataset.ready = '1';
}
})();
+81
View File
@@ -0,0 +1,81 @@
// 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', 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);
})();
+233
View File
@@ -0,0 +1,233 @@
// 5xYourTeam wallet sign-in: the VBB / Downline Banners wallet.js (same AppKit build, chain guard, dead-session recovery)
// with its buy flow (2026-11-14): sendTx() hard-guards the chain, sets Polygon's fee floor from /api/gas and recovers a dead
// WalletConnect session once; waitTx() polls /api/tx; balance() is the pre-flight check. The page builds the call on the server.
window.FXWallet = (function () {
const pad = v => BigInt(v).toString(16).padStart(64, '0');
const padAddr = a => { if (!a) return pad(0); if (!/^0x[0-9a-fA-F]{40}$/.test(a)) throw new Error('Bad address: ' + a); return a.slice(2).toLowerCase().padStart(64, '0'); };
// Normalize a chainId to a decimal number. eth_chainId is meant to return a
// hex string, but some wallets return a number or a decimal string — compare
// numerically so a wallet's shape never crashes the flow.
const chainNum = v => {
if (v == null) return NaN;
if (typeof v === 'number') return v;
const s = String(v).trim();
return /^0x/i.test(s) ? parseInt(s, 16) : parseInt(s, 10);
};
const APPKIT_URL = 'https://cdn.jsdelivr.net/npm/@reown/appkit-cdn@1.8.23/dist/appkit.js';
let modal = null, akPromise = null, provider = null;
async function initAppKit(c) {
if (modal) return modal;
if (akPromise) return akPromise;
akPromise = (async () => {
const mod = await import(APPKIT_URL);
const { createAppKit, WagmiAdapter, networks } = mod;
const netMap = { 80002: networks.polygonAmoy, 137: networks.polygon, 31337: networks.hardhat || networks.localhost };
const base = netMap[Number(c.chainId)] || networks.polygonAmoy;
// Override the chain's RPC with our clean public endpoint. AppKit's built-in
// networks advertise the WalletConnect RPC proxy
// (rpc.walletconnect.org/v1/?chainId=…&projectId=…) as the chain RPC, and
// wallets reject that query-string URL as "Invalid URL" when adding/switching
// the network — the cause of Trust's "Invalid URL", MetaMask's switch loop,
// and the failed mobile buy (the chain switch never completed).
const rpc = String(c.rpc || '').trim();
const net = rpc ? Object.assign({}, base, { rpcUrls: { default: { http: [rpc] }, public: { http: [rpc] } } }) : base;
// Accept the wallet's usual networks too, so AppKit doesn't trap the user in
// its own "Switch Network" modal — that modal loops on a testnet the wallet
// can't auto-add. We switch to `net` ourselves (wallet_addEthereumChain adds
// + switches in one step) and sendTx hard-guards the chain before signing.
const allNets = [net];
for (const k of ['polygon', 'mainnet']) {
try { const n = networks[k]; if (n && n.id !== net.id) allNets.push(n); } catch (e) {}
}
const projectId = String(c.walletConnectProjectId || '').trim();
const wagmiAdapter = new WagmiAdapter({ networks: allNets, projectId });
modal = createAppKit({
adapters: [wagmiAdapter], networks: allNets, projectId, defaultNetwork: net,
metadata: { name: '5xYourTeam', description: 'The weekly draft for people who need a sponsor.',
url: location.origin, icons: [location.origin + '/art/icon-192.png'] },
features: { analytics: false, email: false, socials: [] },
// Picker order: wallets without Trust's balance-proportion block go first.
// Trust Wallet is NOT excluded; it just drops out of the featured row into
// "All wallets" (Marty, 2026-09-09: move Trust to the bottom, not off).
featuredWalletIds: [
'0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150', // SafePal (recommended, listed first)
'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', // MetaMask
'a797aa35c0fadbfc1a53e7f675162ed5226968b44a19ee3d24385c64d1d3c393', // Phantom
'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa' // Coinbase Wallet
]
});
return modal;
})();
return akPromise;
}
function currentAddress() { try { return (modal && modal.getAddress && modal.getAddress()) || null; } catch (e) { return null; } }
function waitForConnection(timeoutMs) {
if (currentAddress()) return Promise.resolve(currentAddress());
return new Promise((resolve, reject) => {
let done = false, unsub = null;
const finish = (addr, err) => { if (done) return; done = true; try { unsub && unsub(); } catch (e) {} err ? reject(err) : resolve(addr); };
try { unsub = modal.subscribeAccount(acc => { if (acc && acc.isConnected && acc.address) finish(acc.address); }); } catch (e) {}
const t0 = Date.now();
(function poll() {
if (done) return;
const a = currentAddress();
if (a) return finish(a);
if (Date.now() - t0 > (timeoutMs || 180000)) return finish(null, new Error('Wallet connection timed out. Tap Connect and try again.'));
setTimeout(poll, 400);
})();
});
}
async function resolveProvider() {
for (let i = 0; i < 20; i++) {
try { const p = modal.getWalletProvider ? await Promise.resolve(modal.getWalletProvider()) : null; if (p && p.request) return p; } catch (e) {}
await new Promise(r => setTimeout(r, 300));
}
throw new Error('Could not reach your wallet. Try connecting again.');
}
function eth() { if (!provider) throw new Error('Connect your wallet first.'); return provider; }
const isInjected = () => !!(provider && window.ethereum && (provider === window.ethereum || provider.isMetaMask));
// the account the wallet will actually sign with: for an injected wallet (MetaMask
// extension) that is its active account, which can differ from AppKit's cached one
async function activeAddress(fallback) {
if (isInjected()) { try { const a = await provider.request({ method: 'eth_accounts' }); if (a && a[0]) return a[0]; } catch (e) {} }
return fallback || currentAddress();
}
// Force the wallet's own account picker. Injected wallets stay connected to the
// site, so a plain disconnect/reconnect never shows one: asking for permissions
// again makes MetaMask open its account-selection prompt, and whatever the user
// ticks becomes the active account. WalletConnect wallets fall back to a fresh
// session (the picker + the wallet app's own account choice).
async function pickAccount() {
const c = await FX.getConfig();
await initAppKit(c);
const inj = window.ethereum;
if (inj && inj.request) {
try {
await inj.request({ method: 'wallet_requestPermissions', params: [{ eth_accounts: {} }] });
const accs = await inj.request({ method: 'eth_accounts' });
if (accs && accs[0]) { provider = inj; await ensureChain(c).catch(() => {}); return accs[0]; }
} catch (e) {
if (e && (e.code === 4001 || /reject|denied/i.test(String(e.message || '')))) throw new Error('You closed the account picker. Pick the account you want and try again.');
}
}
return freshConnect(c);
}
// A WalletConnect session can die underneath AppKit's cached "connected"
// state: the wallet app rejects or kills it (Trust does this after its own
// security stop), the phone sleeps, the relay drops. AppKit still reports an
// address, so the next request fails with a "disconnected" style error.
// Detect that, wipe the stale session, and re-open the picker for a fresh one.
const DEAD_RE = /disconnect|not connected|no matching key|session (topic|expired|deleted|not found)|call connect|please call connect|missing or invalid|relay/i;
const isDead = e => DEAD_RE.test(String((e && e.message) || e || ''));
async function freshConnect(c) {
try { FX.status('Your wallet session dropped. Reconnect in the picker…'); } catch (e) {}
await disconnect();
try { await modal.open(); } catch (e) {}
const addr = await waitForConnection(180000);
try { if (modal && modal.close) await modal.close(); } catch (e) {}
provider = await resolveProvider();
await ensureChain(c).catch(() => {});
return addr;
}
async function connect() {
const c = await FX.getConfig();
await initAppKit(c);
let addr = currentAddress();
if (!addr) {
// give AppKit a moment to rehydrate an existing session before popping the
// picker — otherwise an already-connected wallet still gets the modal
for (let i = 0; i < 8 && !addr; i++) { await new Promise(r => setTimeout(r, 150)); addr = currentAddress(); }
}
if (!addr) { try { await modal.open(); } catch (e) {} addr = await waitForConnection(180000); }
try { if (modal && modal.close) await modal.close(); } catch (e) {} // dismiss the picker once we're connected
provider = await resolveProvider();
// probe the session: a dead WalletConnect session answers with a disconnect error
try { await provider.request({ method: 'eth_chainId' }); }
catch (e) { if (isDead(e)) return freshConnect(c); }
await ensureChain(c).catch(() => {}); // AppKit already connects on the right network; switch is best-effort
return addr;
}
async function ensureChain(c) {
const want = '0x' + Number(c.chainId).toString(16);
let cur; try { cur = await eth().request({ method: 'eth_chainId' }); } catch (e) { return; }
if (chainNum(cur) === Number(c.chainId)) return;
try {
await eth().request({ method: 'wallet_switchEthereumChain', params: [{ chainId: want }] });
} catch (e) {
// any failure (not just 4902): try to add the chain — wallet_addEthereumChain
// adds AND switches in one step, which is what unblocks wallets that can't
// otherwise reach a chain they don't already have (e.g. a testnet).
const addParams = { chainId: want, chainName: c.chainName, nativeCurrency: { name: 'POL', symbol: 'POL', decimals: 18 }, rpcUrls: [c.rpc] };
if (c.explorer && /^https?:\/\//i.test(c.explorer)) addParams.blockExplorerUrls = [c.explorer];
try { await eth().request({ method: 'wallet_addEthereumChain', params: [addParams] }); } catch (e2) {}
}
}
// SIWE: challenge -> personal_sign -> verify (server sets the session cookie)
async function signIn(opts) {
const addr = (opts && opts.pick) ? await pickAccount() : await activeAddress(await connect());
const ch = await (await fetch('/api/auth/challenge', { method: 'POST',
headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ address: addr }) })).json();
if (ch.error) throw new Error(ch.error);
// hex-encode the message (Trust and others require hex for personal_sign)
const hexMsg = '0x' + Array.from(new TextEncoder().encode(ch.message)).map(b => b.toString(16).padStart(2, '0')).join('');
const sig = await eth().request({ method: 'personal_sign', params: [hexMsg, addr] });
const r = await (await fetch('/api/auth/verify', { method: 'POST',
headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ address: addr, signature: sig, asPosition: !!(opts && opts.asPosition) }) })).json();
if (r.error) throw new Error(r.error);
return r;
}
async function sendTx(to, data, valueHex) {
const c = await FX.getConfig();
const addr = await connect();
const wantNum = Number(c.chainId);
let cur; try { cur = await eth().request({ method: 'eth_chainId' }); } catch (e) {}
if (!isNaN(chainNum(cur)) && chainNum(cur) !== wantNum) {
await ensureChain(c);
try { cur = await eth().request({ method: 'eth_chainId' }); } catch (e) {}
if (!isNaN(chainNum(cur)) && chainNum(cur) !== wantNum)
throw new Error('Your wallet is on the wrong network. Switch it to ' + (c.chainName || 'Polygon') + ', then try again.');
}
const tx = { from: await activeAddress(addr), to, data };
if (valueHex) tx.value = valueHex;
try { const g = await (await fetch('/api/gas')).json(); if (g && g.maxPriorityFeePerGas && g.maxFeePerGas) { tx.maxPriorityFeePerGas = g.maxPriorityFeePerGas; tx.maxFeePerGas = g.maxFeePerGas; } } catch (e) {}
try { return await eth().request({ method: 'eth_sendTransaction', params: [tx] }); }
catch (e) {
if (!isDead(e)) throw e;
tx.from = await freshConnect(c);
return eth().request({ method: 'eth_sendTransaction', params: [tx] });
}
}
async function waitTx(hash) {
for (let i = 0; i < 120; i++) {
try { const r = await (await fetch('/api/tx/' + hash)).json(); if (r.found) return r; } catch (e) { /* app switch on a phone: keep polling */ }
await new Promise(res => setTimeout(res, 2500));
}
throw new Error('Still waiting for the transaction. Check it on the explorer; your position shows once it confirms.');
}
async function balance(addr) {
await connect();
return BigInt(await eth().request({ method: 'eth_getBalance', params: [addr || currentAddress(), 'latest'] }));
}
async function disconnect() {
// AppKit's disconnect can hang on the WalletConnect relay (esp. mobile) —
// never block on it, so the UI can't get stuck "disconnecting".
try { if (modal && modal.disconnect) await Promise.race([modal.disconnect(), new Promise(r => setTimeout(r, 1200))]); } catch (e) {}
provider = null;
try { Object.keys(localStorage).forEach(k => { if (/wc@2|walletconnect|w3m|wcm|reown|wagmi|appkit/i.test(k)) localStorage.removeItem(k); }); } catch (e) {}
}
function walletName() { try { const w = modal && modal.getWalletInfo && modal.getWalletInfo(); return (w && w.name) || ''; } catch (e) { return ''; } }
return { connect, signIn, sendTx, waitTx, balance, disconnect, address: currentAddress, activeAddress, pickAccount, walletName };
})();