-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.tsx
More file actions
73 lines (65 loc) · 2.69 KB
/
Copy pathindex.tsx
File metadata and controls
73 lines (65 loc) · 2.69 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
66
67
68
69
70
71
72
73
import { FC } from 'react'
import { Link as RouterLink, useSearchParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { PaginationNext, PaginationPrevious } from '@oasisprotocol/ui-library/src/components/pagination'
import { Tooltip } from '@oasisprotocol/ui-library/src/components/tooltip'
import { ConsensusScope, RuntimeScope, SearchScope } from '../../../types/searchScope'
import { useConsensusFreshness, useRuntimeFreshness } from '../OfflineBanner/hook'
import { RouteUtils } from '../../utils/route-utils'
import { TX_METHOD_QUERY_ARG_NAME } from '../../hooks/useCommonParams'
const PrevBlockButton: FC<{ scope: SearchScope; currentRound: number }> = ({ scope, currentRound }) => {
const { t } = useTranslation()
const [searchParams] = useSearchParams()
const disabled = currentRound === 0
return (
<Tooltip title={disabled ? t('blocks.viewingFirst') : t('blocks.viewPrevious')}>
<div className="ml-4">
<PaginationPrevious
linkComponent={RouterLink}
to={RouteUtils.getBlockRoute(scope, currentRound - 1, searchParams, [TX_METHOD_QUERY_ARG_NAME])}
disabled={disabled}
/>
</div>
</Tooltip>
)
}
export { PrevBlockButton as RuntimePrevBlockButton }
export { PrevBlockButton as ConsensusPrevBlockButton }
const NextBlockButton: FC<{ disabled: boolean; scope: SearchScope; currentRound: number }> = ({
currentRound,
disabled,
scope,
}) => {
const { t } = useTranslation()
const [searchParams] = useSearchParams()
return (
<Tooltip title={disabled ? t('blocks.viewingLatest') : t('blocks.viewNext')}>
<div>
<PaginationNext
linkComponent={RouterLink}
to={RouteUtils.getBlockRoute(scope, currentRound + 1, searchParams, [TX_METHOD_QUERY_ARG_NAME])}
disabled={disabled}
/>
</div>
</Tooltip>
)
}
type NextBlockButtonProps<Scope = SearchScope> = {
scope: Scope
currentRound: number
}
export const ConsensusNextBlockButton: FC<NextBlockButtonProps<ConsensusScope>> = ({
currentRound,
scope,
}) => {
const { latestBlock } = useConsensusFreshness(scope.network)
const disabled = !!latestBlock && currentRound >= latestBlock
useConsensusFreshness(scope.network, { polling: disabled })
return <NextBlockButton currentRound={currentRound} disabled={disabled} scope={scope} />
}
export const RuntimeNextBlockButton: FC<NextBlockButtonProps<RuntimeScope>> = ({ currentRound, scope }) => {
const { latestBlock } = useRuntimeFreshness(scope)
const disabled = !!latestBlock && currentRound >= latestBlock
useRuntimeFreshness(scope, { polling: disabled })
return <NextBlockButton currentRound={currentRound} disabled={disabled} scope={scope} />
}