explorer: Allow sorting block transactions by compute (#24786)
This commit is contained in:
parent
1d6df736a3
commit
aa1d34b09e
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useHistory, useLocation } from "react-router-dom";
|
||||||
import { Location } from "history";
|
import { Location } from "history";
|
||||||
import {
|
import {
|
||||||
BlockResponse,
|
BlockResponse,
|
||||||
|
@ -11,19 +11,25 @@ import {
|
||||||
import { ErrorCard } from "components/common/ErrorCard";
|
import { ErrorCard } from "components/common/ErrorCard";
|
||||||
import { Signature } from "components/common/Signature";
|
import { Signature } from "components/common/Signature";
|
||||||
import { Address } from "components/common/Address";
|
import { Address } from "components/common/Address";
|
||||||
import { useQuery } from "utils/url";
|
import { pickClusterParams, useQuery } from "utils/url";
|
||||||
import { useCluster } from "providers/cluster";
|
import { useCluster } from "providers/cluster";
|
||||||
import { displayAddress } from "utils/tx";
|
import { displayAddress } from "utils/tx";
|
||||||
import { parseProgramLogs } from "utils/program-logs";
|
import { parseProgramLogs } from "utils/program-logs";
|
||||||
|
|
||||||
const PAGE_SIZE = 25;
|
const PAGE_SIZE = 25;
|
||||||
|
|
||||||
const useQueryFilter = (): string => {
|
const useQueryFilter = (query: URLSearchParams): string => {
|
||||||
const query = useQuery();
|
|
||||||
const filter = query.get("filter");
|
const filter = query.get("filter");
|
||||||
return filter || "";
|
return filter || "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type SortMode = "index" | "compute";
|
||||||
|
const useQuerySort = (query: URLSearchParams): SortMode => {
|
||||||
|
const sort = query.get("sort");
|
||||||
|
if (sort === "compute") return "compute";
|
||||||
|
return "index";
|
||||||
|
};
|
||||||
|
|
||||||
type TransactionWithInvocations = {
|
type TransactionWithInvocations = {
|
||||||
index: number;
|
index: number;
|
||||||
signature?: TransactionSignature;
|
signature?: TransactionSignature;
|
||||||
|
@ -36,8 +42,12 @@ type TransactionWithInvocations = {
|
||||||
export function BlockHistoryCard({ block }: { block: BlockResponse }) {
|
export function BlockHistoryCard({ block }: { block: BlockResponse }) {
|
||||||
const [numDisplayed, setNumDisplayed] = React.useState(PAGE_SIZE);
|
const [numDisplayed, setNumDisplayed] = React.useState(PAGE_SIZE);
|
||||||
const [showDropdown, setDropdown] = React.useState(false);
|
const [showDropdown, setDropdown] = React.useState(false);
|
||||||
const filter = useQueryFilter();
|
const query = useQuery();
|
||||||
|
const filter = useQueryFilter(query);
|
||||||
|
const sortMode = useQuerySort(query);
|
||||||
const { cluster } = useCluster();
|
const { cluster } = useCluster();
|
||||||
|
const location = useLocation();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const { transactions, invokedPrograms } = React.useMemo(() => {
|
const { transactions, invokedPrograms } = React.useMemo(() => {
|
||||||
const invokedPrograms = new Map<string, number>();
|
const invokedPrograms = new Map<string, number>();
|
||||||
|
@ -97,7 +107,7 @@ export function BlockHistoryCard({ block }: { block: BlockResponse }) {
|
||||||
|
|
||||||
const filteredTransactions = React.useMemo(() => {
|
const filteredTransactions = React.useMemo(() => {
|
||||||
const voteFilter = VOTE_PROGRAM_ID.toBase58();
|
const voteFilter = VOTE_PROGRAM_ID.toBase58();
|
||||||
return transactions.filter(({ invocations }) => {
|
const filteredTxs = transactions.filter(({ invocations }) => {
|
||||||
if (filter === ALL_TRANSACTIONS) {
|
if (filter === ALL_TRANSACTIONS) {
|
||||||
return true;
|
return true;
|
||||||
} else if (filter === HIDE_VOTES) {
|
} else if (filter === HIDE_VOTES) {
|
||||||
|
@ -106,7 +116,13 @@ export function BlockHistoryCard({ block }: { block: BlockResponse }) {
|
||||||
}
|
}
|
||||||
return invocations.has(filter);
|
return invocations.has(filter);
|
||||||
});
|
});
|
||||||
}, [transactions, filter]);
|
|
||||||
|
if (sortMode === "compute") {
|
||||||
|
filteredTxs.sort((a, b) => b.computeUnits - a.computeUnits);
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredTxs;
|
||||||
|
}, [transactions, filter, sortMode]);
|
||||||
|
|
||||||
if (filteredTransactions.length === 0) {
|
if (filteredTransactions.length === 0) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
|
@ -140,10 +156,26 @@ export function BlockHistoryCard({ block }: { block: BlockResponse }) {
|
||||||
<table className="table table-sm table-nowrap card-table">
|
<table className="table table-sm table-nowrap card-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="text-muted">#</th>
|
<th
|
||||||
|
className="text-muted c-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
query.delete("sort");
|
||||||
|
history.push(pickClusterParams(location, query));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
#
|
||||||
|
</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>
|
||||||
<th className="text-muted">Compute</th>
|
<th
|
||||||
|
className="text-muted c-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
query.set("sort", "compute");
|
||||||
|
history.push(pickClusterParams(location, query));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Compute
|
||||||
|
</th>
|
||||||
<th className="text-muted">Invoked Programs</th>
|
<th className="text-muted">Invoked Programs</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
Loading…
Reference in New Issue