@@ -3,7 +3,7 @@ import { VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react"
33import { CircleAlert , SquareArrowOutUpRight } from "lucide-react"
44import { useAppTranslation } from "@src/i18n/TranslationContext"
55import { vscode } from "@src/utils/vscode"
6- import { formatDateShort } from "@/utils/format"
6+ import { formatDateShort , formatLargeNumber , formatCost } from "@/utils/format"
77
88interface DailyUsage {
99 date : string // ISO date string
@@ -31,21 +31,6 @@ export const UsagePreview = ({ onViewDetails }: UsagePreviewProps) => {
3131 const [ error , setError ] = useState < string | null > ( null )
3232 const [ data , setData ] = useState < UsageStats | null > ( null )
3333
34- // Format large numbers (e.g., 14800000 -> "14.8M")
35- const formatTokenCount = ( tokens : number ) : string => {
36- if ( tokens >= 1_000_000 ) {
37- return `${ ( tokens / 1_000_000 ) . toFixed ( 1 ) } M`
38- } else if ( tokens >= 1_000 ) {
39- return `${ ( tokens / 1_000 ) . toFixed ( 1 ) } K`
40- }
41- return tokens . toString ( )
42- }
43-
44- // Format cost (e.g., 17.81 -> "$17.81")
45- const formatCost = ( cost : number ) : string => {
46- return `$${ cost . toFixed ( 2 ) } `
47- }
48-
4934 // Fetch usage data on mount
5035 useEffect ( ( ) => {
5136 setIsLoading ( true )
@@ -175,7 +160,7 @@ export const UsagePreview = ({ onViewDetails }: UsagePreviewProps) => {
175160 < span className = "text-vscode-foreground" >
176161 { t ( "cloud:usagePreview.tasks" , { count : data . totals . tasks } ) }
177162 < span > · </ span >
178- { t ( "cloud:usagePreview.tokens" , { count : formatTokenCount ( data . totals . tokens ) } ) }
163+ { t ( "cloud:usagePreview.tokens" , { count : formatLargeNumber ( data . totals . tokens ) } ) }
179164 < span > · </ span >
180165 { formatCost ( data . totals . cost ) }
181166 </ span >
0 commit comments