explorer: Add timestamps to transaction history (#14782)
* add timestamps to transaction history * use local timestamps for blocktime display * revert to showing full universal time systemwide
This commit is contained in:
@ -7,6 +7,7 @@ import { Signature } from "components/common/Signature";
|
|||||||
import { ErrorCard } from "components/common/ErrorCard";
|
import { ErrorCard } from "components/common/ErrorCard";
|
||||||
import { LoadingCard } from "components/common/LoadingCard";
|
import { LoadingCard } from "components/common/LoadingCard";
|
||||||
import { Slot } from "components/common/Slot";
|
import { Slot } from "components/common/Slot";
|
||||||
|
import { displayTimestamp } from "utils/date";
|
||||||
|
|
||||||
export function TransactionHistoryCard({ pubkey }: { pubkey: PublicKey }) {
|
export function TransactionHistoryCard({ pubkey }: { pubkey: PublicKey }) {
|
||||||
const address = pubkey.toBase58();
|
const address = pubkey.toBase58();
|
||||||
@ -48,6 +49,7 @@ export function TransactionHistoryCard({ pubkey }: { pubkey: PublicKey }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasTimestamps = !!transactions.find((element) => !!element.blockTime);
|
||||||
const detailsList: React.ReactNode[] = [];
|
const detailsList: React.ReactNode[] = [];
|
||||||
for (var i = 0; i < transactions.length; i++) {
|
for (var i = 0; i < transactions.length; i++) {
|
||||||
const slot = transactions[i].slot;
|
const slot = transactions[i].slot;
|
||||||
@ -58,7 +60,7 @@ export function TransactionHistoryCard({ pubkey }: { pubkey: PublicKey }) {
|
|||||||
slotTransactions.push(transactions[++i]);
|
slotTransactions.push(transactions[++i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
slotTransactions.forEach(({ signature, err }) => {
|
slotTransactions.forEach(({ signature, err, blockTime }) => {
|
||||||
let statusText;
|
let statusText;
|
||||||
let statusClass;
|
let statusClass;
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -75,6 +77,12 @@ export function TransactionHistoryCard({ pubkey }: { pubkey: PublicKey }) {
|
|||||||
<Slot slot={slot} link />
|
<Slot slot={slot} link />
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
{hasTimestamps && (
|
||||||
|
<td className="text-muted">
|
||||||
|
{blockTime ? displayTimestamp(blockTime * 1000, true) : "---"}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<span className={`badge badge-soft-${statusClass}`}>
|
<span className={`badge badge-soft-${statusClass}`}>
|
||||||
{statusText}
|
{statusText}
|
||||||
@ -118,6 +126,7 @@ export function TransactionHistoryCard({ pubkey }: { pubkey: PublicKey }) {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="text-muted w-1">Slot</th>
|
<th className="text-muted w-1">Slot</th>
|
||||||
|
{hasTimestamps && <th className="text-muted">Timestamp</th>}
|
||||||
<th className="text-muted">Result</th>
|
<th className="text-muted">Result</th>
|
||||||
<th className="text-muted">Transaction Signature</th>
|
<th className="text-muted">Transaction Signature</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
export function displayTimestamp(unixTimestamp: number): string {
|
export function displayTimestamp(
|
||||||
|
unixTimestamp: number,
|
||||||
|
shortTimeZoneName = false
|
||||||
|
): string {
|
||||||
const expireDate = new Date(unixTimestamp);
|
const expireDate = new Date(unixTimestamp);
|
||||||
const dateString = new Intl.DateTimeFormat("en-US", {
|
const dateString = new Intl.DateTimeFormat("en-US", {
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
@ -10,12 +13,15 @@ export function displayTimestamp(unixTimestamp: number): string {
|
|||||||
minute: "numeric",
|
minute: "numeric",
|
||||||
second: "numeric",
|
second: "numeric",
|
||||||
hour12: false,
|
hour12: false,
|
||||||
timeZoneName: "long",
|
timeZoneName: shortTimeZoneName ? "short" : "long",
|
||||||
}).format(expireDate);
|
}).format(expireDate);
|
||||||
return `${dateString} at ${timeString}`;
|
return `${dateString} at ${timeString}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function displayTimestampUtc(unixTimestamp: number): string {
|
export function displayTimestampUtc(
|
||||||
|
unixTimestamp: number,
|
||||||
|
shortTimeZoneName = false
|
||||||
|
): string {
|
||||||
const expireDate = new Date(unixTimestamp);
|
const expireDate = new Date(unixTimestamp);
|
||||||
const dateString = new Intl.DateTimeFormat("en-US", {
|
const dateString = new Intl.DateTimeFormat("en-US", {
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
@ -29,6 +35,7 @@ export function displayTimestampUtc(unixTimestamp: number): string {
|
|||||||
second: "numeric",
|
second: "numeric",
|
||||||
hour12: false,
|
hour12: false,
|
||||||
timeZone: "UTC",
|
timeZone: "UTC",
|
||||||
|
timeZoneName: shortTimeZoneName ? "short" : "long",
|
||||||
}).format(expireDate);
|
}).format(expireDate);
|
||||||
return `${dateString} at ${timeString}`;
|
return `${dateString} at ${timeString}`;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user