Skip to content

Commit

Permalink
fix(voting): adjust voting UI
Browse files Browse the repository at this point in the history
  • Loading branch information
phonktown committed Oct 1, 2024
1 parent 9a1ea16 commit c053b1d
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 110 deletions.
24 changes: 17 additions & 7 deletions modules/dashboard/ui/DashboardVote/DashboardVote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useCallback } from 'react'
import { useVotePassedCallback } from 'modules/votes/hooks/useVotePassedCallback'

import Link from 'next/link'
import { Text } from '@lidofinance/lido-ui'
import { VoteStatusBanner } from 'modules/votes/ui/VoteStatusBanner'
import { VoteYesNoBar } from 'modules/votes/ui/VoteYesNoBar'
import { InfoRowFull } from 'modules/shared/ui/Common/InfoRow'
import { VoteDescription } from 'modules/votes/ui/VoteDescription'

import {
Expand All @@ -14,9 +14,10 @@ import {
VoteDescriptionWrap,
VotesBarWrap,
Footer,
NeededToQuorum,
} from './DashboardVoteStyle'
import type { StartVoteEventObject } from 'generated/AragonVotingAbi'
import { Vote, VoteStatus } from 'modules/votes/types'
import { Vote, VotePhase, VoteStatus } from 'modules/votes/types'
import { weiToNum } from 'modules/blockChain/utils/parseWei'
import { getVoteDetailsFormatted } from 'modules/votes/utils/getVoteDetailsFormatted'
import { formatFloatPct } from 'modules/shared/utils/formatFloatPct'
Expand Down Expand Up @@ -106,15 +107,24 @@ export function DashboardVote({
</VoteBody>
<Footer>
<VotesBarWrap>
<InfoRowFull title="Needed to quorum">
{neededToQuorum > 0 && !isEnded
? `${neededToQuorumFormatted}%`
: '-'}
</InfoRowFull>
{vote.phase !== VotePhase.Closed && (
<NeededToQuorum>
<Text size="xxs" color="secondary">
Needed to quorum
</Text>
<Text size="xxs">
{neededToQuorum > 0 && !isEnded
? `${neededToQuorumFormatted}%`
: '-'}
</Text>
</NeededToQuorum>
)}

<VoteYesNoBar
yeaPct={yeaPct}
nayPct={nayPct}
yeaNum={yeaNum}
nayNum={nayNum}
yeaPctOfTotalSupply={yeaPctOfTotalSupplyFormatted}
nayPctOfTotalSupply={nayPctOfTotalSupplyFormatted}
showOnForeground
Expand Down
5 changes: 5 additions & 0 deletions modules/dashboard/ui/DashboardVote/DashboardVoteStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ export const Footer = styled.div`
margin-top: auto;
margin-bottom: 0;
`

export const NeededToQuorum = styled.div`
display: flex;
justify-content: space-between;
`
11 changes: 8 additions & 3 deletions modules/shared/ui/Common/AddressPop/AddressPop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ export function AddressPop({ children, ...badgeProps }: Props) {
position: undefined,
})

const handleOpen = useCallback(() => {
setState({ isOpened: true })
}, [setState])
const handleOpen = useCallback(
(event: React.MouseEvent) => {
// To avoid opening a vote when clicking on the pop from the dashboard
event.preventDefault()
setState({ isOpened: true })
},
[setState],
)

useEffect(() => {
const wrapEl = wrapRef.current
Expand Down
21 changes: 17 additions & 4 deletions modules/shared/ui/Common/AddressPop/calcPopoverPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ export function calcPopoverPosition(wrapEl: HTMLElement, popEl: HTMLElement) {
const wrapBox = wrapEl.getBoundingClientRect()
const popBox = popEl.getBoundingClientRect()

const left = wrapBox.left + wrapBox.width / 2 - popBox.width / 2
const top = wrapBox.top + wrapBox.height / 2 - popBox.height / 2
let offsetParent = wrapEl.offsetParent as HTMLElement | null
let offsetX = 0
let offsetY = 0

while (offsetParent) {
offsetX += offsetParent.offsetLeft - offsetParent.scrollLeft
offsetY += offsetParent.offsetTop - offsetParent.scrollTop
offsetParent = offsetParent.offsetParent as HTMLElement | null
}

const left = wrapBox.left + wrapBox.width / 2 - popBox.width / 2 - offsetX
const top = wrapBox.top + wrapBox.height / 2 - popBox.height / 2 - offsetY

const modalWidth = wrapEl.offsetParent?.clientWidth ?? window.innerWidth
const modalHeight = wrapEl.offsetParent?.clientHeight ?? window.innerHeight

return {
left: minmax(10, left, window.innerWidth - popBox.width - 10),
top: minmax(10, top, window.innerHeight - popBox.height - 10),
left: minmax(10, left, modalWidth - popBox.width - 10),
top: minmax(10, top, modalHeight - popBox.height - 10),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from 'modules/delegation/hooks/useEligibleDelegators'
import { useFormVoteSubmit } from 'modules/votes/ui/VoteForm/useFormVoteSubmit'
import { useFormVoteInfo } from 'modules/votes/ui/VoteForm/useFormVoteInfo'
import { formatBalance } from 'modules/blockChain/utils/formatBalance'
import { useGovernanceSymbol } from 'modules/tokens/hooks/useGovernanceSymbol'

import { ResultTx } from 'modules/blockChain/types'
Expand Down Expand Up @@ -41,7 +40,7 @@ export type VoteFormActionsContextValue = {
setSuccessTx: React.Dispatch<React.SetStateAction<ResultTx | null>>
formVoteSubmitData: ReturnType<typeof useFormVoteSubmit>
setVoteId: React.Dispatch<React.SetStateAction<string>>
ownVotePower: Number
votePower: Number | undefined
handleVote: (mode: VoteMode | null) => Promise<void>
handleDelegatesVote: (
mode: VoteMode | null,
Expand Down Expand Up @@ -99,6 +98,7 @@ export const VoteFormActionsProvider: React.FC = ({ children }) => {
eventsDelegatesVoted,
voterState,
votePhase,
votePower,
mutate: doRevalidate,
} = formVoteInfoData

Expand Down Expand Up @@ -152,8 +152,6 @@ export const VoteFormActionsProvider: React.FC = ({ children }) => {
)
}, [delegatedVotersAddresses, eventsVoted, eventsDelegatesVoted])

const ownVotePower = Number(formatBalance(formVoteInfoData.votePowerWei || 0))

const eligibleDelegatedVoters = useMemo(
() => eligibleDelegatorsData.eligibleDelegatedVoters,
[eligibleDelegatorsData],
Expand All @@ -173,7 +171,7 @@ export const VoteFormActionsProvider: React.FC = ({ children }) => {
formVoteInfoData,
successTx,
setSuccessTx,
ownVotePower,
votePower,
handleVote,
handleDelegatesVote,
votedAs,
Expand Down Expand Up @@ -203,7 +201,7 @@ export const VoteFormActionsProvider: React.FC = ({ children }) => {
formVoteInfoData,
successTx,
setSuccessTx,
ownVotePower,
votePower,
handleVote,
handleDelegatesVote,
votedAs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function DelegatorsList({
</Text>
</SummaryAmount>
<Text size="xxs">
from {pluralize(eligibleDelegatedVoters.length, 'delegate')}
from {pluralize(eligibleDelegatedVoters.length, 'delegator')}
</Text>
</SummaryWrap>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Accordion, Text } from '@lidofinance/lido-ui'
export const SummaryWrap = styled.div`
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
`

Expand Down Expand Up @@ -37,7 +38,7 @@ export const DelegatorsListItem = styled.div`
`

export const DelegatorsVotingPower = styled(Text).attrs({ size: 'xs' })`
min-width: 100px;
min-width: 82px;
text-align: right;
`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export function VoteSubmitModal({ data: { mode }, ...modalProps }: ModalProps) {

const canVoteWithDelegatedPower = eligibleDelegatedVoters.length > 0

const title = `Vote ${
mode === 'yay' ? '“Yes”' : '“No”'
} with Delegated ${governanceSymbol}`
const title = `Vote ${mode === 'yay' ? '“Yes”' : '“No”'} with Delegated VP`

return (
<Modal title={title} center {...modalProps}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface SnapshotData {
eligibleDelegatedVotingPower: BigNumber
votePhase: VotePhase | undefined
votedByDelegate: EligibleDelegator[]
ownVotePower: Number
votePower: Number | undefined
delegationInfo: Record<string, string | null> | undefined
delegatedVotersAddresses: string[]
eligibleDelegatedVoters: EligibleDelegator[]
Expand All @@ -70,7 +70,7 @@ export function VoteSuccessModal({
votedByDelegate,
handleVote,
handleDelegatesVote,
ownVotePower,
votePower,
voterState,
delegationInfo,
votePhase,
Expand All @@ -93,7 +93,7 @@ export function VoteSuccessModal({
eligibleDelegatedVotingPower,
votePhase,
votedByDelegate,
ownVotePower,
votePower,
delegationInfo,
delegatedVotersAddresses,
eligibleDelegatedVoters,
Expand All @@ -104,7 +104,7 @@ export function VoteSuccessModal({
eligibleDelegatedVotingPower,
votePhase,
votedByDelegate,
ownVotePower,
votePower,
delegationInfo,
delegatedVotersAddresses,
eligibleDelegatedVoters,
Expand Down Expand Up @@ -182,7 +182,9 @@ export function VoteSuccessModal({
0

const canVoteWithOwnPower =
currentSnapshot.ownVotePower > 0 && !hasVotedWithOwnVP
currentSnapshot.votePower !== undefined &&
currentSnapshot.votePower > 0 &&
!hasVotedWithOwnVP

const handleEtherscan = useEtherscanOpen(
successTx.hash,
Expand All @@ -199,7 +201,7 @@ export function VoteSuccessModal({
)

const voteOption = useMemo(() => {
return currentSnapshot.mode === 'yay' ? '"Yes"' : '"No"'
return currentSnapshot.mode === 'yay' ? 'Yes' : '“No”'
}, [currentSnapshot.mode])

const title = useRef(
Expand Down Expand Up @@ -287,7 +289,7 @@ export function VoteSuccessModal({
loading={txVote.isPending}
disabled={!txVote.isEmpty && txVote.tx?.type === 'safe'}
>
My own ({currentSnapshot.ownVotePower} {governanceSymbol})
My own ({currentSnapshot.votePower} {governanceSymbol})
</Button>
)}
{!txVote.isEmpty && canVoteWithOwnPower && (
Expand Down
2 changes: 2 additions & 0 deletions modules/votes/ui/VoteDetails/VoteDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export function VoteDetails({
<VoteYesNoBar
yeaPct={yeaPct}
nayPct={nayPct}
yeaNum={yeaNum}
nayNum={nayNum}
yeaPctOfTotalSupply={yeaPctOfTotalSupplyFormatted}
nayPctOfTotalSupply={nayPctOfTotalSupplyFormatted}
showOnForeground
Expand Down
1 change: 1 addition & 0 deletions modules/votes/ui/VoteDetails/VoteDetailsStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const VoteHeader = styled.div`
display: flex;
align-items: center;
justify-content: flex-start;
flex-wrap: wrap;
gap: 8px;
margin-bottom: ${({ theme }) => theme.spaceMap.sm}px;
`
Expand Down
8 changes: 6 additions & 2 deletions modules/votes/ui/VoteForm/VoteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FetchErrorBanner } from 'modules/shared/ui/Common/FetchErrorBanner'
import { VoteInfoDelegated } from 'modules/votes/ui/VoteInfoDelegated'
import { VotePowerInfo } from '../VotePowerInfo'

import { VoteStatus } from 'modules/votes/types'
import { VotePhase, VoteStatus } from 'modules/votes/types'

type Props = {
voteId?: string
Expand All @@ -27,6 +27,7 @@ export function VoteForm({ voteId }: Props) {
startDate,
voteTime,
votePowerWei,
votePower,
canExecute,
objectionPhaseTime,
isLoading,
Expand Down Expand Up @@ -131,14 +132,17 @@ export function VoteForm({ voteId }: Props) {
eventsDelegatesVoted={eventsDelegatesVoted}
walletAddress={walletAddress}
/>
<VotePowerInfo ownVotePower={votePowerWei} />
{votePhase !== VotePhase.Closed && (
<VotePowerInfo votePowerWei={votePowerWei} />
)}
<VoteFormActions
canEnact={canEnact}
voterState={voterState!}
isSubmitting={isSubmitting}
onEnact={handleEnact}
votePhase={votePhase}
votePowerWei={votePowerWei}
votePower={votePower}
voteId={voteId}
/>
</>
Expand Down
28 changes: 18 additions & 10 deletions modules/votes/ui/VoteFormActions/VoteFormActions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, PopupMenu, PopupMenuItem } from '@lidofinance/lido-ui'
import { Actions } from './VoteFormActionsStyle'
import { Button, PopupMenu, PopupMenuItem, Text } from '@lidofinance/lido-ui'
import { Actions, TxStatusWrapper } from './VoteFormActionsStyle'
import CheckSVG from 'assets/check.com.svg.react'
import CrossSVG from 'assets/cross.com.svg.react'

Expand Down Expand Up @@ -28,6 +28,7 @@ type Props = {
onEnact: () => void
voteId: string
votePowerWei: BigNumber | null | undefined
votePower: Number | undefined
}

type ModalData = {
Expand All @@ -46,6 +47,7 @@ export function VoteFormActions({
onEnact,
voteId,
votePowerWei,
votePower,
}: Props) {
const {
data: { eligibleDelegatedVoters, eligibleDelegatedVotingPower },
Expand All @@ -56,7 +58,6 @@ export function VoteFormActions({
handleDelegatesVote,
txVote,
txDelegatesVote,
ownVotePower,
setVoteId: setVoteFormActionsModalsVoteId,
isSubmitting: isVoteSubmitting,
eventsVoted,
Expand Down Expand Up @@ -103,14 +104,15 @@ export function VoteFormActions({
const nayButtonRef = useRef(null)
const yayButtonRef = useRef(null)

const canVoteWithOwnPower = ownVotePower > 0
const canVoteWithOwnPower = votePower !== undefined && votePower > 0
const canVoteWithDelegatedPower = eligibleDelegatedVoters.length > 0

const canVote = useMemo(
() =>
isValidPhaseToVote &&
(eligibleDelegatedVoters.length > 0 || Number(ownVotePower) > 0),
[isValidPhaseToVote, ownVotePower, eligibleDelegatedVoters],
(eligibleDelegatedVoters.length > 0 ||
(votePower !== undefined && votePower > 0)),
[isValidPhaseToVote, votePower, eligibleDelegatedVoters],
)

const preparedOwnVP = useMemo(
Expand Down Expand Up @@ -313,15 +315,21 @@ export function VoteFormActions({
)}
</Actions>
{!txVote.isEmpty && (
<>
<TxStatusWrapper>
<Text size="xxs" color="secondary">
Transaction using own VP
</Text>
<TxRow tx={txVote} onClick={txVote.open} />
</>
</TxStatusWrapper>
)}
<br />
{!txDelegatesVote.isEmpty && (
<>
<TxStatusWrapper>
<Text size="xxs" color="secondary">
Transaction using delegated VP
</Text>
<TxRow tx={txDelegatesVote} onClick={txDelegatesVote.open} />
</>
</TxStatusWrapper>
)}
</>
)
Expand Down
Loading

0 comments on commit c053b1d

Please sign in to comment.