Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

11.6 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title data-i18n="store_index.meta_title">Store · x402</title>
<meta name="description" content="A hosted x402 storefront. Pay-per-call APIs settled on-chain in USDC."  data-i18n-attr="content:store_index.meta_description"/>
<meta name="theme-color" content="#ffffff" />
<style>
	:root { --accent: #0a84ff; }
	* { box-sizing: border-box; }
	html, body { margin: 0; background: #fff; color: #111; font-family: -apple-system, BlinkMacSystemFont, Inter, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; line-height: 1.55; }
	a { color: var(--accent); }

	.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 24px; border-bottom: 1px solid #eef0f4; position: sticky; top: 0; background: rgba(255,255,255,0.9); backdrop-filter: blur(10px); z-index: 20; }
	.topbar .blogo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #60a5fa); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; overflow: hidden; }
	.topbar .blogo img { width: 100%; height: 100%; object-fit: cover; }
	.topbar .bname { font-weight: 700; letter-spacing: -0.01em; }
	.topbar .secured { margin-left: auto; font-size: 12px; color: #889; }

	.b-hero { padding: 80px 24px 56px; max-width: 760px; margin: 0 auto; }
	.b-hero h1 { font-size: clamp(32px, 6vw, 52px); font-weight: 800; letter-spacing: -0.03em; margin: 0 0 14px; }
	.b-hero p { font-size: 18px; color: #555; margin: 0 0 26px; max-width: 60ch; }
	.b-cta { display: inline-block; background: var(--accent); color: #fff; padding: 13px 26px; border-radius: 11px; font-weight: 600; text-decoration: none; }
	.b-products, .b-text, .b-feature { max-width: 1040px; margin: 0 auto; padding: 30px 24px; }
	.b-products h2, .b-text h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 22px; }
	.p-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
	.p-card { border: 1px solid #e6e8ee; border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 10px; background: #fff; transition: box-shadow 0.15s, transform 0.08s; }
	.p-card:hover { box-shadow: 0 12px 32px rgba(0,0,0,0.07); transform: translateY(-2px); }
	.p-img { width: 52px; height: 52px; border-radius: 13px; background: linear-gradient(135deg, var(--accent), #60a5fa); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; overflow: hidden; }
	.p-img img { width: 100%; height: 100%; object-fit: cover; }
	.p-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
	.p-desc { color: #667; font-size: 13.5px; flex: 1; min-height: 36px; }
	.p-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
	.p-price { font-weight: 700; color: #0a7d3a; font-size: 14px; }
	.p-buy { background: #111; color: #fff; border: none; border-radius: 10px; padding: 10px 20px; font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit; transition: background 0.12s; }
	.p-buy:hover { background: #000; }
	.p-result { margin-top: 4px; font-size: 12px; font-family: ui-monospace, Menlo, monospace; color: #0a7d3a; word-break: break-all; display: none; }
	.p-result.show { display: block; }
	.p-result.err { color: #b91c1c; }
	.b-feature .p-card { max-width: 420px; margin: 0 auto; }
	.b-image { max-width: 1040px; margin: 0 auto; padding: 18px 24px; }
	.b-image img { width: 100%; border-radius: 16px; display: block; }
	.b-imgph { height: 240px; border: 1px dashed #ccc; border-radius: 16px; display: flex; align-items: center; justify-content: center; color: #aaa; }
	.b-btnwrap { text-align: center; padding: 20px; }
	.b-div { border: none; border-top: 1px solid #eaecf1; max-width: 1040px; margin: 18px auto; }
	.b-footer { padding: 40px 24px; text-align: center; color: #889; font-size: 13px; border-top: 1px solid #eef0f4; margin-top: 30px; }
	.b-empty { color: #99a; text-align: center; }
	.powered { text-align: center; padding: 14px; font-size: 11px; color: #aab; }
	.powered a { color: #889; text-decoration: none; font-weight: 600; }
	.giving { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; font-size: 13px; background: #ecfdf3; color: #0a7d3a; border-bottom: 1px solid #d3f3df; }
	.giving b { font-weight: 700; }
	@media (prefers-color-scheme: dark) { .giving { background: #0b1f17; color: #4ade80; border-color: #14532d; } }

	.state { max-width: 560px; margin: 90px auto; text-align: center; padding: 0 24px; color: #667; }
	.state h2 { color: #111; font-size: 22px; margin: 0 0 8px; }
	.skel { background: linear-gradient(90deg, transparent, rgba(0,0,0,0.06), transparent); background-size: 200% 100%; animation: shim 1.4s linear infinite; border-radius: 8px; }
	@keyframes shim { from { background-position: 200% 0; } to { background-position: -200% 0; } }

	@media (prefers-color-scheme: dark) {
		html, body { background: #0b0b0b; color: #f0f2f8; }
		.topbar { background: rgba(11,11,11,0.9); border-color: #222; }
		.p-card { background: #161616; border-color: #272727; }
		.b-hero p, .p-desc { color: #9aa0b8; }
		.p-buy { background: #fff; color: #111; }
		.b-div { border-color: #222; }
		.b-footer, .topbar .secured { border-color: #222; color: #777; }
		.b-imgph { border-color: #333; }
		.state h2 { color: #f0f2f8; }
	}
</style>
</head>
<body>

<div id="root">
	<div class="state" id="loading">
		<div class="skel" style="height:22px;width:180px;margin:0 auto 12px"></div>
		<div class="skel" style="height:14px;width:300px;margin:0 auto"></div>
	</div>
</div>

<script type="module" src="/x402.js"></script>
<script>
const HANDLE = location.pathname.replace(/^\/store\//, '').replace(/\/$/, '');
function esc(s){ return String(s==null?'':s).replace(/[&<>"']/g,(c)=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c])); }

async function load(){
	if (!HANDLE){ renderState('No store specified', 'A store URL looks like /store/&lt;handle&gt;.'); return; }
	try {
		const r = await fetch(`/api/x402-merchant?store=${encodeURIComponent(HANDLE)}`);
		if (r.status === 404){ renderState('Store not found', `No published store at <b>/store/${esc(HANDLE)}</b>. The owner may not have published it yet.`); return; }
		if (!r.ok) throw new Error(`HTTP ${r.status}`);
		const data = await r.json();
		render(data);
	} catch (e){ renderState("Couldn't load store", esc(e.message)); }
}

function renderState(title, body){
	document.getElementById('root').innerHTML = `<div class="state"><h2>${title}</h2><p>${body}</p><p style="margin-top:18px"><a href="/x402">About x402 ↗</a></p></div>`;
}

function render(data){
	const s = data.store, prods = data.products || [];
	const accent = (s.store_theme && s.store_theme.accent) || s.accent_color || '#0a84ff';
	document.documentElement.style.setProperty('--accent', accent);
	document.title = `${s.business_name || 'Store'} · x402`;

	const byId = (id)=> prods.find((p)=> p.id===id);
	const priceLabel = (p)=> p.price_atomics ? `${(Number(p.price_atomics)/1e6).toString()} USDC` : 'Pay-per-call';
	const card = (p)=> p ? `<div class="p-card">
		<div class="p-img">${p.image_url?`<img src="${esc(p.image_url)}" alt="">`:esc((p.merchant_name||p.action_name||'·')[0])}</div>
		<div class="p-name">${esc(p.action_name)}</div>
		<div class="p-desc">${esc(p.description||'')}</div>
		<div class="p-foot"><span class="p-price">${esc(priceLabel(p))}</span>
		<button class="p-buy" data-x402-endpoint="${esc(p.target_endpoint||('/api/x402-skus?slug='+p.slug))}" data-x402-method="${esc(p.target_method||'GET')}" data-x402-merchant="${esc(p.merchant_name||s.business_name||'')}" data-x402-action="${esc(p.action_name)}" data-result="r-${esc(p.id)}">Buy</button></div>
		<div class="p-result" id="r-${esc(p.id)}"></div>
	</div>` : '';

	const block = (b)=>{
		const al = b.align==='left'?'left':'center';
		if (b.type==='hero') return `<section class="b-hero" style="text-align:${al}"><h1>${esc(b.heading||'')}</h1>${b.subheading?`<p style="${al==='center'?'margin-left:auto;margin-right:auto':''}">${esc(b.subheading)}</p>`:''}${b.label?`<a class="b-cta" href="#products">${esc(b.label)}</a>`:''}</section>`;
		if (b.type==='products'){ const ids=b.sku_ids&&b.sku_ids.length?b.sku_ids:prods.map(p=>p.id); return `<section class="b-products" id="products">${b.heading?`<h2>${esc(b.heading)}</h2>`:''}<div class="p-grid">${ids.map(byId).filter(Boolean).map(card).join('')||'<p class="b-empty">No products yet.</p>'}</div></section>`; }
		if (b.type==='product'){ const p=byId(b.sku_id); return `<section class="b-feature">${card(p)||'<p class="b-empty">Product unavailable.</p>'}</section>`; }
		if (b.type==='text') return `<section class="b-text" style="text-align:${al}">${b.heading?`<h2>${esc(b.heading)}</h2>`:''}${b.body?`<p>${esc(b.body)}</p>`:''}</section>`;
		if (b.type==='image') return `<section class="b-image">${b.image_url?(b.href?`<a href="${esc(b.href)}"><img src="${esc(b.image_url)}" alt=""></a>`:`<img src="${esc(b.image_url)}" alt="">`):'<div class="b-imgph">Image</div>'}</section>`;
		if (b.type==='button') return `<section class="b-btnwrap"><a class="b-cta" href="${esc(b.href||'#')}">${esc(b.label||'Button')}</a></section>`;
		if (b.type==='divider') return `<hr class="b-div">`;
		if (b.type==='footer') return `<footer class="b-footer">${esc(b.body||'')}</footer>`;
		return '';
	};

	const layout = Array.isArray(s.store_layout) ? s.store_layout : [];
	const body = layout.map(block).join('') || '<section class="b-text"><p class="b-empty">This store has no content yet.</p></section>';
	const logo = s.logo_url ? `<img src="${esc(s.logo_url)}" alt="">` : esc((s.business_name||'·')[0]);

	let giving = '';
	if (s.charity_enabled && s.charity_bps > 0){
		const pct = s.charity_bps / 100;
		const pctLabel = (pct % 1 === 0 ? pct.toFixed(0) : pct.toString());
		const cause = s.charity_name ? esc(s.charity_name) : 'a good cause';
		giving = `<div class="giving">♥ <span><b>${pctLabel}%</b> of every payment supports <b>${cause}</b>${s.roundup_enabled ? ' · round-up at checkout' : ''}</span></div>`;
	}

	document.getElementById('root').innerHTML =
		`<div class="topbar"><div class="blogo">${logo}</div><span class="bname">${esc(s.business_name||'Store')}</span><span class="secured">Secured by x402 · on-chain settlement</span></div>`
		+ giving
		+ body
		+ `<div class="powered">Powered by <a href="/x402" target="_blank" rel="noopener">three.ws x402</a></div>`;

	wireBuyResults();
}

// The drop-in x402.js auto-binds any [data-x402-endpoint] button. We add per-card
// result + error reporting so buyers see the settlement outcome inline.
function wireBuyResults(){
	document.querySelectorAll('.p-buy[data-result]').forEach((btn)=>{
		const panel = document.getElementById(btn.dataset.result);
		btn.addEventListener('x402:result', (e)=>{
			const { payment } = e.detail || {};
			const explorer = payment?.transaction ? (payment.network?.startsWith('solana') ? `https://solscan.io/tx/${payment.transaction}` : `https://basescan.org/tx/${payment.transaction}`) : null;
			panel.className = 'p-result show';
			panel.innerHTML = `✓ Paid${explorer ? ` · <a href="${explorer}" target="_blank" rel="noopener">view tx ↗</a>` : ''}`;
		});
		btn.addEventListener('x402:error', (e)=>{
			if (e.detail?.code === 'cancelled') return;
			panel.className = 'p-result show err';
			panel.textContent = '✗ ' + (e.detail?.error || 'Payment failed');
		});
	});
}

load();
</script>

<script src="/brand.js" defer></script>
	<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
	<script type="module" src="/i18n.js"></script>
</body>
</html>