Skip to content

Commit

Permalink
fixup! feat(voting): fix QA findings
Browse files Browse the repository at this point in the history
  • Loading branch information
phonktown committed Sep 12, 2024
1 parent 1cc467f commit d07f8db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useEffect } from 'react'
import { Text, Checkbox, trimAddress } from '@lidofinance/lido-ui'
import React, { useMemo, useEffect, useCallback } from 'react'
import { Text, Checkbox, trimAddress, ToastInfo } from '@lidofinance/lido-ui'
import {
AccordionWrap,
DelegatorsListItem,
Expand Down Expand Up @@ -40,10 +40,15 @@ export function DelegatorsList({
eventsVoted,
defaultExpanded,
}: Props) {
const TRANSACTION_LIMIT = 5

const initialCheckedItems = Object.fromEntries(
eligibleDelegatedVoters
.filter(delegator => !delegator.votedByDelegate)
.map(delegator => [delegator.address, true]),
.map((delegator, index) => [
delegator.address,
index < TRANSACTION_LIMIT,
]),
)

const [checkedItems, dispatch] = useSimpleReducer(initialCheckedItems)
Expand Down Expand Up @@ -76,6 +81,23 @@ export function DelegatorsList({
[selectedAddresses, eligibleDelegatedVoters],
)

const handleCheckboxChange = useCallback(
(address: string, isChecked: boolean) => {
const currentCheckedCount = selectedAddresses.length

if (isChecked && currentCheckedCount >= TRANSACTION_LIMIT) {
ToastInfo('Transaction limit reached. Vote with the rest next.', {})
return
}

dispatch({
...checkedItems,
[address]: isChecked,
})
},
[selectedAddresses, checkedItems, dispatch],
)

function Summary() {
return (
<SummaryWrap>
Expand Down Expand Up @@ -105,10 +127,7 @@ export function DelegatorsList({
<Checkbox
checked={checkedItems[delegator.address]}
onChange={e =>
dispatch({
...checkedItems,
[delegator.address]: e.target.checked,
})
handleCheckboxChange(delegator.address, e.target.checked)
}
/>
<AddressPop address={delegator.address}>
Expand Down
1 change: 1 addition & 0 deletions modules/votes/ui/VoteFormActions/VoteFormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export function VoteFormActions({
<TxRow tx={txVote} onClick={txVote.open} />
</>
)}
<br />
{!txDelegatesVote.isEmpty && (
<>
<TxRow tx={txDelegatesVote} onClick={txDelegatesVote.open} />
Expand Down

0 comments on commit d07f8db

Please sign in to comment.