From e1662effa6ae50d1f37bb6aa258b28e4fea92738 Mon Sep 17 00:00:00 2001 From: jejolare Date: Thu, 26 Sep 2024 18:32:23 +0700 Subject: [PATCH] fix timestamps on frontend --- src/components/default/LatestBlocks/LatestBlocks.tsx | 2 ++ src/interfaces/common/BlockInfo.ts | 4 ++-- src/pages/block/[hash].tsx | 2 +- src/utils/utils.ts | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/default/LatestBlocks/LatestBlocks.tsx b/src/components/default/LatestBlocks/LatestBlocks.tsx index 21133d1..2ea023e 100644 --- a/src/components/default/LatestBlocks/LatestBlocks.tsx +++ b/src/components/default/LatestBlocks/LatestBlocks.tsx @@ -88,6 +88,8 @@ function LatestBlocks({ fetchedInfo, fetchedLatestBlocks }: { fetchedInfo: Info const tableHeaders = [ "HEIGHT", "TIMESTAMP (UTC)", "AGE", "SIZE", "TRANSACTIONS", "HASH" ]; const tableElements = blocks.map(e => { + console.log(e); + const hash = e.hash; const hashLink = hash ? "/block/" + hash : "/"; return [ diff --git a/src/interfaces/common/BlockInfo.ts b/src/interfaces/common/BlockInfo.ts index 151ebdf..188d148 100644 --- a/src/interfaces/common/BlockInfo.ts +++ b/src/interfaces/common/BlockInfo.ts @@ -1,7 +1,7 @@ interface BlockInfo { type: "PoS" | "PoW"; - timestamp?: Date; - actualTimestamp?: BigInt; + timestamp?: string; + actualTimestamp?: string; difficulty: string; minerTextInfo?: string; cummulativeDiffAdjusted?: string; diff --git a/src/pages/block/[hash].tsx b/src/pages/block/[hash].tsx index 5bd47b9..99e217a 100644 --- a/src/pages/block/[hash].tsx +++ b/src/pages/block/[hash].tsx @@ -154,7 +154,7 @@ function Block(props: BlockProps) { Timestamp (UTC): - {blockInfo?.timestamp ? Utils.formatTimestampUTC(+new Date(blockInfo?.timestamp)) : "-"} + {blockInfo?.timestamp ? Utils.formatTimestampUTC(+new Date(parseInt(blockInfo?.timestamp, 10))) : "-"} ID diff --git a/src/utils/utils.ts b/src/utils/utils.ts index ee50afb..87b2f90 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -81,10 +81,12 @@ class Utils { static transformToBlocks(result: any, reverse: boolean = false, hashField: boolean = false): Block[] { if (result.sucess === false) return []; if (!(result instanceof Array)) return []; + console.log(result); + return (reverse ? result.reverse() : result).map((e: any) => ({ height: e.height, type: e.type === '0' ? "PoS" : "PoW", - timestamp: +new Date(e.timestamp), + timestamp: +new Date(parseInt(e.timestamp, 10)), size: e.total_txs_size, transactions: e.tr_count, hash: !hashField ? e.tx_id : e.hash