fix(billing): normalize TeamUsage API response to prevent crash on navigation#488
Conversation
…vigation getTeamUsage() returned raw backend JSON without normalization, so undefined/null numeric fields caused .toFixed() TypeErrors that crashed the billing page. Add normalizeTeamUsage() (matching the existing normalizeCreditBalance pattern), defensive ?? 0 guards on .toFixed() call sites, and switch BillingPanel to Promise.allSettled for partial rendering on API failure. Closes tinyhumansai#482
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis PR addresses Payment page crashes by implementing client-side normalization of TeamUsage data from the Rust backend, making API data fetching more resilient with Promise.allSettled, and adding null-safe field handling throughout billing-related UI components. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Summary
normalizeTeamUsage()tocreditsApi.tsto safely map backend JSON fields to theTeamUsageinterface with fallback defaults?? 0guards on all.toFixed()call sites inInferenceBudget.tsxandConversations.tsxBillingPanel.tsxfromPromise.alltoPromise.allSettledso a single failing API call doesn't blank the entire pageProblem
creditsApi.getTeamUsage()returned raw backend JSON without normalizationnull,undefined, or differently-named fields, calling.toFixed(2)onundefinedthrew aTypeErrorthat crashed the React treeBillingPanelusedPromise.all, meaning ifgetTeamUsage()failed,getCurrentPlan()andgetBalance()results were also discarded — the entire page went blankcallCoreCommand<TeamUsage>()masked the mismatch at compile time, soyarn typecheckpassed cleanlySolution
normalizeTeamUsage()following the existingnormalizeCreditBalance()pattern — maps camelCase, snake_case, and legacy field names to the interface with safe numeric defaults vianormalizeUsd()getTeamUsage()so all consumers (BillingPanel,useUsageState,Conversations) get safe data automatically?? 0defense-in-depth on.toFixed()call sites in case normalization is bypassedBillingPaneltoPromise.allSettledwith per-result logging for partial rendering on API failureSubmission Checklist
creditsApi.test.tscovering normalization scenariosTeamUsagefields are sufficientImpact
/settings/billingwhen backend returns unexpected field shapesRelated
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests