debug
This commit is contained in:
parent
9c849193a4
commit
55a48d5541
2 changed files with 21 additions and 3 deletions
|
|
@ -133,7 +133,19 @@ function LatestBlocks({ fetchedInfo, fetchedLatestBlocks }: { fetchedInfo: Info
|
|||
]
|
||||
});
|
||||
|
||||
const lastUpdatedText = lastUpdated ? Utils.timeElapsedString(lastUpdated) : undefined;
|
||||
const [lastUpdatedText, setLastUpdatedText] = useState<string | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
function formatLastUpdated() {
|
||||
setLastUpdatedText(lastUpdated ? Utils.timeElapsedString(lastUpdated / 1000, true) : undefined);
|
||||
}
|
||||
|
||||
formatLastUpdated();
|
||||
const interval = setInterval(formatLastUpdated, 1000);
|
||||
return () => clearInterval(interval);
|
||||
|
||||
}, [lastUpdated]);
|
||||
|
||||
|
||||
return (
|
||||
<div className={classes(styles["blockchain__latest_blocks"], styles["custom-scroll"])}>
|
||||
|
|
|
|||
|
|
@ -92,12 +92,18 @@ class Utils {
|
|||
} as Block));
|
||||
}
|
||||
|
||||
static timeElapsedString(timestamp: number): string {
|
||||
static timeElapsedString(timestamp: number, includeSeconds: boolean = false): string {
|
||||
const currentTimestamp: number = Date.now() / 1000;
|
||||
const elapsedSeconds: number = currentTimestamp - timestamp;
|
||||
|
||||
if (elapsedSeconds < 60) {
|
||||
return "just now";
|
||||
|
||||
if (includeSeconds && elapsedSeconds > 0) {
|
||||
const seconds: number = Math.floor(elapsedSeconds);
|
||||
return `${seconds} second${seconds > 1 ? 's' : ''} ago`;
|
||||
} else {
|
||||
return "just now";
|
||||
}
|
||||
} else if (elapsedSeconds < 3600) {
|
||||
const minutes: number = Math.floor(elapsedSeconds / 60);
|
||||
return `${minutes} minute${minutes > 1 ? 's' : ''} ago`;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue