Fix crash when extra_usage fields are null
This commit is contained in:
@@ -491,7 +491,7 @@ struct FooterBar: View {
|
|||||||
struct ExtraUsageRow: View {
|
struct ExtraUsageRow: View {
|
||||||
let extra: ExtraUsage
|
let extra: ExtraUsage
|
||||||
|
|
||||||
var pct: Double { min(100, max(0, extra.utilization)) }
|
var pct: Double { min(100, max(0, extra.utilization ?? 0)) }
|
||||||
var color: Color { pct > 80 ? .red : pct > 50 ? .orange : .green }
|
var color: Color { pct > 80 ? .red : pct > 50 ? .orange : .green }
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -504,7 +504,7 @@ struct ExtraUsageRow: View {
|
|||||||
.font(.system(size: 12, weight: .semibold))
|
.font(.system(size: 12, weight: .semibold))
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
Spacer()
|
Spacer()
|
||||||
Text("\(extra.currency) \(String(format: "%.2f", extra.usedCredits / 100)) / \(String(format: "%.2f", extra.monthlyLimit / 100))")
|
Text("\(extra.currency ?? "") \(String(format: "%.2f", (extra.usedCredits ?? 0) / 100)) / \(String(format: "%.2f", (extra.monthlyLimit ?? 0) / 100))")
|
||||||
.font(.system(size: 11.5, weight: .medium).monospacedDigit())
|
.font(.system(size: 11.5, weight: .medium).monospacedDigit())
|
||||||
.foregroundColor(color)
|
.foregroundColor(color)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,10 +83,10 @@ struct UsageWindow: Codable {
|
|||||||
|
|
||||||
struct ExtraUsage: Codable {
|
struct ExtraUsage: Codable {
|
||||||
let isEnabled: Bool
|
let isEnabled: Bool
|
||||||
let monthlyLimit: Double
|
let monthlyLimit: Double?
|
||||||
let usedCredits: Double
|
let usedCredits: Double?
|
||||||
let utilization: Double
|
let utilization: Double?
|
||||||
let currency: String
|
let currency: String?
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case isEnabled = "is_enabled"
|
case isEnabled = "is_enabled"
|
||||||
case monthlyLimit = "monthly_limit"
|
case monthlyLimit = "monthly_limit"
|
||||||
@@ -94,6 +94,14 @@ struct ExtraUsage: Codable {
|
|||||||
case utilization
|
case utilization
|
||||||
case currency
|
case currency
|
||||||
}
|
}
|
||||||
|
init(from decoder: Decoder) throws {
|
||||||
|
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
isEnabled = (try? c.decodeIfPresent(Bool.self, forKey: .isEnabled)) ?? false
|
||||||
|
monthlyLimit = try? c.decodeIfPresent(Double.self, forKey: .monthlyLimit)
|
||||||
|
usedCredits = try? c.decodeIfPresent(Double.self, forKey: .usedCredits)
|
||||||
|
utilization = try? c.decodeIfPresent(Double.self, forKey: .utilization)
|
||||||
|
currency = try? c.decodeIfPresent(String.self, forKey: .currency)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// (Bootstrap models removed — org ID is configured directly)
|
// (Bootstrap models removed — org ID is configured directly)
|
||||||
|
|||||||
Reference in New Issue
Block a user