From 783c82fa837ddf880c757658d37c26ff8d49419c Mon Sep 17 00:00:00 2001 From: Jan Jaroszczak Date: Thu, 22 Feb 2024 09:46:28 +0100 Subject: [PATCH 1/4] [#210] Sole voter wallet logic for registration and retirement --- govtool/frontend/src/App.tsx | 6 +-- .../src/components/atoms/VotingPowerChips.tsx | 10 ++-- .../components/molecules/VoteActionForm.tsx | 4 +- .../components/organisms/DashboardCards.tsx | 53 +++++++++---------- .../DashboardGovernanceActionDetails.tsx | 4 +- .../organisms/DashboardGovernanceActions.tsx | 4 +- .../components/organisms/DashboardTopNav.tsx | 4 +- .../organisms/DelegateTodRepStepOne.tsx | 6 +-- .../src/components/organisms/Drawer.tsx | 4 +- .../organisms/RetireAsSoleVoterBoxContent.tsx | 4 +- govtool/frontend/src/context/wallet.tsx | 41 ++++++-------- govtool/frontend/src/context/walletUtils.ts | 8 +-- govtool/frontend/src/hooks/index.ts | 1 - govtool/frontend/src/hooks/mutations/index.ts | 7 --- .../useAdaHolderDelegateAbstainMutation.ts | 10 ---- .../mutations/useAdaHolderDelegateMutation.ts | 10 ---- .../useAdaHolderDelegateNoMutation.ts | 10 ---- .../useAdaHolderRemoveDelegationMutation.ts | 10 ---- .../mutations/useDRepRegisterMutation.ts | 18 ------- .../mutations/useDRepRemoveVoteMutation.ts | 10 ---- .../hooks/mutations/useDRepRetireMutation.ts | 19 ------- govtool/frontend/src/i18n/locales/en.ts | 9 ++-- govtool/frontend/src/models/api.ts | 8 +-- .../DashboardGovernanceActionsCategory.tsx | 4 +- .../src/pages/GovernanceActionsCategory.tsx | 4 +- .../src/services/requests/getDRepInfo.ts | 4 +- 26 files changed, 84 insertions(+), 188 deletions(-) delete mode 100644 govtool/frontend/src/hooks/mutations/index.ts delete mode 100644 govtool/frontend/src/hooks/mutations/useAdaHolderDelegateAbstainMutation.ts delete mode 100644 govtool/frontend/src/hooks/mutations/useAdaHolderDelegateMutation.ts delete mode 100644 govtool/frontend/src/hooks/mutations/useAdaHolderDelegateNoMutation.ts delete mode 100644 govtool/frontend/src/hooks/mutations/useAdaHolderRemoveDelegationMutation.ts delete mode 100644 govtool/frontend/src/hooks/mutations/useDRepRegisterMutation.ts delete mode 100644 govtool/frontend/src/hooks/mutations/useDRepRemoveVoteMutation.ts delete mode 100644 govtool/frontend/src/hooks/mutations/useDRepRetireMutation.ts diff --git a/govtool/frontend/src/App.tsx b/govtool/frontend/src/App.tsx index a36a89f8f..fc659e428 100644 --- a/govtool/frontend/src/App.tsx +++ b/govtool/frontend/src/App.tsx @@ -34,7 +34,7 @@ import { useGetDRepInfo, useWalletConnectionListener } from "./hooks"; import { RegisterAsSoleVoter } from "./pages/RegisterAsSoleVoter"; export default function App() { - const { enable, setDRep, setIsDrepLoading } = useCardano(); + const { enable, setUser, setIsDrepLoading } = useCardano(); const navigate = useNavigate(); const { data } = useGetDRepInfo(); const { modal, openModal, modals } = useModal(); @@ -47,11 +47,11 @@ export default function App() { useEffect(() => { setIsDrepLoading(true); - setDRep(data); + setUser(data); const timer = setTimeout(() => setIsDrepLoading(false), 1000); return () => clearTimeout(timer); - }, [data?.isRegistered]); + }, [data?.isRegisteredAsDRep]); const checkTheWalletIsActive = useCallback(() => { const hrefCondition = diff --git a/govtool/frontend/src/components/atoms/VotingPowerChips.tsx b/govtool/frontend/src/components/atoms/VotingPowerChips.tsx index 897ec0ce8..6dbeb0d6a 100644 --- a/govtool/frontend/src/components/atoms/VotingPowerChips.tsx +++ b/govtool/frontend/src/components/atoms/VotingPowerChips.tsx @@ -13,7 +13,7 @@ import { correctAdaFormat } from "@utils"; import { Tooltip } from "@atoms"; export const VotingPowerChips = () => { - const { dRep, stakeKey, isDrepLoading } = useCardano(); + const { user, stakeKey, isDrepLoading } = useCardano(); const { dRepVotingPower, isDRepVotingPowerLoading } = useGetDRepVotingPowerQuery(); const { votingPower, powerIsLoading } = @@ -33,7 +33,7 @@ export const VotingPowerChips = () => { alignItems="center" maxHeight={isMobile ? undefined : 48} > - {dRep?.isRegistered && ( + {user?.isRegisteredAsDRep && ( { {t("votingPower")} )} - {(dRep?.isRegistered && isDRepVotingPowerLoading) || - (!dRep?.isRegistered && powerIsLoading) || + {(user?.isRegisteredAsDRep && isDRepVotingPowerLoading) || + (!user?.isRegisteredAsDRep && powerIsLoading) || isDrepLoading ? ( ) : ( @@ -67,7 +67,7 @@ export const VotingPowerChips = () => { sx={{ whiteSpace: "nowrap" }} > ₳{" "} - {dRep?.isRegistered + {user?.isRegisteredAsDRep ? correctAdaFormat(dRepVotingPower) ?? 0 : correctAdaFormat(votingPower) ?? 0} diff --git a/govtool/frontend/src/components/molecules/VoteActionForm.tsx b/govtool/frontend/src/components/molecules/VoteActionForm.tsx index 3c1645bd2..9a4efbb95 100644 --- a/govtool/frontend/src/components/molecules/VoteActionForm.tsx +++ b/govtool/frontend/src/components/molecules/VoteActionForm.tsx @@ -25,7 +25,7 @@ export const VoteActionForm = ({ const [isContext, setIsContext] = useState(false); const { isMobile, screenWidth } = useScreenDimension(); const { openModal } = useModal(); - const { dRep } = useCardano(); + const { user } = useCardano(); const { t } = useTranslation(); const { @@ -142,7 +142,7 @@ export const VoteActionForm = ({ /> - {dRep?.isRegistered && ( + {user?.isRegisteredAsDRep && (