-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an election progress bar #4556
Changes from 2 commits
e6c06c7
f0cc488
81c88fa
fa50471
41b25e2
7e6479d
b124583
e621846
c2e7141
9491b1d
69dc2ff
12b92d8
1a33802
e5e8deb
5334ef5
149de4e
6a5b320
e676fda
3419650
979f7bb
fe313c6
e3e5d5e
16280e3
801c62d
ceb2944
51aa613
97919db
562e39f
47da2dd
a4147fa
e0dd9fa
9465db9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -27,11 +27,12 @@ interface ElectionProgressBarProps extends StatisticItemProps { | |||||||
electionStage: string | ||||||||
} | ||||||||
|
||||||||
const GENESIS_BLOCK_TIMESTAMP = 1670693046000 | ||||||||
|
||||||||
const blockDurationToMs = (blockDuration: number) => blockDuration * MILLISECONDS_PER_BLOCK | ||||||||
const blockToDate = (duration: number) => { | ||||||||
const now = Date.now() | ||||||||
const msDuration = blockDurationToMs(duration) | ||||||||
return new Date(now + msDuration).toLocaleString('en-gb', { timeZone: 'Europe/Paris' }) | ||||||||
const blockToDate = (block: number) => { | ||||||||
const msDuration = blockDurationToMs(block) | ||||||||
return new Date(GENESIS_BLOCK_TIMESTAMP + msDuration).toLocaleString('en-gb', { timeZone: 'Europe/Paris' }) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally here's how to remove the seconds:
Suggested change
It's closer to the original design and it's a lot better since the time estimation can't be accurate to the second. |
||||||||
} | ||||||||
const blockDurationToDays = (blockDuration: number) => Math.floor(blockDurationToMs(blockDuration) / A_DAY) | ||||||||
|
||||||||
|
@@ -81,8 +82,9 @@ export const ElectionProgressBar = (props: ElectionProgressBarProps) => { | |||||||
const constants = useCouncilConstants() | ||||||||
|
||||||||
const [inactiveEndBlock, announcingEndBlock, votingEndBlock, revealingEndBlock] = periodInformation?.periodEnds ?? [] | ||||||||
const endDates = periodInformation?.periodEnds.map((block) => blockToDate(block - currentBlock)) | ||||||||
const endDates = periodInformation?.periodEnds.map((block) => blockToDate(block)) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead I think this is good enough:
Suggested change
When the page is reloaded the time won't be exactly the same but it will actually be more accurate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tried to use props.electionStage, at that time sometimes the endDate is calculated as undefined, so I changed it to periodInformation.currentStage. |
||||||||
const [inactiveEndDay, announcingEndDay, votingEndDay, revealingEndDay] = endDates ?? [] | ||||||||
|
||||||||
const progresses = periodInformation?.periodEnds.map((end, index) => { | ||||||||
const start = periodInformation.periodStarts[index] | ||||||||
return clamp(((currentBlock - start) * 100) / (end - start), 0, 100) | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to be able to convert block/dates without fetching anything from the network, but Pioneer should avoid hardcoding these kind of data because it should potentially work on other networks too. Also basing the future block date based on a date which is that old is that old makes it less accurate.