Commit 60bd0eb8 authored by Noah Zinsmeister's avatar Noah Zinsmeister Committed by GitHub

add proposal start time (#2738)

parent 188b321c
...@@ -122,6 +122,21 @@ const ProposerAddressLink = styled(ExternalLink)` ...@@ -122,6 +122,21 @@ const ProposerAddressLink = styled(ExternalLink)`
word-break: break-all; word-break: break-all;
` `
function getDateFromBlock(
targetBlock: number | undefined,
currentBlock: number | undefined,
averageBlockTimeInSeconds: number | undefined,
currentTimestamp: BigNumber | undefined
): DateTime | undefined {
return targetBlock && currentBlock && averageBlockTimeInSeconds && currentTimestamp
? DateTime.fromSeconds(
currentTimestamp
.add(BigNumber.from(averageBlockTimeInSeconds).mul(BigNumber.from(targetBlock - currentBlock)))
.toNumber()
)
: undefined
}
export default function VotePage({ export default function VotePage({
match: { match: {
params: { governorIndex, id }, params: { governorIndex, id },
...@@ -146,18 +161,18 @@ export default function VotePage({ ...@@ -146,18 +161,18 @@ export default function VotePage({
// get and format date from data // get and format date from data
const currentTimestamp = useCurrentBlockTimestamp() const currentTimestamp = useCurrentBlockTimestamp()
const currentBlock = useBlockNumber() const currentBlock = useBlockNumber()
const endDate: DateTime | undefined = const startDate: DateTime | undefined = getDateFromBlock(
proposalData && currentTimestamp && currentBlock proposalData?.startBlock,
? DateTime.fromSeconds( currentBlock,
currentTimestamp (chainId && AVERAGE_BLOCK_TIME_IN_SECS[chainId]) ?? DEFAULT_AVERAGE_BLOCK_TIME_IN_SECS,
.add( currentTimestamp
BigNumber.from( )
(chainId && AVERAGE_BLOCK_TIME_IN_SECS[chainId]) ?? DEFAULT_AVERAGE_BLOCK_TIME_IN_SECS const endDate: DateTime | undefined = getDateFromBlock(
).mul(BigNumber.from(proposalData.endBlock - currentBlock)) proposalData?.endBlock,
) currentBlock,
.toNumber() (chainId && AVERAGE_BLOCK_TIME_IN_SECS[chainId]) ?? DEFAULT_AVERAGE_BLOCK_TIME_IN_SECS,
) currentTimestamp
: undefined )
const now: DateTime = DateTime.local() const now: DateTime = DateTime.local()
// get total votes and format percentages for UI // get total votes and format percentages for UI
...@@ -223,14 +238,21 @@ export default function VotePage({ ...@@ -223,14 +238,21 @@ export default function VotePage({
</RowBetween> </RowBetween>
<AutoColumn gap="10px" style={{ width: '100%' }}> <AutoColumn gap="10px" style={{ width: '100%' }}>
<TYPE.largeHeader style={{ marginBottom: '.5rem' }}>{proposalData?.title}</TYPE.largeHeader> <TYPE.largeHeader style={{ marginBottom: '.5rem' }}>{proposalData?.title}</TYPE.largeHeader>
<RowBetween>
<TYPE.main>
{startDate && startDate > now ? (
<Trans>
Voting starts approximately {startDate && startDate.toLocaleString(DateTime.DATETIME_FULL)}
</Trans>
) : null}
</TYPE.main>
</RowBetween>
<RowBetween> <RowBetween>
<TYPE.main> <TYPE.main>
{endDate && endDate < now ? ( {endDate && endDate < now ? (
<Trans>Voting ended {endDate && endDate.toLocaleString(DateTime.DATETIME_FULL)}</Trans> <Trans>Voting ended {endDate && endDate.toLocaleString(DateTime.DATETIME_FULL)}</Trans>
) : proposalData ? (
<Trans>Voting ends approximately {endDate && endDate.toLocaleString(DateTime.DATETIME_FULL)}</Trans>
) : ( ) : (
'' <Trans>Voting ends approximately {endDate && endDate.toLocaleString(DateTime.DATETIME_FULL)}</Trans>
)} )}
</TYPE.main> </TYPE.main>
</RowBetween> </RowBetween>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment