a90d5eee78
Normal people join with email + password (sponsor attribution via cookie at
signup); the wallet only appears when buying or activating payouts, and gets
linked to the account then. Wallet-only sign-in remains for crypto-native
users. Sessions carry {email, address, memberId}.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
51 lines
2.4 KiB
JavaScript
51 lines
2.4 KiB
JavaScript
// Landing page: live ladder, buy buttons, sponsor attribution line.
|
|
(async function () {
|
|
await IAP.renderNav('home');
|
|
const c = await IAP.getConfig();
|
|
IAP.$('contractLink').href = c.explorer + '/address/' + c.contract;
|
|
|
|
const sp = await (await fetch('/api/sponsor')).json();
|
|
if (sp.sponsorId) {
|
|
const el = IAP.$('sponsorLine');
|
|
el.hidden = false;
|
|
el.textContent = 'You were invited by member #' + sp.sponsorId + '. Your purchases pay their team, and your own link will do the same for you.';
|
|
}
|
|
|
|
async function loadLadder() {
|
|
const { products } = await (await fetch('/api/catalog')).json();
|
|
const tb = document.querySelector('#ladder tbody');
|
|
tb.innerHTML = '';
|
|
const NAMES = { 1: 'Micro', 2: 'Activation', 3: 'Builder', 4: 'Growth', 5: 'Leader' };
|
|
for (const p of products) {
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = '<td><b>' + (NAMES[p.id] || 'Package ' + p.id) + '</b></td>'
|
|
+ '<td class="num">' + IAP.fmtUsd(p.priceCents) + '</td>'
|
|
+ '<td class="num">' + p.creditAmount.toLocaleString() + '</td>'
|
|
+ '<td class="num mono">' + (p.costWei ? IAP.fmtPol(p.costWei) + ' POL' : 'paused') + '</td>'
|
|
+ '<td><button class="btn small" data-id="' + p.id + '" data-cost="' + (p.costWei || '') + '"'
|
|
+ (p.costWei ? '' : ' disabled') + '>Buy</button></td>';
|
|
tb.appendChild(tr);
|
|
}
|
|
tb.querySelectorAll('button[data-id]').forEach(b => b.addEventListener('click', () => buyPack(b)));
|
|
}
|
|
async function buyPack(btn) {
|
|
try {
|
|
btn.disabled = true;
|
|
// email members get their wallet linked to the account at buy time
|
|
const me = await (await fetch('/api/me')).json();
|
|
if (me.signedIn && me.email && !me.address) {
|
|
IAP.status('First, a free signature links your wallet to your account…');
|
|
await IAPWallet.signIn();
|
|
}
|
|
IAP.status('Confirm the purchase in your wallet…');
|
|
const r = await IAPWallet.buy(Number(btn.dataset.id), sp.sponsorId || 0, btn.dataset.cost);
|
|
if (r.receipt.status !== '0x1') throw new Error('Transaction reverted. Check the explorer.');
|
|
IAP.status('Purchase settled on-chain. Credits are yours, payouts delivered. Watch it on the ledger.', 'ok');
|
|
IAP.refreshNavWallet();
|
|
} catch (e) {
|
|
IAP.status('Purchase failed: ' + (e.message || e), 'bad');
|
|
} finally { btn.disabled = false; }
|
|
}
|
|
loadLadder();
|
|
})();
|