Skip to content

Commit

Permalink
Merge pull request #2396 from IntersectMBO/fix/2372--ada-quantities-f…
Browse files Browse the repository at this point in the history
…ormat-should-avoid-thousands-when-the-total-is-0

fix(#2372): fix ada quantities format
  • Loading branch information
MSzalowski authored Nov 20, 2024
2 parents 4ff3e14 + e27ab29 commit 1663f56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions govtool/frontend/src/utils/adaFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions govtool/frontend/src/utils/tests/adaFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down

0 comments on commit 1663f56

Please sign in to comment.