diff --git a/pdsync.js b/pdsync.js index 8e75a79..e281648 100644 --- a/pdsync.js +++ b/pdsync.js @@ -52,6 +52,7 @@ async function sync() { for (const row of (served.rows || [])) { const id = String(row.iapId); const now = Number(row.received) || 0; const prev = Number(S.served[id] || 0); if (now <= prev) { if (now < prev) S.served[id] = now; continue; } // PD's counter reset (row recreated): re-baseline, never charge backwards + if (process.env.PD_SYNC_APPLY === '0') { S.served[id] = now; t.ignored = (t.ignored || 0) + (now - prev); continue; } // staging bridge: test views are read and baselined, never counted as delivery try { const res = await X.ads.applyExternalVisits(Number(id), now - prev, 'PassiveDrip'); S.served[id] = now; t.applied += res.applied || 0; if (res.closed) t.closed++; } catch (e) { console.error('pdsync apply', id, e.message); } // one bad row never stops the others; its delta is retried next sync } diff --git a/public/assets/my.js b/public/assets/my.js index c56e460..71a41ec 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -379,7 +379,7 @@ $('dbCredits').textContent = (purchased + earned).toLocaleString(); // the Wallet tab card showed on-chain credits only, so promo/earned credits looked like 0 there (Jim, 2026-09-13) if ($('creditLine')) $('creditLine').innerHTML = (purchased + earned).toLocaleString() + ' ' + purchased.toLocaleString() + ' purchased · ' + earned.toLocaleString() + ' earned'; - $('dbCreditsSub').textContent = purchased.toLocaleString() + ' purchased' + (d.creditedCredits ? ' (' + d.creditedCredits.toLocaleString() + ' credited to you)' : '') + ' · ' + earned.toLocaleString() + ' earned' + (inC ? ' · ' + inC.toLocaleString() + ' in campaigns' : ''); + $('dbCreditsSub').textContent = purchased.toLocaleString() + ' purchased' + (d.creditedCredits ? ' (' + d.creditedCredits.toLocaleString() + ' credited to you)' : '') + ' · ' + earned.toLocaleString() + ' earned' + (d.earnedReserved ? ' (+' + d.earnedReserved.toLocaleString() + ' earned and bonus credits working in your live campaigns)' : '') + (inC ? ' · ' + inC.toLocaleString() + ' in campaigns' : ''); donut($('chDonut'), [{ v: purchased, color: CH.mint }, { v: earned, color: CH.cyan }, { v: inC, color: CH.amber }], { big: (purchased + earned).toLocaleString(), small: 'available' }); @@ -991,14 +991,14 @@ if ($('spendBanner')) { $('spendBanner').hidden = false; $('spendBig').textContent = r.availableCredits.toLocaleString(); - $('spendSub').textContent = '= $' + (r.availableCredits / 100).toLocaleString(undefined, { maximumFractionDigits: 2 }) + ' of ad delivery · ' + r.purchasedCredits.toLocaleString() + ' purchased' + (r.creditedCredits ? ' (' + r.creditedCredits.toLocaleString() + ' of it credited to you, spends on anything)' : '') + ' + ' + (r.earnedCredits || 0).toLocaleString() + ' earned' + (r.positionCount > 1 ? ' · pooled across ' + r.positionCount + ' positions (largest single position ' + (r.largestPosition || 0).toLocaleString() + ')' : ''); + $('spendSub').textContent = '= $' + (r.availableCredits / 100).toLocaleString(undefined, { maximumFractionDigits: 2 }) + ' of ad delivery · ' + r.purchasedCredits.toLocaleString() + ' purchased' + (r.creditedCredits ? ' (' + r.creditedCredits.toLocaleString() + ' of it credited to you, spends on anything)' : '') + ' + ' + (r.earnedCredits || 0).toLocaleString() + ' earned' + (r.earnedReserved ? ' (' + r.earnedReserved.toLocaleString() + ' more earned and bonus credits are already working inside your live campaigns)' : '') + (r.positionCount > 1 ? ' · pooled across ' + r.positionCount + ' positions (largest single position ' + (r.largestPosition || 0).toLocaleString() + ')' : ''); if ($('spendNote')) $('spendNote').textContent = r.inCampaigns ? 'Not counting ' + r.inCampaigns.toLocaleString() + ' credits already set aside for your live campaigns. That budget spends down inside each campaign below. This number only moves when you start, top up or pause a campaign.' : 'This is what is not committed to a campaign. When you start one, its budget moves out of here and spends down inside the campaign.'; $('spendRates').innerHTML = [['Banner', r.rates.bannerCreditsPerBatch + ' cr / ' + r.rates.bannerBatch + ' views'], ['Text', r.rates.textCreditsPerBatch + ' cr / ' + r.rates.textBatch + ' views'], ['Login', r.rates.loginCreditsPerDay + ' cr / day'], ['Solo', r.rates.soloCostPerRecipient + ' cr / delivery'], ['Featured', (r.rates.featuredPerDay || 40) + ' cr / day'], ['Visit', (r.rates.visitCostPerVisit || 3) + ' cr / visit']].map(x => '' + x[0] + ' ' + x[1] + '').join(''); } $('rateLine').textContent = 'Available to spend: ' + r.availableCredits.toLocaleString() - + (r.earnedCredits ? ' (' + r.purchasedCredits.toLocaleString() + ' purchased + ' + r.earnedCredits + ' earned)' : '') + + ((r.earnedCredits || r.earnedReserved) ? ' (' + r.purchasedCredits.toLocaleString() + ' purchased + ' + (r.earnedCredits || 0) + ' earned' + (r.earnedReserved ? ', ' + r.earnedReserved.toLocaleString() + ' more earned and bonus credits already working inside your live campaigns' : '') + ')' : '') + (r.inCampaigns ? ' · ' + r.inCampaigns.toLocaleString() + ' set aside in live campaigns' : '') + ' credits · rates: banner ' + r.rates.bannerCreditsPerBatch + 'cr/' + r.rates.bannerBatch + ' views, text ' + r.rates.textCreditsPerBatch + 'cr/' + r.rates.textBatch diff --git a/public/my.html b/public/my.html index 937209e..f4fdbd7 100644 --- a/public/my.html +++ b/public/my.html @@ -1085,7 +1085,7 @@ - + diff --git a/server.js b/server.js index 582ae55..bb0435b 100644 --- a/server.js +++ b/server.js @@ -1687,7 +1687,7 @@ const server = http.createServer(async (req, res) => { out.buyerCount = mm.buyerCount; out.onchainSponsorId = mm.sponsorId; const bal = await ads.balances((await myMemberIds(s)).ids, s.email); - out.credits = bal.total; out.creditedCredits = bal.credited; out.earnedCredits = bal.earned; out.inCampaigns = bal.inCampaigns; out.availableCredits = bal.available; + out.credits = bal.total; out.creditedCredits = bal.credited; out.earnedCredits = bal.earned; out.earnedReserved = bal.earnedReserved; out.inCampaigns = bal.inCampaigns; out.availableCredits = bal.available; } catch (e) { out.chainReadError = true; } } return json(res, 200, out); @@ -1750,7 +1750,7 @@ const server = http.createServer(async (req, res) => { for (const id of mine.ids) if (id && id !== memberId) { try { out.buyerCountPositions += (await chain.member(id)).buyerCount || 0; } catch (e) {} } out.buyerCountAll = out.buyerCountMain + out.buyerCountPositions; // badges count every position; levels the contract pays #main on depend on buyerCount alone const bal = await ads.balances(mine.ids, s.email); - out.credits = bal.total; out.creditedCredits = bal.credited; out.earnedCredits = bal.earned; out.inCampaigns = bal.inCampaigns; out.availableCredits = bal.available; + out.credits = bal.total; out.creditedCredits = bal.credited; out.earnedCredits = bal.earned; out.earnedReserved = bal.earnedReserved; out.inCampaigns = bal.inCampaigns; out.availableCredits = bal.available; } catch (e) { out.chainReadError = true; } let earned = 0n, n = 0; for (const ev of chain.recentEvents(1e9)) { // whole history, not the last 600