fix(quota): keep balances one quiet color until they run out

Balances under 10% of their total were drawn darker and bolder (and the
tray title added "running low"), so a few cards showed the same kind of
number in different shades with nothing saying why. Balances now stay
gray and only turn red at zero, on the card, in the expanded bar and in
the tray. The left percentage is still computed from the total, so bar
length and which lines get picked are unchanged. Per-tier percentages
keep their under-10% emphasis.
This commit is contained in:
Jason committed 2026-10-04 16:54:30 +08:00
1 parent 2153c1ccf0
commit 8b977f2715
3 files changed
+18 -15

No files matched your search

+4 -10
View File
@@ -672,14 +672,8 @@ fn plan_line(texts: &TrayTexts, data: &crate::provider::UsageData) -> Option<Quo
}
}
if let Some(remaining) = data.remaining {
let has_total = total.is_some_and(|total| total > 0.0);
let left = if remaining <= 0.0 {
0.0
} else if has_total {
remaining / total.unwrap_or(1.0) * 100.0
} else {
f64::INFINITY
};
// 余额不提示「快用完」,只有用完才算(和卡片 `quotaRules.balanceLine` 一致)
let left = if remaining <= 0.0 { 0.0 } else { f64::INFINITY };
let text = if remaining <= 0.0 {
texts.balance_used_up.to_string()
} else {
@@ -3154,7 +3148,7 @@ mod tests {
}
#[test]
fn balance_is_shown_and_warns_below_ten_percent_of_total() {
fn balance_is_shown_and_never_warns_before_running_out() {
let balance = |remaining: f64, total: Option<f64>| UsageData {
plan_name: Some("CNY".to_string()),
extra: None,
@@ -3172,7 +3166,7 @@ mod tests {
);
assert_eq!(
one(balance(5.0, Some(100.0))),
Some(("余额 5.00 CNY".to_string(), true))
Some(("余额 5.00 CNY".to_string(), false))
);
assert_eq!(
one(balance(0.0, Some(100.0))),
+8 -3
View File
@@ -2,8 +2,8 @@ import type { TFunction } from "i18next";
import type { QuotaTier, ResetCredits } from "@/types/subscription";
/**
* 额度的文字和颜色(v7 QuotaSpec):一律写「剩余」,平时灰色;任一档剩余不到 10%(余额不到
* 总额 10%)加深加粗(不用橙色,见 TONE_TEXT);用完 / 过期 / 没查到红色。卡片最多两行:
* 额度的文字和颜色(v7 QuotaSpec):一律写「剩余」,平时灰色;任一档剩余不到 10% 加深加粗
* (不用橙色,见 TONE_TEXT;余额不算,见 balanceLine);用完 / 过期 / 没查到红色。卡片最多两行:
* 档数更多时,第一行固定写窗口最短的那档,其余并成一行(见 cardRows)。
*/
export type QuotaTone = "normal" | "warning" | "danger" | "muted";
@@ -251,6 +251,11 @@ function resetCreditGroups(
});
}
/**
* 余额一律灰色,只有用完才变红:不做「快用完」的加深。几张卡片的余额深浅不一,
* 读起来像出了什么错,而不是「快用完了」(10-04 Jason 定)。left 照旧按总额算,
* 展开时的条长、多行时挑哪几行还用它
*/
export function balanceLine(
t: TFunction,
{
@@ -274,7 +279,7 @@ export function balanceLine(
return {
key,
left,
tone: toneForLeft(left),
tone: remaining <= 0 ? "danger" : "normal",
text:
remaining <= 0 ? t("quota.balanceUsedUp") : t("quota.balance", { value }),
detail,
+6 -2
View File
@@ -74,12 +74,16 @@ describe("quota lines", () => {
expect(toneForLeft(9)).toBe("warning");
});
it("only colors a balance without a total once it runs out", () => {
it("only colors a balance once it runs out, even when nearly gone", () => {
expect(balanceLine(t, { remaining: 82.1, unit: "¥" })).toMatchObject({
text: "余额 82.10 ¥",
tone: "normal",
});
expect(balanceLine(t, { remaining: 5, total: 100 }).tone).toBe("warning");
// 不到总额 10% 也不加深,条长照旧按总额算
expect(balanceLine(t, { remaining: 5, total: 100 })).toMatchObject({
tone: "normal",
left: 5,
});
expect(balanceLine(t, { remaining: 0 })).toMatchObject({
text: "quota.balanceUsedUp",
tone: "danger",