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:
martbost
2026-09-27 06:05:19 -05:00
parent 5059d46bcb
commit 7ef8094a4d
5 changed files with 24 additions and 8 deletions
+9 -1
View File
@@ -248,7 +248,15 @@ async function nudgeTick() {
try {
const ids = [acct.memberId, ...(await accounts.positions(acct.email)).map(p => p.memberId)].filter(Boolean);
const bal = await X.ads.balances(ids, acct.email);
if (bal.available > 0) parts.push('- You have ' + bal.available.toLocaleString() + ' ad credits sitting unspent. That is ' + bal.available.toLocaleString() + ' cents of delivery doing nothing. Campaigns > New campaign, point it at your invite link: https://instantadpay.com/my#campaigns');
if (bal.available > 0) {
// credits sit on positions and each campaign pays from one, so a pooled total alone misleads
// members with linked positions (Jim Watts, 2026-09-27: "561 unspent" but a top-up allowed 19)
const onPos = (bal.per || []).filter(p => p.avail > 0).sort((a, b) => b.avail - a.avail);
const loose = (bal.credited || 0) + (bal.earned || 0);
let where = '';
if (onPos.length > 1) where = ' They are spread across your positions: ' + onPos.map(p => '#' + p.memberId + ' has ' + p.avail.toLocaleString()).join(', ') + (loose ? ', plus ' + loose.toLocaleString() + ' that any position can use' : '') + '. Each campaign pays from one position, so start a new campaign from #' + onPos[0].memberId + ' to use the most in one go.';
parts.push('- You have ' + bal.available.toLocaleString() + ' ad credits sitting unspent. That is ' + bal.available.toLocaleString() + ' cents of delivery doing nothing.' + where + ' Campaigns > New campaign, point it at your invite link: https://instantadpay.com/my#campaigns');
}
else if (bal.inCampaigns > 0) parts.push('- All ' + bal.inCampaigns.toLocaleString() + ' of your credits are working in live campaigns. Good.');
} catch (e) {}
// streak