-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1552 from oasisprotocol/mz/consensusEvents
Prepare components and API for Consensus events sections
- Loading branch information
Showing
11 changed files
with
268 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Prepare components and API for Consensus events sections |
37 changes: 37 additions & 0 deletions
37
src/app/components/ConsensusEvents/ConsensusEventDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { ConsensusEvent } from '../../../oasis-nexus/api' | ||
import { SearchScope } from '../../../types/searchScope' | ||
import { TransactionLink } from '../Transactions/TransactionLink' | ||
|
||
const ConsensusEventDetailsContent: FC<{ | ||
event: ConsensusEvent | ||
}> = ({ event }) => { | ||
// TODO: Handle specific event types. Implement new UI or re-use layout used in runtimes | ||
return ( | ||
<div> | ||
<b>{event.type}</b> | ||
<br /> | ||
<pre>{JSON.stringify(event, null, ' ')}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export const ConsensusEventDetails: FC<{ | ||
scope: SearchScope | ||
event: ConsensusEvent | ||
showTxHash: boolean | ||
}> = ({ scope, event, showTxHash }) => { | ||
const { t } = useTranslation() | ||
return ( | ||
<div> | ||
<ConsensusEventDetailsContent event={event} /> | ||
{showTxHash && event.tx_hash && ( | ||
<p> | ||
{t('event.fields.emittingTransaction')}:{' '} | ||
<TransactionLink scope={scope} alwaysTrim hash={event.tx_hash} /> | ||
</p> | ||
)} | ||
</div> | ||
) | ||
} |
38 changes: 36 additions & 2 deletions
38
src/app/components/ConsensusEvents/ConsensusEventsList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,39 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import Box from '@mui/material/Box' | ||
import Divider from '@mui/material/Divider' | ||
import { SearchScope } from '../../../types/searchScope' | ||
import { ConsensusEvent } from '../../../oasis-nexus/api' | ||
import { TablePagination, TablePaginationProps } from '../Table/TablePagination' | ||
import { CardEmptyState } from '../CardEmptyState' | ||
import { TextSkeleton } from '../Skeleton' | ||
import { ConsensusEventDetails } from './ConsensusEventDetails' | ||
|
||
export const ConsensusEventsList: FC = () => { | ||
return <>{/* TODO: waits for new designs */}</> | ||
export const ConsensusEventsList: FC<{ | ||
scope: SearchScope | ||
events: ConsensusEvent[] | undefined | ||
isLoading: boolean | ||
isError: boolean | ||
pagination: false | TablePaginationProps | ||
showTxHash: boolean | ||
}> = ({ scope, events, isLoading, isError, pagination, showTxHash }) => { | ||
const { t } = useTranslation() | ||
return ( | ||
<> | ||
{isError && <CardEmptyState label={t('event.cantLoadEvents')} />} | ||
{isLoading && <TextSkeleton numberOfRows={10} />} | ||
{events && | ||
events.map((event, index) => ( | ||
<div key={`event-${index}`}> | ||
{index > 0 && <Divider variant="card" />} | ||
<ConsensusEventDetails scope={scope} event={event} showTxHash={showTxHash} /> | ||
</div> | ||
))} | ||
{pagination && ( | ||
<Box sx={{ display: 'flex', justifyContent: 'center' }}> | ||
<TablePagination {...pagination} /> | ||
</Box> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 43 additions & 3 deletions
46
src/app/components/Transactions/ConsensusTransactionEvents.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
import { FC } from 'react' | ||
import { Transaction } from '../../../oasis-nexus/api' | ||
import { useTranslation } from 'react-i18next' | ||
import { Transaction, useGetConsensusEvents } from '../../../oasis-nexus/api' | ||
import { AppErrors } from '../../../types/errors' | ||
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config' | ||
import { ConsensusEventsList } from '../ConsensusEvents/ConsensusEventsList' | ||
import { useSearchParamsPagination } from '../Table/useSearchParamsPagination' | ||
import { EmptyState } from '../EmptyState' | ||
|
||
export const ConsensusTransactionEvents: FC<{ | ||
transaction: Transaction | ||
}> = () => { | ||
return <ConsensusEventsList /> | ||
}> = ({ transaction }) => { | ||
const { t } = useTranslation() | ||
const pagination = useSearchParamsPagination('page') | ||
const offset = (pagination.selectedPage - 1) * limit | ||
const eventsQuery = useGetConsensusEvents(transaction.network, { | ||
tx_hash: transaction.hash, | ||
limit, | ||
offset, | ||
}) | ||
const { isFetched, isLoading, data, isError } = eventsQuery | ||
const events = data?.data.events | ||
if (isFetched && pagination.selectedPage > 1 && !events?.length) { | ||
throw AppErrors.PageDoesNotExist | ||
} | ||
|
||
if (!events?.length && isFetched) { | ||
return ( | ||
<EmptyState description={t('event.cantFindMatchingEvents')} title={t('event.noEvents')} light={true} /> | ||
) | ||
} | ||
|
||
return ( | ||
<ConsensusEventsList | ||
scope={transaction} | ||
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={false} | ||
/> | ||
) | ||
} |
52 changes: 49 additions & 3 deletions
52
src/app/pages/ConsensusAccountDetailsPage/ConsensusAccountEventsCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,63 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useGetConsensusEvents } from '../../../oasis-nexus/api' | ||
import { AppErrors } from '../../../types/errors' | ||
import { ConsensusEventsList } from '../../components/ConsensusEvents/ConsensusEventsList' | ||
import { ConsensusAccountDetailsContext } from './hooks' | ||
import { LinkableCardLayout } from 'app/components/LinkableCardLayout' | ||
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config' | ||
import { LinkableCardLayout } from '../../components/LinkableCardLayout' | ||
import { useSearchParamsPagination } from '../..//components/Table/useSearchParamsPagination' | ||
import { EmptyState } from '../../components/EmptyState' | ||
|
||
export const eventsContainerId = 'events' | ||
|
||
export const ConsensusAccountEventsCard: FC<ConsensusAccountDetailsContext> = () => { | ||
export const ConsensusAccountEventsList: FC<ConsensusAccountDetailsContext> = ({ scope, address }) => { | ||
const { t } = useTranslation() | ||
const pagination = useSearchParamsPagination('page') | ||
const offset = (pagination.selectedPage - 1) * limit | ||
const eventsQuery = useGetConsensusEvents(scope.network, { | ||
rel: address, | ||
limit, | ||
offset, | ||
}) | ||
const { isFetched, isLoading, data, isError } = eventsQuery | ||
const events = data?.data.events | ||
if (isFetched && pagination.selectedPage > 1 && !events?.length) { | ||
throw AppErrors.PageDoesNotExist | ||
} | ||
|
||
if (!events?.length && isFetched) { | ||
return ( | ||
<EmptyState description={t('event.cantFindMatchingEvents')} title={t('event.noEvents')} light={true} /> | ||
) | ||
} | ||
|
||
return ( | ||
<LinkableCardLayout containerId={eventsContainerId} title={t('common.events')}> | ||
<ConsensusEventsList | ||
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 | ||
/> | ||
</LinkableCardLayout> | ||
) | ||
} | ||
|
||
export const ConsensusAccountEventsCard: FC<ConsensusAccountDetailsContext> = ({ scope, address }) => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<LinkableCardLayout containerId={eventsContainerId} title={t('common.events')}> | ||
<ConsensusEventsList /> | ||
<ConsensusAccountEventsList scope={scope} address={address} /> | ||
</LinkableCardLayout> | ||
) | ||
} |
54 changes: 50 additions & 4 deletions
54
src/app/pages/ConsensusBlockDetailPage/ConsensusBlockEventsCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,63 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { ConsensusEventsList } from '../../components/ConsensusEvents/ConsensusEventsList' | ||
import { useGetConsensusEvents } from '../../../oasis-nexus/api' | ||
import { AppErrors } from '../../../types/errors' | ||
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config' | ||
import { LinkableCardLayout } from '../../components/LinkableCardLayout' | ||
import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination' | ||
import { EmptyState } from '../../components/EmptyState' | ||
import { ConsensusBlockDetailsContext } from '.' | ||
import { LinkableCardLayout } from 'app/components/LinkableCardLayout' | ||
import { ConsensusEventsList } from '../../components/ConsensusEvents/ConsensusEventsList' | ||
|
||
export const eventsContainerId = 'events' | ||
|
||
export const ConsensusBlockEventsCard: FC<ConsensusBlockDetailsContext> = () => { | ||
const ConsensusBlockEventsList: FC<ConsensusBlockDetailsContext> = ({ scope, blockHeight }) => { | ||
const { t } = useTranslation() | ||
const pagination = useSearchParamsPagination('page') | ||
const offset = (pagination.selectedPage - 1) * limit | ||
const eventsQuery = useGetConsensusEvents(scope.network, { | ||
block: blockHeight, | ||
limit, | ||
offset, | ||
}) | ||
const { isFetched, isLoading, data, isError } = eventsQuery | ||
const events = data?.data.events | ||
if (isFetched && pagination.selectedPage > 1 && !events?.length) { | ||
throw AppErrors.PageDoesNotExist | ||
} | ||
|
||
if (!events?.length && isFetched) { | ||
return ( | ||
<EmptyState description={t('event.cantFindMatchingEvents')} title={t('event.noEvents')} light={true} /> | ||
) | ||
} | ||
|
||
return ( | ||
<LinkableCardLayout containerId={eventsContainerId} title={t('common.events')}> | ||
<ConsensusEventsList | ||
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 | ||
/> | ||
</LinkableCardLayout> | ||
) | ||
} | ||
|
||
export const ConsensusBlockEventsCard: FC<ConsensusBlockDetailsContext> = ({ scope, blockHeight }) => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<LinkableCardLayout containerId={eventsContainerId} title={t('common.events')}> | ||
<ConsensusEventsList /> | ||
<ConsensusBlockEventsList scope={scope} blockHeight={blockHeight} /> | ||
</LinkableCardLayout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters