From 57bf9949261cc6019abfe5e98bed80469fe91eb4 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 19 Mar 2026 10:18:31 +0400 Subject: [PATCH] fix: more nojs --- apps/web/src/routes/dashboard.ts | 57 ++- apps/web/src/views/checkout.ejs | 587 ++++++++++--------------------- 2 files changed, 243 insertions(+), 401 deletions(-) diff --git a/apps/web/src/routes/dashboard.ts b/apps/web/src/routes/dashboard.ts index 647f7cf..a94b52a 100644 --- a/apps/web/src/routes/dashboard.ts +++ b/apps/web/src/routes/dashboard.ts @@ -236,15 +236,66 @@ export const dashboard = new Elysia() if (!resolved?.accountId) return redirect("/dashboard"); const [acc] = await sql`SELECT plan, plan_expires_at FROM accounts WHERE id = ${resolved.accountId}`; if (acc.plan === "lifetime") return redirect("/dashboard/settings"); - return html("checkout", { nav: "settings", account: acc, payApi: process.env.PAY_API || "https://pay.pingql.com", invoiceId: null }); + + // Fetch coins server-side for no-JS rendering + const payApi = process.env.PAY_API || "https://pay.pingql.com"; + let coins: any[] = []; + try { + const res = await fetch(`${payApi}/coins`); + const data = await res.json(); + coins = data.coins || []; + } catch {} + + return html("checkout", { nav: "settings", account: acc, payApi, invoiceId: null, coins, invoice: null }); }) - // Existing invoice by ID — survives refreshes + // Existing invoice by ID — SSR the payment status .get("/dashboard/checkout/:id", async ({ cookie, headers, params }) => { const resolved = await getAccountId(cookie, headers); if (!resolved?.accountId) return redirect("/dashboard"); const [acc] = await sql`SELECT plan, plan_expires_at FROM accounts WHERE id = ${resolved.accountId}`; - return html("checkout", { nav: "settings", account: acc, payApi: process.env.PAY_API || "https://pay.pingql.com", invoiceId: params.id }); + + const payApi = process.env.PAY_API || "https://pay.pingql.com"; + const key = cookie?.pingql_key?.value; + let invoice: any = null; + let coins: any[] = []; + try { + const [invoiceRes, coinsRes] = await Promise.all([ + fetch(`${payApi}/checkout/${params.id}`, { headers: { "Authorization": `Bearer ${key}` } }), + fetch(`${payApi}/coins`), + ]); + if (invoiceRes.ok) invoice = await invoiceRes.json(); + const coinsData = await coinsRes.json(); + coins = coinsData.coins || []; + } catch {} + + return html("checkout", { nav: "settings", account: acc, payApi, invoiceId: params.id, coins, invoice }); + }) + + // Create checkout via form POST (no-JS) + .post("/dashboard/checkout", async ({ cookie, headers, body }) => { + const resolved = await getAccountId(cookie, headers); + if (!resolved?.accountId) return redirect("/dashboard"); + + const payApi = process.env.PAY_API || "https://pay.pingql.com"; + const key = cookie?.pingql_key?.value; + const b = body as any; + + try { + const res = await fetch(`${payApi}/checkout`, { + method: "POST", + headers: { "Content-Type": "application/json", "Authorization": `Bearer ${key}` }, + body: JSON.stringify({ + plan: b.plan, + coin: b.coin, + months: b.months ? Number(b.months) : undefined, + }), + }); + const data = await res.json(); + if (res.ok && data.id) return redirect(`/dashboard/checkout/${data.id}`); + } catch {} + + return redirect("/dashboard/checkout"); }) // New monitor diff --git a/apps/web/src/views/checkout.ejs b/apps/web/src/views/checkout.ejs index 4980ef8..ad45dbb 100644 --- a/apps/web/src/views/checkout.ejs +++ b/apps/web/src/views/checkout.ejs @@ -3,360 +3,224 @@ <% const plan = it.account.plan; - const expiresAt = it.account.plan_expires_at; + const coins = it.coins || []; + const invoice = it.invoice; + const payApi = it.payApi || ''; %> + +
← Back to settings

Upgrade Plan

- -
+ <% if (!invoice) { %> + +
- -
- <% if (plan !== 'lifetime') { %> - - <% } %> - <% if (plan !== 'lifetime') { %> - - <% } %> +
- + - -