Skip to content

Commit

Permalink
Merge pull request #838 from autonomys/837-its-possible-to-nominate-a…
Browse files Browse the repository at this point in the history
…-slashed-or-deregistered-op

Its possible to nominate a slashed or deregistered op
  • Loading branch information
marc-aurele-besner authored Aug 29, 2024
2 parents 4bc5cf5 + feb2ee0 commit 1acac3a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion explorer/gql/types/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7568,7 +7568,7 @@ export type NominationsListQueryVariables = Exact<{
}>;


export type NominationsListQuery = { __typename?: 'query_root', nominator_aggregate: { __typename?: 'nominator_aggregate', aggregate?: { __typename?: 'nominator_aggregate_fields', count: number } | null }, nominator: Array<{ __typename?: 'nominator', id: string, account_id: string, domain_id: string, operator_id: string, known_shares: any, known_storage_fee_deposit: any, pending_amount: any, pending_storage_fee_deposit: any, pending_effective_domain_epoch: number, total_withdrawal_amounts: any, total_storage_fee_refund: any, unlock_at_confirmed_domain_block_number: Array<number>, pending_shares: any, pending_storage_fee_refund: any, total_deposits: any, status: string, pending_action: string, created_at: number, updated_at: number, domain?: { __typename?: 'domain', id: string, name: string } | null, operator?: { __typename?: 'operator', id: string, account_id: string, status: string, current_total_shares: any } | null, deposits: Array<{ __typename?: 'deposit', id: string, amount: any, storage_fee_deposit: any, timestamp: any, extrinsic_hash: string, status: string, created_at: number, staked_at: number, updated_at: number }>, withdrawals: Array<{ __typename?: 'withdrawal', id: string, shares: any, estimated_amount: any, unlocked_amount: any, unlocked_storage_fee: any, timestamp: any, withdraw_extrinsic_hash: string, unlock_extrinsic_hash: string, status: string, created_at: number, ready_at: number, unlocked_at: number, updated_at: number }> }> };
export type NominationsListQuery = { __typename?: 'query_root', nominator_aggregate: { __typename?: 'nominator_aggregate', aggregate?: { __typename?: 'nominator_aggregate_fields', count: number } | null }, nominator: Array<{ __typename?: 'nominator', id: string, account_id: string, domain_id: string, operator_id: string, known_shares: any, known_storage_fee_deposit: any, pending_amount: any, pending_storage_fee_deposit: any, pending_effective_domain_epoch: number, total_withdrawal_amounts: any, total_storage_fee_refund: any, unlock_at_confirmed_domain_block_number: Array<number>, pending_shares: any, pending_storage_fee_refund: any, total_deposits: any, status: string, pending_action: string, created_at: number, updated_at: number, domain?: { __typename?: 'domain', id: string, name: string } | null, operator?: { __typename?: 'operator', id: string, account_id: string, status: string, pending_action: string, current_total_shares: any } | null, deposits: Array<{ __typename?: 'deposit', id: string, amount: any, storage_fee_deposit: any, timestamp: any, extrinsic_hash: string, status: string, created_at: number, staked_at: number, updated_at: number }>, withdrawals: Array<{ __typename?: 'withdrawal', id: string, shares: any, estimated_amount: any, unlocked_amount: any, unlocked_storage_fee: any, timestamp: any, withdraw_extrinsic_hash: string, unlock_extrinsic_hash: string, status: string, created_at: number, ready_at: number, unlocked_at: number, updated_at: number }> }> };

