Files
yourprogrambuilder/public/assets/buy.js
T
martbost a8a1a8eec7 YourProgramBuilder, the Seed Bed (Marty 2026-11-17: "keep fleshing it out"): STAGING build
Plant a program free (referral link with {id}, link check green / yellow / red, daily recheck, reports), members save their
referral IDs in its packet, a sponsor-first link (member page / ?r= / the hub sponsor line, then the planter), the sprout meter
to REVIEW_SAVES (DEFAULT 25) -> Marty's review queue -> approved packets exported for the CTB builder / DownlineHydra wild heads
with every saved ID. Dormant old programs confirmed by their owner, old-link redirects (oldrefs), Spotlight on YPBShop (NOT
deployed; DEFAULT $10 / 1,000 views, 20/5/5/5/5, company 60), verified views with Spotlight delivery, trust pack (ledger,
contract, toasts, Telegram card, terms / disclaimer / privacy, TrustClickz only), network footer row, chatbot, promo kit,
Guides, PolHunter slot, LinkSpin tracked-link and zone hooks, AI writer through the hub. Seed-catalog look from the approved
mockup. Tests: qa/unit.test.cjs 33/33, qa/e2e.mjs 121/121 on a local anvil chain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:30:59 -06:00

38 lines
2.9 KiB
JavaScript

// One-time Spotlights through YPBShop. The server builds the signed buy() call for the signed-in member (POST /api/my/order: the hub
// sponsor line + the packet); the member's own wallet sends it. After it confirms the page waits for the watcher to record it.
window.YPBBuy = (function () {
const fmtPol = (wei, d) => { const k = d || 4; const s = (BigInt(wei) * 10n ** BigInt(k) / 10n ** 18n).toString().padStart(k + 1, '0'); return s.slice(0, -k) + '.' + s.slice(-k); };
async function quote(qty) { return YPB.getJSON('/api/quote?qty=' + (qty || 1)); }
async function run(o) {
const say = o.say || YPB.status;
const c = await YPB.getConfig();
if (!c.shop || !c.shop.live) throw new Error('Spotlights are not on sale yet.');
const me = await YPB.getJSON('/api/me');
if (!me.signedIn) throw new Error('Sign in on My packets first.');
say('Connecting your wallet...');
const addr = String(await YPBWallet.activeAddress(await YPBWallet.connect()) || '').toLowerCase();
if (!addr) throw new Error('No wallet connected. Tap Buy again and pick SafePal or any other crypto wallet.');
if (addr !== me.address) throw new Error('Your wallet is connected as ' + YPB.short(addr) + ', but your YourProgramBuilder account is ' + YPB.short(me.address) + '. Switch your wallet app to ' + YPB.short(me.address) + ', or sign out and sign in with ' + YPB.short(addr) + '.');
const od = await YPB.post('/api/my/order', { qty: o.qty || 1, packetId: o.packetId });
if (od.error) throw new Error(od.error);
const value = BigInt(od.value);
try { const bal = await YPBWallet.balance(addr); if (bal < value) throw new Error('This wallet holds ' + fmtPol(bal) + ' POL. The Spotlight needs about ' + fmtPol(value) + ' POL plus a little gas. Add POL on Polygon and try again.'); }
catch (e) { if (/holds/.test(e.message)) throw e; }
say('Confirm the payment in your wallet: about ' + fmtPol(value) + ' POL ($' + od.usd + '). Anything above the exact price comes straight back in the same transaction.');
const hash = await YPBWallet.sendTx(od.to, od.data, od.value);
const link = c.explorer ? c.explorer + '/tx/' + hash : '';
say('Payment sent. Waiting for the Polygon network to confirm it...');
const r = await YPBWallet.waitTx(hash);
if (r.status !== '0x1') throw new Error('The transaction did not go through, so nothing was charged except gas. ' + (link ? 'Details: ' + link : ''));
YPB.post('/api/my/paid', {}).catch(() => {});
say('Confirmed on Polygon. Your Spotlight shows on My packets within about a minute.', 'ok');
for (let i = 0; i < 72; i++) {
await new Promise(res => setTimeout(res, 5000));
if (i % 4 === 3) YPB.post('/api/my/paid', {}).catch(() => {});
try { if (await o.done()) return { hash, link, recorded: true }; } catch (e) {}
}
return { hash, link, recorded: false };
}
return { run, quote, fmtPol };
})();