Skip to content

Commit c053055

Browse files
authored
Merge pull request #2881 from IntersectMBO/feat/2880-governance-actions-votes-adjustments
feat(#2880): add suffixes to governance actions votes
2 parents 64819a9 + 947a626 commit c053055

File tree

7 files changed

+104
-37
lines changed

7 files changed

+104
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ changes.
2222

2323
### Changed
2424

25-
-
25+
- Change votes representation on Governance Actions [Issue 2880](https://github.com/IntersectMBO/govtool/issues/2880)
2626

2727
### Removed
2828

govtool/frontend/src/components/molecules/VotesSubmitted.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { IMAGES, SECURITY_RELEVANT_PARAMS_MAP } from "@consts";
55
import { Typography, VotePill } from "@atoms";
66
import { useTranslation } from "@hooks";
77
import {
8-
correctDRepDirectoryFormat,
98
getGovActionVotingThresholdKey,
9+
correctAdaFormatWithSuffix,
1010
} from "@utils";
1111
import { SubmittedVotesData } from "@models";
1212
import { useFeatureFlag, useAppContext } from "@/context";
@@ -254,23 +254,24 @@ const VotesGroup = ({
254254
flex={1}
255255
borderBottom={1}
256256
borderColor="neutralGray"
257+
justifyContent="flex-end"
258+
alignItems="center"
257259
>
258260
<Typography
259261
sx={{
260-
marginRight: 3,
261-
fontSize: 16,
262-
lineHeight: "24px",
263-
fontWeight: "500",
262+
marginRight: 1,
263+
fontSize: 12,
264+
lineHeight: "16px",
265+
fontWeight: "400",
264266
color: "rgba(36, 34, 50, 1)",
265267
}}
266268
>
267269
{t("govActions.threshold")}
268270
</Typography>
269271
<Typography
270272
sx={{
271-
fontSize: 16,
272-
lineHeight: "24px",
273-
fontWeight: "500",
273+
fontSize: 12,
274+
lineHeight: "16px",
274275
color: "neutralGray",
275276
}}
276277
>
@@ -314,13 +315,14 @@ const Vote = ({ type, vote, value, percentage }: VoteProps) => (
314315
}}
315316
>
316317
{type !== "ccCommittee"
317-
? `₳ ${correctDRepDirectoryFormat(value)}`
318+
? `₳ ${correctAdaFormatWithSuffix(value)}`
318319
: value}
319320
</Typography>
320321
{vote !== "abstain" && typeof percentage === "number" && (
321322
<Typography
322323
data-testid={`submitted-votes-${type}-${vote}-percentage`}
323324
sx={{
325+
ml: 1,
324326
fontSize: 16,
325327
lineHeight: "24px",
326328
fontWeight: "500",

govtool/frontend/src/components/organisms/GovernanceActionDetailsCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const GovernanceActionDetailsCard = ({
2929
const [isVoteSubmitted, setIsVoteSubmitted] = useState<boolean>(false);
3030
const { screenWidth, isMobile } = useScreenDimension();
3131

32-
const isOneColumn = (isDashboard && screenWidth < 1036) ?? isMobile;
32+
const isOneColumn = (isDashboard && screenWidth < 1200) ?? isMobile;
3333

3434
return (
3535
<Box

govtool/frontend/src/i18n/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
"submissionDate": "Submission date:",
403403
"submittedDateWithEpoch": "Submitted: <0>{{date}}</0> <1>(Epoch {{epoch}})</1>",
404404
"supportingLinks": "Supporting links",
405-
"threshold": "THRESHOLD",
405+
"threshold": "Ratification Threshold",
406406
"title": "Governance Actions",
407407
"toVote": "To vote",
408408
"viewDetails": "View Details",

govtool/frontend/src/utils/adaFormat.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,24 @@ export const correctDRepDirectoryFormat = (lovelace: number | undefined) => {
2929

3030
return "0";
3131
};
32+
33+
export const correctAdaFormatWithSuffix = (
34+
lovelace: number | undefined,
35+
precision = 2,
36+
) => {
37+
if (!lovelace) return "0";
38+
const ada = lovelace / LOVELACE;
39+
if (ada < 1000)
40+
return ada.toLocaleString("en-us", {
41+
maximumFractionDigits: precision,
42+
});
43+
44+
const suffixes = ["k", "M", "B", "T"];
45+
const divisors = [1000, 1000000, 1000000000, 1000000000000];
46+
47+
for (let i = 0; i < suffixes.length; i++) {
48+
if (ada < divisors[i] * 1000) {
49+
return (ada / divisors[i]).toFixed(precision) + suffixes[i];
50+
}
51+
}
52+
};

govtool/frontend/src/utils/tests/adaFormat.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
correctAdaFormat,
55
correctVoteAdaFormat,
66
correctDRepDirectoryFormat,
7+
correctAdaFormatWithSuffix,
78
} from "..";
89

910
describe("correctAdaFormat", () => {
@@ -102,3 +103,41 @@ describe("correctDRepDirectoryFormat", () => {
102103
expect(correctDRepDirectoryFormat(lovelace)).toBe(expectedResult);
103104
});
104105
});
106+
107+
describe("correctAdaFormatWithSuffix", () => {
108+
test("Correctly formats lovelace value to ada format with suffix (T)", () => {
109+
const lovelace = 123456789012345;
110+
const expectedResult = "123.46M";
111+
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
112+
});
113+
114+
test("Correctly formats lovelace value to ada format with suffix (B)", () => {
115+
const lovelace = 123456789012;
116+
const expectedResult = "123.46k";
117+
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
118+
});
119+
120+
test("Correctly formats lovelace value to ada format with suffix (M)", () => {
121+
const lovelace = 123456789;
122+
const expectedResult = "123.46";
123+
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
124+
});
125+
126+
test("Returns 0 for undefined lovelace value", () => {
127+
const lovelace = undefined;
128+
const expectedResult = "0";
129+
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
130+
});
131+
132+
test("Returns 0 for zero lovelace value", () => {
133+
const lovelace = 0;
134+
const expectedResult = "0";
135+
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
136+
});
137+
138+
test("Returns 0 for small lovelace value", () => {
139+
const lovelace = 123;
140+
const expectedResult = "0";
141+
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
142+
});
143+
});

govtool/frontend/yarn.lock

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,15 +1367,15 @@
13671367
resolved "https://registry.npmjs.org/@emurgo/cardano-serialization-lib-asmjs/-/cardano-serialization-lib-asmjs-12.1.1.tgz"
13681368
integrity sha512-K3f28QUfLDJ7seO6MtKfMYtRm5ccf36TQ5yxyTmZqX1TA85MkriEdxqpgV9KLiLEA95emwnlvU2/WmlHMRPg1A==
13691369

1370-
"@esbuild/darwin-arm64@0.21.5":
1370+
"@esbuild/linux-x64@0.21.5":
13711371
version "0.21.5"
1372-
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz"
1373-
integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==
1372+
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz"
1373+
integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==
13741374

1375-
"@esbuild/darwin-arm64@0.24.2":
1375+
"@esbuild/linux-x64@0.24.2":
13761376
version "0.24.2"
1377-
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz"
1378-
integrity sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA==
1377+
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz"
1378+
integrity sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q==
13791379

13801380
"@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0":
13811381
version "4.4.1"
@@ -2162,10 +2162,15 @@
21622162
resolved "https://registry.npmjs.org/@open-draft/until/-/until-2.1.0.tgz"
21632163
integrity sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==
21642164

2165-
"@parcel/watcher-darwin-arm64@2.5.0":
2165+
"@parcel/watcher-linux-x64-glibc@2.5.0":
21662166
version "2.5.0"
2167-
resolved "https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.5.0.tgz"
2168-
integrity sha512-hyZ3TANnzGfLpRA2s/4U1kbw2ZI4qGxaRJbBH2DCSREFfubMswheh8TeiC1sGZ3z2jUf3s37P0BBlrD3sjVTUw==
2167+
resolved "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.5.0.tgz"
2168+
integrity sha512-d9AOkusyXARkFD66S6zlGXyzx5RvY+chTP9Jp0ypSTC9d4lzyRs9ovGf/80VCxjKddcUvnsGwCHWuF2EoPgWjw==
2169+
2170+
2171+
version "2.5.0"
2172+
resolved "https://registry.npmjs.org/@parcel/watcher-linux-x64-musl/-/watcher-linux-x64-musl-2.5.0.tgz"
2173+
integrity sha512-iqOC+GoTDoFyk/VYSFHwjHhYrk8bljW6zOhPuhi5t9ulqiYq1togGJB5e3PwYVFFfeVgc6pbz3JdQyDoBszVaA==
21692174

21702175
"@parcel/watcher@^2.4.1":
21712176
version "2.5.0"
@@ -2278,10 +2283,15 @@
22782283
estree-walker "^2.0.2"
22792284
picomatch "^4.0.2"
22802285

2281-
"@rollup/rollup-darwin-arm64@4.27.4":
2286+
"@rollup/rollup-linux-x64-gnu@4.27.4":
22822287
version "4.27.4"
2283-
resolved "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.27.4.tgz"
2284-
integrity sha512-PlNiRQapift4LNS8DPUHuDX/IdXiLjf8mc5vdEmUR0fF/pyy2qWwzdLjB+iZquGr8LuN4LnUoSEvKRwjSVYz3Q==
2288+
resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.27.4.tgz"
2289+
integrity sha512-Ni8mMtfo+o/G7DVtweXXV/Ol2TFf63KYjTtoZ5f078AUgJTmaIJnj4JFU7TK/9SVWTaSJGxPi5zMDgK4w+Ez7Q==
2290+
2291+
2292+
version "4.27.4"
2293+
resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.27.4.tgz"
2294+
integrity sha512-5AeeAF1PB9TUzD+3cROzFTnAJAcVUGLuR8ng0E0WXGkYhp6RD6L+6szYVX+64Rs0r72019KHZS1ka1q+zU/wUw==
22852295

22862296
"@rtsao/scc@^1.1.0":
22872297
version "1.1.0"
@@ -2860,10 +2870,15 @@
28602870
"@svgr/plugin-svgo" "^5.5.0"
28612871
loader-utils "^2.0.0"
28622872

2863-
"@swc/core-darwin-arm64@1.9.3":
2873+
"@swc/core-linux-x64-gnu@1.9.3":
28642874
version "1.9.3"
2865-
resolved "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.9.3.tgz"
2866-
integrity sha512-hGfl/KTic/QY4tB9DkTbNuxy5cV4IeejpPD4zo+Lzt4iLlDWIeANL4Fkg67FiVceNJboqg48CUX+APhDHO5G1w==
2875+
resolved "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.9.3.tgz"
2876+
integrity sha512-ivXXBRDXDc9k4cdv10R21ccBmGebVOwKXT/UdH1PhxUn9m/h8erAWjz5pcELwjiMf27WokqPgaWVfaclDbgE+w==
2877+
2878+
2879+
version "1.9.3"
2880+
resolved "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.9.3.tgz"
2881+
integrity sha512-ILsGMgfnOz1HwdDz+ZgEuomIwkP1PHT6maigZxaCIuC6OPEhKE8uYna22uU63XvYcLQvZYDzpR3ms47WQPuNEg==
28672882

28682883
"@swc/core@*", "@swc/core@^1.5.22", "@swc/core@^1.7.26":
28692884
version "1.9.3"
@@ -7169,16 +7184,6 @@ fs@^0.0.1-security:
71697184
resolved "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz"
71707185
integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==
71717186

7172-
fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3:
7173-
version "2.3.3"
7174-
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
7175-
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
7176-
7177-
7178-
version "2.3.2"
7179-
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
7180-
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
7181-
71827187
function-bind@^1.1.2:
71837188
version "1.1.2"
71847189
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"

0 commit comments

Comments
 (0)