diff --git a/src/components/TopBar.tsx b/src/components/TopBar.tsx index 38aa41f5d..352a69298 100644 --- a/src/components/TopBar.tsx +++ b/src/components/TopBar.tsx @@ -9,16 +9,23 @@ import { assetsActions } from "../utils/redux/slices/assetsSlice"; import SendButton from "../views/home/SendButton"; import useBuyTezModal from "./BuyTez/useBuyTezModal"; +const formatRelativeTimestamp = (timestamp: string) => { + return formatDistance(new Date(timestamp), new Date()); +}; + const UpdateButton = () => { const dispatch = useAppDispatch(); const isLoading = useIsLoading(); const lastTimeUpdated = useLastTimeUpdated(); - const [relativeTimestamp, setRelativeTimestamp] = useState(null); + + const [relativeTimestamp, setRelativeTimestamp] = useState( + lastTimeUpdated && formatRelativeTimestamp(lastTimeUpdated) + ); useEffect(() => { if (lastTimeUpdated) { const interval = setInterval(() => { - setRelativeTimestamp(formatDistance(new Date(lastTimeUpdated), new Date())); + setRelativeTimestamp(formatRelativeTimestamp(lastTimeUpdated)); }, 1000); return () => clearInterval(interval); }