Top-ups: check the ad's own position, say where the free credits are, offer to pay from another
Bug: topUpCampaign read the position from the owner's campaign list, which does not carry memberId, so every top-up was checked against the member's MAIN position (Jim Watts: every ad said 19 free). It now reads the ad's row. When the ad's position is short, the error names it and lists the member's other positions with their free credits; the dashboard offers to pay from the best one. Moving an ad settles any charges its old position already ran up (a burn on the old member id) before switching, so the new position only pays for views after the move. Weekly email: unspent credits are broken down by position with the advice to start a campaign from the largest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-5
@@ -22,7 +22,7 @@
|
||||
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);
|
||||
if (r.error) { const e = new Error(r.error); e.data = r; throw e; } // e.data: the full answer (e.g. top-up switch options)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1023,10 +1023,17 @@
|
||||
el.querySelectorAll('button[data-topup]').forEach(b => b.addEventListener('click', async () => {
|
||||
const n = await IAP.ask({ title: 'Add credits', text: 'How many credits to add to this campaign? More credits buy more views. They are set aside now and spend as views are delivered; anything unspent comes back when the campaign ends.', type: 'number', placeholder: 'e.g. 100', ok: 'Add credits' });
|
||||
if (!n) return;
|
||||
try { const r = await api('/api/my/campaigns/' + b.dataset.topup + '/topup', { credits: Number(n) });
|
||||
IAP.status('Added ' + r.added + ' credits' + (r.reactivated ? ' — campaign is live again.' : '.'), 'ok');
|
||||
await loadCampaigns(); loadDashboard();
|
||||
} catch (e) { IAP.status(e.message, 'bad'); }
|
||||
const done = r => { IAP.status('Added ' + r.added + ' credits' + (r.paidFrom ? ', paid from position #' + r.paidFrom : '') + (r.reactivated ? '. The campaign is live again.' : '.'), 'ok'); };
|
||||
try { done(await api('/api/my/campaigns/' + b.dataset.topup + '/topup', { credits: Number(n) })); await loadCampaigns(); loadDashboard(); }
|
||||
catch (e) {
|
||||
// the ad's own position is short but another of yours has the credits: offer to pay from that one
|
||||
const opt = e.data && e.data.switchOptions && e.data.switchOptions[0];
|
||||
if (!opt) { IAP.status(e.message, 'bad'); return; }
|
||||
const yes = await IAP.confirmBox('This ad pays from your position #' + e.data.fundId + ', which has ' + e.data.free + ' credits free. Your position #' + opt.memberId + ' has ' + opt.free + ' free. Pay for this top-up from #' + opt.memberId + '? From now on this ad spends from #' + opt.memberId + '.', { title: 'Pay from another position?', ok: 'Pay from #' + opt.memberId, cancel: 'Cancel' });
|
||||
if (!yes) return;
|
||||
try { done(await api('/api/my/campaigns/' + b.dataset.topup + '/topup', { credits: Number(n), switchTo: opt.memberId })); await loadCampaigns(); loadDashboard(); }
|
||||
catch (e2) { IAP.status(e2.message, 'bad'); }
|
||||
}
|
||||
}));
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1081,7 +1081,7 @@
|
||||
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/wallet.js?v=20260911a"></script>
|
||||
<script src="/assets/promo.js?v=20260925a"></script>
|
||||
<script src="/assets/my.js?v=20260926b"></script>
|
||||
<script src="/assets/my.js?v=20260927a"></script>
|
||||
<script src="/assets/chat.js?v=20260907l"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user