f053c1befa
Zero-dependency Node server on the RM Circle pattern. Chain config lives in the volume so the same code runs the Amoy dress rehearsal and mainnet. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
68 lines
3.2 KiB
JavaScript
68 lines
3.2 KiB
JavaScript
// 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 <b>member #' + me.memberId + '</b><br>wallet <span class="mono">'
|
|
+ me.address.slice(0, 8) + '…' + me.address.slice(-6) + '</span>'
|
|
+ (me.onchainSponsorId ? '<br>sponsored by member #' + me.onchainSponsorId : '<br>no sponsor (house line)');
|
|
$('creditLine').textContent = (me.credits || 0).toLocaleString();
|
|
const bc = me.buyerCount || 0;
|
|
$('qualLine').innerHTML = '<b>' + bc + '</b> qualifying buyer(s) referred<br>'
|
|
+ (bc >= 5 ? '<span class="badge">Level 3 unlocked — full three-level earnings</span>'
|
|
: bc >= 2 ? '<span class="badge">Level 2 unlocked</span> · ' + (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;
|
|
} else {
|
|
$('posLine').innerHTML = 'Signed in as <span class="mono">' + me.address.slice(0, 8) + '…' + me.address.slice(-6)
|
|
+ '</span><br>free member — not on-chain yet'
|
|
+ (me.sponsorId ? '<br>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;
|
|
}
|
|
}
|
|
|
|
$('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 — see 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();
|
|
})();
|