diff --git a/docstore.js b/docstore.js index c3e9359..0bc07e4 100644 --- a/docstore.js +++ b/docstore.js @@ -177,8 +177,15 @@ async function runRows() { const rowPut = (table, id, ts, obj) => rowOp({ table, id: String(id), ts: Number(ts) || 0, body: JSON.stringify(obj) }); const rowDel = (table, ids) => { const list = [...ids].map(String); for (let i = 0; i < list.length; i += 1000) rowOp({ table, del: true, ids: list.slice(i, i + 1000) }); }; function isOn() { return ready && !!pool; } +// once across app copies (two run side by side during a deploy): true for the first caller of a key, false after. Without MySQL: true. +async function claim(key) { + if (!pool) return true; + await pool.query('CREATE TABLE IF NOT EXISTS doc_claims (k VARCHAR(190) PRIMARY KEY, at BIGINT NOT NULL) ENGINE=InnoDB'); + const [r] = await pool.query('INSERT IGNORE INTO doc_claims (k, at) VALUES (?, ?)', [String(key).slice(0, 190), Date.now()]); + return r.affectedRows === 1; +} // SIGTERM during a deploy: write what is pending, then exit async function drain(ms) { const end = Date.now() + (ms || 8000); while ((pending.size || flushing || rowQ.length || rowBusy) && Date.now() < end) { await flush().catch(() => {}); await new Promise(r => setTimeout(r, 100)); } } function view() { return Object.assign({ ready, writer, documents: cache.size, pending: pending.size, rowQueue: rowQ.length, rowTables: Object.fromEntries([...ROWS].map(([k, v]) => [k, v.length])), bytes: [...cache.values()].reduce((t, d) => t + d.body.length, 0) }, stats); } -module.exports = { install, init, drain, flush, view, nameOf, rows, rowPut, rowDel, isOn }; +module.exports = { install, init, drain, flush, view, nameOf, rows, rowPut, rowDel, isOn, claim }; diff --git a/public/assets/common.js b/public/assets/common.js index b254aba..c13539c 100644 --- a/public/assets/common.js +++ b/public/assets/common.js @@ -17,7 +17,7 @@ window.BL = (function () { async function renderNav(active) { const c = await getConfig().catch(() => ({})); const n = document.createElement('nav'); - const links = [['/', 'Home'], ['/board', 'Board'], ['/how', 'How it works'], ['/join', 'Get a spot'], ['/my', 'My Spots']]; + const links = [['/', 'Home'], ['/board', 'Board'], ['/how', 'How it works'], ['/ledger', 'Ledger'], ['/join', 'Get a spot'], ['/my', 'My Spots']]; n.innerHTML = '
Part of the Crypto Team Build Network
' + 'A spot buys 300 guaranteed views on the board and a place in the line. Nothing is promised: you are paid only when spots sell after yours, and a spot can earn back less than it cost.
' - + 'How it works · Board · Live ledger · Contract proof · My Spots
'; document.body.appendChild(f); + toasts(); } // one spot tile; href goes through the /go relay, which counts the click function tile(t, opts) { @@ -50,6 +51,30 @@ window.BL = (function () { if (opts && opts.meta) { const m = document.createElement('span'); m.className = 'lot-meta'; m.textContent = t.t === 'spot' ? '#' + t.id : 'network'; a.appendChild(m); } return a; } + // live sale toasts (Marty 2026-11-13): real sales from the ledger only, bottom-left, one at a time, never older than 30 minutes + let toastsOn = false; + async function toasts() { + if (toastsOn) return; toastsOn = true; + const seen = new Set(); let first = true; + const box = document.createElement('div'); box.className = 'bl-toasts'; box.setAttribute('aria-live', 'polite'); document.body.appendChild(box); + const show = it => { + const top = it.pays.filter(p => !p.failed).sort((a, b) => (BigInt(b.wei) > BigInt(a.wei) ? 1 : -1))[0]; + const name = it.ownerName ? '@' + esc(it.ownerName) : 'A member'; + const el = document.createElement('a'); el.className = 'bl-toast'; el.href = '/ledger'; + el.innerHTML = '' + name + ' took spot #' + it.spotId + + (top ? '' + esc(d.error) + '
'; return; } + const ex = d.explorer; + const addr = (a, label) => a ? '' + esc(a) + '' + (label ? ' ' + esc(label) + '' : '') : '-'; + const rows = [ + ['Contract', addr(d.address) + ' Verified source read the code'], + ['Network', esc(d.chain) + ' (chain ' + esc(d.chainId) + ')'], + ['Deployed', '' + esc(d.deployTx.slice(0, 18)) + '...' + (d.deployBlock ? ' block ' + esc(d.deployBlock) : '')], + ['Owner', addr(d.owner, 'can pause new sales and change the keeper; cannot move funds or change the split')], + ['Keeper', addr(d.keeper, 'the only wallet allowed to make momentum-fund buys')], + ['Company A', addr(d.feeA)], ['Company B', addr(d.feeB)], + ['Price feed', addr(d.priceFeed, 'Chainlink POL/USD')], + ['Spot price now', d.quoteWei ? fmtPol(d.quoteWei) + ' POL ($5)' : '-'], + ['Spots sold', esc(d.spotCount || '0')], + ['Momentum fund', d.fundBalance ? fmtPol(d.fundBalance) + ' POL' : '-'], + ['Sales', d.paused === 'true' ? 'paused' : 'open']]; + $('facts').innerHTML = '| ' + r[0] + ' | ' + r[1] + ' |
|---|
No earlier spots or sponsor to pay yet.
') + + 'Company + momentum fund: ' + fmtPol(it.houseWei) + ' POL' + usd(it.houseWei, it.usd) + + ' · Verify on Polygonscan
No spot sales yet.
'; + $('upd').textContent = 'Updated ' + new Date().toLocaleTimeString(); + } + await load(); setInterval(load, 20000); +})(); diff --git a/public/assets/line.css b/public/assets/line.css index e7b29bc..d4ea5be 100644 --- a/public/assets/line.css +++ b/public/assets/line.css @@ -49,3 +49,14 @@ nav .links a.active{color:var(--mint-ink);background:var(--mint)} .brand img{flex:none;filter:drop-shadow(0 4px 14px rgba(155,123,255,.35))} .brand .logo{letter-spacing:-.02em} .ls-pick{margin:6px 0 4px}.ls-pick .row{gap:8px} +.ledger-row{border-top:1px solid var(--line);padding:12px 0} +.ledger-row:first-child{border-top:0} +.ledger-row .pays{margin:6px 0 4px;padding-left:18px;font-size:14px} +.badge-ok{display:inline-block;font-size:11.5px;font-weight:700;padding:2px 8px;border-radius:999px;background:var(--mint-soft);color:var(--mint);border:1px solid var(--mint-line);margin-left:6px} +.bl-toasts{position:fixed;left:max(16px,env(safe-area-inset-left,0px));bottom:max(16px,env(safe-area-inset-bottom,0px));z-index:50;display:flex;flex-direction:column;gap:8px;pointer-events:none} +.bl-toast{pointer-events:auto;display:block;max-width:300px;background:var(--panel-solid);border:1px solid var(--mint-line);border-radius:14px;padding:10px 14px;color:var(--ink);font-size:13.5px;line-height:1.35; + box-shadow:0 12px 30px -12px rgba(0,0,0,.8);opacity:0;transform:translateY(10px);transition:opacity .35s ease,transform .35s ease;text-decoration:none!important} +.bl-toast.in{opacity:1;transform:none} +.bl-toast span{color:var(--muted);font-size:12.5px} +@media (prefers-reduced-motion:reduce){.bl-toast{transition:none}} +@media (max-width:520px){.bl-toast{max-width:calc(100vw - 32px)}} diff --git a/public/board.html b/public/board.html index 240384a..256f48f 100644 --- a/public/board.html +++ b/public/board.html @@ -7,7 +7,7 @@ - +