Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ changes.

### Changed

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

### Removed

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

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

Expand Down
20 changes: 11 additions & 9 deletions govtool/frontend/src/components/molecules/VotesSubmitted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { IMAGES, SECURITY_RELEVANT_PARAMS_MAP } from "@consts";
import { Typography, VotePill } from "@atoms";
import { useTranslation } from "@hooks";
import {
correctDRepDirectoryFormat,
getGovActionVotingThresholdKey,
correctAdaFormatWithSuffix,
} from "@utils";
import { SubmittedVotesData } from "@models";
import { useFeatureFlag, useAppContext } from "@/context";
Expand Down Expand Up @@ -254,23 +254,24 @@ const VotesGroup = ({
flex={1}
borderBottom={1}
borderColor="neutralGray"
justifyContent="flex-end"
alignItems="center"
>
<Typography
sx={{
marginRight: 3,
fontSize: 16,
lineHeight: "24px",
fontWeight: "500",
marginRight: 1,
fontSize: 12,
lineHeight: "16px",
fontWeight: "400",
color: "rgba(36, 34, 50, 1)",
}}
>
{t("govActions.threshold")}
</Typography>
<Typography
sx={{
fontSize: 16,
lineHeight: "24px",
fontWeight: "500",
fontSize: 12,
lineHeight: "16px",
color: "neutralGray",
}}
>
Expand Down Expand Up @@ -314,13 +315,14 @@ const Vote = ({ type, vote, value, percentage }: VoteProps) => (
}}
>
{type !== "ccCommittee"
? `₳ ${correctDRepDirectoryFormat(value)}`
? `₳ ${correctAdaFormatWithSuffix(value)}`
: value}
</Typography>
{vote !== "abstain" && typeof percentage === "number" && (
<Typography
data-testid={`submitted-votes-${type}-${vote}-percentage`}
sx={{
ml: 1,
fontSize: 16,
lineHeight: "24px",
fontWeight: "500",
Expand Down
4 changes: 0 additions & 4 deletions govtool/frontend/src/components/organisms/DashboardCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,17 @@ export const DashboardCards = () => {
voter={voter}
votingPower={votingPower}
/>

<DRepDashboardCard
dRepID={dRepID}
pendingTransaction={pendingTransaction}
voter={voter}
/>

<DirectVoterDashboardCard
pendingTransaction={pendingTransaction}
voter={voter}
votingPower={votingPower}
/>

<ListGovActionsDashboardCards />

<ProposeGovActionDashboardCard
createGovActionTx={pendingTransaction.createGovAction}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const GovernanceActionDetailsCard = ({
const [isVoteSubmitted, setIsVoteSubmitted] = useState<boolean>(false);
const { screenWidth, isMobile } = useScreenDimension();

const isOneColumn = (isDashboard && screenWidth < 1036) ?? isMobile;
const isOneColumn = (isDashboard && screenWidth < 1200) ?? isMobile;

return (
<Box
Expand Down
52 changes: 22 additions & 30 deletions govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Dispatch, SetStateAction, useCallback, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useFormContext } from "react-hook-form";
import { blake2bHex } from "blakejs";
import * as Sentry from "@sentry/react";
import { useTranslation } from "react-i18next";
import { NodeObject } from "jsonld";

Expand Down Expand Up @@ -129,36 +128,31 @@ export const useCreateGovernanceActionForm = (
hash,
url: data.storingURL,
};
try {
switch (govActionType) {
case GovernanceActionType.InfoAction:
return await buildNewInfoGovernanceAction(commonGovActionDetails);
case GovernanceActionType.TreasuryWithdrawals: {
if (
data.amount === undefined ||
data.receivingAddress === undefined
) {
throw new Error(t("errors.invalidTreasuryGovernanceActionType"));
}
switch (govActionType) {
case GovernanceActionType.InfoAction:
return buildNewInfoGovernanceAction(commonGovActionDetails);
case GovernanceActionType.TreasuryWithdrawals: {
if (
data.amount === undefined ||
data.receivingAddress === undefined
) {
throw new Error(t("errors.invalidTreasuryGovernanceActionType"));
}

const treasuryActionDetails = {
...commonGovActionDetails,
withdrawals: [
{
amount: data.amount,
receivingAddress: data.receivingAddress,
},
],
};
const treasuryActionDetails = {
...commonGovActionDetails,
withdrawals: [
{
amount: data.amount,
receivingAddress: data.receivingAddress,
},
],
};

return await buildTreasuryGovernanceAction(treasuryActionDetails);
}
default:
throw new Error(t("errors.invalidGovernanceActionType"));
return buildTreasuryGovernanceAction(treasuryActionDetails);
}
} catch (error) {
Sentry.setTag("hook", "useCreateGovernanceActionForm");
Sentry.captureException(error);
default:
throw new Error(t("errors.invalidGovernanceActionType"));
}
},
[hash],
Expand Down Expand Up @@ -249,8 +243,6 @@ export const useCreateGovernanceActionForm = (
: undefined,
dataTestId: "create-governance-action-error-modal",
});
Sentry.setTag("hook", "useCreateGovernanceActionForm");
Sentry.captureException(error);
}
} finally {
setIsLoading(false);
Expand Down
4 changes: 0 additions & 4 deletions govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { useFormContext } from "react-hook-form";
import { blake2bHex } from "blakejs";
import * as Sentry from "@sentry/react";
import { NodeObject } from "jsonld";

import { DREP_CONTEXT, PATHS, storageInformationErrorModals } from "@consts";
Expand Down Expand Up @@ -172,9 +171,6 @@ export const useEditDRepInfoForm = (
},
});
} else {
Sentry.setTag("hook", "useEditDRepInfoForm");
Sentry.captureException(error);

openWalletErrorModal({
error: error?.message ? error.message : JSON.stringify(error),
onSumbit: () => backToDashboard(),
Expand Down
25 changes: 5 additions & 20 deletions govtool/frontend/src/hooks/forms/useVoteContextForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Dispatch, SetStateAction, useCallback, useState } from "react";
import { useFormContext } from "react-hook-form";
import { blake2bHex } from "blakejs";
import * as Sentry from "@sentry/react";
import { NodeObject } from "jsonld";

import { downloadJson, generateJsonld, generateMetadataBody } from "@utils";
Expand Down Expand Up @@ -60,16 +59,16 @@ export const useVoteContextForm = (
downloadJson(json, "Vote_Context");
};

const validateHash = useCallback(
async (url: string, localHash: string | null) => {
const onSubmit = useCallback(
async (data: VoteContextFormValues) => {
try {
if (!localHash) {
if (!hash) {
throw new Error(MetadataValidationStatus.INVALID_HASH);
}

const result = await validateMetadata({
hash: localHash,
url,
hash,
url: data.storingURL,
});

if (result.status) {
Expand All @@ -82,20 +81,6 @@ export const useVoteContextForm = (
if (setErrorMessage) setErrorMessage(error);
if (setStep) setStep(4);
}
throw error;
}
},
[],
);

const onSubmit = useCallback(
async (data: VoteContextFormValues) => {
try {
await validateHash(data.storingURL, hash);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
Sentry.setTag("hook", "useVoteContextForm");
Sentry.captureException(error);
} finally {
if (setSavedHash) setSavedHash(hash);
if (setStep) setStep(4);
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
"submissionDate": "Submission date:",
"submittedDateWithEpoch": "Submitted: <0>{{date}}</0> <1>(Epoch {{epoch}})</1>",
"supportingLinks": "Supporting links",
"threshold": "THRESHOLD",
"threshold": "Ratification Threshold",
"title": "Governance Actions",
"toVote": "To vote",
"viewDetails": "View Details",
Expand Down
21 changes: 21 additions & 0 deletions govtool/frontend/src/utils/adaFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@ export const correctDRepDirectoryFormat = (lovelace: number | undefined) => {

return "0";
};

export const correctAdaFormatWithSuffix = (
lovelace: number | undefined,
precision = 2,
) => {
if (!lovelace) return "0";
const ada = lovelace / LOVELACE;
if (ada < 1000)
return ada.toLocaleString("en-us", {
maximumFractionDigits: precision,
});

const suffixes = ["k", "M", "B", "T"];
const divisors = [1000, 1000000, 1000000000, 1000000000000];

for (let i = 0; i < suffixes.length; i++) {
if (ada < divisors[i] * 1000) {
return (ada / divisors[i]).toFixed(precision) + suffixes[i];
}
}
};
39 changes: 39 additions & 0 deletions govtool/frontend/src/utils/tests/adaFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
correctAdaFormat,
correctVoteAdaFormat,
correctDRepDirectoryFormat,
correctAdaFormatWithSuffix,
} from "..";

describe("correctAdaFormat", () => {
Expand Down Expand Up @@ -102,3 +103,41 @@ describe("correctDRepDirectoryFormat", () => {
expect(correctDRepDirectoryFormat(lovelace)).toBe(expectedResult);
});
});

describe("correctAdaFormatWithSuffix", () => {
test("Correctly formats lovelace value to ada format with suffix (T)", () => {
const lovelace = 123456789012345;
const expectedResult = "123.46M";
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
});

test("Correctly formats lovelace value to ada format with suffix (B)", () => {
const lovelace = 123456789012;
const expectedResult = "123.46k";
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
});

test("Correctly formats lovelace value to ada format with suffix (M)", () => {
const lovelace = 123456789;
const expectedResult = "123.46";
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
});

test("Returns 0 for undefined lovelace value", () => {
const lovelace = undefined;
const expectedResult = "0";
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
});

test("Returns 0 for zero lovelace value", () => {
const lovelace = 0;
const expectedResult = "0";
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
});

test("Returns 0 for small lovelace value", () => {
const lovelace = 123;
const expectedResult = "0";
expect(correctAdaFormatWithSuffix(lovelace)).toBe(expectedResult);
});
});
Loading