diff --git a/frontend/src/components/OrderDetails/LinearDeterminate.tsx b/frontend/src/components/OrderDetails/LinearDeterminate.tsx index 9bed73c4..a0a8a30e 100644 --- a/frontend/src/components/OrderDetails/LinearDeterminate.tsx +++ b/frontend/src/components/OrderDetails/LinearDeterminate.tsx @@ -8,16 +8,21 @@ interface Props { } const LinearDeterminate = ({ expiresAt, totalSecsExp }: Props): JSX.Element => { - const [progress, setProgress] = useState(100); + const timePercentLeft = function(){ + if (expiresAt && totalSecsExp){ + const lapseTime = calcTimeDelta(new Date(expiresAt)).total / 1000; + return (lapseTime / totalSecsExp) * 100; + } else { + return 100; + } + } + const [progress, setProgress] = useState(timePercentLeft); + useEffect(() => { const timer = setInterval(() => { - const left = calcTimeDelta(new Date(expiresAt)).total / 1000; - const newProgress = (left / totalSecsExp) * 100; - - setProgress(newProgress); + setProgress(timePercentLeft); }, 1000); - return () => { clearInterval(timer); };