One-tap switch on payouts after a holding-tank assignment + reminders (Marty approved 2026-10-27)

- Assignment chat + member email (manual adoption and the 24h auto-assign) carry "Switch on payouts" -> https://instantadpay.com/my?activate=1#wallet
- /my?activate=1: signed in, wallet linked, real sponsor, no hold -> Wallet tab, explainer line, the Activate button's own flow (injected wallet or the WalletConnect picker on a phone). Survives sign-in and the wallet link (sessionStorage); never starts on tankHold, a blocked/routed sponsor or the #1 fallback (/api/me sponsorFallback)
- payTick (in the 15-min readyTick): not activated 24h after the assignment -> ONE member email + ONE in-app notice to the sponsor; 72h -> last member email; stops on memberId / MemberActivated / sponsor change. State tank-ready.json `pay`, each send gated by marks.claim (deploy overlap), record saved before the send; Admin tank view gets payReminders
- Chatbot: tank-activate-link canned answer + system prompt; my.js ?v=20261027pa
- qa/tank-hold.mjs: link texts, reminder schedule on a mocked clock, overlap copy, ?activate=1 browser flows (stubbed wallet)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-27 07:29:43 -05:00
parent e5c55c2d8b
commit 59607d0c94
6 changed files with 251 additions and 23 deletions
+70 -5
View File
@@ -140,11 +140,13 @@ async function adopt(adopterEmail, who, note, opts) {
const text = String(note || '').trim().slice(0, 600) || ('Hi, I am ' + nameOf(me) + '. You joined InstantAdPay without a sponsor, so I picked you up from the holding tank. I will walk you through the first three steps whenever you are ready. Reply here.');
const ad = await impl().add({ adoptee: target.email, adopter: e, ts: now, expires: now + TTL_MS, status: 'open', note: (opts && opts.recordNote) || text });
{ const rr = RS.load().ready[target.email]; if (rr && !rr.done) { rr.done = now; rr.adoptedBy = e; RS.save(); } } // the hold lifts: their sponsor resolves now
try { await messages.sendChat(me.memberId || 0, e, target.email, text); } catch (err) {}
payTrack(target.email, e, ad.id, auto); // switch-on-payouts reminders at 24 h and 72 h (payTick)
const link = activateLink();
try { await messages.sendChat(me.memberId || 0, e, target.email, text + '\n\n' + chatPayLine(link)); } catch (err) {}
if (mailer && mailer.hasKey()) {
try {
await mailer.send(target.email, nameOf(me) + ' is now your sponsor on InstantAdPay',
'You joined InstantAdPay without a sponsor. ' + nameOf(me) + ' has picked you up from the holding tank and is your sponsor now, which means a real person to walk you through the first steps.\n\nTheir message:\n\n' + text + '\n\nReply in your member area: ' + siteUrl + '/my#messages\n\nInstantAdPay');
'You joined InstantAdPay without a sponsor. ' + nameOf(me) + ' has picked you up from the holding tank and is your sponsor now, which means a real person to walk you through the first steps.\n\nTheir message:\n\n' + text + '\n\n' + mailPayBlock(nameOf(me), link, !!target.wallet) + '\n\nReply in your member area: ' + siteUrl + '/my#messages\n\nInstantAdPay');
} catch (err) {}
if (auto) {
try {
@@ -476,15 +478,78 @@ async function readyTick() {
}
RS.save();
const auto = await autoAssign();
return { fresh, aligned, assigned: auto.assigned, held: auto.held };
const pay = await payTick().catch(e => { console.error('tank payTick', e.message); return { sent: [] }; });
return { fresh, aligned, assigned: auto.assigned, held: auto.held, reminders: pay.sent };
}
// ── one-tap switch on payouts after an assignment (Marty, 2026-10-27) ──
// The contract only has activate(sponsorId) from the member's OWN wallet (non-custodial), so the site cannot switch
// payouts on for them. What it can do: every assignment (manual adoption or the 24-hour safety net) carries a link to
// /my?activate=1#wallet, which starts the Activate flow with the sponsor filled in (my.js), and a member who has not
// switched on payouts gets ONE reminder email at 24 hours (and the new sponsor ONE notice), and a last email at 72 hours.
// Stops as soon as they activate or buy (memberId / MemberActivated), or the sponsor changes. State: tank-ready.json
// `pay` (adoptee email -> { at, adopter, adoptionId, auto, r1, r2, done }). Deploy overlap: each send is gated by
// hooks.claim (marks.claim, one MySQL row per key across both app copies) and the record is saved before the send.
const PAY_R1_MS = 24 * 3600 * 1000; // first reminder (member email + sponsor notice)
const PAY_R2_MS = 72 * 3600 * 1000; // last reminder (member email only)
const activateLink = () => siteUrl + '/my?activate=1#wallet';
const chatPayLine = link => 'Switch on payouts in one tap (one free transaction, it locks me in as your sponsor): ' + link;
function mailPayBlock(sponsorName, link, hasWallet) {
return 'Switch on payouts: ' + link + '\n'
+ 'One tap opens your wallet with ' + sponsorName + ' already filled in as your sponsor. It is one free transaction, no package needed, and it locks ' + sponsorName + ' in as your sponsor so every payment in your line can reach you.'
+ (hasWallet ? '' : ' No wallet linked yet? The same link shows you how (one free signature) and then carries on.');
}
function payTrack(adoptee, adopter, adoptionId, auto) {
const st = RS.load(); st.pay = st.pay || {};
st.pay[String(adoptee).toLowerCase()] = { at: clock(), adopter: String(adopter).toLowerCase(), adoptionId: adoptionId || null, auto: !!auto, r1: 0, r2: 0, done: null };
RS.save();
}
const claimOnce = async key => { if (!hooks.claim) return true; try { return !!(await hooks.claim(key)); } catch (e) { return false; } };
async function payTick() {
const st = RS.load(); st.pay = st.pay || {}; const now = clock(); const sent = [];
for (const [e, rec] of Object.entries(st.pay)) {
if (rec.done) continue;
const a = await accounts.byEmail(e);
if (!a) { rec.done = 'gone'; rec.doneAt = now; continue; }
if (Number(a.memberId) > 0) { rec.done = 'activated'; rec.doneAt = now; continue; } // switched on payouts or bought
if (a.address && hooks.activated) { let act = null; try { act = await hooks.activated(a); } catch (err) {} if (act) { rec.done = 'activated'; rec.doneAt = now; continue; } }
const sp = await accounts.byEmail(rec.adopter);
const toks = sp ? [sp.code, sp.username, sp.memberId ? String(sp.memberId) : null].filter(Boolean).map(x => String(x).toLowerCase()) : [];
if (!sp || !toks.includes(String(a.sponsorRef || '').toLowerCase())) { rec.done = 'moved'; rec.doneAt = now; continue; } // released, expired or moved
const age = now - rec.at; const link = activateLink(); const spName = nameOf(sp); const name = nameOf(a);
const noWallet = a.address ? '' : '\n\nNo wallet linked yet? The same link shows you how (one free signature) and then carries on.';
if (!rec.r1 && age >= PAY_R1_MS) {
rec.r1 = now; RS.save();
if (age >= PAY_R2_MS) rec.r1skipped = true; // already past 72 h (e.g. the app was down): one email only, the last one below
else if (await claimOnce('tankpay1:' + e + ':' + rec.at)) {
if (mailer && mailer.hasKey()) { try { await mailer.send(e, 'Reminder: switch on payouts with ' + spName + ' on InstantAdPay',
'Yesterday ' + spName + ' became your sponsor on InstantAdPay, but your payouts are not switched on yet, so nothing in your line can pay you.\n\nSwitch on payouts: ' + link + '\n\nOne tap opens your wallet with ' + spName + ' already filled in as your sponsor. It is one free transaction, no package needed, and it locks ' + spName + ' in as your sponsor.' + noWallet + '\n\nQuestions? Message ' + spName + ' in your member area: ' + siteUrl + '/my#messages\n\nInstantAdPay'); } catch (err) {} }
if (hooks.notify) { try { await hooks.notify(sp.email, name + ' hasn\'t switched on payouts yet',
name + ' hasn\'t switched on payouts yet; a nudge from you helps. They were assigned to you 24 hours ago and we sent them a reminder with a one-tap link.\n\nSend them a chat from My line (' + siteUrl + '/my#line), or pass on the same link: ' + link + '\n\nWhen they tap it, their wallet opens with you filled in as their sponsor.'); } catch (err) {} }
sent.push({ email: e, stage: 1, adopter: sp.email });
}
}
if (!rec.r2 && age >= PAY_R2_MS) {
rec.r2 = now; RS.save();
if (await claimOnce('tankpay2:' + e + ':' + rec.at)) {
if (mailer && mailer.hasKey()) { try { await mailer.send(e, 'Last reminder: switch on payouts with ' + spName + ' on InstantAdPay',
'Three days ago ' + spName + ' became your sponsor on InstantAdPay, and your payouts are still switched off, so any payment meant for you in your line cannot reach you.\n\nSwitch on payouts: ' + link + '\n\nOne tap opens your wallet with ' + spName + ' already filled in. It is one free transaction, no package needed, and it locks ' + spName + ' in as your sponsor.' + noWallet + '\n\nThis is the last reminder. Your account and your sponsor stay as they are.\n\nInstantAdPay'); } catch (err) {} }
sent.push({ email: e, stage: 2, adopter: sp.email });
}
rec.done = 'reminded'; rec.doneAt = now;
}
}
RS.save();
return { sent };
}
function payView() { return Object.entries(RS.load().pay || {}).map(([email, r]) => Object.assign({ email }, r)).sort((x, y) => y.at - x.at).slice(0, 100); }
function alignedRecent(n) { return RS.load().aligned.slice(-(n || 50)).reverse(); }
async function adminView() {
const recent = await impl().recent(200);
const names = {};
for (const ad of recent) for (const em of [ad.adoptee, ad.adopter]) if (!(em in names)) { const a = await accounts.byEmail(em); names[em] = a ? nameOf(a) : em; }
return { waiting: await waiting(), adoptions: recent.map(ad => Object.assign({}, ad, { adopteeName: names[ad.adoptee], adopterName: names[ad.adopter] })), cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, aligned: alignedRecent(30) };
return { waiting: await waiting(), adoptions: recent.map(ad => Object.assign({}, ad, { adopteeName: names[ad.adoptee], adopterName: names[ad.adopter] })), cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, aligned: alignedRecent(30), payReminders: payView() };
}
module.exports = { init, view, adopt, holdFor, markReady, readyRec, readyTick, autoAssign, alignToNetwork, alignedRecent, setClock, eligibility, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };
module.exports = { init, view, adopt, holdFor, markReady, readyRec, readyTick, autoAssign, payTick, payView, activateLink, PAY_R1_MS, PAY_R2_MS, alignToNetwork, alignedRecent, setClock, eligibility, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };