From e27ab29c1265c6d16b6a3af5209e1e220a820c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Wed, 20 Nov 2024 07:22:36 +0100 Subject: [PATCH] fix(#2372): fix ada quantities format --- CHANGELOG.md | 1 + govtool/frontend/src/utils/adaFormat.ts | 4 ++-- govtool/frontend/src/utils/tests/adaFormat.test.ts | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5466f15ba..e602ff39f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ changes. - Fix listing voted-on governance actions [Issue 2379](https://github.com/IntersectMBO/govtool/issues/2379) - Fix wronly displayed markdown on slider card [Issue 2263](https://github.com/IntersectMBO/govtool/issues/2316) +- fix ada quantities format to avoid thousands when the total is 0 [Issue 2372](https://github.com/IntersectMBO/govtool/issues/2382) ### Changed diff --git a/govtool/frontend/src/utils/adaFormat.ts b/govtool/frontend/src/utils/adaFormat.ts index ec4f9a3e7..851061623 100644 --- a/govtool/frontend/src/utils/adaFormat.ts +++ b/govtool/frontend/src/utils/adaFormat.ts @@ -14,12 +14,12 @@ export const correctVoteAdaFormat = ( ) => { if (lovelace) { const ada = lovelace / LOVELACE; + return ada.toLocaleString(locale, { - minimumFractionDigits: 3, maximumFractionDigits: 3, }); } - return "0,000"; + return "0"; }; export const correctDRepDirectoryFormat = (lovelace: number | undefined) => { diff --git a/govtool/frontend/src/utils/tests/adaFormat.test.ts b/govtool/frontend/src/utils/tests/adaFormat.test.ts index 6b8aa4625..faa667ec3 100644 --- a/govtool/frontend/src/utils/tests/adaFormat.test.ts +++ b/govtool/frontend/src/utils/tests/adaFormat.test.ts @@ -66,19 +66,19 @@ describe("correctVoteAdaFormat", () => { test("Returns 0 for undefined lovelace value", () => { const lovelace = undefined; - const expectedResult = "0,000"; + const expectedResult = "0"; expect(correctVoteAdaFormat(lovelace, "en-US")).toBe(expectedResult); }); test("Returns 0 for zero lovelace value", () => { const lovelace = 0; - const expectedResult = "0,000"; + const expectedResult = "0"; expect(correctVoteAdaFormat(lovelace, "en-US")).toBe(expectedResult); }); test("Returns 0 for small lovelace value", () => { const lovelace = 123; - const expectedResult = "0.000"; + const expectedResult = "0"; expect(correctVoteAdaFormat(lovelace, "en-US")).toBe(expectedResult); }); });