Qualified Start help: every Add-a-position step logged (browser stages + server answers, DATA_DIR/position-attempts.json, admin GET /api/admin/position-attempts?email=), a 20 s 'waiting on your wallet' tip when MetaMask stays silent, and Buy from always shown once a main wallet is linked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-19 04:23:05 -05:00
parent 2aef2c4b83
commit a9994e708d
3 changed files with 46 additions and 12 deletions
+18 -6
View File
@@ -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 = '<option value="main">Main wallet ' + (ME && ME.address ? short(ME.address) : '') + (ME && ME.memberId ? ' · #' + ME.memberId : '') + (main && main.noPayout ? ' · linkage only' : '') + '</option>'
+ list.map((x, i) => '<option value="' + esc(String(x.address).toLowerCase()) + '"' + (x.noPayout ? ' disabled' : '') + '>Position ' + (i + 2) + ' ' + short(x.address) + (x.memberId ? ' · #' + x.memberId : ' · not registered yet') + (x.noPayout ? ' · linkage only' : x.counted ? ' · counted' : '') + '</option>').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: '<div class="ink2" style="display:grid;gap:8px"><div>Your wallet asks which account to connect. Choose <b>only the new account</b> (not ' + esc(short(me.address)) + '), then sign once. No transaction, no cost.</div><div>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.</div></div>', 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();
+1 -1
View File
@@ -83,6 +83,6 @@
<script src="/assets/common.js?v=20261018p25"></script>
<script src="/assets/wallet.js?v=20261018a"></script>
<script src="/assets/cr-shell.js?v=20261018c"></script>
<script src="/assets/credits-screen.js?v=20261018p25"></script>
<script src="/assets/credits-screen.js?v=20261019pos"></script>
</body>
</html>
+27 -5
View File
@@ -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);