From 6f63b180e5bdcc4cc07706461844ce8c66dc1f86 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:40:24 -0400 Subject: [PATCH 1/3] add all staking enum --- explorer/src/constants/staking.ts | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 explorer/src/constants/staking.ts diff --git a/explorer/src/constants/staking.ts b/explorer/src/constants/staking.ts new file mode 100644 index 00000000..b946be4a --- /dev/null +++ b/explorer/src/constants/staking.ts @@ -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' +} From 5c52c399fd43be5d218f01c5c2e170877d7cbdc3 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:49:54 -0400 Subject: [PATCH 2/3] improve logic and implement enum --- explorer/gql/types/staking.ts | 2 +- .../components/Staking/NominationsTable.tsx | 19 +++++++------------ .../src/components/Staking/OperatorsList.tsx | 12 ++++-------- .../src/components/Staking/staking.query.ts | 1 + 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/explorer/gql/types/staking.ts b/explorer/gql/types/staking.ts index c6d26e54..a14059dd 100644 --- a/explorer/gql/types/staking.ts +++ b/explorer/gql/types/staking.ts @@ -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, 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, 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']; diff --git a/explorer/src/components/Staking/NominationsTable.tsx b/explorer/src/components/Staking/NominationsTable.tsx index cac5086f..8fb0ab8a 100644 --- a/explorer/src/components/Staking/NominationsTable.tsx +++ b/explorer/src/components/Staking/NominationsTable.tsx @@ -1,13 +1,12 @@ '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 { @@ -15,11 +14,13 @@ import { 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' @@ -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( @@ -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 ( = ({ 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 ( Date: Wed, 28 Aug 2024 09:50:14 -0400 Subject: [PATCH 3/3] improve table filters and bump store --- explorer/src/constants/tables.ts | 4 +++- explorer/src/states/tables.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/explorer/src/constants/tables.ts b/explorer/src/constants/tables.ts index 6ebcdd64..5a1e1042 100644 --- a/explorer/src/constants/tables.ts +++ b/explorer/src/constants/tables.ts @@ -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: [ @@ -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' }, diff --git a/explorer/src/states/tables.ts b/explorer/src/states/tables.ts index c346f688..7d54f31a 100644 --- a/explorer/src/states/tables.ts +++ b/explorer/src/states/tables.ts @@ -98,7 +98,7 @@ export const useTableStates = create()( }), { name: 'table-storage', - version: 2, + version: 3, storage: createJSONStorage(() => localStorage), serialize: (state) => JSON.stringify(state, bigIntSerializer), deserialize: (str) => JSON.parse(str, bigIntDeserializer),