Skip to content

Commit e3203e4

Browse files
authored
Merge pull request #2882 from IntersectMBO/develop
GovTool - v2.0.10-patch4
2 parents a8c14ba + e1831a9 commit e3203e4

File tree

10 files changed

+132
-92
lines changed

10 files changed

+132
-92
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ 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

29-
-
29+
- Remove redundant sentry reports on handled wallet exceptions [Issue 2680](https://github.com/IntersectMBO/govtool/issues/2680)
3030

3131
## [v2.0.10](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.10) 2025-01-29
3232

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/hooks/forms/useCreateGovernanceActionForm.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Dispatch, SetStateAction, useCallback, useState } from "react";
22
import { useNavigate } from "react-router-dom";
33
import { useFormContext } from "react-hook-form";
44
import { blake2bHex } from "blakejs";
5-
import * as Sentry from "@sentry/react";
65
import { useTranslation } from "react-i18next";
76
import { NodeObject } from "jsonld";
87

@@ -129,36 +128,31 @@ export const useCreateGovernanceActionForm = (
129128
hash,
130129
url: data.storingURL,
131130
};
132-
try {
133-
switch (govActionType) {
134-
case GovernanceActionType.InfoAction:
135-
return await buildNewInfoGovernanceAction(commonGovActionDetails);
136-
case GovernanceActionType.TreasuryWithdrawals: {
137-
if (
138-
data.amount === undefined ||
139-
data.receivingAddress === undefined
140-
) {
141-
throw new Error(t("errors.invalidTreasuryGovernanceActionType"));
142-
}
131+
switch (govActionType) {
132+
case GovernanceActionType.InfoAction:
133+
return buildNewInfoGovernanceAction(commonGovActionDetails);
134+
case GovernanceActionType.TreasuryWithdrawals: {
135+
if (
136+
data.amount === undefined ||
137+
data.receivingAddress === undefined
138+
) {
139+
throw new Error(t("errors.invalidTreasuryGovernanceActionType"));
140+
}
143141

144-
const treasuryActionDetails = {
145-
...commonGovActionDetails,
146-
withdrawals: [
147-
{
148-
amount: data.amount,
149-
receivingAddress: data.receivingAddress,
150-
},
151-
],
152-
};
142+
const treasuryActionDetails = {
143+
...commonGovActionDetails,
144+
withdrawals: [
145+
{
146+
amount: data.amount,
147+
receivingAddress: data.receivingAddress,
148+
},
149+
],
150+
};
153151

154-
return await buildTreasuryGovernanceAction(treasuryActionDetails);
155-
}
156-
default:
157-
throw new Error(t("errors.invalidGovernanceActionType"));
152+
return buildTreasuryGovernanceAction(treasuryActionDetails);
158153
}
159-
} catch (error) {
160-
Sentry.setTag("hook", "useCreateGovernanceActionForm");
161-
Sentry.captureException(error);
154+
default:
155+
throw new Error(t("errors.invalidGovernanceActionType"));
162156
}
163157
},
164158
[hash],
@@ -249,8 +243,6 @@ export const useCreateGovernanceActionForm = (
249243
: undefined,
250244
dataTestId: "create-governance-action-error-modal",
251245
});
252-
Sentry.setTag("hook", "useCreateGovernanceActionForm");
253-
Sentry.captureException(error);
254246
}
255247
} finally {
256248
setIsLoading(false);

govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useNavigate } from "react-router-dom";
33
import { useTranslation } from "react-i18next";
44
import { useFormContext } from "react-hook-form";
55
import { blake2bHex } from "blakejs";
6-
import * as Sentry from "@sentry/react";
76
import { NodeObject } from "jsonld";
87

98
import { DREP_CONTEXT, PATHS, storageInformationErrorModals } from "@consts";
@@ -172,9 +171,6 @@ export const useEditDRepInfoForm = (
172171
},
173172
});
174173
} else {
175-
Sentry.setTag("hook", "useEditDRepInfoForm");
176-
Sentry.captureException(error);
177-
178174
openWalletErrorModal({
179175
error: error?.message ? error.message : JSON.stringify(error),
180176
onSumbit: () => backToDashboard(),

govtool/frontend/src/hooks/forms/useVoteContextForm.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Dispatch, SetStateAction, useCallback, useState } from "react";
22
import { useFormContext } from "react-hook-form";
33
import { blake2bHex } from "blakejs";
4-
import * as Sentry from "@sentry/react";
54
import { NodeObject } from "jsonld";
65

76
import { downloadJson, generateJsonld, generateMetadataBody } from "@utils";
@@ -60,16 +59,16 @@ export const useVoteContextForm = (
6059
downloadJson(json, "Vote_Context");
6160
};
6261

63-
const validateHash = useCallback(
64-
async (url: string, localHash: string | null) => {
62+
const onSubmit = useCallback(
63+
async (data: VoteContextFormValues) => {
6564
try {
66-
if (!localHash) {
65+
if (!hash) {
6766
throw new Error(MetadataValidationStatus.INVALID_HASH);
6867
}
6968

7069
const result = await validateMetadata({
71-
hash: localHash,
72-
url,
70+
hash,
71+
url: data.storingURL,
7372
});
7473

7574
if (result.status) {
@@ -82,20 +81,6 @@ export const useVoteContextForm = (
8281
if (setErrorMessage) setErrorMessage(error);
8382
if (setStep) setStep(4);
8483
}
85-
throw error;
86-
}
87-
},
88-
[],
89-
);
90-
91-
const onSubmit = useCallback(
92-
async (data: VoteContextFormValues) => {
93-
try {
94-
await validateHash(data.storingURL, hash);
95-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
96-
} catch (error: any) {
97-
Sentry.setTag("hook", "useVoteContextForm");
98-
Sentry.captureException(error);
9984
} finally {
10085
if (setSavedHash) setSavedHash(hash);
10186
if (setStep) setStep(4);

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+
});

0 commit comments

Comments
 (0)