f26ac15712
$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>
45 lines
4.2 KiB
JavaScript
45 lines
4.2 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;
|
|
}
|
|
$('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; }
|
|
};
|
|
})();
|