-
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 #1310 from oasisprotocol/mz/consensusValidatorTabs
Validator delegators and debonding delegations cards
- Loading branch information
Showing
10 changed files
with
314 additions
and
19 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 @@ | ||
Add validator delegators and debonding delegations cards |
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
93 changes: 93 additions & 0 deletions
93
src/app/pages/ValidatorDetailsPage/DebondingDelegationsCard.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,93 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import Card from '@mui/material/Card' | ||
import CardHeader from '@mui/material/CardHeader' | ||
import CardContent from '@mui/material/CardContent' | ||
import { | ||
DebondingDelegation, | ||
useGetConsensusAccountsAddressDebondingDelegationsTo, | ||
} from '../../../oasis-nexus/api' | ||
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config' | ||
import { ErrorBoundary } from '../../components/ErrorBoundary' | ||
import { LinkableDiv } from '../../components/PageLayout/LinkableDiv' | ||
import { CardEmptyState } from '../../components/CardEmptyState' | ||
import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination' | ||
import { Delegations } from '../../components/Delegations' | ||
import { ValidatorDetailsContext } from './hooks' | ||
import { debondingContainerId } from './tabAnchors' | ||
import { SimplePaginationEngine } from 'app/components/Table/PaginationEngine' | ||
|
||
export const DebondingDelegationsCard: FC<ValidatorDetailsContext> = ({ scope, address }) => { | ||
const { t } = useTranslation() | ||
const { network } = scope | ||
const pagination = useSearchParamsPagination('page') | ||
const offset = (pagination.selectedPage - 1) * limit | ||
const debondingQuery = useGetConsensusAccountsAddressDebondingDelegationsTo(network, address, { | ||
limit, | ||
offset, | ||
}) | ||
const { isFetched, isLoading, data } = debondingQuery | ||
const debondingDelegations = data?.data.debonding_delegations | ||
|
||
return ( | ||
<Card> | ||
<LinkableDiv id={debondingContainerId}> | ||
<CardHeader disableTypography component="h3" title={t('validator.undelegations')} /> | ||
</LinkableDiv> | ||
<CardContent> | ||
<ErrorBoundary light={true}> | ||
<DebondingDelegationsView | ||
debondingDelegations={debondingDelegations} | ||
isFetched={isFetched} | ||
isLoading={isLoading} | ||
pagination={{ | ||
...pagination, | ||
isTotalCountClipped: data?.data.is_total_count_clipped, | ||
totalCount: data?.data.total_count, | ||
}} | ||
/> | ||
</ErrorBoundary> | ||
</CardContent> | ||
</Card> | ||
) | ||
} | ||
|
||
type DebondingDelegationsViewProps = { | ||
debondingDelegations: DebondingDelegation[] | undefined | ||
isFetched: boolean | ||
isLoading: boolean | ||
pagination: SimplePaginationEngine & { | ||
isTotalCountClipped: boolean | undefined | ||
totalCount: number | undefined | ||
} | ||
} | ||
|
||
const DebondingDelegationsView: FC<DebondingDelegationsViewProps> = ({ | ||
debondingDelegations, | ||
isFetched, | ||
isLoading, | ||
pagination, | ||
}) => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<> | ||
{isFetched && !debondingDelegations?.length && ( | ||
<CardEmptyState label={t('validator.emptyDebondingList')} /> | ||
)} | ||
<Delegations | ||
debonding | ||
delegations={debondingDelegations} | ||
isLoading={isLoading} | ||
limit={limit} | ||
pagination={{ | ||
selectedPage: pagination.selectedPage, | ||
linkToPage: pagination.linkToPage, | ||
totalCount: pagination.totalCount, | ||
isTotalCountClipped: pagination.isTotalCountClipped, | ||
rowsPerPage: limit, | ||
}} | ||
/> | ||
</> | ||
) | ||
} |
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,82 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import Card from '@mui/material/Card' | ||
import CardHeader from '@mui/material/CardHeader' | ||
import CardContent from '@mui/material/CardContent' | ||
import { Delegation, useGetConsensusAccountsAddressDelegationsTo } from '../../../oasis-nexus/api' | ||
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config' | ||
import { ErrorBoundary } from '../../components/ErrorBoundary' | ||
import { LinkableDiv } from '../../components/PageLayout/LinkableDiv' | ||
import { CardEmptyState } from '../../components/CardEmptyState' | ||
import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination' | ||
import { Delegations } from '../../components/Delegations' | ||
import { ValidatorDetailsContext } from './hooks' | ||
import { delegatorsContainerId } from './tabAnchors' | ||
import { SimplePaginationEngine } from 'app/components/Table/PaginationEngine' | ||
|
||
export const DelegatorsCard: FC<ValidatorDetailsContext> = ({ scope, address }) => { | ||
const { t } = useTranslation() | ||
const { network } = scope | ||
const pagination = useSearchParamsPagination('page') | ||
const offset = (pagination.selectedPage - 1) * limit | ||
const delegationsQuery = useGetConsensusAccountsAddressDelegationsTo(network, address, { | ||
limit, | ||
offset, | ||
}) | ||
const { isFetched, isLoading, data } = delegationsQuery | ||
const delegations = data?.data.delegations | ||
|
||
return ( | ||
<Card> | ||
<LinkableDiv id={delegatorsContainerId}> | ||
<CardHeader disableTypography component="h3" title={t('validator.delegators')} /> | ||
</LinkableDiv> | ||
<CardContent> | ||
<ErrorBoundary light={true}> | ||
<DelegatorsCardView | ||
delegations={delegations} | ||
isFetched={isFetched} | ||
isLoading={isLoading} | ||
pagination={{ | ||
...pagination, | ||
isTotalCountClipped: data?.data.is_total_count_clipped, | ||
totalCount: data?.data.total_count, | ||
}} | ||
/> | ||
</ErrorBoundary> | ||
</CardContent> | ||
</Card> | ||
) | ||
} | ||
|
||
type DelegatorsViewProps = { | ||
delegations: Delegation[] | undefined | ||
isFetched: boolean | ||
isLoading: boolean | ||
pagination: SimplePaginationEngine & { | ||
isTotalCountClipped: boolean | undefined | ||
totalCount: number | undefined | ||
} | ||
} | ||
|
||
const DelegatorsCardView: FC<DelegatorsViewProps> = ({ delegations, isFetched, isLoading, pagination }) => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<> | ||
{isFetched && !delegations?.length && <CardEmptyState label={t('validator.emptyDelegationsList')} />} | ||
<Delegations | ||
delegations={delegations} | ||
isLoading={isLoading} | ||
limit={limit} | ||
pagination={{ | ||
selectedPage: pagination.selectedPage, | ||
linkToPage: pagination.linkToPage, | ||
totalCount: pagination.totalCount, | ||
isTotalCountClipped: pagination.isTotalCountClipped, | ||
rowsPerPage: limit, | ||
}} | ||
/> | ||
</> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const delegatorsContainerId = 'delegators' | ||
export const debondingContainerId = 'debonding' |
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
Oops, something went wrong.