Skip to content

Commit 2748bd3

Browse files
committed
Add countdown
1 parent 75bb994 commit 2748bd3

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"noop-ts": "^1.0.3",
5656
"react": "^16.9.6",
5757
"react-copy-to-clipboard": "^5.0.2",
58+
"react-countdown": "^2.3.2",
5859
"react-dom": "npm:@hot-loader/react-dom@^17.0.1",
5960
"react-i18next": "^11.16.5",
6061
"react-markdown": "^4.3.1",

src/components/v2/VoteProposalUi/index.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,38 @@ export const Active = () => (
2121
votedAgainst="2130.02 XVS"
2222
abstain="100 XVS"
2323
voteStatus="votedFor"
24-
cancelDate="27 Jun 13:54"
24+
cancelDate={new Date(Date.now() + 3650000)}
2525
/>
2626
);
2727
export const Queued = () => (
2828
<VoteProposalUi
2929
proposalNumber={58}
3030
proposalText="Buy back and burn and Tokenomic contribution finised soon"
3131
proposalStatus="queued"
32+
cancelDate={new Date(Date.now() + 3650000)}
3233
/>
3334
);
3435
export const ReadyToExecute = () => (
3536
<VoteProposalUi
3637
proposalNumber={58}
3738
proposalText="Buy back and burn and Tokenomic contribution finised soon"
3839
proposalStatus="readyToExecute"
40+
cancelDate={new Date(Date.now() + 3650000)}
3941
/>
4042
);
4143
export const Executed = () => (
4244
<VoteProposalUi
4345
proposalNumber={58}
4446
proposalText="Buy back and burn and Tokenomic contribution finised soon"
4547
proposalStatus="executed"
48+
cancelDate={new Date(Date.now() + 3650000)}
4649
/>
4750
);
4851
export const Cancelled = () => (
4952
<VoteProposalUi
5053
proposalNumber={58}
5154
proposalText="Buy back and burn and Tokenomic contribution finised soon"
5255
proposalStatus="cancelled"
56+
cancelDate={new Date(Date.now())}
5357
/>
5458
);

src/components/v2/VoteProposalUi/index.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** @jsxImportSource @emotion/react */
22
import React, { useMemo } from 'react';
3+
import Countdown from 'react-countdown';
4+
import { CountdownRenderProps } from 'react-countdown/dist/Countdown';
35
import { SerializedStyles } from '@emotion/react';
46
import Paper from '@mui/material/Paper';
57
import Grid from '@mui/material/Grid';
@@ -87,7 +89,7 @@ interface IVoteProposalUiProps {
8789
proposalNumber: number;
8890
proposalText: string;
8991
proposalStatus: ProposalStatus;
90-
cancelDate?: string;
92+
cancelDate?: Date;
9193
voteStatus?: VoteStatus;
9294
votedFor?: string;
9395
votedAgainst?: string;
@@ -121,6 +123,30 @@ export const VoteProposalUi: React.FC<IVoteProposalUiProps> = ({
121123
}
122124
}, [voteStatus]);
123125

126+
const countdownRenderer = ({
127+
days,
128+
hours,
129+
minutes,
130+
seconds,
131+
completed,
132+
}: CountdownRenderProps) => {
133+
if (completed) {
134+
// Render a completed state
135+
return null;
136+
}
137+
// Render a countdown
138+
if (days) {
139+
return `${days}d ${hours}h : ${minutes}m : ${seconds}s`;
140+
}
141+
if (hours) {
142+
return `${hours}h : ${minutes}m : ${seconds}s`;
143+
}
144+
if (minutes) {
145+
return `${minutes}m : ${seconds}s`;
146+
}
147+
return `${seconds}s`;
148+
};
149+
124150
return (
125151
<Paper className={className} css={styles.root}>
126152
<Grid container>
@@ -157,13 +183,18 @@ export const VoteProposalUi: React.FC<IVoteProposalUiProps> = ({
157183
<Typography variant="small2">
158184
{t('voteProposalUi.activeUntil')}
159185
<Typography css={styles.activeUntilDate} variant="small2" color="textPrimary">
160-
{cancelDate}
186+
{cancelDate.toLocaleString('en-US', {
187+
month: 'long',
188+
day: 'numeric',
189+
hour: '2-digit',
190+
minute: '2-digit',
191+
})}
161192
</Typography>
162193
</Typography>
163194
)}
164195

165196
<Typography color="textPrimary" variant="small2">
166-
27h : 13m : 54s {/* // TODO: countdown calculating */}
197+
<Countdown date={cancelDate} renderer={countdownRenderer} />
167198
</Typography>
168199
</div>
169200
</Grid>

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18995,6 +18995,13 @@ react-copy-to-clipboard@^5.0.2:
1899518995
copy-to-clipboard "^3"
1899618996
prop-types "^15.5.8"
1899718997

18998+
react-countdown@^2.3.2:
18999+
version "2.3.2"
19000+
resolved "https://registry.yarnpkg.com/react-countdown/-/react-countdown-2.3.2.tgz#4cc27f28f2dcd47237ee66e4b9f6d2a21fc0b0ad"
19001+
integrity sha512-Q4SADotHtgOxNWhDdvgupmKVL0pMB9DvoFcxv5AzjsxVhzOVxnttMbAywgqeOdruwEAmnPhOhNv/awAgkwru2w==
19002+
dependencies:
19003+
prop-types "^15.7.2"
19004+
1899819005
react-dev-utils@^11.0.3:
1899919006
version "11.0.4"
1900019007
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-11.0.4.tgz#a7ccb60257a1ca2e0efe7a83e38e6700d17aa37a"

0 commit comments

Comments
 (0)