Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 76c6043

Browse files
authored
Fix Treasury proposal countdown text and display Active timestamp (#383)
1 parent 9ee69f1 commit 76c6043

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

ts/pages/governance/countdown.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import * as React from 'react';
55
import { Paragraph } from 'ts/components/text';
66

77
interface Props {
8-
deadline: moment.Moment;
8+
startDate: moment.Moment;
9+
endDate: moment.Moment;
910
}
1011

1112
interface TimeStructure {
@@ -21,13 +22,23 @@ interface TimeStructure {
2122

2223
const now = moment();
2324

24-
export const Countdown: React.StatelessComponent<Props> = ({ deadline }) => {
25+
export const Countdown: React.StatelessComponent<Props> = ({ startDate, endDate }) => {
2526
const pstOffset = '-0800';
26-
const time = deadline.utcOffset(pstOffset);
27-
const isPassed = time.isBefore(now);
28-
const voteTextPrefix = isPassed ? `Voting ended: ` : `Vote ends: `;
29-
const timeText = !isPassed ? ` • ${getRelativeTime(time)}` : '';
30-
const voteText = `${voteTextPrefix} ${time.format('L LT')} PST ${timeText}`;
27+
const startTime = startDate.utcOffset(pstOffset);
28+
const endTime = endDate.utcOffset(pstOffset);
29+
const isUpcoming = now.isBefore(startTime);
30+
const isOver = endTime.isBefore(now);
31+
let voteTextPrefix;
32+
if (isUpcoming) {
33+
voteTextPrefix = 'Voting starts: ';
34+
} else if (isOver) {
35+
voteTextPrefix = 'Voting ended: ';
36+
} else {
37+
voteTextPrefix = 'Voting ends: ';
38+
}
39+
const timeToDisplay = isUpcoming ? startTime : endTime;
40+
const timeText = ` • ${getRelativeTime(timeToDisplay)}`;
41+
const voteText = `${voteTextPrefix} ${timeToDisplay.format('L LT')} PST ${timeText}`;
3142

3243
// TODO convert to container component
3344
return (
@@ -39,8 +50,8 @@ export const Countdown: React.StatelessComponent<Props> = ({ deadline }) => {
3950
);
4051
};
4152

42-
function getRelativeTime(deadline: moment.Moment): string {
43-
const diff = moment().diff(deadline);
53+
function getRelativeTime(time: moment.Moment): string {
54+
const diff = moment().diff(time);
4455
const duration = moment.duration(diff);
4556

4657
return millisToDaysHoursMinutes(duration.asMilliseconds());

ts/pages/governance/governance.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ export class Governance extends React.Component<RouteComponentProps<any>> {
107107
<DocumentTitle {...documentConstants.VOTE} />
108108
<Section maxWidth="1170px" isFlex={true}>
109109
<Column width="55%" maxWidth="560px">
110-
<Countdown deadline={this._proposalData.voteEndDate} />
110+
<Countdown
111+
startDate={this._proposalData.voteStartDate}
112+
endDate={this._proposalData.voteEndDate}
113+
/>
111114
<Heading size="medium">{this._proposalData.title}</Heading>
112115
{_.map(this._proposalData.summary, (link, index) => (
113116
<Paragraph key={`summarytext-${index}`}>{this._proposalData.summary[index]}</Paragraph>

ts/pages/governance/treasury.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ export const Treasury: React.FC<{}> = () => {
173173
}
174174

175175
const {
176-
timestamp,
177176
happening: isHappening,
178177
description,
179178
id,
@@ -184,8 +183,6 @@ export const Treasury: React.FC<{}> = () => {
184183
executionEpochEndDate,
185184
} = proposal;
186185

187-
const pstOffset = '-0800';
188-
const deadlineToVote = moment(timestamp)?.utcOffset(pstOffset);
189186
const isVoteActive = isHappening;
190187

191188
const tokens = marked.lexer(description);
@@ -238,7 +235,7 @@ export const Treasury: React.FC<{}> = () => {
238235
<DocumentTitle {...documentConstants.VOTE} />
239236
<Section maxWidth="1170px" isFlex={true}>
240237
<Column width="55%" maxWidth="560px">
241-
<Countdown deadline={deadlineToVote} />
238+
<Countdown startDate={proposal.startDate} endDate={proposal.endDate} />
242239
<Tag>Treasury</Tag>
243240
<Heading size="medium" marginBottom="0px">
244241
{(heading as Tokens.Heading).text}
@@ -314,7 +311,7 @@ export const Treasury: React.FC<{}> = () => {
314311
fontSize="17px"
315312
fontWeight={300}
316313
>
317-
{historyState.done
314+
{historyState.done || state === 'active'
318315
? historyState.timestamp.format('MMMM Do, YYYY - hh:mm a')
319316
: 'TBD'}
320317
</Text>

0 commit comments

Comments
 (0)