// LinkSpin Wallet (payer rows show @username, the server attaches names; Marty 2026-10-09): paid-to-this-wallet, credits, positions, payout history (engine APIs). Connect/link a wallet and buy live on /credits. (function () { const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt; CR.mount({ active: 'wallet', title: 'Wallet', sub: 'loading' }); const pol = wei => { try { return (Number(BigInt(wei || '0') / 10000000000000000n) / 100).toFixed(2); } catch (e) { return '0.00'; } }; async function load() { let D, ME, POS = [], E = null; try { [D, ME] = await Promise.all([CR.get('/api/my/dashboard'), CR.me()]); } catch (e) { CR.sub('could not load'); return; } try { POS = await CR.get('/api/my/positions'); } catch (e) {} try { E = await CR.get('/api/my/activity'); } catch (e) {} // dollar value at today's POL price (Marty, 2026-10-22): one cached rate from our own server, US dollars let U = { usd: 0, at: 0 }; try { U = await CR.get('/api/public/polusd'); } catch (e) {} const usd = wei => { if (!(U.usd > 0)) return ''; let p = 0; try { p = Number(BigInt(wei || '0') / 10n ** 12n) / 1e6; } catch (e) {} return '≈ $' + (p * U.usd).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }; const addr = ME.address || ''; const on = !!ME.memberId; CR.sub(addr ? addr.slice(0, 6) + '…' + addr.slice(-4) + (on ? ' · payouts on' : ' · payouts off') : 'no wallet linked'); $('tiles').innerHTML = [['Paid to this wallet', pol(D.earnedWei || '0') + ' POL', (D.earnCount || 0) + ' transactions' + (U.usd > 0 && D.earnedWei && D.earnedWei !== '0' ? ' · ' + usd(D.earnedWei) + ' today' : '')], ['Credits', fmt((D.credits || 0) + (D.earnedCredits || 0)), fmt(D.credits || 0) + ' purchased · ' + fmt(D.earnedCredits || 0) + ' earned'], ['In campaigns', fmt(D.inCampaigns || 0), 'reserved by live campaigns'], ['Qualifying buyers', fmt(D.buyerCount || 0), (D.buyerCount || 0) >= 5 ? 'level 3 open' : (D.buyerCount || 0) >= 2 ? 'level 2 open' : 'level 2 at 2 buyers']] .map(([k, v, n], i) => '