From 701bfb8f0e62cc686238e3f980e253ebe3195fc6 Mon Sep 17 00:00:00 2001 From: Pierre Bertet Date: Fri, 20 Dec 2024 18:15:40 +0000 Subject: [PATCH] Voting panel: various improvements --- .../src/screens/StakeScreen/PanelVoting.tsx | 64 +++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/frontend/app/src/screens/StakeScreen/PanelVoting.tsx b/frontend/app/src/screens/StakeScreen/PanelVoting.tsx index f254e83d6..817dce74e 100644 --- a/frontend/app/src/screens/StakeScreen/PanelVoting.tsx +++ b/frontend/app/src/screens/StakeScreen/PanelVoting.tsx @@ -1,21 +1,22 @@ -import type { Address, Dnum, Initiative, Vote, VoteAllocations } from "@/src/types"; +import type { Address, Dnum, Entries, Initiative, Vote, VoteAllocations } from "@/src/types"; import { Amount } from "@/src/comps/Amount/Amount"; import { ConnectWarningBox } from "@/src/comps/ConnectWarningBox/ConnectWarningBox"; import { Tag } from "@/src/comps/Tag/Tag"; import { VoteInput } from "@/src/comps/VoteInput/VoteInput"; import content from "@/src/content"; +import { CHAIN_BLOCK_EXPLORER } from "@/src/env"; import { formatDate } from "@/src/formatting"; -import { useGovernanceState, useInitiatives, useInitiativeState, useUserStates } from "@/src/liquity-governance"; -import { useAccount } from "@/src/services/Ethereum"; +import { useGovernanceState, useInitiatives } from "@/src/liquity-governance"; import { useTransactionFlow } from "@/src/services/TransactionFlow"; import { css } from "@/styled-system/css"; -import { AnchorTextButton, Button, IconExternal, VFlex } from "@liquity2/uikit"; +import { AnchorTextButton, Button, IconExternal, shortenAddress, VFlex } from "@liquity2/uikit"; import * as dn from "dnum"; import { useState } from "react"; export function PanelVoting() { const txFlow = useTransactionFlow(); + const initiatives = useInitiatives(); const governanceState = useGovernanceState(); @@ -221,7 +222,7 @@ export function PanelVoting() { @@ -266,12 +267,20 @@ export function PanelVoting() { size="large" wide onClick={() => { + // Filter out allocations with no vote or zero value + const voteAllocationsFiltered = { ...voteAllocations }; + for (const [address, data] of Object.entries(voteAllocations) as Entries) { + if (data.vote === null || dn.eq(data.value, 0)) { + delete voteAllocationsFiltered[address]; + } + } + txFlow.start({ flowId: "allocateVotingPower", backLink: ["/stake/voting", "Back"], successLink: ["/", "Go to the Dashboard"], successMessage: "Your voting power has been allocated.", - voteAllocations, + voteAllocations: voteAllocationsFiltered, }); }} /> @@ -282,17 +291,15 @@ export function PanelVoting() { function InitiativeRow({ initiative, - voteAllocations, + voteAllocation, onVote, onVoteInputChange, }: { initiative: Initiative; - voteAllocations: VoteAllocations; + voteAllocation?: VoteAllocations[Address]; onVote: (initiative: Address, vote: Vote) => void; onVoteInputChange: (initiative: Address, value: Dnum) => void; }) { - const initiativeState = useInitiativeState(initiative.address); - console.log(initiativeState.data); return ( @@ -303,30 +310,37 @@ function InitiativeRow({ })} >
- {initiative.name} + {initiative.name ?? "Initiative"}
-
- {initiative.protocol} +
+
- +
+ +
@@ -357,8 +371,8 @@ function InitiativeRow({ })} > { onVoteInputChange(initiative.address, value); }}