From 5a0e7698e1296b0f15fe20209793f884cc1a5afa Mon Sep 17 00:00:00 2001
From: Frank
Date: Thu, 28 Aug 2025 17:05:51 -0400
Subject: [PATCH] wip cloud
---
cloud/app/src/routes/[workspaceID].tsx | 98 ++++++++++++++++++++++++--
1 file changed, 92 insertions(+), 6 deletions(-)
diff --git a/cloud/app/src/routes/[workspaceID].tsx b/cloud/app/src/routes/[workspaceID].tsx
index 98d03753..1afcc979 100644
--- a/cloud/app/src/routes/[workspaceID].tsx
+++ b/cloud/app/src/routes/[workspaceID].tsx
@@ -1,7 +1,7 @@
import { Billing } from "@opencode/cloud-core/billing.js"
import { Key } from "@opencode/cloud-core/key.js"
import { action, createAsync, revalidate, query, useAction, useSubmission } from "@solidjs/router"
-import { createSignal, For, Show } from "solid-js"
+import { createEffect, createSignal, For, onMount, Show } from "solid-js"
import { getActor, withActor } from "~/context/auth"
/////////////////////////////////////
@@ -42,17 +42,16 @@ const createCheckoutUrl = action(async (successUrl: string, cancelUrl: string) =
return withActor(() => Billing.generateCheckoutUrl({ successUrl, cancelUrl }))
}, "checkoutUrl")
-const createPortalUrl = action(async (returnUrl: string) => {
- "use server"
- return withActor(() => Billing.generatePortalUrl({ returnUrl }))
-}, "portalUrl")
-
//export const route = {
// preload: () => listKeys(),
//}
export default function () {
const actor = createAsync(() => getActor())
+
+ /////////////////
+ // Keys section
+ /////////////////
const keys = createAsync(() => listKeys())
const createKeyAction = useAction(createKey)
const removeKeyAction = useAction(removeKey)
@@ -103,6 +102,51 @@ export default function () {
}
}
+ /////////////////
+ // Billing section
+ /////////////////
+ const billingInfo = createAsync(() => getBillingInfo())
+ const [isLoading, setIsLoading] = createSignal(false)
+ const createCheckoutUrlAction = useAction(createCheckoutUrl)
+
+ // Run once on component mount to check URL parameters
+ onMount(() => {
+ const url = new URL(window.location.href)
+ const result = url.hash
+
+ console.log("STRIPE RESULT", result)
+
+ if (url.hash === "#success") {
+ setIsLoading(true)
+ // Remove the hash from the URL
+ window.history.replaceState(null, "", window.location.pathname + window.location.search)
+ }
+ })
+
+ createEffect((old?: number) => {
+ if (old && old !== billingInfo()?.billing?.balance) {
+ setIsLoading(false)
+ }
+ return billingInfo()?.billing?.balance
+ })
+
+ const handleBuyCredits = async () => {
+ try {
+ setIsLoading(true)
+ const baseUrl = window.location.href
+ const successUrl = new URL(baseUrl)
+ successUrl.hash = "success"
+
+ const checkoutUrl = await createCheckoutUrlAction(successUrl.toString(), baseUrl)
+ if (checkoutUrl) {
+ window.location.href = checkoutUrl
+ }
+ } catch (error) {
+ console.error("Failed to get checkout URL:", error)
+ setIsLoading(false)
+ }
+ }
+
return (
Actor
@@ -182,6 +226,48 @@ export default function () {
)}
+
+ Balance
+ Manage your billing and add credits to your account.
+
+ {(() => {
+ const balanceStr = ((billingInfo()?.billing?.balance ?? 0) / 100000000).toFixed(2)
+ return `$${balanceStr === "-0.00" ? "0.00" : balanceStr}`
+ })()}
+
+
+
+ Payments History
+ Your recent payment transactions.
+ No payments found.}>
+ {(payment) => (
+
+ {payment.id}
+ {" | "}
+ ${((payment.amount ?? 0) / 100000000).toFixed(2)}
+ {" | "}
+ {new Date(payment.timeCreated).toLocaleDateString()}
+
+ )}
+
+
+ Usage History
+ Your recent API usage and costs.
+ No usage found.}>
+ {(usage) => (
+
+ {usage.model}
+ {" | "}
+ {usage.inputTokens + usage.outputTokens} tokens
+ {" | "}
+ ${((usage.cost ?? 0) / 100000000).toFixed(4)}
+ {" | "}
+ {new Date(usage.timeCreated).toLocaleDateString()}
+
+ )}
+
)
}