Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Add timestamp zone toggle to Explorer #22616

Merged
merged 2 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions explorer/src/components/common/TimestampToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useState } from "react";
import { displayTimestampUtc, displayTimestamp } from "utils/date";

type State = "hide" | "show";

function Tooltip({ state }: { state: State }) {
const tooltip = {
maxWidth: "20rem",
};

if (state === "hide") return null;
return (
<div className="popover bs-popover-bottom show" style={tooltip}>
<div className="arrow" />
<div className="popover-body">
(Click to toggle between local and UTC)
</div>
</div>
);
}

export function TimestampToggle({ unixTimestamp }: { unixTimestamp: number }) {
const [isTimestampTypeUtc, toggleTimestampType] = useState(true);
const [showTooltip, toggleTooltip] = useState<State>("hide");

const toggle = () => {
toggleTimestampType(!isTimestampTypeUtc);
};

const tooltipContainer = {
cursor: "pointer",
};

return (
<div className="popover-container w-100" style={tooltipContainer}>
<span
onClick={toggle}
onMouseOver={() => toggleTooltip("show")}
onMouseOut={() => toggleTooltip("hide")}
>
{isTimestampTypeUtc === true
? displayTimestampUtc(unixTimestamp)
: displayTimestamp(unixTimestamp)}
</span>
<Tooltip state={showTooltip} />
</div>
);
}
5 changes: 3 additions & 2 deletions explorer/src/pages/ClusterStatsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import {
import { abbreviatedNumber, lamportsToSol, slotsToHumanString } from "utils";
import { ClusterStatus, useCluster } from "providers/cluster";
import { TpsCard } from "components/TpsCard";
import { displayTimestampWithoutDate, displayTimestampUtc } from "utils/date";
import { displayTimestampWithoutDate } from "utils/date";
import { Status, useFetchSupply, useSupply } from "providers/supply";
import { ErrorCard } from "components/common/ErrorCard";
import { LoadingCard } from "components/common/LoadingCard";
import { useVoteAccounts } from "providers/accounts/vote-accounts";
import { CoingeckoStatus, useCoinGecko } from "utils/coingecko";
import { Epoch } from "components/common/Epoch";
import { TimestampToggle } from "components/common/TimestampToggle";

const CLUSTER_STATS_TIMEOUT = 5000;

Expand Down Expand Up @@ -253,7 +254,7 @@ function StatsCardBody() {
<tr>
<td className="w-100">Cluster time</td>
<td className="text-lg-end font-monospace">
{displayTimestampUtc(blockTime)}
<TimestampToggle unixTimestamp={blockTime}></TimestampToggle>
</td>
</tr>
)}
Expand Down