Skip to content

Commit

Permalink
Merge pull request #726 from subspace/725-on-manage-my-nomination-tab…
Browse files Browse the repository at this point in the history
…-the-option-to-nominate-a-deregistered-operator-should-be-removed

improve the filtering of Actions in Staking section especially for de…
  • Loading branch information
marc-aurele-besner authored Jul 15, 2024
2 parents cd1f82b + 73b0d59 commit 8aea3db
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 51 deletions.
2 changes: 2 additions & 0 deletions explorer/src/components/Operator/ActionsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const ActionsDropdown: FC<ActionsDropdownProps> = ({
[excludeActions],
)

if (actionsAvailable.length === 0) return <></>

return (
<Listbox
value={action.type}
Expand Down
47 changes: 30 additions & 17 deletions explorer/src/components/Operator/NominationManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,36 @@ export const NominationManagement: FC = () => {
enableSorting: false,
cell: ({
row,
}: Cell<NominatorsConnectionQuery['nominatorsConnection']['edges'][0]['node']>) => (
<ActionsDropdown
action={action}
handleAction={handleAction}
row={
{
...row,
original: {
...row.original,
totalShares: row.original.shares,
},
} as ActionsDropdownRow
}
excludeActions={[OperatorActionType.Deregister, OperatorActionType.UnlockFunds]}
nominatorMaxShares={BigInt(row.original.shares)}
/>
),
}: Cell<NominatorsConnectionQuery['nominatorsConnection']['edges'][0]['node']>) => {
const excludeActions = [OperatorActionType.Deregister, OperatorActionType.UnlockFunds]
if (
row.original.operator.status &&
JSON.parse(row.original.operator.status ?? '{}')?.deregistered
)
excludeActions.push(OperatorActionType.Nominating)
if (
row.original.operator.status &&
JSON.parse(row.original.operator.status ?? '{}')?.slashed === null
)
return <></>
return (
<ActionsDropdown
action={action}
handleAction={handleAction}
row={
{
...row,
original: {
...row.original,
totalShares: row.original.shares,
},
} as ActionsDropdownRow
}
excludeActions={excludeActions}
nominatorMaxShares={BigInt(row.original.shares)}
/>
)
},
},
]
return cols
Expand Down
15 changes: 13 additions & 2 deletions explorer/src/components/Operator/NominatorsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,18 @@ export const NominatorsList: FC = () => {
header: 'Actions',
enableSorting: false,
cell: ({ row }) => {
if (row.original.account.id !== subspaceAccount) return <> </>
if (row.original.account.id !== subspaceAccount) return <></>
const excludeActions = [OperatorActionType.Deregister, OperatorActionType.UnlockFunds]
if (
row.original.operator.status &&
JSON.parse(row.original.operator.status ?? '{}')?.deregistered
)
excludeActions.push(OperatorActionType.Nominating)
if (
row.original.operator.status &&
JSON.parse(row.original.operator.status ?? '{}')?.slashed === null
)
return <></>
return (
<ActionsDropdown
action={action}
Expand All @@ -247,7 +258,7 @@ export const NominatorsList: FC = () => {
},
} as ActionsDropdownRow
}
excludeActions={[OperatorActionType.Deregister, OperatorActionType.UnlockFunds]}
excludeActions={excludeActions}
nominatorMaxShares={BigInt(row.original.shares)}
/>
)
Expand Down
4 changes: 2 additions & 2 deletions explorer/src/components/Operator/Operator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Spinner } from 'components/common/Spinner'
import { NotFound } from 'components/layout/NotFound'
import { Routes } from 'constants/routes'
import { OperatorByIdQuery, OperatorByIdQueryVariables, Operator as TOperator } from 'gql/graphql'
import type { OperatorByIdQuery, OperatorByIdQueryVariables } from 'gql/oldSquidTypes'
import useMediaQuery from 'hooks/useMediaQuery'
import { useSquidQuery } from 'hooks/useSquidQuery'
import { useWindowFocus } from 'hooks/useWindowFocus'
Expand Down Expand Up @@ -39,7 +39,7 @@ export const Operator: FC = () => {
} = useQueryStates()

const operatorDetails = useMemo(
() => (hasValue(operator) ? operator.value.operatorById : []) as TOperator,
() => hasValue(operator) && operator.value.operatorById,
[operator],
)

Expand Down
6 changes: 4 additions & 2 deletions explorer/src/components/Operator/OperatorDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Chains } from 'constants/'
import { INTERNAL_ROUTES, Routes } from 'constants/routes'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { Operator } from 'gql/graphql'
import { OperatorByIdQuery } from 'gql/graphql'
import useDomains from 'hooks/useDomains'
import useMediaQuery from 'hooks/useMediaQuery'
import Link from 'next/link'
Expand All @@ -18,14 +18,16 @@ import { AccountIcon } from '../common/AccountIcon'
dayjs.extend(relativeTime)

