Files
explore/ui/verifiedContracts/VerifiedContractsTable.tsx
tom goriunovandGitHub f982eb07a0 Time format toggle for table views (#2729)
* cookie for storing time format value

* rename TimeAgo component

* add toggle to tables (pt. 1)

* move TimeWithTooltip component

* add toggle to tables (pt. 2)

* change implementation of toggle component

* remove unnecessary timestamp label

* update screenshots

* more screenshot updates

* [skip ci] update clock icon

* update screenshots
2025-06-03 14:01:12 +02:00

75 lines
2.7 KiB
TypeScript

import React from 'react';
import type { VerifiedContract } from 'types/api/contracts';
import type { VerifiedContractsSortingField, VerifiedContractsSortingValue } from 'types/api/verifiedContracts';
import { currencyUnits } from 'lib/units';
import { TableBody, TableColumnHeader, TableColumnHeaderSortable, TableHeaderSticky, TableRoot, TableRow } from 'toolkit/chakra/table';
import { ACTION_BAR_HEIGHT_DESKTOP } from 'ui/shared/ActionBar';
import getNextSortValue from 'ui/shared/sort/getNextSortValue';
import TimeFormatToggle from 'ui/shared/time/TimeFormatToggle';
import { SORT_SEQUENCE } from 'ui/verifiedContracts/utils';
import VerifiedContractsTableItem from './VerifiedContractsTableItem';
interface Props {
data: Array<VerifiedContract>;
sort: VerifiedContractsSortingValue;
setSorting: ({ value }: { value: Array<string> }) => void;
isLoading?: boolean;
}
const VerifiedContractsTable = ({ data, sort, setSorting, isLoading }: Props) => {
const onSortToggle = React.useCallback((field: VerifiedContractsSortingField) => {
const value = getNextSortValue<VerifiedContractsSortingField, VerifiedContractsSortingValue>(SORT_SEQUENCE, field)(sort);
setSorting({ value: [ value ] });
}, [ sort, setSorting ]);
return (
<TableRoot minW="1100px">
<TableHeaderSticky top={ ACTION_BAR_HEIGHT_DESKTOP }>
<TableRow>
<TableColumnHeader width="50%">Contract</TableColumnHeader>
<TableColumnHeaderSortable
width="130px"
isNumeric
sortField="balance"
sortValue={ sort }
onSortToggle={ onSortToggle }
disabled={ isLoading }
>
Balance { currencyUnits.ether }
</TableColumnHeaderSortable>
<TableColumnHeaderSortable
width="130px"
isNumeric
sortField="transactions_count"
sortValue={ sort }
onSortToggle={ onSortToggle }
disabled={ isLoading }
>
Txs
</TableColumnHeaderSortable>
<TableColumnHeader width="50%">Language / Compiler version</TableColumnHeader>
<TableColumnHeader width="80px">Settings</TableColumnHeader>
<TableColumnHeader width="200px">
Verified
<TimeFormatToggle/>
</TableColumnHeader>
<TableColumnHeader width="130px">License</TableColumnHeader>
</TableRow>
</TableHeaderSticky>
<TableBody>
{ data.map((item, index) => (
<VerifiedContractsTableItem
key={ item.address.hash + (isLoading ? index : '') }
data={ item }
isLoading={ isLoading }/>
)) }
</TableBody>
</TableRoot>
);
};
export default React.memo(VerifiedContractsTable);