@devries-cameron20 / t3code-1 / commits / 9cee35ac4a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): accept comma as decimal in usage price entry (#21939)

Co-authored-by: maria-rcks <maria@kuuro.net>

Mika Krul committed Oct 31, 2026 at 09:36 UTC 9cee35ac4a382d03afd55a16a7d2969af7017d3b
2 files changed +30 -3
apps/web/src/components/usage/usagePriceForm.test.ts
+28 -1
@@ -32,7 +32,7 @@ describe("model price entry", () => {
32 });
33 });
34
35 - it.each(["", " ", "-1", "Infinity", "NaN", "1e999", "$2", "0x10"])(
35 + it.each(["", " ", "-1", "Infinity", "NaN", "1e999", "$2", "0x10", "1,2,3", "1.2,3", "1,2.3"])(
36 "rejects invalid required prices: %j",
37 (inputCostPerMillionTokens) => {
38 expect(
@@ -47,6 +47,33 @@ describe("model price entry", () => {
47 },
48 );
49
50 + it("reads a comma as the decimal point", () => {
51 + const form = usagePriceForm("example-model", {
52 + inputCostPerMillionTokens: 2,
53 + outputCostPerMillionTokens: 8,
54 + });
55 + expect(
56 + parseUsagePriceForm({
57 + ...form,
58 + inputCostPerMillionTokens: "2,5",
59 + outputCostPerMillionTokens: "0,075",
60 + }),
61 + ).toEqual({
62 + model: "example-model",
63 + price: { inputCostPerMillionTokens: 2.5, outputCostPerMillionTokens: 0.075 },
64 + });
65 + expect(parseUsagePriceForm({ ...form, inputCostPerMillionTokens: "1,2,3" })).toBeNull();
66 + expect(isUsagePriceEdit("", "2,5")).toBe(true);
67 + expect(isUsagePriceEdit("", ",5")).toBe(true);
68 + expect(isUsagePriceEdit("", "1,2,3")).toBe(false);
69 + expect(isUsagePriceEdit("1,2", "1,2.3")).toBe(false);
70 + for (const value of ["2,5", ",5", "0,075", "1,5e-7"]) {
71 + for (let end = 1; end <= value.length; end++) {
72 + expect(isUsagePriceEdit(value.slice(0, end - 1), value.slice(0, end))).toBe(true);
73 + }
74 + }
75 + });
76 +
77 it("never blocks deleting part of a price, but blocks replacing it with a non-number", () => {
78 expect(isUsagePriceEdit("1e-7", "e-7")).toBe(true);
79 expect(isUsagePriceEdit("1e-7", "1-7")).toBe(true);
apps/web/src/components/usage/usagePriceForm.ts
+2 -2
@@ -25,7 +25,7 @@ export function usagePriceForm(model = "", price?: UsageModelPriceOverride): Usa
25 /** Allow decimal/exponent edits and all deletions, including temporarily invalid values; saving validates
26 * the result. */
27 export function isUsagePriceEdit(previous: string, next: string): boolean {
28 - if (/^\s*(?:\d*\.?\d*|(?:\d+\.?\d*|\.\d+)e[+-]?\d*)\s*$/i.test(next)) return true;
28 + if (/^\s*(?:\d*[.,]?\d*|(?:\d+[.,]?\d*|[.,]\d+)e[+-]?\d*)\s*$/i.test(next)) return true;
29 if (next.length >= previous.length) return false;
30 let start = 0;
31 while (start < next.length && next[start] === previous[start]) start++;
@@ -40,7 +40,7 @@ export function parseUsagePriceForm(
40 if (model.length === 0) return null;
41 const rates: Partial<Record<(typeof USAGE_PRICE_FIELDS)[number]["key"], number>> = {};
42 for (const field of USAGE_PRICE_FIELDS) {
43 - const raw = form[field.key].trim();
43 + const raw = form[field.key].trim().replace(",", ".");
44 if (raw === "") {
45 if (field.optional) continue;
46 return null;