From 2895cab5c91c2707c14a31b522fc003114acfd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Fri, 31 Jan 2025 18:24:08 +0100 Subject: [PATCH 1/3] dummy: nothing changed: --- govtool/frontend/src/components/organisms/DashboardCards.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/govtool/frontend/src/components/organisms/DashboardCards.tsx b/govtool/frontend/src/components/organisms/DashboardCards.tsx index c31448450..c08ba5278 100644 --- a/govtool/frontend/src/components/organisms/DashboardCards.tsx +++ b/govtool/frontend/src/components/organisms/DashboardCards.tsx @@ -63,21 +63,17 @@ export const DashboardCards = () => { voter={voter} votingPower={votingPower} /> - - - - From a132b76f498543a09ab95d4e4041f060a081f973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Sat, 1 Feb 2025 19:13:03 +0100 Subject: [PATCH 2/3] fix(#2680): remove redundant sentry reports an handled wallet exceptions --- CHANGELOG.md | 2 +- .../forms/useCreateGovernanceActionForm.ts | 52 ++++++++----------- .../src/hooks/forms/useEditDRepInfoForm.ts | 4 -- .../src/hooks/forms/useVoteContextForm.tsx | 25 ++------- 4 files changed, 28 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d53bdc86e..2b6e59e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ changes. ### 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 diff --git a/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts b/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts index 867857240..0760b27cd 100644 --- a/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts +++ b/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts @@ -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"; @@ -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], @@ -249,8 +243,6 @@ export const useCreateGovernanceActionForm = ( : undefined, dataTestId: "create-governance-action-error-modal", }); - Sentry.setTag("hook", "useCreateGovernanceActionForm"); - Sentry.captureException(error); } } finally { setIsLoading(false); diff --git a/govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts b/govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts index dd92d59f7..8d3e3fb63 100644 --- a/govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts +++ b/govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts @@ -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"; @@ -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(), diff --git a/govtool/frontend/src/hooks/forms/useVoteContextForm.tsx b/govtool/frontend/src/hooks/forms/useVoteContextForm.tsx index 1da1587c3..2d8c423b4 100644 --- a/govtool/frontend/src/hooks/forms/useVoteContextForm.tsx +++ b/govtool/frontend/src/hooks/forms/useVoteContextForm.tsx @@ -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"; @@ -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) { @@ -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); From 947a626753995e84c9ec17ef85a0762df27e26ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Mon, 3 Feb 2025 12:33:11 +0100 Subject: [PATCH 3/3] feat(#2880): add suffixes to governance actions votes --- CHANGELOG.md | 2 +- .../components/molecules/VotesSubmitted.tsx | 20 ++++--- .../organisms/GovernanceActionDetailsCard.tsx | 2 +- govtool/frontend/src/i18n/locales/en.json | 2 +- govtool/frontend/src/utils/adaFormat.ts | 21 +++++++ .../src/utils/tests/adaFormat.test.ts | 39 +++++++++++++ govtool/frontend/yarn.lock | 55 ++++++++++--------- 7 files changed, 104 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d53bdc86e..657d3116b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ changes. ### Changed -- +- Change votes representation on Governance Actions [Issue 2880](https://github.com/IntersectMBO/govtool/issues/2880) ### Removed diff --git a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx index bc81e4e7c..de4a64c12 100644 --- a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx +++ b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx @@ -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"; @@ -254,13 +254,15 @@ const VotesGroup = ({ flex={1} borderBottom={1} borderColor="neutralGray" + justifyContent="flex-end" + alignItems="center" > @@ -268,9 +270,8 @@ const VotesGroup = ({ @@ -314,13 +315,14 @@ const Vote = ({ type, vote, value, percentage }: VoteProps) => ( }} > {type !== "ccCommittee" - ? `₳ ${correctDRepDirectoryFormat(value)}` + ? `₳ ${correctAdaFormatWithSuffix(value)}` : value} {vote !== "abstain" && typeof percentage === "number" && ( (false); const { screenWidth, isMobile } = useScreenDimension(); - const isOneColumn = (isDashboard && screenWidth < 1036) ?? isMobile; + const isOneColumn = (isDashboard && screenWidth < 1200) ?? isMobile; return ( {{date}} <1>(Epoch {{epoch}})", "supportingLinks": "Supporting links", - "threshold": "THRESHOLD", + "threshold": "Ratification Threshold", "title": "Governance Actions", "toVote": "To vote", "viewDetails": "View Details", diff --git a/govtool/frontend/src/utils/adaFormat.ts b/govtool/frontend/src/utils/adaFormat.ts index 851061623..d742b8d37 100644 --- a/govtool/frontend/src/utils/adaFormat.ts +++ b/govtool/frontend/src/utils/adaFormat.ts @@ -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]; + } + } +}; diff --git a/govtool/frontend/src/utils/tests/adaFormat.test.ts b/govtool/frontend/src/utils/tests/adaFormat.test.ts index faa667ec3..8c37f2fc6 100644 --- a/govtool/frontend/src/utils/tests/adaFormat.test.ts +++ b/govtool/frontend/src/utils/tests/adaFormat.test.ts @@ -4,6 +4,7 @@ import { correctAdaFormat, correctVoteAdaFormat, correctDRepDirectoryFormat, + correctAdaFormatWithSuffix, } from ".."; describe("correctAdaFormat", () => { @@ -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); + }); +}); diff --git a/govtool/frontend/yarn.lock b/govtool/frontend/yarn.lock index e0f4aac63..f24f8e693 100644 --- a/govtool/frontend/yarn.lock +++ b/govtool/frontend/yarn.lock @@ -1367,15 +1367,15 @@ resolved "https://registry.npmjs.org/@emurgo/cardano-serialization-lib-asmjs/-/cardano-serialization-lib-asmjs-12.1.1.tgz" integrity sha512-K3f28QUfLDJ7seO6MtKfMYtRm5ccf36TQ5yxyTmZqX1TA85MkriEdxqpgV9KLiLEA95emwnlvU2/WmlHMRPg1A== -"@esbuild/darwin-arm64@0.21.5": +"@esbuild/linux-x64@0.21.5": version "0.21.5" - resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz" - integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ== + resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz" + integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ== -"@esbuild/darwin-arm64@0.24.2": +"@esbuild/linux-x64@0.24.2": version "0.24.2" - resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz" - integrity sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA== + resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz" + integrity sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q== "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.1" @@ -2162,10 +2162,15 @@ resolved "https://registry.npmjs.org/@open-draft/until/-/until-2.1.0.tgz" integrity sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg== -"@parcel/watcher-darwin-arm64@2.5.0": +"@parcel/watcher-linux-x64-glibc@2.5.0": version "2.5.0" - resolved "https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.5.0.tgz" - integrity sha512-hyZ3TANnzGfLpRA2s/4U1kbw2ZI4qGxaRJbBH2DCSREFfubMswheh8TeiC1sGZ3z2jUf3s37P0BBlrD3sjVTUw== + resolved "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.5.0.tgz" + integrity sha512-d9AOkusyXARkFD66S6zlGXyzx5RvY+chTP9Jp0ypSTC9d4lzyRs9ovGf/80VCxjKddcUvnsGwCHWuF2EoPgWjw== + +"@parcel/watcher-linux-x64-musl@2.5.0": + version "2.5.0" + resolved "https://registry.npmjs.org/@parcel/watcher-linux-x64-musl/-/watcher-linux-x64-musl-2.5.0.tgz" + integrity sha512-iqOC+GoTDoFyk/VYSFHwjHhYrk8bljW6zOhPuhi5t9ulqiYq1togGJB5e3PwYVFFfeVgc6pbz3JdQyDoBszVaA== "@parcel/watcher@^2.4.1": version "2.5.0" @@ -2278,10 +2283,15 @@ estree-walker "^2.0.2" picomatch "^4.0.2" -"@rollup/rollup-darwin-arm64@4.27.4": +"@rollup/rollup-linux-x64-gnu@4.27.4": version "4.27.4" - resolved "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.27.4.tgz" - integrity sha512-PlNiRQapift4LNS8DPUHuDX/IdXiLjf8mc5vdEmUR0fF/pyy2qWwzdLjB+iZquGr8LuN4LnUoSEvKRwjSVYz3Q== + resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.27.4.tgz" + integrity sha512-Ni8mMtfo+o/G7DVtweXXV/Ol2TFf63KYjTtoZ5f078AUgJTmaIJnj4JFU7TK/9SVWTaSJGxPi5zMDgK4w+Ez7Q== + +"@rollup/rollup-linux-x64-musl@4.27.4": + version "4.27.4" + resolved "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.27.4.tgz" + integrity sha512-5AeeAF1PB9TUzD+3cROzFTnAJAcVUGLuR8ng0E0WXGkYhp6RD6L+6szYVX+64Rs0r72019KHZS1ka1q+zU/wUw== "@rtsao/scc@^1.1.0": version "1.1.0" @@ -2860,10 +2870,15 @@ "@svgr/plugin-svgo" "^5.5.0" loader-utils "^2.0.0" -"@swc/core-darwin-arm64@1.9.3": +"@swc/core-linux-x64-gnu@1.9.3": version "1.9.3" - resolved "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.9.3.tgz" - integrity sha512-hGfl/KTic/QY4tB9DkTbNuxy5cV4IeejpPD4zo+Lzt4iLlDWIeANL4Fkg67FiVceNJboqg48CUX+APhDHO5G1w== + resolved "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.9.3.tgz" + integrity sha512-ivXXBRDXDc9k4cdv10R21ccBmGebVOwKXT/UdH1PhxUn9m/h8erAWjz5pcELwjiMf27WokqPgaWVfaclDbgE+w== + +"@swc/core-linux-x64-musl@1.9.3": + version "1.9.3" + resolved "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.9.3.tgz" + integrity sha512-ILsGMgfnOz1HwdDz+ZgEuomIwkP1PHT6maigZxaCIuC6OPEhKE8uYna22uU63XvYcLQvZYDzpR3ms47WQPuNEg== "@swc/core@*", "@swc/core@^1.5.22", "@swc/core@^1.7.26": version "1.9.3" @@ -7169,16 +7184,6 @@ fs@^0.0.1-security: resolved "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz" integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w== -fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3: - version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" - integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== - -fsevents@2.3.2: - version "2.3.2" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" - integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== - function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"