From 1ad10e61c6030f8bda141eb21ca242d947277683 Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 3 Feb 2023 20:47:37 +0200 Subject: [PATCH] Move pools location (adjusted interface) (#8935) * Move pools location (adjusted interface) * Adjust type import --- .../page-staking/src/Actions/Pool/Account.tsx | 2 +- .../src/Actions/Pool/BondExtra.tsx | 2 +- .../page-staking/src/Actions/Pool/index.tsx | 3 ++- packages/page-staking/src/Actions/Pools.tsx | 3 ++- packages/page-staking/src/Actions/index.tsx | 3 ++- packages/page-staking/src/Payouts/index.tsx | 2 +- packages/page-staking/src/index.tsx | 4 +-- packages/page-staking/src/types.ts | 16 ------------ .../src/Pools/Create.tsx | 0 .../src/Pools/Join.tsx | 0 .../src/Pools/Pool.tsx | 0 .../src/Pools/Pools.tsx | 3 +-- .../src/Pools/Summary.tsx | 0 .../src/Pools/index.tsx | 8 +++--- .../src/Pools/types.ts | 16 +++++++++++- .../src/Pools/useAmountError.ts | 0 .../src/Pools/useMembers.ts | 0 .../src/Pools}/useOwnPools.ts | 0 .../src/Pools/useParams.ts | 0 .../src/Pools}/usePoolAccounts.ts | 0 .../src/Pools/usePoolIds.ts | 0 .../src/Pools/usePoolInfo.ts | 2 +- packages/page-staking2/src/index.tsx | 26 ++++++++++++++++++- 23 files changed, 58 insertions(+), 32 deletions(-) rename packages/{page-staking => page-staking2}/src/Pools/Create.tsx (100%) rename packages/{page-staking => page-staking2}/src/Pools/Join.tsx (100%) rename packages/{page-staking => page-staking2}/src/Pools/Pool.tsx (100%) rename packages/{page-staking => page-staking2}/src/Pools/Pools.tsx (97%) rename packages/{page-staking => page-staking2}/src/Pools/Summary.tsx (100%) rename packages/{page-staking => page-staking2}/src/Pools/index.tsx (71%) rename packages/{page-staking => page-staking2}/src/Pools/types.ts (74%) rename packages/{page-staking => page-staking2}/src/Pools/useAmountError.ts (100%) rename packages/{page-staking => page-staking2}/src/Pools/useMembers.ts (100%) rename packages/{page-staking/src => page-staking2/src/Pools}/useOwnPools.ts (100%) rename packages/{page-staking => page-staking2}/src/Pools/useParams.ts (100%) rename packages/{page-staking/src => page-staking2/src/Pools}/usePoolAccounts.ts (100%) rename packages/{page-staking => page-staking2}/src/Pools/usePoolIds.ts (100%) rename packages/{page-staking => page-staking2}/src/Pools/usePoolInfo.ts (97%) diff --git a/packages/page-staking/src/Actions/Pool/Account.tsx b/packages/page-staking/src/Actions/Pool/Account.tsx index 60e77ebbc7..84515ae5b0 100644 --- a/packages/page-staking/src/Actions/Pool/Account.tsx +++ b/packages/page-staking/src/Actions/Pool/Account.tsx @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import type { DeriveSessionProgress, DeriveUnlocking } from '@polkadot/api-derive/types'; +import type { PoolInfo } from '@polkadot/app-staking2/Pools/types'; import type { PalletNominationPoolsPoolMember, PalletNominationPoolsPoolRoles } from '@polkadot/types/lookup'; -import type { PoolInfo } from '../../Pools/types'; import type { SortedTargets } from '../../types'; import React, { useCallback, useMemo } from 'react'; diff --git a/packages/page-staking/src/Actions/Pool/BondExtra.tsx b/packages/page-staking/src/Actions/Pool/BondExtra.tsx index 8dfd2e46b9..7849e7663b 100644 --- a/packages/page-staking/src/Actions/Pool/BondExtra.tsx +++ b/packages/page-staking/src/Actions/Pool/BondExtra.tsx @@ -5,12 +5,12 @@ import type { BN } from '@polkadot/util'; import React, { useRef, useState } from 'react'; +import useAmountError from '@polkadot/app-staking2/Pools/useAmountError'; import { Dropdown, InputBalance, Modal, TxButton } from '@polkadot/react-components'; import { useApi } from '@polkadot/react-hooks'; import { BalanceFree } from '@polkadot/react-query'; import { BN_ZERO } from '@polkadot/util'; -import useAmountError from '../../Pools/useAmountError'; import { useTranslation } from '../../translate'; import PoolInfo from '../partials/PoolInfo'; diff --git a/packages/page-staking/src/Actions/Pool/index.tsx b/packages/page-staking/src/Actions/Pool/index.tsx index b198d8f7af..661a513410 100644 --- a/packages/page-staking/src/Actions/Pool/index.tsx +++ b/packages/page-staking/src/Actions/Pool/index.tsx @@ -8,7 +8,8 @@ import type { SortedTargets } from '../../types'; import React from 'react'; -import usePoolInfo from '../../Pools/usePoolInfo'; +import usePoolInfo from '@polkadot/app-staking2/Pools/usePoolInfo'; + import Account from './Account'; interface Props { diff --git a/packages/page-staking/src/Actions/Pools.tsx b/packages/page-staking/src/Actions/Pools.tsx index de42f460d8..9b9c001d81 100644 --- a/packages/page-staking/src/Actions/Pools.tsx +++ b/packages/page-staking/src/Actions/Pools.tsx @@ -2,8 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import type { DeriveSessionProgress } from '@polkadot/api-derive/types'; +import type { OwnPool } from '@polkadot/app-staking2/Pools/types'; import type { PalletStakingUnappliedSlash } from '@polkadot/types/lookup'; -import type { OwnPool, SortedTargets } from '../types'; +import type { SortedTargets } from '../types'; import React, { useRef } from 'react'; diff --git a/packages/page-staking/src/Actions/index.tsx b/packages/page-staking/src/Actions/index.tsx index 80bbda406f..c59159b3bf 100644 --- a/packages/page-staking/src/Actions/index.tsx +++ b/packages/page-staking/src/Actions/index.tsx @@ -3,8 +3,9 @@ import '@polkadot/api-augment'; +import type { OwnPool } from '@polkadot/app-staking2/Pools/types'; import type { StakerState } from '@polkadot/react-hooks/types'; -import type { OwnPool, SortedTargets } from '../types'; +import type { SortedTargets } from '../types'; import React, { useMemo, useRef, useState } from 'react'; diff --git a/packages/page-staking/src/Payouts/index.tsx b/packages/page-staking/src/Payouts/index.tsx index 1acafafe89..c10b0fdf24 100644 --- a/packages/page-staking/src/Payouts/index.tsx +++ b/packages/page-staking/src/Payouts/index.tsx @@ -3,8 +3,8 @@ import type { TFunction } from 'i18next'; import type { DeriveStakerReward } from '@polkadot/api-derive/types'; +import type { OwnPool } from '@polkadot/app-staking2/Pools/types'; import type { StakerState } from '@polkadot/react-hooks/types'; -import type { OwnPool } from '../types'; import type { PayoutStash, PayoutValidator } from './types'; import React, { useMemo, useRef, useState } from 'react'; diff --git a/packages/page-staking/src/index.tsx b/packages/page-staking/src/index.tsx index 434a6cbf6b..df7b7bdd26 100644 --- a/packages/page-staking/src/index.tsx +++ b/packages/page-staking/src/index.tsx @@ -11,6 +11,8 @@ import { Route, Switch } from 'react-router'; import { useLocation } from 'react-router-dom'; import styled from 'styled-components'; +import Pools from '@polkadot/app-staking2/Pools'; +import useOwnPools from '@polkadot/app-staking2/Pools/useOwnPools'; import { Tabs } from '@polkadot/react-components'; import { useAccounts, useApi, useAvailableSlashes, useCall, useCallMulti, useFavorites, useOwnStashInfos } from '@polkadot/react-hooks'; import { isFunction } from '@polkadot/util'; @@ -19,13 +21,11 @@ import Actions from './Actions'; import Bags from './Bags'; import { STORE_FAVS_BASE } from './constants'; import Payouts from './Payouts'; -import Pools from './Pools'; import Query from './Query'; import Slashes from './Slashes'; import Targets from './Targets'; import { useTranslation } from './translate'; import useNominations from './useNominations'; -import useOwnPools from './useOwnPools'; import useSortedTargets from './useSortedTargets'; import Validators from './Validators'; diff --git a/packages/page-staking/src/types.ts b/packages/page-staking/src/types.ts index d122bb509b..60c436cc9f 100644 --- a/packages/page-staking/src/types.ts +++ b/packages/page-staking/src/types.ts @@ -2,9 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { Inflation } from '@polkadot/react-hooks/types'; -import type { u32 } from '@polkadot/types'; import type { AccountId, Balance, BlockNumber, EraIndex, Exposure, Hash, SessionIndex, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces'; -import type { PalletNominationPoolsPoolMember } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; export type Nominators = Record; @@ -97,17 +95,3 @@ export interface SortedTargets { validatorIds?: string[]; waitingIds?: string[]; } - -export interface PoolAccounts { - rewardId: string; - stashId: string; -} - -export interface OwnPoolBase { - members: Record; - poolId: u32; -} - -export interface OwnPool extends OwnPoolBase, PoolAccounts { - // nothing additional, only combined -} diff --git a/packages/page-staking/src/Pools/Create.tsx b/packages/page-staking2/src/Pools/Create.tsx similarity index 100% rename from packages/page-staking/src/Pools/Create.tsx rename to packages/page-staking2/src/Pools/Create.tsx diff --git a/packages/page-staking/src/Pools/Join.tsx b/packages/page-staking2/src/Pools/Join.tsx similarity index 100% rename from packages/page-staking/src/Pools/Join.tsx rename to packages/page-staking2/src/Pools/Join.tsx diff --git a/packages/page-staking/src/Pools/Pool.tsx b/packages/page-staking2/src/Pools/Pool.tsx similarity index 100% rename from packages/page-staking/src/Pools/Pool.tsx rename to packages/page-staking2/src/Pools/Pool.tsx diff --git a/packages/page-staking/src/Pools/Pools.tsx b/packages/page-staking2/src/Pools/Pools.tsx similarity index 97% rename from packages/page-staking/src/Pools/Pools.tsx rename to packages/page-staking2/src/Pools/Pools.tsx index 1ca3b21890..f1992c70ce 100644 --- a/packages/page-staking/src/Pools/Pools.tsx +++ b/packages/page-staking2/src/Pools/Pools.tsx @@ -2,8 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { BN } from '@polkadot/util'; -import type { OwnPool } from '../types'; -import type { Params } from './types'; +import type { OwnPool, Params } from './types'; import React, { useMemo, useRef, useState } from 'react'; diff --git a/packages/page-staking/src/Pools/Summary.tsx b/packages/page-staking2/src/Pools/Summary.tsx similarity index 100% rename from packages/page-staking/src/Pools/Summary.tsx rename to packages/page-staking2/src/Pools/Summary.tsx diff --git a/packages/page-staking/src/Pools/index.tsx b/packages/page-staking2/src/Pools/index.tsx similarity index 71% rename from packages/page-staking/src/Pools/index.tsx rename to packages/page-staking2/src/Pools/index.tsx index e43f4eb09e..e900cae03e 100644 --- a/packages/page-staking/src/Pools/index.tsx +++ b/packages/page-staking2/src/Pools/index.tsx @@ -1,12 +1,13 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { OwnPool } from '../types'; +import type { OwnPool } from './types'; import React from 'react'; import Pools from './Pools'; import Summary from './Summary'; +import useOwnPools from './useOwnPools'; import useParams from './useParams'; import usePoolIds from './usePoolIds'; @@ -15,8 +16,9 @@ interface Props { ownPools?: OwnPool[]; } -function NominationPools ({ className, ownPools }: Props): React.ReactElement { +function NominationPools ({ className, ownPools: ownPoolProp }: Props): React.ReactElement { const ids = usePoolIds(); + const ownPools = useOwnPools(); const params = useParams(); return ( @@ -27,7 +29,7 @@ function NominationPools ({ className, ownPools }: Props): React.ReactElement diff --git a/packages/page-staking/src/Pools/types.ts b/packages/page-staking2/src/Pools/types.ts similarity index 74% rename from packages/page-staking/src/Pools/types.ts rename to packages/page-staking2/src/Pools/types.ts index dae85eea9b..851bdc24f7 100644 --- a/packages/page-staking/src/Pools/types.ts +++ b/packages/page-staking2/src/Pools/types.ts @@ -1,9 +1,23 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { u32 } from '@polkadot/types'; import type { PalletNominationPoolsBondedPoolInner, PalletNominationPoolsPoolMember, PalletNominationPoolsRewardPool } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; -import type { PoolAccounts } from '../types'; + +export interface PoolAccounts { + rewardId: string; + stashId: string; +} + +export interface OwnPoolBase { + members: Record; + poolId: u32; +} + +export interface OwnPool extends OwnPoolBase, PoolAccounts { + // nothing additional, only combined +} export interface Params { lastPoolId: BN; diff --git a/packages/page-staking/src/Pools/useAmountError.ts b/packages/page-staking2/src/Pools/useAmountError.ts similarity index 100% rename from packages/page-staking/src/Pools/useAmountError.ts rename to packages/page-staking2/src/Pools/useAmountError.ts diff --git a/packages/page-staking/src/Pools/useMembers.ts b/packages/page-staking2/src/Pools/useMembers.ts similarity index 100% rename from packages/page-staking/src/Pools/useMembers.ts rename to packages/page-staking2/src/Pools/useMembers.ts diff --git a/packages/page-staking/src/useOwnPools.ts b/packages/page-staking2/src/Pools/useOwnPools.ts similarity index 100% rename from packages/page-staking/src/useOwnPools.ts rename to packages/page-staking2/src/Pools/useOwnPools.ts diff --git a/packages/page-staking/src/Pools/useParams.ts b/packages/page-staking2/src/Pools/useParams.ts similarity index 100% rename from packages/page-staking/src/Pools/useParams.ts rename to packages/page-staking2/src/Pools/useParams.ts diff --git a/packages/page-staking/src/usePoolAccounts.ts b/packages/page-staking2/src/Pools/usePoolAccounts.ts similarity index 100% rename from packages/page-staking/src/usePoolAccounts.ts rename to packages/page-staking2/src/Pools/usePoolAccounts.ts diff --git a/packages/page-staking/src/Pools/usePoolIds.ts b/packages/page-staking2/src/Pools/usePoolIds.ts similarity index 100% rename from packages/page-staking/src/Pools/usePoolIds.ts rename to packages/page-staking2/src/Pools/usePoolIds.ts diff --git a/packages/page-staking/src/Pools/usePoolInfo.ts b/packages/page-staking2/src/Pools/usePoolInfo.ts similarity index 97% rename from packages/page-staking/src/Pools/usePoolInfo.ts rename to packages/page-staking2/src/Pools/usePoolInfo.ts index 9ff6ca9cbc..8feed3da26 100644 --- a/packages/page-staking/src/Pools/usePoolInfo.ts +++ b/packages/page-staking2/src/Pools/usePoolInfo.ts @@ -11,7 +11,7 @@ import { useMemo } from 'react'; import { createNamedHook, useApi, useCallMulti } from '@polkadot/react-hooks'; import { BN_ZERO, bnMax } from '@polkadot/util'; -import usePoolAccounts from '../usePoolAccounts'; +import usePoolAccounts from './usePoolAccounts'; const OPT_MULTI = { defaultValue: null, diff --git a/packages/page-staking2/src/index.tsx b/packages/page-staking2/src/index.tsx index 50a55a6772..a63c815935 100644 --- a/packages/page-staking2/src/index.tsx +++ b/packages/page-staking2/src/index.tsx @@ -8,16 +8,33 @@ import { Route, Switch } from 'react-router'; import { Tabs } from '@polkadot/react-components'; import { useApi, useFavorites } from '@polkadot/react-hooks'; +import { isFunction } from '@polkadot/util'; import { STORE_FAVS_BASE } from './constants'; +import Pools from './Pools'; import { useTranslation } from './translate'; import { clearCache } from './useCache'; import useSessionInfo from './useSessionInfo'; import Validators from './Validators'; +function createPathRef (basePath: string): Record { + return { + bags: `${basePath}/bags`, + payout: `${basePath}/payout`, + pools: `${basePath}/pools`, + query: [ + `${basePath}/query/:value`, + `${basePath}/query` + ], + slashes: `${basePath}/slashes`, + targets: `${basePath}/targets` + }; +} + function StakingApp ({ basePath }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); + const pathRef = useRef(createPathRef(basePath)); // on unmount anything else, ensure that for the next round we // are starting with a fresh cache (there could be large delays) @@ -41,6 +58,10 @@ function StakingApp ({ basePath }: Props): React.ReactElement { isRoot: true, name: 'sign', text: t('Validators') + }, + isFunction(api.query.nominationPools?.minCreateBond) && { + name: 'pools', + text: t('Pools') } ]); @@ -51,7 +72,10 @@ function StakingApp ({ basePath }: Props): React.ReactElement { items={itemsRef.current} /> - + + + +