Skip to content
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

Only show Delegations and Debonding tabs in account details #1946

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1946.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only show Delegations and Debonding tabs in account details
20 changes: 12 additions & 8 deletions src/app/pages/AccountPage/Features/AccountDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ import { useSelector } from 'react-redux'
import { SendTransaction } from '../SendTransaction'
import { TransactionHistory } from '../TransactionHistory'
import { selectIsAddressInWallet } from 'app/state/selectIsAddressInWallet'
import { AccountSubnavigation } from '../AccountSubnavigation'

interface Props {}

export const AccountDetails = memo((props: Props) => {
const isAddressInWallet = useSelector(selectIsAddressInWallet)

return (
<Box direction="row" wrap style={{ gap: '24px' }}>
{isAddressInWallet && (
<Box flex={{ grow: 1 }} basis="32ex" width={{ max: '100%' }}>
<SendTransaction isAddressInWallet={isAddressInWallet} />
<>
<AccountSubnavigation />
<Box direction="row" wrap style={{ gap: '24px' }}>
{isAddressInWallet && (
<Box flex={{ grow: 1 }} basis="32ex" width={{ max: '100%' }}>
<SendTransaction isAddressInWallet={isAddressInWallet} />
</Box>
)}
<Box flex={{ grow: 3 }} basis="80ex" width={{ max: '100%' }}>
<TransactionHistory />
</Box>
)}
<Box flex={{ grow: 3 }} basis="80ex" width={{ max: '100%' }}>
<TransactionHistory />
</Box>
</Box>
</>
)
})
87 changes: 87 additions & 0 deletions src/app/pages/AccountPage/Features/AccountSubnavigation/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { selectStaking } from 'app/state/staking/selectors'
import { Nav } from 'grommet/es6/components/Nav'
import { ResponsiveContext } from 'grommet/es6/contexts/ResponsiveContext'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'
import { NavLink, useParams } from 'react-router-dom'
import styled from 'styled-components'
import { normalizeColor } from 'grommet/es6/utils'

import { AccountPageParams } from '../../validateAccountPageRoute'
import { Button } from 'grommet/es6/components/Button'

const StyledNavItem = styled(NavLink)`
padding: ${({ theme }) => theme.global?.edgeSize?.small};

:hover {
background-color: ${({ theme }) => normalizeColor('background-contrast', theme)};
}

&.active {
background-color: ${({ theme }) => normalizeColor('background-back', theme)};
}

@media only screen and (max-width: ${({ theme }) => `${theme.global?.breakpoints?.small?.value}px`}) {
padding: ${({ theme }) => theme.global?.edgeSize?.xsmall};
}
`

interface NavItemProps {
counter?: number
label: string
route: string
}

const NavItem = ({ counter, label, route }: NavItemProps) => {
return (
<StyledNavItem end to={route}>
<Button badge={counter} tabIndex={-1}>
{label}
</Button>
</StyledNavItem>
)
}

export function AccountSubnavigation() {
const { t } = useTranslation()
const isMobile = React.useContext(ResponsiveContext) === 'small'
const address = useParams<keyof AccountPageParams>().address!
const stake = useSelector(selectStaking)

return (
<Nav
background="background-front"
justify={isMobile ? 'evenly' : 'start'}
margin={{ bottom: 'small' }}
direction="row"
gap="none"
wrap
>
<NavItem
label={t('account.subnavigation.transactions', 'Transactions')}
route={`/account/${address}`}
/>

<NavItem
counter={stake.delegations?.length}
label={
isMobile
? t('account.subnavigation.mobileActiveDelegations', 'Delegations')
: t('account.subnavigation.activeDelegations', 'Active delegations')
}
route={`/account/${address}/active-delegations`}
/>

<NavItem
counter={stake.debondingDelegations?.length}
label={
isMobile
? t('account.subnavigation.mobileDebondingDelegations', 'Debonding')
: t('account.subnavigation.debondingDelegations', 'Debonding delegations')
}
route={`/account/${address}/debonding-delegations`}
/>
</Nav>
)
}
75 changes: 2 additions & 73 deletions src/app/pages/AccountPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ import { selectStaking } from 'app/state/staking/selectors'
import { selectTransaction } from 'app/state/transaction/selectors'
import { Box } from 'grommet/es6/components/Box'
import { Layer } from 'grommet/es6/components/Layer'
import { Nav } from 'grommet/es6/components/Nav'
import { Spinner } from 'grommet/es6/components/Spinner'
import { ResponsiveContext } from 'grommet/es6/contexts/ResponsiveContext'
import { Text } from 'grommet/es6/components/Text'
import * as React from 'react'
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import { NavLink, Outlet, useParams } from 'react-router-dom'
import styled from 'styled-components'
import { normalizeColor } from 'grommet/es6/utils'
import { Outlet, useParams } from 'react-router-dom'