type Props = {
operator: Operator
operator: OperatorByIdQuery['operatorById']
isDesktop?: boolean
}

export const OperatorDetailsCard: FC<Props> = ({ operator, isDesktop = false }) => {
const { selectedChain } = useDomains()
const isLargeLaptop = useMediaQuery('(min-width: 1440px)')

if (!operator) return null

return (
<div className='w-full'>
<div className='mb-4 w-full rounded-[20px] border border-slate-100 bg-white px-3 py-4 shadow dark:border-none dark:bg-gradient-to-r dark:from-gradientTwilight dark:via-gradientDusk dark:to-gradientSunset sm:p-6'>
Expand Down
38 changes: 26 additions & 12 deletions explorer/src/components/Operator/OperatorManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,32 @@ export const OperatorManagement: FC = () => {
row,
}: Cell<
OperatorsConnectionQuery['operatorsConnection']['edges'][0]['node'] | Operators
>) => (
<ActionsDropdown
action={action}
handleAction={handleAction}
row={row as ActionsDropdownRow}
excludeActions={
operatorReadyToUnlock(row.original.status, lastBlock)
? [OperatorActionType.Deregister, OperatorActionType.UnlockNominator]
: [OperatorActionType.UnlockFunds, OperatorActionType.UnlockFunds]
}
/>
),
>) => {
const excludeActions = operatorReadyToUnlock(row.original.status, lastBlock)
? [OperatorActionType.Deregister, OperatorActionType.UnlockNominator]
: [OperatorActionType.UnlockFunds, OperatorActionType.UnlockFunds]

if (
!useRpcData &&
row.original.status &&
JSON.parse(row.original.status ?? '{}')?.deregistered
)
excludeActions.push(OperatorActionType.Nominating)
if (
!useRpcData &&
row.original.status &&
JSON.parse(row.original.status ?? '{}')?.slashed === null
)
return <></>
return (
<ActionsDropdown
action={action}
handleAction={handleAction}
row={row as ActionsDropdownRow}
excludeActions={excludeActions}
/>
)
},
},
]
}, [
Expand Down
25 changes: 10 additions & 15 deletions explorer/src/components/Operator/OperatorNominatorTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { limitNumberDecimals, numberWithCommas } from '@/utils/number'
import { shortString } from '@/utils/string'
import { SortedTable } from 'components/common/SortedTable'
import { INTERNAL_ROUTES, Routes } from 'constants/routes'
import { Nominator, Operator } from 'gql/graphql'
import { Nominator, OperatorByIdQuery } from 'gql/graphql'
import useDomains from 'hooks/useDomains'
import useMediaQuery from 'hooks/useMediaQuery'
import Link from 'next/link'
Expand All @@ -11,15 +11,16 @@ import type { Cell } from 'types/table'
import { AccountIcon } from '../common/AccountIcon'

interface Props {
operator: Operator
operator: OperatorByIdQuery['operatorById']
}

export const OperatorNominatorTable: FC<Props> = ({ operator }) => {
const { selectedChain } = useDomains()
const isLargeLaptop = useMediaQuery('(min-width: 1440px)')

const columns = useMemo(
() => [
const columns = useMemo(() => {
if (!operator) return []
return [
{
accessorKey: 'account',
header: 'Account Id',
Expand Down Expand Up @@ -87,20 +88,14 @@ export const OperatorNominatorTable: FC<Props> = ({ operator }) => {
cell: ({ row }: Cell<Nominator>) =>
operator.operatorOwner === row.original.account.id ? 'Yes' : 'No',
},
],
[
isLargeLaptop,
operator.currentTotalStake,
operator.operatorOwner,
operator.totalShares,
selectedChain.token.symbol,
selectedChain.urls.page,
],
)
]
}, [isLargeLaptop, operator, selectedChain.token.symbol, selectedChain.urls.page])

if (!operator) return null

return (
<SortedTable
data={operator.nominators}
data={operator.nominators as Nominator[]}
columns={columns}
showNavigation={false}
pagination={{
Expand Down
8 changes: 7 additions & 1 deletion explorer/src/components/Operator/OperatorsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ export const OperatorsList: FC = () => {
!useRpcData &&
!nominator &&
row.original.status &&
(JSON.parse(row.original.status) as unknown as { deregistered: object }).deregistered
JSON.parse(row.original.status ?? '{}')?.deregistered
)
excludeActions.push(OperatorActionType.Nominating)
if (
!useRpcData &&
row.original.status &&
JSON.parse(row.original.status ?? '{}')?.slashed === null
)
return <></>
return (
Expand Down

0 comments on commit 8aea3db

Please sign in to comment.