Skip to content

Commit

Permalink
Merge pull request #311 from trilitech/fix-refetch-button
Browse files Browse the repository at this point in the history
Fix refetch button
  • Loading branch information
serjonya-trili authored Jul 31, 2023
2 parents dd07290 + a1488da commit 2a3927a
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 2a3927a

Please sign in to comment.