export type OperatorsListQueryVariables = Exact<{
limit: Scalars['Int']['input'];
Expand Down
19 changes: 7 additions & 12 deletions explorer/src/components/Staking/NominationsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
'use client'

import useChains from '@/hooks/useChains'
import { useViewStates } from '@/states/view'
import { sendGAEvent } from '@next/third-parties/google'
import { SortingState, createColumnHelper } from '@tanstack/react-table'
import { Accordion } from 'components/common/Accordion'
import { SortedTable } from 'components/common/SortedTable'
import { Spinner } from 'components/common/Spinner'
import { BIGINT_ZERO, INTERNAL_ROUTES, Routes, TOKEN } from 'constants/'
import { OperatorPendingAction, OperatorStatus } from 'constants/staking'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import {
NominationsListQuery,
NominationsListQueryVariables,
Order_By as OrderBy,
} from 'gql/types/staking'
import useChains from 'hooks/useChains'
import { useSquidQuery } from 'hooks/useSquidQuery'
import useWallet from 'hooks/useWallet'
import Link from 'next/link'
import { FC, useCallback, useEffect, useMemo, useState } from 'react'
import { useInView } from 'react-intersection-observer'
import { useViewStates } from 'states/view'
import { bigNumberToFormattedString, numberWithCommas } from 'utils/number'
import { capitalizeFirstLetter } from 'utils/string'
import { MyPositionSwitch } from '../common/MyPositionSwitch'
Expand Down Expand Up @@ -209,19 +210,13 @@ export const NominationsTable: FC = () => {
OperatorActionType.UnlockNominator,
]

if (nominator.operator?.status === 'REGISTERED')
excludeActions.push(
OperatorActionType.Deregister,
OperatorActionType.Nominating,
)
else if (nominator.operator?.status === 'DEREGISTERED')
excludeActions.push(OperatorActionType.Nominating)
else if (nominator.operator?.status === 'READY_TO_UNLOCK')
if (nominator.operator?.status === OperatorStatus.DEREGISTERED)
excludeActions.push(
OperatorActionType.Nominating,
OperatorActionType.Deregister,
)
else excludeActions.push(OperatorActionType.UnlockNominator)
if (nominator.operator?.pending_action !== OperatorPendingAction.READY_FOR_UNLOCK_NOMINATOR)
excludeActions.push(OperatorActionType.UnlockNominator)

if (!nominator)
excludeActions.push(
Expand All @@ -233,7 +228,7 @@ export const NominationsTable: FC = () => {
nominator.unlock_at_confirmed_domain_block_number.length === 0
)
excludeActions.push(OperatorActionType.UnlockFunds)
if (nominator.operator?.status === 'SLASHED') return <></>
if (nominator.operator?.status === OperatorStatus.SLASHED) return <></>
return (
<ActionsDropdown
action={action}
Expand Down
12 changes: 4 additions & 8 deletions explorer/src/components/Staking/OperatorsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SortedTable } from 'components/common/SortedTable'
import { Spinner } from 'components/common/Spinner'
import { BIGINT_ZERO, PAGE_SIZE, SHARES_CALCULATION_MULTIPLIER, TOKEN } from 'constants/'
import { INTERNAL_ROUTES, Routes } from 'constants/routes'
import { OperatorPendingAction, OperatorStatus } from 'constants/staking'
import {
OperatorsListQuery,
OperatorsListQueryVariables,
Expand Down Expand Up @@ -574,20 +575,15 @@ export const OperatorsList: FC<OperatorsListProps> = ({ domainId }) => {
if (!isOperator)
excludeActions.push(OperatorActionType.Deregister, OperatorActionType.UnlockNominator)

const status = operatorStatus(JSON.parse(row.original.raw_status ?? '{}'))

if (status === 'REGISTERED')
excludeActions.push(OperatorActionType.Deregister, OperatorActionType.Nominating)
else if (status === 'DEREGISTERED') excludeActions.push(OperatorActionType.Nominating)
else if (status === 'READY_TO_UNLOCK')
if (row.original.status === OperatorStatus.DEREGISTERED)
excludeActions.push(OperatorActionType.Nominating, OperatorActionType.Deregister)
else excludeActions.push(OperatorActionType.UnlockNominator)
if (row.original.pending_action !== OperatorPendingAction.READY_FOR_UNLOCK_NOMINATOR) excludeActions.push(OperatorActionType.UnlockNominator)

if (!nominator)
excludeActions.push(OperatorActionType.Withdraw, OperatorActionType.UnlockFunds)
if (!nominator || nominator.unlock_at_confirmed_domain_block_number.length === 0)
excludeActions.push(OperatorActionType.UnlockFunds)
if (status === 'SLASHED') return <></>
if (row.original.status === OperatorStatus.SLASHED) return <></>
return (
<ActionsDropdown
action={action}
Expand Down
1 change: 1 addition & 0 deletions explorer/src/components/Staking/staking.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const QUERY_NOMINATIONS_LIST = gql`
id
account_id
status
pending_action
current_total_shares
}
known_shares
Expand Down
44 changes: 44 additions & 0 deletions explorer/src/constants/staking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export enum OperatorStatus {
PENDING = 'PENDING',
REGISTERED = 'REGISTERED',
DEREGISTERED = 'DEREGISTERED',
SLASHED = 'SLASHED'
}

export enum OperatorPendingAction {
NO_ACTION_REQUIRED = 'NO_ACTION_REQUIRED',
PENDING_REGISTRATION = 'PENDING_REGISTRATION',
WAITING_TO_UNLOCK_NOMINATOR = 'WAITING_TO_UNLOCK_NOMINATOR',
READY_FOR_UNLOCK_NOMINATOR = 'READY_FOR_UNLOCK_NOMINATOR',
READY_FOR_UNLOCK_FUNDS = 'READY_FOR_UNLOCK_FUNDS'
}

export enum NominatorStatus {
PENDING = 'PENDING',
STAKED = 'STAKED',
SLASHED = 'SLASHED',
WITHDRAW = 'WITHDRAW'
}

export enum NominatorPendingAction {
NO_ACTION_REQUIRED = 'NO_ACTION_REQUIRED',
PENDING_EPOCH_CHANGE = 'PENDING_EPOCH_CHANGE',
PENDING_DEREGISTRATION_LOCK = 'PENDING_DEREGISTRATION_LOCK',
READY_TO_UNLOCK_ALL_FUNDS = 'READY_TO_UNLOCK_ALL_FUNDS'
}

export enum DepositStatus {
PENDING = 'PENDING',
DEPOSITED = 'DEPOSITED',
PARTIALLY_WITHDRAWN = 'PARTIALLY_WITHDRAWN',
WITHDRAWN = 'WITHDRAWN',
SLASHED = 'SLASHED'
}

export enum WithdrawalStatus {
PENDING_LOCK = 'PENDING_LOCK',
PENDING_OPERATOR = 'PENDING_OPERATOR',
READY = 'READY',
WITHDRAW = 'WITHDRAW',
SLASHED = 'SLASHED'
}
4 changes: 3 additions & 1 deletion explorer/src/constants/tables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AvailableColumns, FiltersOptions, InitialTables } from 'types/table'
import { allCapsToNormal } from 'utils/string'
import { PAGE_SIZE } from './general'
import { OperatorStatus } from './staking'

export const AVAILABLE_COLUMNS: AvailableColumns = {
domains: [
Expand Down Expand Up @@ -179,7 +181,7 @@ export const FILTERS_OPTIONS: FiltersOptions = {
type: 'checkbox',
label: 'Status',
key: 'status',
options: ['Registered', 'Deregistered', 'Slashed', 'Ready To Unlock'],
options: Object.values(OperatorStatus).map((status) => allCapsToNormal(status)),
},
{ type: 'range', label: 'Active Epoch Count', key: 'activeEpochCount' },
{ type: 'range', label: 'Bundle Count', key: 'bundleCount' },
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/states/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const useTableStates = create<TableStatesAndFn>()(
}),
{
name: 'table-storage',
version: 2,
version: 3,
storage: createJSONStorage(() => localStorage),
serialize: (state) => JSON.stringify(state, bigIntSerializer),
deserialize: (str) => JSON.parse(str, bigIntDeserializer),
Expand Down

0 comments on commit 1acac3a

Please sign in to comment.