// My account: SIWE sign-in, member state, free activation, invite link. (async function () { await IAP.renderNav('my'); const $ = IAP.$; async function render() { const me = await IAP.refreshNavWallet(); if (!me || !me.signedIn) { $('signinCard').hidden = false; $('memberArea').hidden = true; return; } $('signinCard').hidden = true; $('memberArea').hidden = false; if (me.memberId) { $('posLine').innerHTML = 'On-chain member #' + me.memberId + '
wallet ' + me.address.slice(0, 8) + '…' + me.address.slice(-6) + '' + (me.onchainSponsorId ? '
sponsored by member #' + me.onchainSponsorId : '
no sponsor (house line)'); $('creditLine').textContent = (me.credits || 0).toLocaleString(); const bc = me.buyerCount || 0; $('qualLine').innerHTML = '' + bc + ' qualifying buyer(s) referred
' + (bc >= 5 ? 'Level 3 unlocked: full three-level earnings' : bc >= 2 ? 'Level 2 unlocked · ' + (5 - bc) + ' more for level 3' : (2 - bc) + ' more ≥$20 buyer(s) unlock level 2'); $('activateCard').hidden = true; $('inviteLine').textContent = location.origin + '/join/' + me.memberId; $('copyInvite').hidden = false; loadActivity(); } else { $('posLine').innerHTML = 'Signed in as ' + me.address.slice(0, 8) + '…' + me.address.slice(-6) + '
free member, not on-chain yet' + (me.sponsorId ? '
invited by member #' + me.sponsorId : ''); $('creditLine').textContent = '0'; $('qualLine').textContent = 'Activate your payout wallet (or buy any package) to start; referrals who buy ≥$20 packages qualify you.'; $('activateCard').hidden = false; $('inviteLine').textContent = 'Your link appears after your free on-chain activation.'; $('copyInvite').hidden = true; } } async function loadActivity() { try { const c = await IAP.getConfig(); const a = await (await fetch('/api/my/activity')).json(); const fill = (id, evs, empty) => { const el = $(id); el.innerHTML = ''; if (!evs.length) { el.innerHTML = '
' + empty + '
'; return; } for (const ev of evs) el.appendChild(IAP.feedRow(ev, c)); }; fill('earnFeed', a.earnings, 'No payouts yet. They appear here the moment one lands.'); fill('refFeed', a.referrals, 'No referral activity yet. Share your invite link.'); fill('buyFeed', a.purchases, 'No purchases from this wallet yet.'); } catch (e) {} } $('signinBtn').addEventListener('click', async () => { try { $('signinBtn').disabled = true; IAP.status('Check your wallet for the free sign-in signature…'); await IAPWallet.signIn(); IAP.status('Signed in.', 'ok'); await render(); } catch (e) { IAP.status((e && e.message) || String(e), 'bad'); } finally { $('signinBtn').disabled = false; } }); $('activateBtn').addEventListener('click', async () => { try { $('activateBtn').disabled = true; const me = await (await fetch('/api/me')).json(); IAP.status('Confirm the free activation in your wallet…'); const r = await IAPWallet.activate(me.sponsorId || 0); if (r.receipt.status !== '0x1') throw new Error('Transaction reverted. Check the explorer.'); IAP.status('Payout wallet activated. Your invite link is live.', 'ok'); await render(); } catch (e) { IAP.status('Activation failed: ' + ((e && e.message) || e), 'bad'); } finally { $('activateBtn').disabled = false; } }); $('copyInvite').addEventListener('click', async () => { try { await navigator.clipboard.writeText($('inviteLine').textContent); IAP.status('Link copied.', 'ok'); } catch (e) { IAP.status('Copy failed. Select and copy the link text.', 'bad'); } }); render(); })();