// My account: email-first join/login, wallet link at purchase time,
// free payout activation, invite link, on-chain activity.
(async function () {
await IAP.renderNav('my');
const $ = IAP.$;
async function api(path, body) {
const r = await (await fetch(path, { method: 'POST',
headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) })).json();
if (r.error) throw new Error(r.error);
return r;
}
async function render() {
const me = await IAP.refreshNavWallet();
const signedIn = me && me.signedIn;
$('authArea').hidden = !!signedIn;
$('memberArea').hidden = !signedIn;
if (!signedIn) return;
const who = [];
if (me.email) who.push(me.email);
if (me.address) who.push('wallet ' + me.address.slice(0, 8) + '…' + me.address.slice(-6) + '');
else who.push('no wallet linked yet');
if (me.memberId) who.push('on-chain member #' + me.memberId + ''
+ (me.onchainSponsorId ? ', sponsored by #' + me.onchainSponsorId : ''));
else if (me.sponsorId) who.push('invited by member #' + me.sponsorId);
$('posLine').innerHTML = who.join('
');
$('creditLine').textContent = (me.credits || 0).toLocaleString();
$('linkCard').hidden = !!me.address;
$('activateCard').hidden = !(me.address && !me.memberId);
$('activityArea').hidden = !me.memberId;
if (me.memberId) {
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 buyer(s) of $20+ unlock level 2');
$('inviteLine').textContent = location.origin + '/join/' + me.memberId;
$('copyInvite').hidden = false;
loadActivity();
} else {
$('qualLine').textContent = 'Level 1 pays the moment you are on-chain. Referrals who buy packages of $20 or more unlock levels 2 and 3.';
$('inviteLine').textContent = me.address
? 'Activate payouts above and your invite link appears here.'
: 'Link a wallet and switch on payouts to get your invite link.';
$('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 || !evs.length) { el.innerHTML = '