|
| 1 | +import { FC } from 'react' |
| 2 | +import { Link as RouterLink } from 'react-router-dom' |
| 3 | +import { useTranslation } from 'react-i18next' |
| 4 | +import { Link } from '@oasisprotocol/ui-library/src/components/link' |
| 5 | +import { RecentBlock } from '../../../oasis-nexus/api' |
| 6 | +import { useScreenSize } from '../../hooks/useScreensize' |
| 7 | +import { getLayerLabels } from '../../utils/content' |
| 8 | +import { RouteUtils } from '../../utils/route-utils' |
| 9 | +import { Table, TableCellAlign, TableColProps } from '../Table' |
| 10 | +import { TableCellAge } from '../TableCellAge' |
| 11 | +import { TableHeaderAge } from '../TableHeaderAge' |
| 12 | +import { BlockHashLink, BlockLink } from './BlockLink' |
| 13 | + |
| 14 | +export type TableBlockList = { |
| 15 | + blocks: RecentBlock[] |
| 16 | + total_count: number |
| 17 | + is_total_count_clipped: boolean |
| 18 | +} |
| 19 | + |
| 20 | +type RecentBlocksProps = { |
| 21 | + blocks?: RecentBlock[] |
| 22 | + isLoading: boolean |
| 23 | + limit: number |
| 24 | +} |
| 25 | + |
| 26 | +export const RecentBlocks: FC<RecentBlocksProps> = ({ isLoading, blocks, limit }) => { |
| 27 | + const { t } = useTranslation() |
| 28 | + const { isLaptop } = useScreenSize() |
| 29 | + const layerLabels = getLayerLabels(t) |
| 30 | + const tableColumns: TableColProps[] = [ |
| 31 | + { key: 'layer', content: t('common.layer') }, |
| 32 | + { key: 'height', content: t('common.height') }, |
| 33 | + { |
| 34 | + key: 'hash', |
| 35 | + content: t('common.hash'), |
| 36 | + }, |
| 37 | + { key: 'age', content: <TableHeaderAge />, align: TableCellAlign.Right }, |
| 38 | + { |
| 39 | + key: 'transaction', |
| 40 | + content: isLaptop ? t('common.transactionAbbreviation') : t('common.transactions'), |
| 41 | + align: TableCellAlign.Right, |
| 42 | + }, |
| 43 | + ] |
| 44 | + |
| 45 | + const tableRows = blocks?.map(block => { |
| 46 | + return { |
| 47 | + key: block.hash, |
| 48 | + data: [ |
| 49 | + { |
| 50 | + content: ( |
| 51 | + <Link asChild className="font-medium"> |
| 52 | + <RouterLink to={RouteUtils.getDashboardRoute({ layer: block.layer, network: block.network })}> |
| 53 | + {layerLabels[block.layer]} |
| 54 | + </RouterLink> |
| 55 | + </Link> |
| 56 | + ), |
| 57 | + key: 'layer', |
| 58 | + }, |
| 59 | + |
| 60 | + { |
| 61 | + content: <BlockLink scope={{ network: block.network, layer: block.layer }} height={block.height} />, |
| 62 | + key: 'block', |
| 63 | + }, |
| 64 | + { |
| 65 | + content: ( |
| 66 | + <BlockHashLink |
| 67 | + scope={{ network: block.network, layer: block.layer }} |
| 68 | + hash={block.hash} |
| 69 | + height={block.height} |
| 70 | + alwaysTrim |
| 71 | + /> |
| 72 | + ), |
| 73 | + key: 'hash', |
| 74 | + }, |
| 75 | + { |
| 76 | + align: TableCellAlign.Right, |
| 77 | + content: <TableCellAge sinceTimestamp={block.timestamp} />, |
| 78 | + key: 'timestamp', |
| 79 | + }, |
| 80 | + { |
| 81 | + align: TableCellAlign.Right, |
| 82 | + content: block.num_transactions.toLocaleString(), |
| 83 | + key: 'txs', |
| 84 | + }, |
| 85 | + ], |
| 86 | + } |
| 87 | + }) |
| 88 | + |
| 89 | + return ( |
| 90 | + <Table |
| 91 | + columns={tableColumns} |
| 92 | + rows={tableRows} |
| 93 | + rowsNumber={limit} |
| 94 | + name={t('blocks.latest')} |
| 95 | + isLoading={isLoading} |
| 96 | + pagination={false} |
| 97 | + /> |
| 98 | + ) |
| 99 | +} |
0 commit comments