diff --git a/public/assets/credits-screen.js b/public/assets/credits-screen.js index 46b95ce..7aa19c6 100644 --- a/public/assets/credits-screen.js +++ b/public/assets/credits-screen.js @@ -48,16 +48,17 @@ const fp = fromPos(), n = fp ? posList().findIndex(x => String(x.address).toLowerCase() === fp) + 2 : 0; $('buyBtn').textContent = addr ? 'Buy ' + usd(p.priceCents) + ' package' + (fp ? ' from position ' + n : '') : 'Connect a wallet to buy'; } - // "Buy from": the main wallet or one of the positions (shown once a position exists) + // "Buy from": the main wallet or one of the positions. Always shown once a main wallet is linked (Michael 2026-10-18: + // the instructions say "pick it under Buy from" and the menu did not exist until a position was added) function paintFrom() { const list = posList(), main = POS && POS.main; if (!fromPos()) FROM = 'main'; - $('fromWrap').hidden = !list.length; - if (!list.length) return; + $('fromWrap').hidden = !(ME && ME.address); + if (!(ME && ME.address)) return; $('buyFrom').innerHTML = '' + list.map((x, i) => '').join(''); $('buyFrom').value = FROM; - $('fromHint').textContent = fromPos() ? 'Your wallet app must be on this position\'s account when you confirm. Its first package registers it under you.' : 'Your wallet app must be on this account when you confirm.'; + $('fromHint').textContent = fromPos() ? 'Your wallet app must be on this position\'s account when you confirm. Its first package registers it under you.' : (list.length ? 'Your wallet app must be on this account when you confirm.' : 'Your main wallet. Positions you add with "Add a position wallet" on this screen appear in this list.'); } function paintGoes() { const p = sel(); if (!p) return; @@ -104,14 +105,25 @@ else CR.toast('Connected as ' + short(a) + '. That account is not on LinkSpin yet. To buy from it, use Add a position wallet.'); paintFrom(); paintQuote(); } + // every Add-a-position attempt is reported to the server log, so support can see where it stopped (never blocks the flow) + function posReport(stage, detail) { try { fetch('/api/my/position-attempt', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ stage, detail: String(detail || '').slice(0, 300), ua: navigator.userAgent.slice(0, 160), wallet: !!window.ethereum, mm: !!(window.ethereum && window.ethereum.isMetaMask) }), keepalive: true }).catch(() => {}); } catch (e) {} } async function addPosition() { + posReport('click', ''); const me = await CR.me(true); if (!me.address) throw new Error('Link your main wallet first, then add positions under it.'); if (!me.memberId) throw new Error('Switch on payouts for your main wallet first. Positions register under your member number.'); const ok = await CR.dialog({ title: 'Add a position wallet', html: '
Your wallet asks which account to connect. Choose only the new account (not ' + esc(short(me.address)) + '), then sign once. No transaction, no cost.
No second account yet? MetaMask: account menu, Add account. SafePal or Trust: create or switch wallet. Phone with WalletConnect: pick the other wallet app in the list.
', ok: 'Ready', no: 'Cancel' }); - if (!ok) return; + if (!ok) { posReport('cancelled', ''); return; } CR.toast('Pick the new account in your wallet, then sign once…'); - const r = await IAPWallet.signIn({ asPosition: true, pick: true }); + posReport('start', ''); + // the wallet can sit silent (a request already waiting in MetaMask, its window behind the browser, or only one + // account to offer): after 20 s say what to check instead of looking like nothing happened (Michael 2026-10-18) + const tip = setTimeout(() => { posReport('no-answer-20s', ''); CR.dialog({ title: 'Waiting on your wallet', text: 'Your wallet has not answered yet. Open MetaMask (the fox icon in the browser toolbar): a request may be waiting there, or its window may be behind this one. You also need a second account in MetaMask: Accounts, then Add account. Pick only that new account and sign once.', ok: 'OK' }).catch(() => {}); }, 20000); + let r; + try { r = await IAPWallet.signIn({ asPosition: true, pick: true }); } + catch (e) { posReport('error', (e && e.message) || String(e)); throw e; } + finally { clearTimeout(tip); } + posReport('added', r && r.address); FROM = String(r.address || '').toLowerCase(); CR.toast('Position added: ' + short(r.address) + '. It is selected under Buy from. Pick a qualifying package and buy.'); await load(); diff --git a/public/credits.html b/public/credits.html index b47e359..7290263 100644 --- a/public/credits.html +++ b/public/credits.html @@ -83,6 +83,6 @@ - + diff --git a/server.js b/server.js index 326056b..5e0bbf5 100644 --- a/server.js +++ b/server.js @@ -526,6 +526,14 @@ async function adChecks(type, f) { } return { ok: true, warn }; } +// Qualified Start attempts (2026-10-19, Michael: 'Add a position and nothing happens'): every step the browser reports +// and every server answer to a position sign-in, kept as the last 1000 in DATA_DIR/position-attempts.json + one log line +function posLog(x) { + const e = Object.assign({ ts: Date.now() }, x); e.email = e.email ? String(e.email).toLowerCase() : null; + console.log('position attempt', e.email || '-', e.stage, String(e.detail || '').slice(0, 160), e.address || ''); + try { const f = path.join(DATA_DIR, 'position-attempts.json'); let a = []; try { a = JSON.parse(fs.readFileSync(f, 'utf8')); } catch (er) {} + a.push(e); if (a.length > 1000) a = a.slice(-1000); fs.writeFileSync(f + '.tmp', JSON.stringify(a)); fs.renameSync(f + '.tmp', f); } catch (er) {} +} const editFee = () => { const n = Math.floor(Number(siteConfig().campaignEditFee)); return n >= 0 ? n : 100; }; // one path for member and admin edits: the outside checks on whatever changed, then ads.editCampaign (shape checks, // fee, history, network copy). Open ad-viewer tokens for this campaign get the new link, so a view in flight frames it. @@ -1573,14 +1581,28 @@ const server = http.createServer(async (req, res) => { const r = auth.makeChallenge(b.address); return json(res, r.error ? 400 : 200, r); } + if (p === '/api/my/position-attempt' && req.method === 'POST') { // browser-side steps of Add a position (support diagnostics) + const s = await auth.fromRequest(req).catch(() => null); const b = await readBody(req).catch(() => ({})); + const stage = String(b.stage || '').replace(/[^a-z0-9-]/gi, '').slice(0, 30); if (!stage) return json(res, 400, { error: 'stage' }); + posLog({ email: s && s.email, stage: 'client-' + stage, detail: String(b.detail || '').slice(0, 300), ua: String(b.ua || '').slice(0, 160), wallet: !!b.wallet, mm: !!b.mm }); + return json(res, 200, { ok: true }); + } + if (p === '/api/admin/position-attempts' && (req.method === 'GET' || req.method === 'POST')) { + if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); + let a = []; try { a = JSON.parse(fs.readFileSync(path.join(DATA_DIR, 'position-attempts.json'), 'utf8')); } catch (e) {} + const em = String(u.searchParams.get('email') || '').toLowerCase(); if (em) a = a.filter(x => x.email === em); + return json(res, 200, { attempts: a.slice(-200).reverse() }); + } if (p === '/api/auth/verify' && req.method === 'POST') { const b = await readBody(req); const r = await auth.verifyChallenge(b.address, b.signature); - if (r.error) return json(res, 400, r); + if (r.error) { if (b.asPosition) { const s0 = await auth.fromRequest(req).catch(() => null); posLog({ email: s0 && s0.email, stage: 'server-verify', detail: r.error, address: b.address }); } return json(res, 400, r); } let memberId = 0; try { memberId = await chain.memberIdByAccount(r.address); } catch (e) {} const s = await auth.fromRequest(req); + if (b.asPosition && !(s && s.email)) posLog({ stage: 'server-no-session', detail: 'position sign-in without a signed-in account', address: r.address }); if (s && s.email && b.asPosition) { + const jsonP = (code, body) => { posLog({ email: s.email, stage: code === 200 ? 'server-added' : 'server-refused', detail: body.error || '', address: r.address, memberId }); return json(res, code, body); }; // Qualified Start: a second (third…) wallet on the same account. It becomes // its own on-chain member under this member's id when it buys; the session // stays on the main wallet. @@ -1590,17 +1612,17 @@ const server = http.createServer(async (req, res) => { const MAX_POS = 5; const have = await accounts.positions(s.email); if (!have.find(p => p.address === r.address.toLowerCase()) && have.length >= MAX_POS) - return json(res, 400, { error: 'You can link up to ' + MAX_POS + ' positions, which is everything Qualified Start needs. Once qualified, buy from your main wallet so your sponsor is paid in full.' }); + return jsonP(400, { error: 'You can link up to ' + MAX_POS + ' positions, which is everything Qualified Start needs. Once qualified, buy from your main wallet so your sponsor is paid in full.' }); if (memberId) { const mainId = await auth.refreshMemberId(s); let mm = null; try { mm = await chain.member(memberId); } catch (e) {} if (mm && mainId && mm.sponsorId !== mainId) - return json(res, 400, { error: 'That wallet is already registered on-chain under ' + (mm.sponsorId ? 'member #' + mm.sponsorId : 'no sponsor') + ', not under your main member #' + mainId + '. Only positions registered directly under you can be linked.' }); + return jsonP(400, { error: 'That wallet is already registered on-chain under ' + (mm.sponsorId ? 'member #' + mm.sponsorId : 'no sponsor') + ', not under your main member #' + mainId + '. Only positions registered directly under you can be linked.' }); } const pr = await accounts.addPosition(s.email, r.address); - if (pr.error) return json(res, 400, pr); + if (pr.error) return jsonP(400, pr); if (memberId) await accounts.setPositionMember(r.address, memberId); - return json(res, 200, { ok: true, position: true, address: r.address, memberId }); + return jsonP(200, { ok: true, position: true, address: r.address, memberId }); } if (s && s.email) { const lr = await accounts.linkWallet(s.email, r.address);