diff --git a/.changeset/flat-ducks-love.md b/.changeset/flat-ducks-love.md new file mode 100644 index 000000000..0fc9d596b --- /dev/null +++ b/.changeset/flat-ducks-love.md @@ -0,0 +1,5 @@ +--- +"@blobscan/web": patch +--- + +Resolved timestamp normalization issue diff --git a/apps/web/src/components/Cards/SurfaceCards/BlobTransactionCard.tsx b/apps/web/src/components/Cards/SurfaceCards/BlobTransactionCard.tsx index e25914ab1..323bbf862 100644 --- a/apps/web/src/components/Cards/SurfaceCards/BlobTransactionCard.tsx +++ b/apps/web/src/components/Cards/SurfaceCards/BlobTransactionCard.tsx @@ -10,8 +10,6 @@ import { animated, useSpring } from "@react-spring/web"; import "react-loading-skeleton/dist/skeleton.css"; import Skeleton from "react-loading-skeleton"; -import dayjs from "@blobscan/dayjs"; - import type { Block } from "~/types"; import { buildAddressRoute, @@ -19,6 +17,7 @@ import { buildBlockRoute, buildTransactionRoute, formatBytes, + normalizeTimestamp, } from "~/utils"; import { Link } from "../../Link"; import { SurfaceCardBase } from "./SurfaceCardBase"; @@ -164,7 +163,7 @@ const BlobTransactionCard: FC = function ({ {number}
- {dayjs(timestamp).fromNow()} + {normalizeTimestamp(timestamp).fromNow()}
)} diff --git a/apps/web/src/components/Cards/SurfaceCards/BlockCard.tsx b/apps/web/src/components/Cards/SurfaceCards/BlockCard.tsx index ac281d977..0f51344d3 100644 --- a/apps/web/src/components/Cards/SurfaceCards/BlockCard.tsx +++ b/apps/web/src/components/Cards/SurfaceCards/BlockCard.tsx @@ -4,10 +4,8 @@ import type { FC } from "react"; import "react-loading-skeleton/dist/skeleton.css"; import Skeleton from "react-loading-skeleton"; -import dayjs from "@blobscan/dayjs"; - import type { Block } from "~/types"; -import { buildBlockRoute } from "~/utils"; +import { buildBlockRoute, normalizeTimestamp } from "~/utils"; import { Link } from "../../Link"; import { CardHeader } from "../Card"; import { SurfaceCardBase } from "./SurfaceCardBase"; @@ -40,7 +38,7 @@ const BlockCard: FC> = function ({
{timestamp ? (
- {dayjs(timestamp).fromNow()} + {normalizeTimestamp(timestamp).fromNow()}
) : ( diff --git a/apps/web/src/utils/date.ts b/apps/web/src/utils/date.ts index 09dab81b2..310285902 100644 --- a/apps/web/src/utils/date.ts +++ b/apps/web/src/utils/date.ts @@ -1,8 +1,13 @@ import dayjs from "@blobscan/dayjs"; +export function normalizeTimestamp(timestamp: number | Date) { + return typeof timestamp === "number" + ? dayjs.unix(timestamp) + : dayjs(timestamp); +} + export function formatTimestamp(timestamp: number | Date) { - const unixHandler = - typeof timestamp === "number" ? dayjs.unix(timestamp) : dayjs(timestamp); + const unixHandler = normalizeTimestamp(timestamp); return `${unixHandler.fromNow()} (${unixHandler.format( "MMM D, YYYY h:mm AZ"