mirror of
https://github.com/stablyai/orca.git
synced 2026-10-12 16:03:03 +00:00
Display provider credit and currency balances separately from rate limits. Preserve quotas when balance data is unavailable and translate complete labels. Supersedes #9363; credit to @mmarabel for the original implementation. Co-authored-by: mmarabel <166927047+mmarabel@users.noreply.github.com>
22 lines
799 B
TypeScript
22 lines
799 B
TypeScript
/**
|
|
* Format a major-unit amount (e.g. 12.4) as a localized currency string
|
|
* (e.g. "$12.40"). Shared by the usage popover and the compact status-bar
|
|
* balance token so both render identically.
|
|
*
|
|
* Why: `Intl.NumberFormat` throws on an unrecognized currency code (the code
|
|
* comes from a provider API we don't control), so fall back to a plain
|
|
* "<CODE> <amount>" rendering rather than crashing the status bar.
|
|
*/
|
|
export function formatCurrencyAmount(amount: number, currencyCode: string): string {
|
|
const safeAmount = Number.isFinite(amount) ? amount : 0
|
|
const code = currencyCode.trim() || 'USD'
|
|
try {
|
|
return new Intl.NumberFormat(undefined, {
|
|
style: 'currency',
|
|
currency: code
|
|
}).format(safeAmount)
|
|
} catch {
|
|
return `${code} ${safeAmount.toFixed(2)}`
|
|
}
|
|
}
|