forked from Uniswap/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Merging details part 3 (Uniswap#4637)
* Merging details part 3 Co-authored-by: Alex Ball <[email protected]>
- Loading branch information
aballerr
and
Alex Ball
authored
Sep 19, 2022
1 parent
02b617d
commit e7d498c
Showing
4 changed files
with
256 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
const MINUTE = 1000 * 60 | ||
const HOUR = MINUTE * 60 | ||
const DAY = 24 * HOUR | ||
|
||
const getReturnValues = (countDown: number): [number, number, number, number] => { | ||
// calculate time left | ||
const days = Math.floor(countDown / DAY) | ||
const hours = Math.floor((countDown % DAY) / HOUR) | ||
const minutes = Math.floor((countDown % HOUR) / MINUTE) | ||
const seconds = Math.floor((countDown % MINUTE) / 1000) | ||
|
||
return [days, hours, minutes, seconds] | ||
} | ||
|
||
export const useTimeout = (targetDate: Date) => { | ||
const countDownDate = new Date(targetDate).getTime() | ||
|
||
const [countDown, setCountDown] = useState<number>(countDownDate - new Date().getTime()) | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setCountDown(countDownDate - new Date().getTime()) | ||
}, 1000) | ||
|
||
return () => clearInterval(interval) | ||
}, [countDownDate]) | ||
|
||
return getReturnValues(countDown) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.