1
- import React , { useState , useEffect } from 'react' ;
1
+ import React , { useState , useEffect } from 'react'
2
+
3
+ interface TimeLeft {
4
+ days ?: string
5
+ hours ?: string
6
+ minutes ?: string
7
+ seconds ?: string
8
+ }
2
9
3
10
const Countdown : React . FC = ( ) => {
4
- const calculateTimeLeft = ( ) => {
5
- const targetDate = new Date ( new Date ( ) . getFullYear ( ) , 5 , 1 ) ; // June 1st
6
- const now = new Date ( ) ;
7
- const difference = targetDate . getTime ( ) - now . getTime ( ) ;
8
-
9
- let timeLeft : { days ?: string ; hours ?: string ; minutes ?: string ; seconds ?: string } = { } ;
10
-
11
- if ( difference > 0 ) {
12
- timeLeft = {
13
- days : Math . floor ( difference / ( 1000 * 60 * 60 * 24 ) ) . toString ( ) . padStart ( 2 , '0' ) ,
14
- hours : Math . floor ( ( difference % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) )
15
- . toString ( )
16
- . padStart ( 2 , '0' ) ,
17
- minutes : Math . floor ( ( difference % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) )
18
- . toString ( )
19
- . padStart ( 2 , '0' ) ,
20
- seconds : Math . floor ( ( difference % ( 1000 * 60 ) ) / 1000 )
21
- . toString ( )
22
- . padStart ( 2 , '0' ) ,
23
- } ;
24
- }
25
-
26
- return timeLeft ;
27
- } ;
11
+ const calculateTimeLeft = ( ) : TimeLeft => {
12
+ const targetDate = new Date ( new Date ( ) . getFullYear ( ) , 5 , 1 ) // June 1st
13
+ const now = new Date ( )
14
+ const difference = targetDate . getTime ( ) - now . getTime ( )
28
15
29
- const [ timeLeft , setTimeLeft ] = useState ( calculateTimeLeft ( ) ) ;
30
- const [ isMounted , setIsMounted ] = useState ( false ) ;
16
+ let timeLeft : TimeLeft = { }
31
17
32
- useEffect ( ( ) => {
33
- setIsMounted ( true ) ;
34
- const timer = setInterval ( ( ) => {
35
- setTimeLeft ( calculateTimeLeft ( ) ) ;
36
- } , 1000 ) ;
18
+ if ( difference > 0 ) {
19
+ timeLeft = {
20
+ days : Math . floor ( difference / ( 1000 * 60 * 60 * 24 ) )
21
+ . toString ( )
22
+ . padStart ( 2 , '0' ) ,
23
+ hours : Math . floor (
24
+ ( difference % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) ,
25
+ )
26
+ . toString ( )
27
+ . padStart ( 2 , '0' ) ,
28
+ minutes : Math . floor ( ( difference % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) )
29
+ . toString ( )
30
+ . padStart ( 2 , '0' ) ,
31
+ seconds : Math . floor ( ( difference % ( 1000 * 60 ) ) / 1000 )
32
+ . toString ( )
33
+ . padStart ( 2 , '0' ) ,
34
+ }
35
+ }
37
36
38
- return ( ) => clearInterval ( timer ) ;
39
- } , [ ] ) ;
37
+ return timeLeft
38
+ }
40
39
41
- if ( ! isMounted ) {
42
- return null ;
43
- }
40
+ const [ timeLeft , setTimeLeft ] = useState < TimeLeft > ( calculateTimeLeft ( ) )
41
+ const [ isMounted , setIsMounted ] = useState ( false )
44
42
45
- if ( timeLeft . seconds === undefined ) {
46
- return null ;
43
+ useEffect ( ( ) => {
44
+ setIsMounted ( true )
45
+ const timer = setInterval ( ( ) => {
46
+ setTimeLeft ( calculateTimeLeft ( ) )
47
+ } , 1000 )
48
+
49
+ return ( ) => {
50
+ clearInterval ( timer )
47
51
}
52
+ } , [ ] )
53
+
54
+ if ( ! isMounted ) {
55
+ return null
56
+ }
57
+
58
+ if ( timeLeft . seconds === undefined ) {
59
+ return null
60
+ }
48
61
49
- return (
50
- < div className = ' px-6 pb-6' >
51
- < p
52
- className = ' cursor-default'
53
- title = "Using Client smart contract is available only for new applications. Select Contract as allocation type to start using it"
54
- >
55
- Direct client allocation will be deprecated in{ ' ' }
56
- < span className = "inline-block text-center" style = { { width : '90px' } } >
57
- { timeLeft . days } :{ timeLeft . hours } :{ timeLeft . minutes } :{ timeLeft . seconds }
58
- </ span >
59
- . Start using the Client smart contract today.
60
- </ p >
61
- </ div >
62
- ) ;
63
- } ;
62
+ return (
63
+ < div className = " px-6 pb-6" >
64
+ < p
65
+ className = " cursor-default"
66
+ title = "Using Client smart contract is available only for new applications. Select Contract as allocation type to start using it"
67
+ >
68
+ Direct client allocation will be deprecated in{ ' ' }
69
+ < span className = "inline-block text-center" style = { { width : '90px' } } >
70
+ { timeLeft . days } :{ timeLeft . hours } :{ timeLeft . minutes } :{ timeLeft . seconds }
71
+ </ span >
72
+ . Start using the Client smart contract today.
73
+ </ p >
74
+ </ div >
75
+ )
76
+ }
64
77
65
- export default Countdown ;
78
+ export default Countdown
0 commit comments