Просмотр исходного кода

fix: add null coalescing for cost values in my-usage page

- usage-logs-table.tsx: (log.cost ?? 0).toFixed(4)
- today-usage-card.tsx: Number(item.costUsd ?? 0).toFixed(4)

Fixes 'e.toFixed is not a function' error when cost is null/undefined
ding113 2 месяцев назад
Родитель
Сommit
a151b56fd2

+ 1 - 1
src/app/[locale]/my-usage/_components/today-usage-card.tsx

@@ -76,7 +76,7 @@ export function TodayUsageCard({
                     <div>{t("callsShort", { count: item.calls })}</div>
                     <div>{t("tokensShort", { in: item.inputTokens, out: item.outputTokens })}</div>
                     <div className="font-semibold text-foreground">
-                      {`${stats.currencyCode || "USD"} ${Number(item.costUsd).toFixed(4)}`}
+                      {`${stats.currencyCode || "USD"} ${Number(item.costUsd ?? 0).toFixed(4)}`}
                     </div>
                   </div>
                 </div>

+ 1 - 1
src/app/[locale]/my-usage/_components/usage-logs-table.tsx

@@ -77,7 +77,7 @@ export function UsageLogsTable({
                     {log.inputTokens}/{log.outputTokens}
                   </TableCell>
                   <TableCell className="text-right text-sm font-mono">
-                    {currencyCode} {log.cost.toFixed(4)}
+                    {currencyCode} {(log.cost ?? 0).toFixed(4)}
                   </TableCell>
                   <TableCell>
                     <Badge