Skip to content

Commit

Permalink
[explorer] Update transaction to use new block terminology (MystenLab…
Browse files Browse the repository at this point in the history
…s#9958)

## Description 

This makes some changes to the explorer to use new terminology.

## Test Plan 

Tests should still pass
  • Loading branch information
Jordan-Mysten authored Mar 28, 2023
1 parent 76c1ef9 commit 5abb611
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 122 deletions.
18 changes: 15 additions & 3 deletions apps/explorer/src/components/Activity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PlayPause } from '~/ui/PlayPause';
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from '~/ui/Tabs';

type Props = {
initialTab?: string | null;
initialLimit: number;
disablePagination?: boolean;
};
Expand All @@ -19,7 +20,14 @@ const AUTO_REFRESH_ID = 'auto-refresh';
const REFETCH_INTERVAL_SECONDS = 10;
const REFETCH_INTERVAL = REFETCH_INTERVAL_SECONDS * 1000;

export function Activity({ initialLimit, disablePagination }: Props) {
export function Activity({
initialTab,
initialLimit,
disablePagination,
}: Props) {
const [selectedIndex, setSelectedIndex] = useState(
initialTab === 'checkpoints' ? 1 : 0
);
const [paused, setPaused] = useState(false);

const handlePauseChange = () => {
Expand All @@ -39,10 +47,14 @@ export function Activity({ initialLimit, disablePagination }: Props) {

return (
<div>
<TabGroup size="lg">
<TabGroup
size="lg"
selectedIndex={selectedIndex}
onChange={setSelectedIndex}
>
<div className="relative">
<TabList>
<Tab>Transactions</Tab>
<Tab>Transaction Blocks</Tab>
<Tab>Checkpoints</Tab>
</TabList>

Expand Down
4 changes: 2 additions & 2 deletions apps/explorer/src/components/HomeMetrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export function HomeMetrics() {
{formatAmount(countsData?.objects)}
</StatsWrapper>
<StatsWrapper
label="Transactions"
tooltip="Total transactions counter (updates every one min)"
label="Transaction Blocks"
tooltip="Total transaction blocks counter (updates every one min)"
>
{formatAmount(countsData?.transactions)}
</StatsWrapper>
Expand Down
4 changes: 3 additions & 1 deletion apps/explorer/src/components/Table/TableFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Props {
data?: PaginationResponse<any>;
limit: number;
onLimitChange(value: number): void;
href: string;
}

export function TableFooter({
Expand All @@ -30,12 +31,13 @@ export function TableFooter({
count,
limit,
onLimitChange,
href,
}: Props) {
return (
<div className="flex items-center justify-between">
{disablePagination ? (
<>
<Link to="/transactions" after={<ArrowRight12 />}>
<Link to={href} after={<ArrowRight12 />}>
More {label}
</Link>
<Text variant="body/medium" color="steel-dark">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export function FunctionExecutionResult({
>
<div className="space-y-4 text-bodySmall">
<LinkGroup
title="Transaction ID"
title="Digest"
links={
result
? [
{
text: getTransactionDigest(result),
to: `/transaction/${encodeURIComponent(
to: `/txblock/${encodeURIComponent(
getTransactionDigest(result)
)}`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useRpcClient } from '@mysten/core';
import { type SuiTransactionBlockResponse } from '@mysten/sui.js';
import { useQuery } from '@tanstack/react-query';

import { genTableDataFromTxData } from './TxCardUtils';
Expand Down Expand Up @@ -41,9 +42,18 @@ export function TransactionsForAddress({ address, type }: Props) {
)
);

return [...results[0].data, ...results[1].data].sort(
(a, b) => (b.timestampMs ?? 0) - (a.timestampMs ?? 0)
);
const inserted = new Map();
const uniqueList: SuiTransactionBlockResponse[] = [];

[...results[0].data, ...results[1].data]
.sort((a, b) => (b.timestampMs ?? 0) - (a.timestampMs ?? 0))
.forEach((txb) => {
if (inserted.get(txb.digest)) return;
uniqueList.push(txb);
inserted.set(txb.digest, true);
});

return uniqueList;
}
);

Expand Down
6 changes: 3 additions & 3 deletions apps/explorer/src/components/transactions/TxCardUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const genTableDataFromTxData = (
<TxTimeType timestamp={transaction.timestampMs} />
</TxTableCol>
),
transactionId: (
digest: (
<TxTableCol isFirstCol isHighlightedOnHover>
<TransactionLink
digest={transaction.digest}
Expand Down Expand Up @@ -124,8 +124,8 @@ export const genTableDataFromTxData = (
}),
columns: [
{
header: 'Transaction ID',
accessorKey: 'transactionId',
header: 'Digest',
accessorKey: 'digest',
},
{
header: () => <TxTableHeader label="Sender" />,
Expand Down
11 changes: 3 additions & 8 deletions apps/explorer/src/components/transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,21 @@ export function Transactions({
<PlaceholderTable
rowCount={initialLimit}
rowHeight="16px"
colHeadings={[
'Transaction ID',
'Sender',
'Amount',
'Gas',
'Time',
]}
colHeadings={['Digest', 'Sender', 'Amount', 'Gas', 'Time']}
colWidths={['100px', '120px', '204px', '90px', '38px']}
/>
)}

<div className="py-3">
<TableFooter
label="Transactions"
label="Transaction Blocks"
count={Number(countQuery.data)}
data={transactionQuery.data}
disablePagination={disablePagination}
pagination={pagination}
limit={limit}
onLimitChange={setLimit}
href="/recent"
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/pages/address-result/AddressResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function AddressResult() {
<div>
<div className="border-b border-gray-45 pb-5">
<Heading color="gray-90" variant="heading4/semibold">
Transactions
Transaction Blocks
</Heading>
</div>
<ErrorBoundary>
Expand Down
1 change: 1 addition & 0 deletions apps/explorer/src/pages/checkpoints/CheckpointsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function CheckpointsTable({
onLimitChange={setLimit}
pagination={pagination}
disablePagination={disablePagination}
href="/recent?tab=checkpoints"
/>
</div>
</div>
Expand Down
20 changes: 13 additions & 7 deletions apps/explorer/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import CheckpointDetail from './checkpoints/CheckpointDetail';
import EpochDetail from './epochs/EpochDetail';
import Home from './home/Home';
import { ObjectResult } from './object-result/ObjectResult';
import SearchError from './searcherror/SearchError';
import { Recent } from './recent';
import TransactionResult from './transaction-result/TransactionResult';
import Transactions from './transactions/Transactions';
import { ValidatorDetails } from './validator/ValidatorDetails';
import { ValidatorPageResult } from './validators/Validators';

Expand All @@ -36,25 +35,32 @@ export const router = sentryCreateBrowserRouter([
element: <Layout />,
children: [
{ path: '/', element: <Home /> },
{ path: 'transactions', element: <Transactions /> },
{ path: 'recent', element: <Recent /> },
{ path: 'object/:id', element: <ObjectResult /> },
{ path: 'checkpoint/:id', element: <CheckpointDetail /> },
{ path: 'epoch/current', element: <EpochDetail /> },
{ path: 'transaction/:id', element: <TransactionResult /> },
{ path: 'txblock/:id', element: <TransactionResult /> },
{ path: 'address/:id', element: <AddressResult /> },
{ path: 'validators', element: <ValidatorPageResult /> },
{ path: 'validator/:id', element: <ValidatorDetails /> },
{ path: 'error/:category/:id', element: <SearchError /> },
],
},
// Support legacy plural routes:
{
path: '/transactions',
element: <Navigate to="/recent" replace />,
},
// Support legacy routes:
{
path: '/objects/:id',
element: <RedirectWithId base="object" />,
},
{
path: '/transaction/:id',
element: <RedirectWithId base="txblock" />,
},
{
path: '/transactions/:id',
element: <RedirectWithId base="transaction" />,
element: <RedirectWithId base="txblock" />,
},
{
path: '/addresses/:id',
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/pages/object-result/views/PkgView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function PkgView({ data }: { data: DataType }) {
<PkgModulesWrapper id={data.id} modules={properties} />
</ErrorBoundary>
<div className={styles.txsection}>
<h2 className={styles.header}>Transactions</h2>
<h2 className={styles.header}>Transaction Blocks</h2>
<ErrorBoundary>
<TransactionsForAddress
address={viewedData.id}
Expand Down
4 changes: 2 additions & 2 deletions apps/explorer/src/pages/object-result/views/TokenView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function TokenView({ data }: { data: DataType }) {
{data.version}
</Text>
</DescriptionItem>
<DescriptionItem title="Last Transaction ID">
<DescriptionItem title="Last Transaction Block Digest">
<TransactionLink
digest={data.data.tx_digest!}
noTruncate
Expand Down Expand Up @@ -267,7 +267,7 @@ export function TokenView({ data }: { data: DataType }) {
</div>
</div>
<div>
<h2 className={styles.header}>Transactions</h2>
<h2 className={styles.header}>Transaction Blocks</h2>
<TransactionsForAddress address={data.id} type="object" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
import { Activity } from '../../components/Activity';
import { ErrorBoundary } from '../../components/error-boundary/ErrorBoundary';

import { useSearchParamsMerged } from '~/ui/utils/LinkWithQuery';

const TRANSACTIONS_LIMIT = 20;

function Transactions() {
export function Recent() {
const [searchParams] = useSearchParamsMerged();

return (
<div
data-testid="transaction-page"
id="transaction"
className="mx-auto"
>
<ErrorBoundary>
<Activity initialLimit={TRANSACTIONS_LIMIT} />
<Activity
initialLimit={TRANSACTIONS_LIMIT}
initialTab={searchParams.get('tab')}
/>
</ErrorBoundary>
</div>
);
}

export default Transactions;
41 changes: 0 additions & 41 deletions apps/explorer/src/pages/searcherror/SearchError.tsx

This file was deleted.

Loading

0 comments on commit 5abb611

Please sign in to comment.