@@ -9,19 +9,20 @@ import { CardSection, DataCard } from '../../components/earn/styled'
99import { ArrowLeft } from 'react-feather'
1010import { ButtonPrimary } from '../../components/Button'
1111import { ProposalStatus } from './styled'
12- import { useProposalData , useUserVotes , useUserDelegatee , ProposalData } from '../../state/governance/hooks'
12+ import { useProposalData , useUserVotesAsOfBlock , ProposalData , useUserDelegatee } from '../../state/governance/hooks'
1313import { useTimestampFromBlock } from '../../hooks/useTimestampFromBlock'
1414import { DateTime } from 'luxon'
1515import ReactMarkdown from 'react-markdown'
1616import VoteModal from '../../components/vote/VoteModal'
1717import { TokenAmount , JSBI } from '@uniswap/sdk'
18- import { useTokenBalance } from '../../state/wallet/hooks'
1918import { useActiveWeb3React } from '../../hooks'
20- import { UNI , ZERO_ADDRESS , PROPOSAL_LENGTH_IN_DAYS , COMMON_CONTRACT_NAMES } from '../../constants'
19+ import { PROPOSAL_LENGTH_IN_DAYS , COMMON_CONTRACT_NAMES , UNI , ZERO_ADDRESS } from '../../constants'
2120import { isAddress , getEtherscanLink } from '../../utils'
2221import { ApplicationModal } from '../../state/application/actions'
2322import { useModalOpen , useToggleDelegateModal , useToggleVoteModal } from '../../state/application/hooks'
2423import DelegateModal from '../../components/vote/DelegateModal'
24+ import { GreyCard } from '../../components/Card'
25+ import { useTokenBalance } from '../../state/wallet/hooks'
2526
2627const PageWrapper = styled ( AutoColumn ) `
2728 width: 100%;
@@ -102,7 +103,7 @@ export default function VotePage({
102103 params : { id }
103104 }
104105} : RouteComponentProps < { id : string } > ) {
105- const { account , chainId } = useActiveWeb3React ( )
106+ const { chainId , account } = useActiveWeb3React ( )
106107
107108 // get data for this specific proposal
108109 const proposalData : ProposalData | undefined = useProposalData ( id )
@@ -132,11 +133,21 @@ export default function VotePage({
132133 const againstPercentage : string =
133134 proposalData && totalVotes ? ( ( proposalData . againstCount * 100 ) / totalVotes ) . toFixed ( 0 ) + '%' : '0%'
134135
135- // show delegation option if they have have a balance, have not delegated
136- const availableVotes : TokenAmount | undefined = useUserVotes ( )
136+ // only count available votes as of the proposal start block
137+ const availableVotes : TokenAmount | undefined = useUserVotesAsOfBlock ( proposalData ?. startBlock ?? undefined )
138+
139+ // only show voting if user has > 0 votes at proposal start block and proposal is active,
140+ const showVotingButtons =
141+ availableVotes &&
142+ JSBI . greaterThan ( availableVotes . raw , JSBI . BigInt ( 0 ) ) &&
143+ proposalData &&
144+ proposalData . status === 'active'
145+
137146 const uniBalance : TokenAmount | undefined = useTokenBalance ( account ?? undefined , chainId ? UNI [ chainId ] : undefined )
138147 const userDelegatee : string | undefined = useUserDelegatee ( )
139- const showUnlockVoting = Boolean (
148+
149+ // in blurb link to home page if they are able to unlock
150+ const showLinkForUnlock = Boolean (
140151 uniBalance && JSBI . notEqual ( uniBalance . raw , JSBI . BigInt ( 0 ) ) && userDelegatee === ZERO_ADDRESS
141152 )
142153
@@ -171,23 +182,22 @@ export default function VotePage({
171182 ? 'Voting ends approximately ' + ( endDate && endDate . toLocaleString ( DateTime . DATETIME_FULL ) )
172183 : '' }
173184 </ TYPE . main >
174- { showUnlockVoting && endDate && endDate > now && (
175- < ButtonPrimary
176- style = { { width : 'fit-content' } }
177- padding = "8px"
178- borderRadius = "8px"
179- onClick = { toggelDelegateModal }
180- >
181- Unlock Voting
182- </ ButtonPrimary >
183- ) }
184185 </ RowBetween >
186+ { proposalData && proposalData . status === 'active' && ! showVotingButtons && (
187+ < GreyCard >
188+ < TYPE . black >
189+ Only UNI votes that were self delegated or delegated to another address before block{ ' ' }
190+ { proposalData . startBlock } are eligible for voting.{ ' ' }
191+ { showLinkForUnlock && (
192+ < span >
193+ < StyledInternalLink to = "/vote" > Unlock voting</ StyledInternalLink > to prepare for the next proposal.
194+ </ span >
195+ ) }
196+ </ TYPE . black >
197+ </ GreyCard >
198+ ) }
185199 </ AutoColumn >
186- { ! showUnlockVoting &&
187- availableVotes &&
188- JSBI . greaterThan ( availableVotes ?. raw , JSBI . BigInt ( 0 ) ) &&
189- endDate &&
190- endDate > now ? (
200+ { showVotingButtons ? (
191201 < RowFixed style = { { width : '100%' , gap : '12px' } } >
192202 < ButtonPrimary
193203 padding = "8px"
0 commit comments