Skip to content

Commit

Permalink
(feat) Use a timestamp rather than an age in block lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Jul 8, 2024
1 parent d1f768b commit 614ff7e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
14 changes: 10 additions & 4 deletions src/components/Timestamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TimestampAge from "./TimestampAge";

type TimestampProps = {
value: number;
age?: boolean;
};

const months = [
Expand All @@ -22,7 +23,7 @@ const months = [
"Dec",
];

const Timestamp: React.FC<TimestampProps> = ({ value }) => {
const Timestamp: React.FC<TimestampProps> = ({ value, age }) => {
const d = new Date(value * 1000);
let hour = d.getUTCHours() % 12;
if (hour === 0) {
Expand All @@ -42,12 +43,17 @@ const Timestamp: React.FC<TimestampProps> = ({ value }) => {
minimumIntegerDigits: 2,
})} ${am ? "AM" : "PM"} +UTC`;

let snippet;
if (age === undefined || age) {
snippet = <span><TimestampAge timestamp={value} /> ({tsString})</span>;
} else {
snippet = <span>{tsString}</span>;
}

return (
<div className="flex items-baseline space-x-1">
<FontAwesomeIcon className="self-center" icon={faClock} size="sm" />
<span>
<TimestampAge timestamp={value} /> ({tsString})
</span>
{ snippet }
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/BlockItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { NavLink } from "react-router-dom";
import BlockLink from "../components/BlockLink";
import HexValue from "../components/HexValue";
import TimestampAge from "../components/TimestampAge";
import Timestamp from "../components/Timestamp";
import { formatValue } from "../components/formatter";
import BlockReward from "../execution/components/BlockReward";
import { blockTxsURL } from "../url";
Expand Down Expand Up @@ -48,7 +48,7 @@ const BlockItem: React.FC<BlockItemProps> = ({ block, feeDisplay }) => {
<span className="truncate">
<BlockReward block={block} />
</span>
<TimestampAge timestamp={block.timestamp} />
<Timestamp age={false} value={block.timestamp} />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/search/BlockResultHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const BlockResultHeader: React.FC<ResultHeaderProps> = ({
</button>
</div>
<div>Rewards</div>
<div>Age</div>
<div>Timestamp</div>
</div>
);

Expand Down
12 changes: 6 additions & 6 deletions src/search/DSBlockItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DsBlockObj } from "@zilliqa-js/core/dist/types/src/types";
import React from "react";
import DSBlockLink from "../components/DSBlockLink";
import HexValue from "../components/HexValue";
import TimestampAge from "../components/TimestampAge";
import Timestamp from "../components/Timestamp";
import TransactionAddress from "../execution/components/TransactionAddress";
import {
addHexPrefix,
Expand Down Expand Up @@ -30,17 +30,17 @@ const DSBlockItem: React.FC<DSBlockItemProps> = ({
</span>
<span>{commify(block.header.Difficulty)}</span>
<span>{commify(block.header.DifficultyDS)}</span>
<TimestampAge
timestamp={zilliqaToOtterscanTimestamp(block.header.Timestamp)}
/>
<span className="col-span-4 truncate">
<span className="col-span-2 truncate"><Timestamp
age={false} value={zilliqaToOtterscanTimestamp(block.header.Timestamp)}
/></span>
<span className="col-span-2 truncate">
<TransactionAddress
address={pubKeyToAddr(block.header.LeaderPubKey)}
selectedAddress={selectedAddress}
miner={true}
/>
</span>
<span className="col-span-4 truncate">
<span className="col-span-2 truncate">
<HexValue value={addHexPrefix(block.header.PrevHash)} />
</span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/search/DSBlockResultHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const DSBlockResultHeader: React.FC = () => (
<div>Height</div>
<div>Difficulty</div>
<div>DS Difficulty</div>
<div>Age</div>
<div className="col-span-4">DS Leader</div>
<div className="col-span-4">Prev Block Hash</div>
<div className="col-span-2">Timestamp</div>
<div className="col-span-2">DS Leader</div>
<div className="col-span-2">Prev Block Hash</div>
</div>
);

Expand Down
3 changes: 2 additions & 1 deletion src/search/RecentBlockItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { NavLink } from "react-router-dom";
import BlockLink from "../components/BlockLink";
import TimestampAge from "../components/TimestampAge";
import Timestamp from "../components/Timestamp";
import { formatValue } from "../components/formatter";
import BlockReward from "../execution/components/BlockReward";
import { blockTxsURL } from "../url";
Expand Down Expand Up @@ -44,7 +45,7 @@ const RecentBlockItem: React.FC<BlockItemProps> = ({ block, feeDisplay }) => {
<span className="truncate">
<BlockReward block={block} />
</span>
<TimestampAge timestamp={block.timestamp} />
<Timestamp age={false} value={block.timestamp} />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/search/RecentBlockResultHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const RecentBlockResultHeader: React.FC<ResultHeaderProps> = ({
</button>
</div>
<div>Rewards</div>
<div>Age</div>
<div>Timestamp</div>
</div>
);

Expand Down

0 comments on commit 614ff7e

Please sign in to comment.