feat(explorer): add timestamp to tx list (#5174)
This commit is contained in:
parent
443220283c
commit
06cfd79415
@ -82,7 +82,7 @@ describe('Txs infinite list item', () => {
|
|||||||
expect(screen.getByText('Missing vital data')).toBeInTheDocument();
|
expect(screen.getByText('Missing vital data')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders data correctly', () => {
|
it('renders data even with missing time', () => {
|
||||||
render(
|
render(
|
||||||
<MockedProvider>
|
<MockedProvider>
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
@ -105,5 +105,33 @@ describe('Txs infinite list item', () => {
|
|||||||
expect(screen.getByTestId('pub-key')).toHaveTextContent('testPubKey');
|
expect(screen.getByTestId('pub-key')).toHaveTextContent('testPubKey');
|
||||||
expect(screen.getByTestId('tx-type')).toHaveTextContent('testType');
|
expect(screen.getByTestId('tx-type')).toHaveTextContent('testType');
|
||||||
expect(screen.getByTestId('tx-block')).toHaveTextContent('1');
|
expect(screen.getByTestId('tx-block')).toHaveTextContent('1');
|
||||||
|
expect(screen.getByTestId('tx-time')).toHaveTextContent('-');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders data correctly', () => {
|
||||||
|
render(
|
||||||
|
<MockedProvider>
|
||||||
|
<MemoryRouter>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<TxsInfiniteListItem
|
||||||
|
type="testType"
|
||||||
|
submitter="testPubKey"
|
||||||
|
hash="testTxHash"
|
||||||
|
block="1"
|
||||||
|
code={0}
|
||||||
|
command={{}}
|
||||||
|
createdAt="1970-11-01T18:07:15Z"
|
||||||
|
/>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</MemoryRouter>
|
||||||
|
</MockedProvider>
|
||||||
|
);
|
||||||
|
expect(screen.getByTestId('tx-hash')).toHaveTextContent('testTxHash');
|
||||||
|
expect(screen.getByTestId('pub-key')).toHaveTextContent('testPubKey');
|
||||||
|
expect(screen.getByTestId('tx-type')).toHaveTextContent('testType');
|
||||||
|
expect(screen.getByTestId('tx-block')).toHaveTextContent('1');
|
||||||
|
expect(screen.getByTestId('tx-time').textContent).toMatch(/years ago/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -9,6 +9,7 @@ import { PartyLink } from '../links';
|
|||||||
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
||||||
import type { Screen } from '@vegaprotocol/react-helpers';
|
import type { Screen } from '@vegaprotocol/react-helpers';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
import { TimeAgo } from '../time-ago';
|
||||||
|
|
||||||
const DEFAULT_TRUNCATE_LENGTH = 7;
|
const DEFAULT_TRUNCATE_LENGTH = 7;
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ export const TxsInfiniteListItem = ({
|
|||||||
type,
|
type,
|
||||||
block,
|
block,
|
||||||
command,
|
command,
|
||||||
|
createdAt,
|
||||||
}: Partial<BlockExplorerTransactionResult>) => {
|
}: Partial<BlockExplorerTransactionResult>) => {
|
||||||
const { screenSize } = useScreenDimensions();
|
const { screenSize } = useScreenDimensions();
|
||||||
const idTruncateLength = useMemo(
|
const idTruncateLength = useMemo(
|
||||||
@ -85,6 +87,11 @@ export const TxsInfiniteListItem = ({
|
|||||||
endChars={5}
|
endChars={5}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
|
{['lg', 'xl', 'xxl', 'xxxl'].includes(screenSize) && (
|
||||||
|
<td className="text-sm items-center font-mono" data-testid="tx-time">
|
||||||
|
{createdAt ? <TimeAgo date={createdAt} /> : '-'}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@ import { TxsInfiniteListItem } from './txs-infinite-list-item';
|
|||||||
import type { BlockExplorerTransactionResult } from '../../routes/types/block-explorer-response';
|
import type { BlockExplorerTransactionResult } from '../../routes/types/block-explorer-response';
|
||||||
import EmptyList from '../empty-list/empty-list';
|
import EmptyList from '../empty-list/empty-list';
|
||||||
import { Loader } from '@vegaprotocol/ui-toolkit';
|
import { Loader } from '@vegaprotocol/ui-toolkit';
|
||||||
|
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
||||||
|
|
||||||
interface TxsInfiniteListProps {
|
interface TxsInfiniteListProps {
|
||||||
hasMoreTxs: boolean;
|
hasMoreTxs: boolean;
|
||||||
@ -19,7 +20,16 @@ interface ItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Item = ({ tx }: ItemProps) => {
|
const Item = ({ tx }: ItemProps) => {
|
||||||
const { hash, submitter, type, command, block, code, index: blockIndex } = tx;
|
const {
|
||||||
|
hash,
|
||||||
|
submitter,
|
||||||
|
type,
|
||||||
|
command,
|
||||||
|
block,
|
||||||
|
code,
|
||||||
|
createdAt,
|
||||||
|
index: blockIndex,
|
||||||
|
} = tx;
|
||||||
return (
|
return (
|
||||||
<TxsInfiniteListItem
|
<TxsInfiniteListItem
|
||||||
type={type}
|
type={type}
|
||||||
@ -29,6 +39,7 @@ const Item = ({ tx }: ItemProps) => {
|
|||||||
hash={hash}
|
hash={hash}
|
||||||
block={block}
|
block={block}
|
||||||
index={blockIndex}
|
index={blockIndex}
|
||||||
|
createdAt={createdAt}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -39,6 +50,7 @@ export const TxsInfiniteList = ({
|
|||||||
className,
|
className,
|
||||||
hasFilters = false,
|
hasFilters = false,
|
||||||
}: TxsInfiniteListProps) => {
|
}: TxsInfiniteListProps) => {
|
||||||
|
const { screenSize } = useScreenDimensions();
|
||||||
if (!txs || txs.length === 0) {
|
if (!txs || txs.length === 0) {
|
||||||
if (!areTxsLoading) {
|
if (!areTxsLoading) {
|
||||||
return (
|
return (
|
||||||
@ -66,6 +78,9 @@ export const TxsInfiniteList = ({
|
|||||||
<th>{t('Type')}</th>
|
<th>{t('Type')}</th>
|
||||||
<th className="text-left">{t('From')}</th>
|
<th className="text-left">{t('From')}</th>
|
||||||
<th>{t('Block')}</th>
|
<th>{t('Block')}</th>
|
||||||
|
{['lg', 'xl', 'xxl', 'xxxl'].includes(screenSize) && (
|
||||||
|
<th>{t('Time')}</th>
|
||||||
|
)}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -14,6 +14,10 @@ export interface BlockExplorerTransactionResult {
|
|||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
error?: string;
|
error?: string;
|
||||||
|
// These aren't strictly optional but are new in 0.73.0 so we need to make them optional
|
||||||
|
createdAt?: string;
|
||||||
|
version?: string;
|
||||||
|
pow?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BlockExplorerTransactions {
|
export interface BlockExplorerTransactions {
|
||||||
|
Loading…
Reference in New Issue
Block a user