From e65fa89566d3cb696d3819498d8cedb7ef82675d Mon Sep 17 00:00:00 2001 From: Frostbourne Date: Fri, 21 Mar 2025 20:03:41 -0700 Subject: [PATCH] [ENG-251] Add Account View (#2324) * Accounts Modal mocked * fix dividers * Fix flex styling * Fix account card in other views * Move AccountInfoCard to tailwind and fix flex styling * Get credits data from endpoint * refactor creditshistorytable * prettier * changeset * Properly connect and format data from endpoint * Overflow scroll box * linter * Update webview-ui/src/utils/format.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Make svg asset a component * fix svg type * Use clineprovider weakref * Move shared types to shared folder * Make account view buttons full width * Make history table take full height * Update webview-ui/src/components/account/AccountView.tsx Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> --- .changeset/plenty-falcons-hammer.md | 5 + package.json | 12 +- src/core/webview/ClineProvider.ts | 26 ++ src/extension.ts | 4 +- src/services/account/ClineAccountService.ts | 118 +++++++++ src/shared/ClineAccount.ts | 18 ++ src/shared/ExtensionMessage.ts | 8 + src/shared/WebviewMessage.ts | 2 + webview-ui/package-lock.json | 27 +- webview-ui/package.json | 3 +- webview-ui/src/App.tsx | 3 +- webview-ui/src/assets/ClineLogoWhite.tsx | 11 + .../src/components/account/AccountView.tsx | 239 +++++++++--------- .../account/CreditsHistoryTable.tsx | 114 +++++++++ .../src/components/chat/CreditLimitError.tsx | 2 +- .../src/components/settings/ApiOptions.tsx | 4 +- .../settings/ClineAccountInfoCard.tsx | 72 ++++++ webview-ui/src/utils/format.ts | 24 ++ 18 files changed, 555 insertions(+), 137 deletions(-) create mode 100644 .changeset/plenty-falcons-hammer.md create mode 100644 src/services/account/ClineAccountService.ts create mode 100644 src/shared/ClineAccount.ts create mode 100644 webview-ui/src/assets/ClineLogoWhite.tsx create mode 100644 webview-ui/src/components/account/CreditsHistoryTable.tsx create mode 100644 webview-ui/src/components/settings/ClineAccountInfoCard.tsx diff --git a/.changeset/plenty-falcons-hammer.md b/.changeset/plenty-falcons-hammer.md new file mode 100644 index 00000000..c2171d53 --- /dev/null +++ b/.changeset/plenty-falcons-hammer.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +Added Cline Account panel in extension for easier credits management diff --git a/package.json b/package.json index 5d5c5c76..686a3835 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,11 @@ "title": "Open in Editor", "icon": "$(link-external)" }, + { + "command": "cline.accountButtonClicked", + "title": "Account", + "icon": "$(account)" + }, { "command": "cline.settingsButtonClicked", "title": "Settings", @@ -119,9 +124,14 @@ "when": "view == claude-dev.SidebarProvider" }, { - "command": "cline.settingsButtonClicked", + "command": "cline.accountButtonClicked", "group": "navigation@5", "when": "view == claude-dev.SidebarProvider" + }, + { + "command": "cline.settingsButtonClicked", + "group": "navigation@6", + "when": "view == claude-dev.SidebarProvider" } ] }, diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 6018a4ab..b0850554 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -14,6 +14,7 @@ import { fetchOpenGraphData, isImageUrl } from "../../integrations/misc/link-pre import { selectImages } from "../../integrations/misc/process-images" import { getTheme } from "../../integrations/theme/getTheme" import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker" +import { ClineAccountService } from "../../services/account/ClineAccountService" import { McpHub } from "../../services/mcp/McpHub" import { UserInfo } from "../../shared/UserInfo" import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api" @@ -122,6 +123,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { private cline?: Cline workspaceTracker?: WorkspaceTracker mcpHub?: McpHub + accountService?: ClineAccountService private latestAnnouncementId = "feb-19-2025" // update to some unique identifier when we add a new announcement conversationTelemetryService: ConversationTelemetryService @@ -133,6 +135,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { ClineProvider.activeInstances.add(this) this.workspaceTracker = new WorkspaceTracker(this) this.mcpHub = new McpHub(this) + this.accountService = new ClineAccountService(this) this.conversationTelemetryService = new ConversationTelemetryService(this) // Clean up legacy checkpoints @@ -164,6 +167,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { this.workspaceTracker = undefined this.mcpHub?.dispose() this.mcpHub = undefined + this.accountService = undefined this.conversationTelemetryService.shutdown() this.outputChannel.appendLine("Disposed all disposables") ClineProvider.activeInstances.delete(this) @@ -725,6 +729,14 @@ export class ClineProvider implements vscode.WebviewViewProvider { await this.handleSignOut() break } + case "showAccountViewClicked": { + await this.postMessageToWebview({ type: "action", action: "accountButtonClicked" }) + break + } + case "fetchUserCreditsData": { + await this.fetchUserCreditsData() + break + } case "showMcpView": { await this.postMessageToWebview({ type: "action", action: "mcpButtonClicked" }) break @@ -1314,6 +1326,20 @@ export class ClineProvider implements vscode.WebviewViewProvider { } } + // Account + + async fetchUserCreditsData() { + try { + await Promise.all([ + this.accountService?.fetchBalance(), + this.accountService?.fetchUsageTransactions(), + this.accountService?.fetchPaymentTransactions(), + ]) + } catch (error) { + console.error("Failed to fetch user credits data:", error) + } + } + // Auth public async validateAuthState(state: string | null): Promise { diff --git a/src/extension.ts b/src/extension.ts index bbdd49b0..18bbeb97 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -115,10 +115,10 @@ export function activate(context: vscode.ExtensionContext) { ) context.subscriptions.push( - vscode.commands.registerCommand("cline.accountLoginClicked", () => { + vscode.commands.registerCommand("cline.accountButtonClicked", () => { sidebarProvider.postMessageToWebview({ type: "action", - action: "accountLoginClicked", + action: "accountButtonClicked", }) }), ) diff --git a/src/services/account/ClineAccountService.ts b/src/services/account/ClineAccountService.ts new file mode 100644 index 00000000..225578f2 --- /dev/null +++ b/src/services/account/ClineAccountService.ts @@ -0,0 +1,118 @@ +import axios, { AxiosRequestConfig, AxiosResponse } from "axios" +import { ClineProvider } from "../../core/webview/ClineProvider" +import type { BalanceResponse, PaymentTransaction, UsageTransaction } from "../../shared/ClineAccount" + +export class ClineAccountService { + private readonly baseUrl = "https://api.cline.bot/v1" + private providerRef: WeakRef + + constructor(provider: ClineProvider) { + this.providerRef = new WeakRef(provider) + } + + /** + * Get the user's Cline Account key from the apiConfiguration + */ + private async getClineApiKey(): Promise { + const provider = this.providerRef.deref() + if (!provider) { + return undefined + } + + const { apiConfiguration } = await provider.getStateToPostToWebview() + return apiConfiguration?.clineApiKey + } + + /** + * Helper function to make authenticated requests to the Cline API + * @param endpoint The API endpoint to call (without the base URL) + * @param config Additional axios request configuration + * @returns The API response data + * @throws Error if the API key is not found or the request fails + */ + private async authenticatedRequest(endpoint: string, config: AxiosRequestConfig = {}): Promise { + const clineApiKey = await this.getClineApiKey() + + if (!clineApiKey) { + throw new Error("Cline API key not found") + } + + const url = `${this.baseUrl}${endpoint}` + const requestConfig: AxiosRequestConfig = { + ...config, + headers: { + Authorization: `Bearer ${clineApiKey}`, + "Content-Type": "application/json", + ...config.headers, + }, + } + + const response: AxiosResponse = await axios.get(url, requestConfig) + + if (!response.data) { + throw new Error(`Invalid response from ${endpoint} API`) + } + + return response.data + } + + /** + * Fetches the user's current credit balance + */ + async fetchBalance(): Promise { + try { + const data = await this.authenticatedRequest("/user/credits/balance") + + // Post to webview + await this.providerRef.deref()?.postMessageToWebview({ + type: "userCreditsBalance", + userCreditsBalance: data, + }) + + return data + } catch (error) { + console.error("Failed to fetch balance:", error) + return undefined + } + } + + /** + * Fetches the user's usage transactions + */ + async fetchUsageTransactions(): Promise { + try { + const data = await this.authenticatedRequest("/user/credits/usage") + + // Post to webview + await this.providerRef.deref()?.postMessageToWebview({ + type: "userCreditsUsage", + userCreditsUsage: data, + }) + + return data + } catch (error) { + console.error("Failed to fetch usage transactions:", error) + return undefined + } + } + + /** + * Fetches the user's payment transactions + */ + async fetchPaymentTransactions(): Promise { + try { + const data = await this.authenticatedRequest("/user/credits/payments") + + // Post to webview + await this.providerRef.deref()?.postMessageToWebview({ + type: "userCreditsPayments", + userCreditsPayments: data, + }) + + return data + } catch (error) { + console.error("Failed to fetch payment transactions:", error) + return undefined + } + } +} diff --git a/src/shared/ClineAccount.ts b/src/shared/ClineAccount.ts new file mode 100644 index 00000000..a6d40b57 --- /dev/null +++ b/src/shared/ClineAccount.ts @@ -0,0 +1,18 @@ +export interface BalanceResponse { + currentBalance: number +} + +export interface UsageTransaction { + spentAt: string + credits: string + modelProvider: string + model: string + promptTokens: string + completionTokens: string +} + +export interface PaymentTransaction { + paidAt: string + amountCents: string + credits: string +} diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index b1a65de1..d37171d7 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -8,6 +8,7 @@ import { ChatSettings } from "./ChatSettings" import { HistoryItem } from "./HistoryItem" import { McpServer, McpMarketplaceCatalog, McpMarketplaceItem, McpDownloadResponse } from "./mcp" import { TelemetrySetting } from "./TelemetrySetting" +import type { BalanceResponse, UsageTransaction, PaymentTransaction } from "../shared/ClineAccount" // webview will hold state export interface ExtensionMessage { @@ -34,6 +35,9 @@ export interface ExtensionMessage { | "openGraphData" | "isImageUrlResult" | "didUpdateSettings" + | "userCreditsBalance" + | "userCreditsUsage" + | "userCreditsPayments" | "totalTasksSize" text?: string action?: @@ -44,6 +48,7 @@ export interface ExtensionMessage { | "didBecomeVisible" | "accountLoginClicked" | "accountLogoutClicked" + | "accountButtonClicked" invoke?: Invoke state?: ExtensionState images?: string[] @@ -70,6 +75,9 @@ export interface ExtensionMessage { } url?: string isImage?: boolean + userCreditsBalance?: BalanceResponse + userCreditsUsage?: UsageTransaction[] + userCreditsPayments?: PaymentTransaction[] totalTasksSize?: number | null } diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index cb511d95..b50e4c64 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -45,6 +45,7 @@ export interface WebviewMessage { | "getLatestState" | "accountLoginClicked" | "accountLogoutClicked" + | "showAccountViewClicked" | "authStateChanged" | "authCallback" | "fetchMcpMarketplace" @@ -61,6 +62,7 @@ export interface WebviewMessage { | "invoke" | "updateSettings" | "clearAllTaskHistory" + | "fetchUserCreditsData" | "optionsResponse" | "requestTotalTasksSize" // | "relaunchChromeDebugMode" diff --git a/webview-ui/package-lock.json b/webview-ui/package-lock.json index c0357c77..0c3f84b3 100644 --- a/webview-ui/package-lock.json +++ b/webview-ui/package-lock.json @@ -21,6 +21,7 @@ "posthog-js": "^1.224.0", "pretty-bytes": "^6.1.1", "react": "^18.3.1", + "react-countup": "^6.5.3", "react-dom": "^18.3.1", "react-remark": "^2.1.0", "react-textarea-autosize": "^8.5.7", @@ -49,7 +50,7 @@ "tailwindcss": "^4.0.12", "typescript": "^5.7.3", "typescript-eslint": "^8.18.2", - "vite": "^6.1.1", + "vite": "^6.2.1", "vitest": "^3.0.5" } }, @@ -4177,6 +4178,12 @@ "layout-base": "^1.0.0" } }, + "node_modules/countup.js": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/countup.js/-/countup.js-2.8.0.tgz", + "integrity": "sha512-f7xEhX0awl4NOElHulrl4XRfKoNH3rB+qfNSZZyjSZhaAoUk6elvhH+MNxMmlmuUJ2/QNTWPSA7U4mNtIAKljQ==", + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -7095,6 +7102,18 @@ "node": ">=0.10.0" } }, + "node_modules/react-countup": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/react-countup/-/react-countup-6.5.3.tgz", + "integrity": "sha512-udnqVQitxC7QWADSPDOxVWULkLvKUWrDapn5i53HE4DPRVgs+Y5rr4bo25qEl8jSh+0l2cToJgGMx+clxPM3+w==", + "license": "MIT", + "dependencies": { + "countup.js": "^2.8.0" + }, + "peerDependencies": { + "react": ">= 16.3.0" + } + }, "node_modules/react-dom": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", @@ -8359,9 +8378,9 @@ } }, "node_modules/vite": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/vite/-/vite-6.2.0.tgz", - "integrity": "sha512-7dPxoo+WsT/64rDcwoOjk76XHj+TqNTIvHKcuMQ1k4/SeHDaQt5GFAeLYzrimZrMpn/O6DtdI03WUjdxuPM0oQ==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-6.2.1.tgz", + "integrity": "sha512-n2GnqDb6XPhlt9B8olZPrgMD/es/Nd1RdChF6CBD/fHW6pUyUTt2sQW2fPRX5GiD9XEa6+8A6A4f2vT6pSsE7Q==", "dev": true, "license": "MIT", "dependencies": { diff --git a/webview-ui/package.json b/webview-ui/package.json index e303db05..360ec876 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -25,6 +25,7 @@ "posthog-js": "^1.224.0", "pretty-bytes": "^6.1.1", "react": "^18.3.1", + "react-countup": "^6.5.3", "react-dom": "^18.3.1", "react-remark": "^2.1.0", "react-textarea-autosize": "^8.5.7", @@ -53,7 +54,7 @@ "tailwindcss": "^4.0.12", "typescript": "^5.7.3", "typescript-eslint": "^8.18.2", - "vite": "^6.1.1", + "vite": "^6.2.1", "vitest": "^3.0.5" } } diff --git a/webview-ui/src/App.tsx b/webview-ui/src/App.tsx index a51066f8..d5dc5125 100644 --- a/webview-ui/src/App.tsx +++ b/webview-ui/src/App.tsx @@ -42,7 +42,7 @@ const AppContent = () => { setShowMcp(true) setShowAccount(false) break - case "accountLoginClicked": + case "accountButtonClicked": setShowSettings(false) setShowHistory(false) setShowMcp(false) @@ -96,6 +96,7 @@ const AppContent = () => { showHistoryView={() => { setShowSettings(false) setShowMcp(false) + setShowAccount(false) setShowHistory(true) }} isHidden={showSettings || showHistory || showMcp || showAccount} diff --git a/webview-ui/src/assets/ClineLogoWhite.tsx b/webview-ui/src/assets/ClineLogoWhite.tsx new file mode 100644 index 00000000..9a918870 --- /dev/null +++ b/webview-ui/src/assets/ClineLogoWhite.tsx @@ -0,0 +1,11 @@ +import { SVGProps } from "react" + +const ClineLogoWhite = (props: SVGProps) => ( + + + +) +export default ClineLogoWhite diff --git a/webview-ui/src/components/account/AccountView.tsx b/webview-ui/src/components/account/AccountView.tsx index c9bd0f28..5c6d63eb 100644 --- a/webview-ui/src/components/account/AccountView.tsx +++ b/webview-ui/src/components/account/AccountView.tsx @@ -1,8 +1,12 @@ -import { VSCodeButton, VSCodeDivider } from "@vscode/webview-ui-toolkit/react" -import { memo } from "react" +import { VSCodeButton, VSCodeDivider, VSCodeLink } from "@vscode/webview-ui-toolkit/react" +import { memo, useEffect, useState } from "react" import { useFirebaseAuth } from "../../context/FirebaseAuthContext" import { vscode } from "../../utils/vscode" import VSCodeButtonLink from "../common/VSCodeButtonLink" +import ClineLogoWhite from "../../assets/ClineLogoWhite" +import CountUp from "react-countup" +import CreditsHistoryTable from "./CreditsHistoryTable" +import { UsageTransaction, PaymentTransaction } from "../../../../src/shared/ClineAccount" type AccountViewProps = { onDone: () => void @@ -10,38 +14,13 @@ type AccountViewProps = { const AccountView = ({ onDone }: AccountViewProps) => { return ( -
-
-

Cline Account

+
+
+

Cline Account

Done
-
-
+
+
@@ -51,6 +30,37 @@ const AccountView = ({ onDone }: AccountViewProps) => { export const ClineAccountView = () => { const { user, handleSignOut } = useFirebaseAuth() + const [balance, setBalance] = useState(0) + const [isLoading, setIsLoading] = useState(true) + const [usageData, setUsageData] = useState([]) + const [paymentsData, setPaymentsData] = useState([]) + + // Listen for balance and transaction data updates from the extension + useEffect(() => { + const handleMessage = (event: MessageEvent) => { + const message = event.data + if (message.type === "userCreditsBalance" && message.userCreditsBalance) { + setBalance(message.userCreditsBalance.currentBalance) + } else if (message.type === "userCreditsUsage" && message.userCreditsUsage) { + setUsageData(message.userCreditsUsage.usageTransactions) + } else if (message.type === "userCreditsPayments" && message.userCreditsPayments) { + setPaymentsData(message.userCreditsPayments.paymentTransactions) + } + setIsLoading(false) + } + + window.addEventListener("message", handleMessage) + + // Fetch all account data when component mounts + if (user) { + setIsLoading(true) + vscode.postMessage({ type: "fetchUserCreditsData" }) + } + + return () => { + window.removeEventListener("message", handleMessage) + } + }, [user]) const handleLogin = () => { vscode.postMessage({ type: "accountLoginClicked" }) @@ -63,108 +73,87 @@ export const ClineAccountView = () => { handleSignOut() } return ( -
+
{user ? ( -
-
- {user.photoURL ? ( - Profile - ) : ( -
- {user.displayName?.[0] || user.email?.[0] || "?"} -
- )} -
- {user.displayName && ( -
- {user.displayName} +
+
+
+ {user.photoURL ? ( + Profile + ) : ( +
+ {user.displayName?.[0] || user.email?.[0] || "?"}
)} - {user.email && ( -
- {user.email} -
- )} -
- - Account - - - Log out - + +
+ {user.displayName && ( +

+ {user.displayName} +

+ )} + + {user.email && ( +
{user.email}
+ )}
+ +
+
+ + Account + +
+ + Log out + +
+ + + +
+
CURRENT BALANCE
+ +
+ {isLoading ? ( +
Loading...
+ ) : ( + <> + $ + + + )} +
+ +
+ + Add Credits + +
+
+ + + +
+ +
) : ( -
- - Sign Up with Cline +
+ + +

Sign up with Cline

+ + + Login with Cline + +

+ By continuing, you agree to the Terms of Service and{" "} + Privacy Policy. +

)}
diff --git a/webview-ui/src/components/account/CreditsHistoryTable.tsx b/webview-ui/src/components/account/CreditsHistoryTable.tsx new file mode 100644 index 00000000..cd97b2e7 --- /dev/null +++ b/webview-ui/src/components/account/CreditsHistoryTable.tsx @@ -0,0 +1,114 @@ +import { VSCodeDataGrid, VSCodeDataGridRow, VSCodeDataGridCell } from "@vscode/webview-ui-toolkit/react" +import { useState } from "react" +import { TabButton } from "../mcp/McpView" +import { UsageTransaction, PaymentTransaction } from "../../../../src/shared/ClineAccount" +import { formatDollars, formatTimestamp } from "../../utils/format" + +interface CreditsHistoryTableProps { + isLoading: boolean + usageData: UsageTransaction[] + paymentsData: PaymentTransaction[] +} + +const CreditsHistoryTable = ({ isLoading, usageData, paymentsData }: CreditsHistoryTableProps) => { + const [activeTab, setActiveTab] = useState<"usage" | "payments">("usage") + + return ( +
+ {/* Tabs container */} +
+ setActiveTab("usage")}> + USAGE HISTORY + + setActiveTab("payments")}> + PAYMENTS HISTORY + +
+ + {/* Content container */} +
+ {isLoading ? ( +
+
Loading...
+
+ ) : ( + <> + {activeTab === "usage" && ( + <> + {usageData.length > 0 ? ( + + + + Date + + + Model + + + Tokens Used + + + Credits Used + + + + {usageData.map((row, index) => ( + + + {formatTimestamp(row.spentAt)} + + {`${row.modelProvider}/${row.model}`} + {`${row.promptTokens} → ${row.completionTokens}`} + {`$${Number(row.credits).toFixed(7)}`} + + ))} + + ) : ( +
+
No usage history
+
+ )} + + )} + + {activeTab === "payments" && ( + <> + {paymentsData.length > 0 ? ( + + + + Date + + + Total Cost + + + Credits + + + + {paymentsData.map((row, index) => ( + + + {formatTimestamp(row.paidAt)} + + {`$${formatDollars(parseInt(row.amountCents))}`} + {`${row.credits}`} + + ))} + + ) : ( +
+
No payment history
+
+ )} + + )} + + )} +
+
+ ) +} + +export default CreditsHistoryTable diff --git a/webview-ui/src/components/chat/CreditLimitError.tsx b/webview-ui/src/components/chat/CreditLimitError.tsx index b782e791..967442ca 100644 --- a/webview-ui/src/components/chat/CreditLimitError.tsx +++ b/webview-ui/src/components/chat/CreditLimitError.tsx @@ -30,7 +30,7 @@ const CreditLimitError: React.FC = ({ currentBalance, tot
- +
)} diff --git a/webview-ui/src/components/settings/ClineAccountInfoCard.tsx b/webview-ui/src/components/settings/ClineAccountInfoCard.tsx new file mode 100644 index 00000000..fc4989bf --- /dev/null +++ b/webview-ui/src/components/settings/ClineAccountInfoCard.tsx @@ -0,0 +1,72 @@ +import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" +import { useFirebaseAuth } from "../../context/FirebaseAuthContext" +import { vscode } from "../../utils/vscode" + +export const ClineAccountInfoCard = () => { + const { user, handleSignOut } = useFirebaseAuth() + + const handleLogin = () => { + vscode.postMessage({ type: "accountLoginClicked" }) + } + + const handleLogout = () => { + // First notify extension to clear API keys and state + vscode.postMessage({ type: "accountLogoutClicked" }) + // Then sign out of Firebase + handleSignOut() + } + + const handleShowAccount = () => { + vscode.postMessage({ type: "showAccountViewClicked" }) + } + + return ( +
+ {user ? ( +
+
+ {user.photoURL ? ( + Profile + ) : ( +
+ {user.displayName?.[0] || user.email?.[0] || "?"} +
+ )} +
+ {user.displayName && ( +
+ {user.displayName} +
+ )} + {user.email && ( +
+ {user.email} +
+ )} +
+ + Account + + + Log out + +
+
+
+
+ ) : ( +
+ + Sign Up with Cline + +
+ )} +
+ ) +} diff --git a/webview-ui/src/utils/format.ts b/webview-ui/src/utils/format.ts index 2e473c9b..2663f7ac 100644 --- a/webview-ui/src/utils/format.ts +++ b/webview-ui/src/utils/format.ts @@ -10,3 +10,27 @@ export function formatLargeNumber(num: number): string { } return num.toString() } + +// Helper to format cents as dollars with 2 decimal places +export function formatDollars(cents?: number): string { + if (cents === undefined) { + return "" + } + + return (cents / 100).toFixed(2) +} + +export function formatTimestamp(timestamp: string): string { + const date = new Date(timestamp) + + const dateFormatter = new Intl.DateTimeFormat("en-US", { + month: "2-digit", + day: "2-digit", + year: "2-digit", + hour: "numeric", + minute: "2-digit", + hour12: true, + }) + + return dateFormatter.format(date) +}