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>