Skip to content

Commit

Permalink
fix: 🐛 add voting check
Browse files Browse the repository at this point in the history
  • Loading branch information
chef-ryan committed Jan 6, 2025
1 parent 8878ca2 commit d908b6e
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions apps/web/src/views/Voting/CreateProposal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { spaceAtom } from '../atom/spaceAtom'
import Layout from '../components/Layout'
import VoteDetailsModal from '../components/VoteDetailsModal'
import { PANCAKE_SPACE, VOTE_THRESHOLD } from '../config'
import useGetVotingPower from '../hooks/useGetVotingPower'
import Choices, { MINIMUM_CHOICES, makeChoice } from './Choices'
import { combineDateAndTime, getFormErrors } from './helpers' // You can adapt or remove this
import { FormErrors, Label, SecondaryLabel } from './styles'
Expand Down Expand Up @@ -87,6 +88,10 @@ const CreateProposal = () => {
},
})

const { total, isLoading } = useGetVotingPower(watch('snapshot'))
console.log(total)
const enoughVotingPower = total >= VOTE_THRESHOLD

const {
fields: choiceFields,
replace: replaceChoices,
Expand Down Expand Up @@ -338,6 +343,13 @@ const CreateProposal = () => {
</Flex>
)}

<Flex alignItems="center" mb="8px">
<Text color="textSubtle" mr="16px">
{t('Voting Power')}
</Text>
<Text>{isLoading ? '-' : total ?? 0}</Text>
</Flex>

{/* Snapshot */}
<Flex alignItems="center" mb="16px">
<Text color="textSubtle" mr="16px">
Expand All @@ -353,17 +365,19 @@ const CreateProposal = () => {
<Button
type="submit"
width="100%"
disabled={isSubmitting}
disabled={isSubmitting || !enoughVotingPower || isLoading}
endIcon={isSubmitting ? <AutoRenewIcon spin color="currentColor" /> : null}
mb="16px"
>
{t('Publish')}
</Button>
<Text color="failure" as="p" mb="4px">
{t('You need at least %count% voting power to publish a proposal.', {
count: VOTE_THRESHOLD,
})}
</Text>
{!enoughVotingPower && (
<Text color="failure" as="p" mb="4px">
{t('You need at least %count% voting power to publish a proposal.', {
count: VOTE_THRESHOLD,
})}
</Text>
)}
<Button scale="sm" type="button" variant="text" onClick={onPresentVoteDetailsModal} p={0}>
{t('Check voting power')}
</Button>
Expand Down

0 comments on commit d908b6e

Please sign in to comment.