Skip to content

Commit

Permalink
chore: replace hardcoded values with a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelae committed Oct 28, 2024
1 parent 241bced commit 6f65ed2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ui/hooks/bridge/useCountdownTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import { getBridgeQuotes } from '../../ducks/bridge/selectors';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { REFRESH_INTERVAL_MS } from '../../../app/scripts/controllers/bridge/constants';
import { SECOND } from '../../../shared/constants/time';

/**
* Custom hook that provides a countdown timer based on the last fetched quotes timestamp.
*
* This hook calculates the remaining time until the next refresh interval and updates every second.
*
* @returns The formatted remaining time in 'm:ss' format.
*/
export const useCountdownTimer = () => {
const [timeRemaining, setTimeRemaining] = useState(REFRESH_INTERVAL_MS);
const { quotesLastFetchedMs } = useSelector(getBridgeQuotes);
Expand All @@ -20,8 +28,8 @@ export const useCountdownTimer = () => {

useEffect(() => {
const interval = setInterval(() => {
setTimeRemaining(Math.max(0, timeRemaining - 1000));
}, 1000);
setTimeRemaining(Math.max(0, timeRemaining - SECOND));
}, SECOND);
return () => clearInterval(interval);
}, [timeRemaining]);

Expand Down

0 comments on commit 6f65ed2

Please sign in to comment.