-
Notifications
You must be signed in to change notification settings - Fork 12
Show runtime account delegations #2288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| Show runtime account delegations |
21 changes: 21 additions & 0 deletions
21
src/app/pages/RuntimeAccountDetailsPage/AccountCardEmptyState.tsx
This file contains hidden or 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,21 @@ | ||
| import { FC, ReactNode } from 'react' | ||
| import { Typography } from '@oasisprotocol/ui-library/src/components/typography' | ||
| import StackedBarChartIcon from '@mui/icons-material/StackedBarChart' | ||
| import { COLORS } from '../../../styles/theme/colors' | ||
|
|
||
| type AccountCardEmptyStateProps = { | ||
| children?: ReactNode | ||
| label: string | ||
| } | ||
|
|
||
| export const AccountCardEmptyState: FC<AccountCardEmptyStateProps> = ({ children, label }) => { | ||
| return ( | ||
| <div className="flex flex-col justify-center items-center gap-2 text-center pt-1 pb-2"> | ||
| <StackedBarChartIcon sx={{ color: COLORS.grayMedium, fontSize: 40, opacity: 0.5 }} /> | ||
| <Typography textColor="muted" className="font-semibold text-center"> | ||
| {label} | ||
| </Typography> | ||
| {children} | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or 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,155 @@ | ||
| import { FC } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
| import { Card, CardContent, CardHeader, CardTitle } from '@oasisprotocol/ui-library/src/components/cards' | ||
| import Link from '@mui/material/Link' | ||
| import { Skeleton } from '@oasisprotocol/ui-library/src/components/ui/skeleton' | ||
| import { Tabs, TabsContent, TabsList, TabsTrigger } from '@oasisprotocol/ui-library/src/components/tabs' | ||
| import { | ||
| Runtime, | ||
| RuntimeAccount, | ||
| useGetRuntimeAccountsAddressDebondingDelegations, | ||
| useGetRuntimeAccountsAddressDelegations, | ||
| } from '../../../oasis-nexus/api' | ||
| import { useRequiredScopeParam } from '../../../app/hooks/useScopeParam' | ||
| import { AppErrors } from '../../../types/errors' | ||
| import { NUMBER_OF_ITEMS_ON_DASHBOARD as PAGE_SIZE } from '../../../config' | ||
| import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination' | ||
| import { Delegations } from '../../components/Delegations' | ||
| import { dapps } from '../../utils/externalLinks' | ||
| import { t } from 'i18next' | ||
| import { AccountCardEmptyState } from './AccountCardEmptyState' | ||
| import { Typography } from '@oasisprotocol/ui-library/src/components/typography' | ||
|
|
||
| type StakingProps = { | ||
| account: RuntimeAccount | undefined | ||
| isLoading: boolean | ||
| } | ||
|
|
||
| export const Staking: FC<StakingProps> = ({ account, isLoading }) => { | ||
| const { t } = useTranslation() | ||
|
|
||
| return ( | ||
| <Card variant="layout"> | ||
| <CardHeader> | ||
| <CardTitle> | ||
| <Typography variant="h3">{t('stakingOverview')}</Typography> | ||
| </CardTitle> | ||
| </CardHeader> | ||
| <CardContent> | ||
| <Tabs defaultValue="staked" aria-label={t('validator.delegations')}> | ||
| <TabsList variant="layout" className="md:max-w-[400px] rounded-b-md mb-2"> | ||
| <TabsTrigger value="staked">{t('common.staked')}</TabsTrigger> | ||
| <TabsTrigger value="debonding">{t('common.debonding')}</TabsTrigger> | ||
| </TabsList> | ||
| {isLoading && <Skeleton className="h-[200px] mt-8" />} | ||
| {!isLoading && account && ( | ||
| <> | ||
| <TabsContent value="staked" className="min-h-28"> | ||
| <ActiveDelegations address={account?.address} /> | ||
| </TabsContent> | ||
| <TabsContent value="debonding" className="min-h-28"> | ||
| <DebondingDelegations address={account?.address} /> | ||
| </TabsContent> | ||
| </> | ||
| )} | ||
| </Tabs> | ||
| </CardContent> | ||
| </Card> | ||
| ) | ||
| } | ||
|
|
||
| type DelegationCardProps = { | ||
| address: string | ||
| } | ||
|
|
||
| const ActiveDelegations: FC<DelegationCardProps> = ({ address }) => { | ||
| const pagination = useSearchParamsPagination('activeDelegations') | ||
| const offset = (pagination.selectedPage - 1) * PAGE_SIZE | ||
| const scope = useRequiredScopeParam() | ||
| const { network } = scope | ||
| const delegationsQuery = useGetRuntimeAccountsAddressDelegations(network, scope.layer as Runtime, address, { | ||
| limit: PAGE_SIZE, | ||
| offset, | ||
| }) | ||
| const { isLoading, isFetched, data } = delegationsQuery | ||
| if (isFetched && offset && !delegationsQuery.data?.data?.delegations?.length) { | ||
| throw AppErrors.PageDoesNotExist | ||
| } | ||
|
|
||
| if (isFetched && !delegationsQuery.data?.data.delegations.length) { | ||
| return ( | ||
| <AccountCardEmptyState label={t('account.notStaking')}> | ||
| <Link href={dapps.stake} rel="noopener noreferrer" target="_blank"> | ||
| {t('account.startStaking')} | ||
| </Link> | ||
| </AccountCardEmptyState> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {isFetched && ( | ||
| <Delegations | ||
| delegations={delegationsQuery.data?.data.delegations} | ||
| isLoading={isLoading} | ||
| limit={PAGE_SIZE} | ||
| linkType="validator" | ||
| pagination={{ | ||
| className: 'mt-2', | ||
| selectedPage: pagination.selectedPage, | ||
| linkToPage: pagination.linkToPage, | ||
| totalCount: data?.data.total_count, | ||
| isTotalCountClipped: data?.data.is_total_count_clipped, | ||
| rowsPerPage: PAGE_SIZE, | ||
| }} | ||
| /> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| const DebondingDelegations: FC<DelegationCardProps> = ({ address }) => { | ||
| const pagination = useSearchParamsPagination('debondingDelegations') | ||
| const offset = (pagination.selectedPage - 1) * PAGE_SIZE | ||
| const scope = useRequiredScopeParam() | ||
| const { network } = scope | ||
| const delegationsQuery = useGetRuntimeAccountsAddressDebondingDelegations( | ||
| network, | ||
| scope.layer as Runtime, | ||
| address, | ||
| { | ||
| limit: PAGE_SIZE, | ||
| offset, | ||
| }, | ||
| ) | ||
| const { isLoading, isFetched, data } = delegationsQuery | ||
| if (isFetched && offset && !delegationsQuery.data?.data?.debonding_delegations?.length) { | ||
| throw AppErrors.PageDoesNotExist | ||
| } | ||
|
|
||
| if (isFetched && !delegationsQuery.data?.data.debonding_delegations.length) { | ||
| return <AccountCardEmptyState label={t('account.notDebonding')} /> | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {isFetched && ( | ||
| <Delegations | ||
| debonding | ||
| delegations={delegationsQuery.data?.data.debonding_delegations} | ||
| isLoading={isLoading} | ||
| limit={PAGE_SIZE} | ||
| linkType="validator" | ||
| pagination={{ | ||
| className: 'mt-2', | ||
| selectedPage: pagination.selectedPage, | ||
| linkToPage: pagination.linkToPage, | ||
| totalCount: data?.data.total_count, | ||
| isTotalCountClipped: data?.data.is_total_count_clipped, | ||
| rowsPerPage: PAGE_SIZE, | ||
| }} | ||
| /> | ||
| )} | ||
| </> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Total delegated/undelegated balance are not shown. Is that planned as a separate PR, or did some commits get lost?

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not part of this PR. Other than that we probably need to adjust API endpoints first
https://nexus.oasis.io/v1/spec/v1.html#/paths/~1consensus~1accounts~1%7Baddress%7D/get
vs
https://nexus.oasis.io/v1/spec/v1.html#/paths/~1%7Bruntime%7D~1accounts~1%7Baddress%7D/get