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 a1488da
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 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 Down

0 comments on commit a1488da

Please sign in to comment.