Skip to content

Commit

Permalink
Fix refetch button
Browse files Browse the repository at this point in the history
It didn't persist between route changes
  • Loading branch information
serjonya-trili committed Jul 31, 2023
1 parent dd07290 commit 44cdadd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>(null);

const [relativeTimestamp, setRelativeTimestamp] = useState<string | null>(
lastTimeUpdated && formatRelativeTimestamp(lastTimeUpdated)
);

useEffect(() => {
if (lastTimeUpdated) {
const interval = setInterval(() => {
setRelativeTimestamp(formatDistance(new Date(lastTimeUpdated), new Date()));
setRelativeTimestamp(formatRelativeTimestamp(lastTimeUpdated));
}, 1000);
return () => clearInterval(interval);
}
Expand All @@ -30,7 +37,7 @@ const UpdateButton = () => {

return (
<>
{relativeTimestamp && (
{lastTimeUpdated && (
<Text size="sm" color={colors.gray[400]} display="inline">
Last updated: {relativeTimestamp} ago
</Text>
Expand Down

0 comments on commit 44cdadd

Please sign in to comment.