PolyWarriors mint bar: 4 h cookie (was 7 days), cleared on every exit, x to hide
Members who tapped Mint, saw the price and went back to the game kept the blue "PolyWarriors mint" bar on the dashboard for a week. The cookie now lives 4 h, is cleared by Back to PolyWarriors / Cancel (new /pw/mint/leave), by the mint-pass success redirect, and by an x on the bar (/pw/mint/dismiss). The waiting order itself is untouched: a later package still completes the mint. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -1384,6 +1384,7 @@ async function swCallback(cbUrl, receipt) {
|
||||
if (!swIsGameUrl(cbUrl)) return false;
|
||||
try { const r = await fetch(cbUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ t: receipt }), signal: AbortSignal.timeout(8000) }); return r.ok; } catch (e) { console.warn('spellwheel callback', e.message); return false; }
|
||||
}
|
||||
const PW_MINT_COOKIE_S = 4 * 3600; // the dashboard "back to the mint" bar lives this long (was 7 days: people who looked at the price and left saw it for a week, Marty 2026-10-11)
|
||||
// -- PolyWarriors paid mints (2026-10-05): the first mint is free in the game; later mints cost PW_MINT_CREDITS (100) from
|
||||
// PURCHASED credits only (package credits on a position; earned credits never count, Marty's rule). The game signs an order
|
||||
// with PW_SSO_SECRET (kind 'pw-mint'), the member confirms here, ads.gamePurchase(purchasedOnly) charges, and a signed
|
||||
@@ -3083,21 +3084,21 @@ const server = http.createServer(async (req, res) => {
|
||||
const done = pwOrders.get(c.order);
|
||||
if (done && done.status === 'paid') { const rc = pwReceipt(c.order, done); res.writeHead(302, { Location: (pwIsGameUrl(done.ret) ? done.ret : PW_URL() + '/api/iap/mint-receipt') + '?t=' + rc, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.pwmint', '', 0) }); return res.end(); }
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) { res.writeHead(302, { Location: '/my', 'Cache-Control': 'no-store', 'Set-Cookie': [gkCookie('iap.pwmint', t, 7 * 86400), gkCookie('iap.return', 'pwmint', 1800)] }); return res.end(); }
|
||||
if (!s || !s.email) { res.writeHead(302, { Location: '/my', 'Cache-Control': 'no-store', 'Set-Cookie': [gkCookie('iap.pwmint', t, PW_MINT_COOKIE_S), gkCookie('iap.return', 'pwmint', 1800)] }); return res.end(); }
|
||||
if (String(s.email).toLowerCase() !== String(c.email).toLowerCase()) return gkPage(res, 403, 'Different account', '<h1>Different account</h1><p class="sub">This mint was started by the PolyWarriors player ' + gkEsc(c.email) + ', but you are signed in to InstantAdPay as ' + gkEsc(s.email) + '. Sign in with the same account and tap Mint again.</p>');
|
||||
// the order waits here until a new package purchase from this account lands on chain (oldest waiting order first)
|
||||
if (!done) pwOrders.set(c.order, { status: 'waiting', email: String(s.email).toLowerCase(), serial: Number(c.serial), label: String(c.label || '').slice(0, 60), ret: c.ret, cb: c.cb, ts: Date.now() });
|
||||
res.setHeader('Set-Cookie', gkCookie('iap.pwmint', t, 7 * 86400));
|
||||
res.setHeader('Set-Cookie', gkCookie('iap.pwmint', t, PW_MINT_COOKIE_S));
|
||||
const have = pwPassN(String(s.email).toLowerCase());
|
||||
if (have > 0) {
|
||||
const csrf = pwSign('pass:' + c.order + ':' + String(s.email).toLowerCase());
|
||||
return gkPage(res, 200, 'Mint your warrior', '<p class="sub">PolyWarriors · Mint to your wallet</p><h1>' + gkEsc(c.label || ('Warrior #' + c.serial)) + '</h1><div class="big">' + have + ' mint pass' + (have === 1 ? '' : 'es') + '</div>'
|
||||
+ '<form method="post" action="/pw/mint/pass" onsubmit="var b=this.querySelector(\'button\');b.disabled=true;b.textContent=\'Minting… one moment\';b.style.opacity=.7"><input type="hidden" name="t" value="' + gkEsc(t) + '"><input type="hidden" name="csrf" value="' + csrf + '"><button class="btn" type="submit">Use 1 mint pass and mint</button></form>'
|
||||
+ '<a class="alt" href="' + PW_URL() + '/play">Cancel and go back</a><p class="fine">You earned these passes with your package purchases: one mint for every $5. The game pays the network fee.</p>');
|
||||
+ '<a class="alt" href="/pw/mint/leave">Cancel and go back</a><p class="fine">You earned these passes with your package purchases: one mint for every $5. The game pays the network fee.</p>');
|
||||
}
|
||||
return gkPage(res, 200, 'Mint your warrior', '<p class="sub">PolyWarriors · Mint to your wallet</p><h1>' + gkEsc(c.label || ('Warrior #' + c.serial)) + '</h1><div class="big">Comes with a $5 package</div>'
|
||||
+ '<p class="sub">Your first mint was free. After that, every $5 of new ad packages earns one mint: $5 mints this warrior, $10 earns 2 mints, $20 earns 4, and any extra mints stay on your account for next time. You keep every package\'s ad credits.</p>'
|
||||
+ '<a class="btn" href="/my?from=polywarriors#buy">Buy a $5 package</a><a class="btn blue" href="' + PW_URL() + '/play">Back to PolyWarriors</a>'
|
||||
+ '<a class="btn" href="/my?from=polywarriors#buy">Buy a $5 package</a><a class="btn blue" href="/pw/mint/leave">Back to PolyWarriors</a>'
|
||||
+ '<p class="fine">Buy while this mint is waiting and it mints to your wallet automatically. Credits you already have cannot be used for mints. The game pays the network fee.</p>');
|
||||
}
|
||||
if (!IS_PROD && p === '/api/dev/pw-purchase' && req.method === 'POST') { const b = await readBody(req); return json(res, 200, { order: await pwMintOnEvent({ type: 'Purchase', priceCents: Number(b.cents) || 500, buyerId: 0, tx: '0x' + crypto.randomBytes(32).toString('hex'), ts: Date.now(), devEmail: b.email }) }); } // local tests only
|
||||
@@ -3113,8 +3114,10 @@ const server = http.createServer(async (req, res) => {
|
||||
// receipt too, so the mint never waits on this callback). Marty's phone sat on this form on 2026-10-09 while the mint had
|
||||
// already gone through.
|
||||
if (o && o.status === 'waiting' && pwPassN(e) > 0) { pwPassAdd(e, -1, 'mint:' + c.order); pwOrders.set(c.order, Object.assign({}, o, { status: 'paid', tx: 'pass', cents: 500, paidAt: Date.now() })); pwDeliver(c.order).catch(() => {}); }
|
||||
res.writeHead(303, { Location: '/pw/mint?t=' + encodeURIComponent(t), 'Cache-Control': 'no-store' }); return res.end();
|
||||
res.writeHead(303, Object.assign({ Location: '/pw/mint?t=' + encodeURIComponent(t), 'Cache-Control': 'no-store' }, pwOrders.get(c.order) && pwOrders.get(c.order).status === 'paid' ? { 'Set-Cookie': gkCookie('iap.pwmint', '', 0) } : {})); return res.end();
|
||||
}
|
||||
if (p === '/pw/mint/leave' && req.method === 'GET') { res.writeHead(302, { Location: PW_URL() + '/play', 'Cache-Control': 'no-store', 'Set-Cookie': [gkCookie('iap.pwmint', '', 0), gkCookie('iap.return', '', 0)] }); return res.end(); } // the waiting order stays; a later package still completes the mint
|
||||
if (p === '/pw/mint/dismiss' && req.method === 'POST') { res.writeHead(204, { 'Set-Cookie': [gkCookie('iap.pwmint', '', 0), gkCookie('iap.return', '', 0)] }); return res.end(); } // the dashboard bar's x
|
||||
if (p === '/pw/mint/resume' && req.method === 'GET') { const t = parseCookies(req)['iap.pwmint']; res.writeHead(302, { Location: t ? '/pw/mint?t=' + encodeURIComponent(t) : PW_URL() + '/play', 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end(); }
|
||||
if (p === '/gk/shop/topup' && req.method === 'GET') { // the detour to Buy packages, remembered for the way back
|
||||
const t = u.searchParams.get('t') || ''; if (gkOpen(t).error) { res.writeHead(302, { Location: '/my#buy' }); return res.end(); }
|
||||
|
||||
Reference in New Issue
Block a user