import { accountActions } from 'app/state/account'
import { selectAccount } from 'app/state/account/selectors'
Expand All @@ -30,45 +25,11 @@ import { selectActiveWallet, selectHasAccounts, selectHasOneAccount } from 'app/
import { walletActions } from 'app/state/wallet'
import { AccountSummary } from './Features/AccountSummary'
import { AccountPageParams } from './validateAccountPageRoute'
import { Button } from 'grommet/es6/components/Button'

const StyledNavItem = styled(NavLink)`
padding: ${({ theme }) => theme.global?.edgeSize?.small};

:hover {
background-color: ${({ theme }) => normalizeColor('background-contrast', theme)};
}

&.active {
background-color: ${({ theme }) => normalizeColor('background-back', theme)};
}

@media only screen and (max-width: ${({ theme }) => `${theme.global?.breakpoints?.small?.value}px`}) {
padding: ${({ theme }) => theme.global?.edgeSize?.xsmall};
}
`

interface NavItemProps {
counter?: number
label: string
route: string
}

const NavItem = ({ counter, label, route }: NavItemProps) => {
return (
<StyledNavItem end to={route}>
<Button badge={counter} tabIndex={-1}>
{label}
</Button>
</StyledNavItem>
)
}

interface AccountPageProps {}

export function AccountPage(props: AccountPageProps) {
const { t } = useTranslation()
const isMobile = React.useContext(ResponsiveContext) === 'small'
const address = useParams<keyof AccountPageParams>().address!
const dispatch = useDispatch()

Expand Down Expand Up @@ -145,39 +106,7 @@ export function AccountPage(props: AccountPageProps) {
wallet={wallet}
walletHasAccounts={walletHasAccounts}
/>
<Nav
background="background-front"
justify={isMobile ? 'evenly' : 'start'}
margin={{ vertical: 'small' }}
direction="row"
gap="none"
wrap
>
<NavItem
label={t('account.subnavigation.transactions', 'Transactions')}
route={`/account/${address}`}
/>

<NavItem
counter={stake.delegations?.length}
label={
isMobile
? t('account.subnavigation.mobileActiveDelegations', 'Delegations')
: t('account.subnavigation.activeDelegations', 'Active delegations')
}
route="active-delegations"
/>

<NavItem
counter={stake.debondingDelegations?.length}
label={
isMobile
? t('account.subnavigation.mobileDebondingDelegations', 'Debonding')
: t('account.subnavigation.debondingDelegations', 'Debonding delegations')
}
route="debonding-delegations"
/>
</Nav>
<Box margin={{ bottom: 'small' }}></Box>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Box margin={{ bottom: 'small' }}></Box>
<Box margin={{ bottom: 'small' }} />

<Outlet />
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'

import { DelegationList } from '.'
import { AccountSubnavigation } from '../../../AccountPage/Features/AccountSubnavigation'

export const ActiveDelegationList = () => {
const { t } = useTranslation()
const delegations = useSelector(selectActiveDelegations)
return (
<Box pad="medium" background="background-front">
<Header>{t('delegations.activeDelegations', 'Active delegations')}</Header>
<DelegationList type="active" delegations={delegations ?? []} />
</Box>
<>
<AccountSubnavigation />
<Box pad="medium" background="background-front">
<Header level={2}>{t('delegations.activeDelegations', 'Active delegations')}</Header>
<DelegationList type="active" delegations={delegations ?? []} />
</Box>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'

import { DelegationList } from '.'
import { AccountSubnavigation } from '../../../AccountPage/Features/AccountSubnavigation'

export const DebondingDelegationList = () => {
const { t } = useTranslation()
const delegations = useSelector(selectDebondingDelegations)
return (
<Box pad="medium" background="background-front">
<Header>{t('delegations.debondingDelegations', 'Debonding delegations')}</Header>
<DelegationList type="debonding" delegations={delegations ?? []} />
</Box>
<>
<AccountSubnavigation />
<Box pad="medium" background="background-front">
<Header level={2}>{t('delegations.debondingDelegations', 'Debonding delegations')}</Header>
<DelegationList type="debonding" delegations={delegations ?? []} />
</Box>
</>
)
}
Loading