Files
martbost 47389a4169 Traffic-exchange frames: framed pages open sign-in, Get a Position, My Team, wallet and off-site links in a new tab carrying ?ref=<sponsor>
Traffic exchanges, rotators and Massifly Adpoints show 5xyourteam.com inside another site's frame, where the browser drops the
SameSite=Lax fx.ref and fx.sid cookies, so signing in, buying or joining from the frame lost the sponsor (Marty 2026-11-19).
- common.js: framed (window.top !== window.self) -> /team, /join, /admin, /sso/ and off-site links get target=_blank
  rel=noopener (on load and again at click time); /team, /join and /sso/ links add ?ref= from the page's ?ref= (or ?r=), the
  coach page it is, or the cookie. The wallet buttons ([data-wallet-signin], Pay = [data-full-window]) open this page in a new
  tab with ?ref= instead of signing inside the frame. Public pages stay in the frame.
- server: /sso/start?...&ref=<name> sets fx.ref first-party and 302s to the plain start; /sso/* sends X-Frame-Options DENY
  (/team and /admin already did). Sponsor rules unchanged.
- coach.js marks the coach; join.js keeps Pay clickable when framed; asset tags bumped.
Checked with the fake traffic-exchange harness (cross-site frame, JS a.click()): 11/11 flows open a new tab with the sponsor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 07:21:13 -06:00

45 lines
4.3 KiB
JavaScript

// 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 && !FX.framed); // framed: the button opens this page in a new tab (common.js)
}
$('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; }
};
})();