-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathRuntimeBlockEventsCard.tsx
More file actions
65 lines (58 loc) · 2.13 KB
/
RuntimeBlockEventsCard.tsx
File metadata and controls
65 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { Layer, useGetRuntimeEvents } from '../../../oasis-nexus/api'
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config'
import { LinkableCardLayout } from '../../components/LinkableCardLayout'
import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination'
import { AppErrors } from '../../../types/errors'
import { RuntimeEventsDetailedList } from '../../components/RuntimeEvents/RuntimeEventsDetailedList'
import { RuntimeBlockDetailsContext } from '.'
import { eventsContainerId } from '../../utils/tabAnchors'
import { CardEmptyState } from 'app/components/CardEmptyState'
const EventsList: FC<RuntimeBlockDetailsContext> = ({ scope, blockHeight }) => {
const { t } = useTranslation()
const pagination = useSearchParamsPagination('page')
const offset = (pagination.selectedPage - 1) * limit
if (scope.layer === Layer.consensus) {
// Loading events for consensus blocks is not yet supported.
// Should use useGetConsensusEvents()
throw AppErrors.UnsupportedLayer
}
const eventsQuery = useGetRuntimeEvents(scope.network, scope.layer, {
block: blockHeight,
// TODO: search for tx_hash = null
limit,
offset,
})
const { isLoading, isError, data } = eventsQuery
const events = data?.data.events
if (!events?.length && !isLoading) {
return <CardEmptyState label={t('event.cantFindMatchingEvents')} />
}
return (
<RuntimeEventsDetailedList
scope={scope}
events={events}
isLoading={isLoading}
isError={isError}
pagination={{
selectedPage: pagination.selectedPage,
linkToPage: pagination.linkToPage,
totalCount: data?.data.total_count,
isTotalCountClipped: data?.data.is_total_count_clipped,
rowsPerPage: limit,
}}
showTxHash
/>
)
}
export const RuntimeBlockEventsCard: FC<RuntimeBlockDetailsContext> = props => {
if (!props.blockHeight) {
return null
}
return (
<LinkableCardLayout containerId={eventsContainerId} title="">
<EventsList {...props} />
</LinkableCardLayout>
)
}