From 42f5209c52567d2df06fcf8c5c31247918e71dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 07:40:12 +1200 Subject: [PATCH 1/8] feat: better `useCall` hook type inference --- packages/react-hooks/src/types.ts | 10 ++++++++++ packages/react-hooks/src/useCall.ts | 24 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/react-hooks/src/types.ts b/packages/react-hooks/src/types.ts index 99401d73ca72..c589dd939351 100644 --- a/packages/react-hooks/src/types.ts +++ b/packages/react-hooks/src/types.ts @@ -36,6 +36,16 @@ export type TxSource = [T, boolean]; export type CollectiveType = 'alliance' | 'council' | 'membership' | 'technicalCommittee'; +export type Diverge = TType extends infer TDiverge & TIntersect ? TDiverge : TType + +export type Leading = T extends [...infer Leading, any] ? Leading : [] + +export type NullablePartial = { [P in keyof T]?: T[P] | null; } + +export type PickKnownKeys = { + [P in keyof T as string extends P ? never : number extends P ? never : P]: T[P] +} + export interface ModalState { isOpen: boolean; onOpen: () => void; diff --git a/packages/react-hooks/src/useCall.ts b/packages/react-hooks/src/useCall.ts index 63a9c8182b37..a0af3b85ef77 100644 --- a/packages/react-hooks/src/useCall.ts +++ b/packages/react-hooks/src/useCall.ts @@ -1,11 +1,12 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { Observable } from 'rxjs'; import type { ApiPromise } from '@polkadot/api'; -import type { PromiseResult, QueryableStorageEntry } from '@polkadot/api/types'; +import type { GenericStorageEntryFunction, PromiseResult, QueryableStorageEntry, StorageEntryPromiseOverloads } from '@polkadot/api/types'; import type { StorageEntryTypeLatest } from '@polkadot/types/interfaces'; import type { AnyFunction, Codec } from '@polkadot/types/types'; -import type { CallOptions, CallParam, CallParams } from './types.js'; +import type { CallOptions, CallParam, CallParams, Diverge, Leading, NullablePartial } from './types.js'; import type { MountedRef } from './useIsMountedRef.js'; import { useEffect, useRef, useState } from 'react'; @@ -157,13 +158,26 @@ export function throwOnError (tracker: Tracker): void { // tracks a stream, typically an api.* call (derive, rpc, query) that // - returns a promise with an unsubscribe function // - has a callback to set the value -// FIXME The typings here need some serious TLC // FIXME This is generic, we cannot really use createNamedHook -export function useCall (fn: TrackFn | undefined | null | false, params?: CallParams | null, options?: CallOptions): T | undefined { +export function useCall< + TTransformedResult, + TFunc extends TrackFn | undefined | null | boolean, + TDivergedFunc extends Diverge, StorageEntryPromiseOverloads & QueryableStorageEntry & PromiseResult>, + TParams extends TDivergedFunc extends AnyFunction + ? NullablePartial>> + : any[], + TFuncResult extends TDivergedFunc extends AnyFunction + ? TDivergedFunc extends PromiseResult< (...args: any) => Observable> + ? TResult + : any + : any, + TResult extends TCallOptions extends CallOptions ? R : TFuncResult, + TCallOptions extends CallOptions | void = void, +>(fn: TFunc, params?: TParams, options?: TCallOptions): TResult { const { api } = useApi(); const mountedRef = useIsMountedRef(); const tracker = useRef({ error: null, fn: null, isActive: false, serialized: null, subscriber: null, type: 'useCall' }); - const [value, setValue] = useState((options || {}).defaultValue); + const [value, setValue] = useState((options || {}).defaultValue); // initial effect, we need an un-subscription useEffect((): () => void => { From e7ac349637e331bbc4b003088cff1311a84f3359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 08:04:19 +1200 Subject: [PATCH 2/8] chore: remove manual typing --- packages/apps/src/Content/Status.tsx | 2 +- packages/apps/src/Menu/ChainInfo.tsx | 4 +--- packages/apps/src/Menu/index.tsx | 3 +-- packages/apps/src/WarmUp.tsx | 6 +++--- packages/page-accounts/src/Accounts/Account.tsx | 6 +++--- packages/page-accounts/src/modals/IdentityMain.tsx | 6 +++--- packages/page-accounts/src/modals/InputValidateAmount.tsx | 3 +-- packages/page-addresses/src/modals/Create.tsx | 3 +-- packages/page-alliance/src/index.tsx | 4 +--- packages/page-alliance/src/useAnnoucements.ts | 2 +- packages/page-alliance/src/useCounter.ts | 2 +- packages/page-alliance/src/useMembers.ts | 6 +++--- packages/page-alliance/src/useRule.ts | 2 +- packages/page-alliance/src/useUnscrupulous.ts | 4 ++-- packages/page-bounties/src/hooks/useBalance.ts | 3 +-- packages/page-bounties/src/hooks/useBounties.tsx | 6 +++--- packages/page-bounties/src/useCounter.ts | 4 +--- packages/page-collator/src/useCollators.ts | 6 +++--- packages/page-contracts/src/Codes/Code.tsx | 4 +--- packages/page-contracts/src/Codes/ValidateCode.tsx | 5 +---- packages/page-contracts/src/Contracts/Contract.tsx | 2 +- packages/page-contracts/src/Contracts/ContractsTable.tsx | 3 +-- packages/page-contracts/src/Contracts/ValidateAddr.tsx | 5 +---- packages/page-contracts/src/shared/Messages.tsx | 4 +--- packages/page-council/src/Overview/index.tsx | 6 +++--- packages/page-council/src/index.tsx | 7 ++----- packages/page-council/src/useCounter.ts | 2 +- packages/page-democracy/src/Overview/ExternalCell.tsx | 3 +-- packages/page-democracy/src/Overview/Externals.tsx | 4 +--- packages/page-democracy/src/Overview/Proposals.tsx | 4 +--- packages/page-democracy/src/Overview/Propose.tsx | 2 +- packages/page-democracy/src/Overview/Referendum.tsx | 3 +-- packages/page-democracy/src/Overview/Summary.tsx | 2 +- packages/page-democracy/src/Overview/TreasuryCell.tsx | 2 +- packages/page-democracy/src/Overview/index.tsx | 4 +--- packages/page-democracy/src/useChangeCalc.ts | 2 +- packages/page-democracy/src/useCounter.ts | 4 ++-- packages/page-explorer/src/BestHash.tsx | 4 +--- packages/page-explorer/src/Latency/useLatency.ts | 2 +- packages/page-explorer/src/SummarySession.tsx | 7 ++----- packages/page-membership/src/useCounter.ts | 2 +- packages/page-parachains/src/Auctions/Summary.tsx | 4 ++-- .../page-parachains/src/Crowdloan/useContributions.ts | 6 +++--- packages/page-parachains/src/Overview/useChainDetails.ts | 4 ++-- packages/page-parachains/src/Overview/useEvents.ts | 2 +- packages/page-parachains/src/Parathreads/Actions.tsx | 3 +-- packages/page-parachains/src/Parathreads/useParaMap.ts | 2 +- packages/page-parachains/src/useFunds.ts | 4 ++-- packages/page-referenda/src/Referenda/index.tsx | 4 ++-- packages/page-referenda/src/useAccountLocks.ts | 4 ++-- packages/page-referenda/src/useReferenda.ts | 2 +- packages/page-scheduler/src/DispatchQueue.tsx | 4 +--- packages/page-scheduler/src/Scheduler.tsx | 2 +- packages/page-society/src/Candidates/Bids.tsx | 4 +--- packages/page-society/src/Overview/Defender.tsx | 2 +- packages/page-society/src/Overview/Summary.tsx | 2 +- packages/page-society/src/Suspended/index.tsx | 4 ++-- packages/page-society/src/index.tsx | 4 ++-- packages/page-society/src/useCounter.ts | 4 +--- packages/page-society/src/useMembers.ts | 2 +- packages/page-society/src/useVoters.ts | 2 +- packages/page-staking/src/Actions/Account/BondExtra.tsx | 2 +- .../src/Actions/Account/InputValidateAmount.tsx | 3 +-- .../src/Actions/Account/InputValidationController.tsx | 7 +++---- .../page-staking/src/Actions/Account/KickNominees.tsx | 3 +-- .../page-staking/src/Actions/Account/ListNominees.tsx | 6 +++--- .../src/Actions/Account/SetRewardDestination.tsx | 3 +-- packages/page-staking/src/Actions/Account/index.tsx | 5 ++--- packages/page-staking/src/Actions/Pools.tsx | 3 +-- packages/page-staking/src/Actions/partials/Bond.tsx | 5 ++--- packages/page-staking/src/Actions/useInactives.ts | 2 +- packages/page-staking/src/Actions/useSlashingSpans.ts | 2 +- packages/page-staking/src/Actions/useUnbondDuration.ts | 3 +-- packages/page-staking/src/Bags/Summary.tsx | 3 +-- packages/page-staking/src/Bags/useBagEntries.tsx | 4 +--- packages/page-staking/src/Payouts/index.tsx | 2 +- packages/page-staking/src/Payouts/useEraBlocks.ts | 6 ++---- packages/page-staking/src/Query/ChartPoints.tsx | 4 ++-- packages/page-staking/src/Query/ChartPrefs.tsx | 4 ++-- packages/page-staking/src/Query/ChartRewards.tsx | 8 ++++---- packages/page-staking/src/Query/ChartStake.tsx | 4 ++-- packages/page-staking/src/Query/index.tsx | 6 ++---- packages/page-staking/src/Query/useBlockCounts.tsx | 5 ++--- packages/page-staking/src/Slashes/Summary.tsx | 3 +-- packages/page-staking/src/Targets/Summary.tsx | 2 +- packages/page-staking/src/Validators/Address/index.tsx | 4 ++-- packages/page-staking/src/Validators/index.tsx | 4 ++-- packages/page-staking/src/index.tsx | 3 +-- packages/page-staking/src/useIdentities.ts | 2 +- packages/page-staking/src/useSortedTargets.ts | 6 +++--- packages/page-staking2/src/Pools/useAmountError.ts | 3 +-- packages/page-staking2/src/useSessionInfo.ts | 2 +- packages/page-tech-comm/src/App.tsx | 5 ++--- packages/page-tech-comm/src/Overview/Summary.tsx | 3 +-- packages/page-tech-comm/src/Proposals/Proposal.tsx | 3 +-- packages/page-tech-comm/src/useCounter.ts | 2 +- packages/page-treasury/src/Overview/Summary.tsx | 4 +--- packages/page-treasury/src/Overview/index.tsx | 4 +--- packages/page-treasury/src/Tips/TipEndorse.tsx | 2 +- packages/page-treasury/src/Tips/TipReason.tsx | 2 +- packages/page-treasury/src/useCounter.ts | 4 +--- packages/react-components/src/StakingRedeemable.tsx | 2 +- packages/react-components/src/StakingUnbonding.tsx | 2 +- packages/react-components/src/VoteValue.tsx | 2 +- packages/react-components/src/modals/Transfer.tsx | 5 ++--- packages/react-hooks/src/ctx/BlockAuthors.tsx | 3 +-- packages/react-hooks/src/ctx/BlockEvents.tsx | 2 +- packages/react-hooks/src/useAccountInfo.ts | 5 ++--- packages/react-hooks/src/useBalancesAll.ts | 2 +- packages/react-hooks/src/useBestHash.ts | 2 +- packages/react-hooks/src/useBestNumber.ts | 6 ++---- packages/react-hooks/src/useCall.ts | 2 +- packages/react-hooks/src/useDelegations.ts | 4 ++-- packages/react-hooks/src/useDeriveAccountInfo.ts | 2 +- packages/react-hooks/src/useEventTrigger.ts | 3 +-- packages/react-hooks/src/useExtrinsicTrigger.ts | 3 +-- packages/react-hooks/src/useProxies.ts | 4 ++-- packages/react-hooks/src/useRegistrars.ts | 4 +--- packages/react-hooks/src/useStakingInfo.ts | 6 ++---- packages/react-hooks/src/useSubidentities.ts | 6 ++---- packages/react-hooks/src/useSudo.ts | 2 +- packages/react-query/src/BestFinalized.tsx | 4 +--- packages/react-query/src/BestNumber.tsx | 4 +--- packages/react-query/src/Nonce.tsx | 3 +-- packages/react-query/src/SessionToTime.tsx | 3 +-- packages/react-query/src/TimeNow.tsx | 2 +- packages/react-query/src/TotalInactive.tsx | 2 +- packages/react-query/src/TotalIssuance.tsx | 2 +- packages/react-signer/src/PaymentInfo.tsx | 3 +-- 129 files changed, 183 insertions(+), 275 deletions(-) diff --git a/packages/apps/src/Content/Status.tsx b/packages/apps/src/Content/Status.tsx index 95667e075092..f05b1e5b8fc7 100644 --- a/packages/apps/src/Content/Status.tsx +++ b/packages/apps/src/Content/Status.tsx @@ -66,7 +66,7 @@ function Status ({ optionsAll }: Props): React.ReactElement { const { api, isApiReady } = useApi(); const { allAccounts } = useAccounts(); const { t } = useTranslation(); - const events = useCall(isApiReady && api.query.system?.events); + const events = useCall(isApiReady && api.query.system?.events); useEffect((): void => { const filtered = filterEvents(allAccounts, t, optionsAll, events); diff --git a/packages/apps/src/Menu/ChainInfo.tsx b/packages/apps/src/Menu/ChainInfo.tsx index 953273814a2a..e05b0ee5d499 100644 --- a/packages/apps/src/Menu/ChainInfo.tsx +++ b/packages/apps/src/Menu/ChainInfo.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/apps authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { RuntimeVersion } from '@polkadot/types/interfaces'; - import React from 'react'; import { ChainImg, Icon, styled } from '@polkadot/react-components'; @@ -17,7 +15,7 @@ interface Props { function ChainInfo ({ className }: Props): React.ReactElement { const { api, isApiReady } = useApi(); - const runtimeVersion = useCall(isApiReady && api.rpc.state.subscribeRuntimeVersion); + const runtimeVersion = useCall(isApiReady && api.rpc.state.subscribeRuntimeVersion); const { ipnsChain } = useIpfs(); const [isEndpointsVisible, toggleEndpoints] = useToggle(); const canToggle = !ipnsChain; diff --git a/packages/apps/src/Menu/index.tsx b/packages/apps/src/Menu/index.tsx index a6d9195f7c91..e4a719c5f378 100644 --- a/packages/apps/src/Menu/index.tsx +++ b/packages/apps/src/Menu/index.tsx @@ -4,7 +4,6 @@ import type { TFunction } from 'i18next'; import type { Route, Routes } from '@polkadot/apps-routing/types'; import type { ApiProps } from '@polkadot/react-api/types'; -import type { AccountId } from '@polkadot/types/interfaces'; import type { Group, Groups, ItemRoute } from './types.js'; import React, { useMemo, useRef } from 'react'; @@ -92,7 +91,7 @@ function Menu ({ className = '' }: Props): React.ReactElement { const { allAccounts, hasAccounts } = useAccounts(); const apiProps = useApi(); const { allowTeleport } = useTeleport(); - const sudoKey = useCall(apiProps.isApiReady && apiProps.api.query.sudo?.key); + const sudoKey = useCall(apiProps.isApiReady && apiProps.api.query.sudo?.key); const location = useLocation(); const externalRef = useRef(createExternals(t)); diff --git a/packages/apps/src/WarmUp.tsx b/packages/apps/src/WarmUp.tsx index c96a23fdbf4d..ff8b62ca7d6c 100644 --- a/packages/apps/src/WarmUp.tsx +++ b/packages/apps/src/WarmUp.tsx @@ -7,9 +7,9 @@ import { useApi, useCall } from '@polkadot/react-hooks'; function WarmUp (): React.ReactElement { const { api, isApiReady } = useApi(); - const indexes = useCall(isApiReady && api.derive.accounts?.indexes); - const registrars = useCall(isApiReady && api.query.identity?.registrars); - const issuance = useCall(isApiReady && api.query.balances?.totalIssuance); + const indexes = useCall(isApiReady && api.derive.accounts?.indexes); + const registrars = useCall(isApiReady && api.query.identity?.registrars); + const issuance = useCall(isApiReady && api.query.balances?.totalIssuance); const [hasValues, setHasValues] = useState(false); useEffect((): void => { diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index a97fe4b94529..8a50dcaf3b84 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -3,7 +3,7 @@ import type { ApiPromise } from '@polkadot/api'; import type { SubmittableExtrinsic } from '@polkadot/api/types'; -import type { DeriveDemocracyLock, DeriveStakingAccount } from '@polkadot/api-derive/types'; +import type { DeriveStakingAccount } from '@polkadot/api-derive/types'; import type { Ledger } from '@polkadot/hw-ledger'; import type { ActionStatus } from '@polkadot/react-components/Status/types'; import type { Option } from '@polkadot/types'; @@ -155,8 +155,8 @@ function Account ({ account: { address, meta }, className = '', delegation, filt const bestNumber = useBestNumber(); const balancesAll = useBalancesAll(address); const stakingInfo = useStakingInfo(address); - const democracyLocks = useCall(api.api.derive.democracy?.locks, [address]); - const recoveryInfo = useCall(api.api.query.recovery?.recoverable, [address], transformRecovery); + const democracyLocks = useCall(api.api.derive.democracy?.locks, [address]); + const recoveryInfo = useCall(api.api.query.recovery?.recoverable, [address], transformRecovery); const multiInfos = useMultisigApprovals(address); const proxyInfo = useProxies(address); const { flags: { isDevelopment, isEditable, isEthereum, isExternal, isHardware, isInjected, isMultisig, isProxied }, genesisHash, identity, name: accName, onSetGenesisHash, tags } = useAccountInfo(address); diff --git a/packages/page-accounts/src/modals/IdentityMain.tsx b/packages/page-accounts/src/modals/IdentityMain.tsx index 37e0c6bb471b..8afb888cbd5e 100644 --- a/packages/page-accounts/src/modals/IdentityMain.tsx +++ b/packages/page-accounts/src/modals/IdentityMain.tsx @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import type { ApiPromise } from '@polkadot/api'; -import type { Data, Option } from '@polkadot/types'; -import type { IdentityInfo, Registration } from '@polkadot/types/interfaces'; +import type { Data } from '@polkadot/types'; +import type { IdentityInfo } from '@polkadot/types/interfaces'; import React, { useEffect, useState } from 'react'; @@ -70,7 +70,7 @@ function checkValue (hasValue: boolean, value: string | null | undefined, minLen function IdentityMain ({ address, className = '', onClose }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const identityOpt = useCall>(api.query.identity.identityOf, [address]); + const identityOpt = useCall(api.query.identity.identityOf, [address]); const [{ info, okAll, okDiscord, okDisplay, okEmail, okLegal, okRiot, okTwitter, okWeb }, setInfo] = useState({ info: {}, okAll: false }); const [hasEmail, setHasEmail] = useState(false); const [hasLegal, setHasLegal] = useState(false); diff --git a/packages/page-accounts/src/modals/InputValidateAmount.tsx b/packages/page-accounts/src/modals/InputValidateAmount.tsx index a7e83c93f08c..543f112d9eb6 100644 --- a/packages/page-accounts/src/modals/InputValidateAmount.tsx +++ b/packages/page-accounts/src/modals/InputValidateAmount.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { BN } from '@polkadot/util'; import type { AmountValidateState } from '../Accounts/types.js'; @@ -22,7 +21,7 @@ interface Props { function ValidateAmount ({ amount, delegatingAccount, onError }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const delegatingAccountBalance = useCall(api.derive.balances?.all, [delegatingAccount]); + const delegatingAccountBalance = useCall(api.derive.balances?.all, [delegatingAccount]); const [{ error, warning }, setResult] = useState({ error: null, warning: null }); useEffect((): void => { diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index 09f70a9128b9..c683fc37eb5e 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-addresses authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveAccountInfo } from '@polkadot/api-derive/types'; import type { ActionStatus } from '@polkadot/react-components/Status/types'; import type { ModalProps as Props } from '../types.js'; @@ -33,7 +32,7 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement const { api, isEthereum } = useApi(); const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' }); const [{ address, addressInput, isAddressExisting, isAddressValid }, setAddress] = useState({ address: '', addressInput: '', isAddressExisting: false, isAddressValid: false, isPublicKey: false }); - const info = useCall(!!address && isAddressValid && api.derive.accounts.info, [address]); + const info = useCall(!!address && isAddressValid && api.derive.accounts.info, [address]); const isValid = (isAddressValid && isNameValid) && !!info?.accountId; const _onChangeAddress = useCallback( diff --git a/packages/page-alliance/src/index.tsx b/packages/page-alliance/src/index.tsx index 2a1fbc6bcaf0..bba2cb901dd0 100644 --- a/packages/page-alliance/src/index.tsx +++ b/packages/page-alliance/src/index.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-alliance authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Hash } from '@polkadot/types/interfaces'; - import React, { useCallback, useMemo } from 'react'; import { Route, Routes } from 'react-router'; @@ -32,7 +30,7 @@ const DEFAULT_THRESHOLD = 2 / 3; function AllianceApp ({ basePath, className }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const proposalHashes = useCall(api.derive.alliance.proposalHashes); + const proposalHashes = useCall(api.derive.alliance.proposalHashes); const { isMember: isVoter, members: voters, prime } = useCollectiveMembers('alliance'); const accouncements = useAnnoucements(); const members = useMembers(); diff --git a/packages/page-alliance/src/useAnnoucements.ts b/packages/page-alliance/src/useAnnoucements.ts index c7b94619311d..0cd93f94a1e9 100644 --- a/packages/page-alliance/src/useAnnoucements.ts +++ b/packages/page-alliance/src/useAnnoucements.ts @@ -16,7 +16,7 @@ const OPT_ANN = { function useAnnouncementsImpl (): Cid[] | undefined { const { api } = useApi(); - return useCall(api.query.alliance.announcements, [], OPT_ANN); + return useCall(api.query.alliance.announcements, [], OPT_ANN); } export default createNamedHook('useAnnouncements', useAnnouncementsImpl); diff --git a/packages/page-alliance/src/useCounter.ts b/packages/page-alliance/src/useCounter.ts index 86b4d9abc182..54ae043b4019 100644 --- a/packages/page-alliance/src/useCounter.ts +++ b/packages/page-alliance/src/useCounter.ts @@ -7,7 +7,7 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useCounterImpl (): number { const { api, isApiReady } = useApi(); - const proposalHashes = useCall(isApiReady && api.derive.alliance.proposalHashes); + const proposalHashes = useCall(isApiReady && api.derive.alliance.proposalHashes); return useMemo( () => (proposalHashes && proposalHashes.length) || 0, diff --git a/packages/page-alliance/src/useMembers.ts b/packages/page-alliance/src/useMembers.ts index 446ce295415a..f23008da24f9 100644 --- a/packages/page-alliance/src/useMembers.ts +++ b/packages/page-alliance/src/useMembers.ts @@ -37,9 +37,9 @@ function addMembers (prev: Member[], ...query: AccountId32[][]): Member[] { function useMembersImpl (): Member[] | undefined { const { api } = useApi(); const [state, setState] = useState(); - const role0 = useCall(api.query.alliance.members, [ROLES[0]]); - const role1 = useCall(api.query.alliance.members, [ROLES[1]]); - const role2 = useCall(api.query.alliance.members, [ROLES[2]]); + const role0 = useCall(api.query.alliance.members, [ROLES[0]]); + const role1 = useCall(api.query.alliance.members, [ROLES[1]]); + const role2 = useCall(api.query.alliance.members, [ROLES[2]]); useEffect((): void => { role0 && role1 && role2 && diff --git a/packages/page-alliance/src/useRule.ts b/packages/page-alliance/src/useRule.ts index 69fbe24da489..afc5c70e72ce 100644 --- a/packages/page-alliance/src/useRule.ts +++ b/packages/page-alliance/src/useRule.ts @@ -19,7 +19,7 @@ const OPT_RULE = { function useRuleImpl (): Rule | undefined { const { api } = useApi(); - return useCall(api.query.alliance.rule, [], OPT_RULE); + return useCall(api.query.alliance.rule, [], OPT_RULE); } export default createNamedHook('useRule', useRuleImpl); diff --git a/packages/page-alliance/src/useUnscrupulous.ts b/packages/page-alliance/src/useUnscrupulous.ts index 01b0356c63e9..1c53daf9ebbb 100644 --- a/packages/page-alliance/src/useUnscrupulous.ts +++ b/packages/page-alliance/src/useUnscrupulous.ts @@ -25,8 +25,8 @@ const OPT_WEB = { function useUnscrupulousImpl (): Unscrupulous | undefined { const { api } = useApi(); - const accounts = useCall(api.query.alliance.unscrupulousAccounts, [], OPT_ACC); - const websites = useCall(api.query.alliance.unscrupulousWebsites, [], OPT_WEB); + const accounts = useCall(api.query.alliance.unscrupulousAccounts, [], OPT_ACC); + const websites = useCall(api.query.alliance.unscrupulousWebsites, [], OPT_WEB); return useMemo( () => accounts && websites && { accounts, websites }, diff --git a/packages/page-bounties/src/hooks/useBalance.ts b/packages/page-bounties/src/hooks/useBalance.ts index c8d22652aae4..d9f7b79b95d7 100644 --- a/packages/page-bounties/src/hooks/useBalance.ts +++ b/packages/page-bounties/src/hooks/useBalance.ts @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-bounties authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { Balance } from '@polkadot/types/interfaces'; import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; @@ -9,7 +8,7 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useBalanceImpl (accountId: string | null): Balance | undefined { const { api } = useApi(); - return useCall(api.derive.balances?.all, [accountId])?.availableBalance; + return useCall(api.derive.balances?.all, [accountId])?.availableBalance; } export const useBalance = createNamedHook('useBalance', useBalanceImpl); diff --git a/packages/page-bounties/src/hooks/useBounties.tsx b/packages/page-bounties/src/hooks/useBounties.tsx index 99c4a46a1f9c..89493a98c5c4 100644 --- a/packages/page-bounties/src/hooks/useBounties.tsx +++ b/packages/page-bounties/src/hooks/useBounties.tsx @@ -73,9 +73,9 @@ function getStatics (api: ApiPromise): BountyApiStatics { function useBountiesImpl (): BountyApi { const { api } = useApi(); - const bounties = useCall(api.derive.bounties.bounties); - const bountyCount = useCall((api.query.bounties || api.query.treasury).bountyCount); - const childCount = useCall(api.query.childBounties?.childBountyCount); + const bounties = useCall(api.derive.bounties.bounties); + const bountyCount = useCall((api.query.bounties || api.query.treasury).bountyCount); + const childCount = useCall(api.query.childBounties?.childBountyCount); const bestNumber = useBestNumber(); const statics = useMemo( diff --git a/packages/page-bounties/src/useCounter.ts b/packages/page-bounties/src/useCounter.ts index f8b5e9a8f49a..259427c67da3 100644 --- a/packages/page-bounties/src/useCounter.ts +++ b/packages/page-bounties/src/useCounter.ts @@ -1,15 +1,13 @@ // Copyright 2017-2023 @polkadot/app-bounties authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBounties } from '@polkadot/api-derive/types'; - import { useMemo } from 'react'; import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useCounterImpl (): number { const { api, isApiReady } = useApi(); - const bounties = useCall(isApiReady && api.derive.bounties?.bounties); + const bounties = useCall(isApiReady && api.derive.bounties?.bounties); return useMemo( () => bounties?.length || 0, diff --git a/packages/page-collator/src/useCollators.ts b/packages/page-collator/src/useCollators.ts index 0f7f52a1fdf5..5c5fa9d1bd9c 100644 --- a/packages/page-collator/src/useCollators.ts +++ b/packages/page-collator/src/useCollators.ts @@ -74,9 +74,9 @@ function useCollatorImpl (): Collator[] | undefined { [state] ); - const invulnerables = useCall(api.query.collatorSelection.invulnerables, [], OPT_INV); - const candidates = useCall(api.query.collatorSelection.candidates, [], OPT_CAN); - const lastBlocks = useCall(accountIds && api.query.collatorSelection.lastAuthoredBlock?.multi, [accountIds], OPT_AUT); + const invulnerables = useCall(api.query.collatorSelection.invulnerables, [], OPT_INV); + const candidates = useCall(api.query.collatorSelection.candidates, [], OPT_CAN); + const lastBlocks = useCall(accountIds && api.query.collatorSelection.lastAuthoredBlock?.multi, [accountIds], OPT_AUT); useEffect( () => invulnerables && candidates && setState(() => diff --git a/packages/page-contracts/src/Codes/Code.tsx b/packages/page-contracts/src/Codes/Code.tsx index 1c260e334813..11cbca80a2ec 100644 --- a/packages/page-contracts/src/Codes/Code.tsx +++ b/packages/page-contracts/src/Codes/Code.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Option } from '@polkadot/types'; -import type { Codec } from '@polkadot/types/types'; import type { CodeStored } from '../types.js'; import React, { useCallback } from 'react'; @@ -24,7 +22,7 @@ interface Props { function Code ({ className, code, onShowDeploy }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const optCode = useCall>(api.query.contracts.codeStorage, [code.json.codeHash]); + const optCode = useCall(api.query.contracts.codeStorage, [code.json.codeHash]); const [isForgetOpen, toggleIsForgetOpen] = useToggle(); const { contractAbi } = useAbi([code.json.abi, code.contractAbi], code.json.codeHash, true); diff --git a/packages/page-contracts/src/Codes/ValidateCode.tsx b/packages/page-contracts/src/Codes/ValidateCode.tsx index 6bb0e0907f20..efebd901d499 100644 --- a/packages/page-contracts/src/Codes/ValidateCode.tsx +++ b/packages/page-contracts/src/Codes/ValidateCode.tsx @@ -3,9 +3,6 @@ /* eslint-disable camelcase */ -import type { Option } from '@polkadot/types'; -import type { PrefabWasmModule } from '@polkadot/types/interfaces'; - import React, { useMemo } from 'react'; import { InfoForInput } from '@polkadot/react-components'; @@ -22,7 +19,7 @@ interface Props { function ValidateCode ({ codeHash, onChange }: Props): React.ReactElement | null { const { api } = useApi(); const { t } = useTranslation(); - const codeStorage = useCall>((api.query.contracts || api.query.contract).codeStorage, [codeHash]); + const codeStorage = useCall((api.query.contracts || api.query.contract).codeStorage, [codeHash]); const [isValidHex, isValid] = useMemo( (): [boolean, boolean] => { const isValidHex = !!codeHash && isHex(codeHash) && codeHash.length === 66; diff --git a/packages/page-contracts/src/Contracts/Contract.tsx b/packages/page-contracts/src/Contracts/Contract.tsx index 0e1a3326b114..2d240596f996 100644 --- a/packages/page-contracts/src/Contracts/Contract.tsx +++ b/packages/page-contracts/src/Contracts/Contract.tsx @@ -33,7 +33,7 @@ function transformInfo (optInfo: Option): ContractInfo | null { function Contract ({ className, contract, index, links, onCall }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const info = useCall(api.query.contracts.contractInfoOf, [contract.address], { transform: transformInfo }); + const info = useCall(api.query.contracts.contractInfoOf, [contract.address], { transform: transformInfo }); const [isForgetOpen, toggleIsForgetOpen] = useToggle(); const _onCall = useCallback( diff --git a/packages/page-contracts/src/Contracts/ContractsTable.tsx b/packages/page-contracts/src/Contracts/ContractsTable.tsx index a085f5311246..7f623e11e7d7 100644 --- a/packages/page-contracts/src/Contracts/ContractsTable.tsx +++ b/packages/page-contracts/src/Contracts/ContractsTable.tsx @@ -4,7 +4,6 @@ import type { ApiPromise } from '@polkadot/api'; import type { ContractPromise } from '@polkadot/api-contract'; import type { ContractCallOutcome } from '@polkadot/api-contract/types'; -import type { SignedBlockExtended } from '@polkadot/api-derive/types'; import type { ContractLink } from './types.js'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; @@ -38,7 +37,7 @@ function filterContracts (api: ApiPromise, keyringContracts: string[] = []): Con function ContractsTable ({ contracts: keyringContracts }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const newBlock = useCall(api.derive.chain.subscribeNewBlocks); + const newBlock = useCall(api.derive.chain.subscribeNewBlocks); const [{ contractIndex, messageIndex, onCallResult }, setIndexes] = useState({ contractIndex: 0, messageIndex: 0 }); const [isCallOpen, setIsCallOpen] = useState(false); const [contractLinks, setContractLinks] = useState>({}); diff --git a/packages/page-contracts/src/Contracts/ValidateAddr.tsx b/packages/page-contracts/src/Contracts/ValidateAddr.tsx index 8e26979fa5e8..eb8ed95bf865 100644 --- a/packages/page-contracts/src/Contracts/ValidateAddr.tsx +++ b/packages/page-contracts/src/Contracts/ValidateAddr.tsx @@ -1,9 +1,6 @@ // Copyright 2017-2023 @polkadot/app-contracts authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Option } from '@polkadot/types'; -import type { ContractInfo } from '@polkadot/types/interfaces'; - import React, { useEffect, useState } from 'react'; import { InfoForInput } from '@polkadot/react-components'; @@ -20,7 +17,7 @@ interface Props { function ValidateAddr ({ address, onChange }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const contractInfo = useCall>(api.query.contracts.contractInfoOf, [address]); + const contractInfo = useCall(api.query.contracts.contractInfoOf, [address]); const [isAddress, setIsAddress] = useState(false); const [isStored, setIsStored] = useState(false); diff --git a/packages/page-contracts/src/shared/Messages.tsx b/packages/page-contracts/src/shared/Messages.tsx index c7d4b92ab504..a9e612aa448a 100644 --- a/packages/page-contracts/src/shared/Messages.tsx +++ b/packages/page-contracts/src/shared/Messages.tsx @@ -3,8 +3,6 @@ import type { Abi, ContractPromise } from '@polkadot/api-contract'; import type { AbiMessage, ContractCallOutcome } from '@polkadot/api-contract/types'; -import type { Option } from '@polkadot/types'; -import type { ContractInfo } from '@polkadot/types/interfaces'; import React, { useCallback, useEffect, useState } from 'react'; @@ -46,7 +44,7 @@ function sortMessages (messages: AbiMessage[]): [AbiMessage, number][] { function Messages ({ className = '', contract, contractAbi: { constructors, info: { source }, messages }, isLabelled, isWatching, onSelect, onSelectConstructor, trigger, withConstructors, withMessages, withWasm }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const optInfo = useCall>(contract && api.query.contracts.contractInfoOf, [contract?.address]); + const optInfo = useCall(contract && api.query.contracts.contractInfoOf, [contract?.address]); const [isUpdating, setIsUpdating] = useState(false); const [lastResults, setLastResults] = useState<(ContractCallOutcome | undefined)[]>([]); diff --git a/packages/page-council/src/Overview/index.tsx b/packages/page-council/src/Overview/index.tsx index bfed48205de1..18a39d71ca70 100644 --- a/packages/page-council/src/Overview/index.tsx +++ b/packages/page-council/src/Overview/index.tsx @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/app-council authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveCouncilVotes, DeriveElectionsInfo } from '@polkadot/api-derive/types'; +import type { DeriveCouncilVotes } from '@polkadot/api-derive/types'; import type { AccountId } from '@polkadot/types/interfaces'; import React from 'react'; @@ -41,8 +41,8 @@ const transformVotes = { function Overview ({ className = '', prime }: Props): React.ReactElement { const { api } = useApi(); const bestNumber = useBestNumber(); - const electionsInfo = useCall(api.derive.elections.info); - const allVotes = useCall>(api.derive.council.votes, undefined, transformVotes); + const electionsInfo = useCall(api.derive.elections.info); + const allVotes = useCall(api.derive.council.votes, undefined, transformVotes); const modElections = useModuleElections(); const hasElections = !!modElections; diff --git a/packages/page-council/src/index.tsx b/packages/page-council/src/index.tsx index 10d4908b608c..b0caafa0198e 100644 --- a/packages/page-council/src/index.tsx +++ b/packages/page-council/src/index.tsx @@ -1,9 +1,6 @@ // Copyright 2017-2023 @polkadot/app-council authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types'; -import type { AccountId } from '@polkadot/types/interfaces'; - import React, { useMemo } from 'react'; import { Route, Routes } from 'react-router'; import { useLocation } from 'react-router-dom'; @@ -28,8 +25,8 @@ function CouncilApp ({ basePath, className }: Props): React.ReactElement const { api } = useApi(); const { pathname } = useLocation(); const numMotions = useCounter(); - const prime = useCall(api.derive.council.prime); - const motions = useCall(api.derive.council.proposals); + const prime = useCall(api.derive.council.prime); + const motions = useCall(api.derive.council.proposals); const items = useMemo(() => [ { diff --git a/packages/page-council/src/useCounter.ts b/packages/page-council/src/useCounter.ts index 30bb6df2c657..ffbcf5980d91 100644 --- a/packages/page-council/src/useCounter.ts +++ b/packages/page-council/src/useCounter.ts @@ -12,7 +12,7 @@ const transformCounter = { function useCounterImpl (): number { const { hasAccounts } = useAccounts(); const { api, isApiReady } = useApi(); - const counter = useCall(isApiReady && hasAccounts && api.derive.council?.proposals, undefined, transformCounter) || 0; + const counter = useCall(isApiReady && hasAccounts && api.derive.council?.proposals, undefined, transformCounter) || 0; return counter; } diff --git a/packages/page-democracy/src/Overview/ExternalCell.tsx b/packages/page-democracy/src/Overview/ExternalCell.tsx index 5df22e55acd7..246562b5b4d2 100644 --- a/packages/page-democracy/src/Overview/ExternalCell.tsx +++ b/packages/page-democracy/src/Overview/ExternalCell.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-democracy authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveProposalImage } from '@polkadot/api-derive/types'; import type { Hash } from '@polkadot/types/interfaces'; import React from 'react'; @@ -19,7 +18,7 @@ interface Props { function ExternalCell ({ className = '', value }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const preimage = useCall(api.derive.democracy.preimage, [value]); + const preimage = useCall(api.derive.democracy.preimage, [value]); if (!preimage?.proposal) { return null; diff --git a/packages/page-democracy/src/Overview/Externals.tsx b/packages/page-democracy/src/Overview/Externals.tsx index cb07e0ae4fe2..d5e1c80523ed 100644 --- a/packages/page-democracy/src/Overview/Externals.tsx +++ b/packages/page-democracy/src/Overview/Externals.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-democracy authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveProposalExternal } from '@polkadot/api-derive/types'; - import React, { useRef } from 'react'; import { Table } from '@polkadot/react-components'; @@ -18,7 +16,7 @@ interface Props { function Externals ({ className }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const external = useCall(api.derive.democracy.nextExternal); + const external = useCall(api.derive.democracy.nextExternal); const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([ [t('external'), 'start'], diff --git a/packages/page-democracy/src/Overview/Proposals.tsx b/packages/page-democracy/src/Overview/Proposals.tsx index b687853ecfc2..c27e354025e7 100644 --- a/packages/page-democracy/src/Overview/Proposals.tsx +++ b/packages/page-democracy/src/Overview/Proposals.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-democracy authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveProposal } from '@polkadot/api-derive/types'; - import React, { useRef } from 'react'; import { Table } from '@polkadot/react-components'; @@ -18,7 +16,7 @@ interface Props { function Proposals ({ className }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const proposals = useCall(api.derive.democracy.proposals); + const proposals = useCall(api.derive.democracy.proposals); const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([ [t('proposals'), 'start', 2], diff --git a/packages/page-democracy/src/Overview/Propose.tsx b/packages/page-democracy/src/Overview/Propose.tsx index 73a1e9559477..e8e8ea0f7279 100644 --- a/packages/page-democracy/src/Overview/Propose.tsx +++ b/packages/page-democracy/src/Overview/Propose.tsx @@ -29,7 +29,7 @@ function Propose ({ className = '', onClose }: Props): React.ReactElement const [accountId, setAccountId] = useState(null); const [balance, setBalance] = useState(); const [{ hash, isHashValid }, setHash] = useState({ isHashValid: false }); - const publicProps = useCall(api.query.democracy.publicProps); + const publicProps = useCall(api.query.democracy.publicProps); const preimage = usePreimage(hash); const _onChangeHash = useCallback( diff --git a/packages/page-democracy/src/Overview/Referendum.tsx b/packages/page-democracy/src/Overview/Referendum.tsx index b0c4c6051722..6e892c3a619b 100644 --- a/packages/page-democracy/src/Overview/Referendum.tsx +++ b/packages/page-democracy/src/Overview/Referendum.tsx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { DeriveReferendumExt } from '@polkadot/api-derive/types'; -import type { Balance } from '@polkadot/types/interfaces'; import React, { useMemo } from 'react'; @@ -44,7 +43,7 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash const { allAccounts } = useAccounts(); const bestNumber = useBestNumber(); const [isExpanded, toggleIsExpanded] = useToggle(false); - const totalIssuance = useCall(api.query.balances?.totalIssuance); + const totalIssuance = useCall(api.query.balances?.totalIssuance); const { changeAye, changeNay } = useChangeCalc(status.threshold, votedAye, votedNay, votedTotal); const threshold = useMemo( () => status.threshold.type.toString().replace('majority', ' majority '), diff --git a/packages/page-democracy/src/Overview/Summary.tsx b/packages/page-democracy/src/Overview/Summary.tsx index 9060d98bfc41..dd2ea426d639 100644 --- a/packages/page-democracy/src/Overview/Summary.tsx +++ b/packages/page-democracy/src/Overview/Summary.tsx @@ -22,7 +22,7 @@ const optMulti = { function Summary ({ referendumCount }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const activeProposals = useCall(api.derive.democracy.proposals); + const activeProposals = useCall(api.derive.democracy.proposals); const bestNumber = useBestNumber(); const [publicPropCount, referendumTotal] = useCallMulti<[BN | undefined, BN | undefined]>([ api.query.democracy.publicPropCount, diff --git a/packages/page-democracy/src/Overview/TreasuryCell.tsx b/packages/page-democracy/src/Overview/TreasuryCell.tsx index bd2fa24fd6be..3420a55b33e6 100644 --- a/packages/page-democracy/src/Overview/TreasuryCell.tsx +++ b/packages/page-democracy/src/Overview/TreasuryCell.tsx @@ -44,7 +44,7 @@ function TreasuryCell ({ className = '', value }: Props): React.ReactElement value.unwrap()); - const proposal = useCall(api.query.treasury.proposals, [proposalId], OPT_PROP); + const proposal = useCall(api.query.treasury.proposals, [proposalId], OPT_PROP); const [{ params, values }, setExtracted] = useState(DEFAULT_PARAMS); useEffect((): void => { diff --git a/packages/page-democracy/src/Overview/index.tsx b/packages/page-democracy/src/Overview/index.tsx index a47d1e246ba0..4a17e56675e7 100644 --- a/packages/page-democracy/src/Overview/index.tsx +++ b/packages/page-democracy/src/Overview/index.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-democracy authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveReferendumExt } from '@polkadot/api-derive/types'; - import React from 'react'; import { Button } from '@polkadot/react-components'; @@ -25,7 +23,7 @@ function Overview ({ className }: Props): React.ReactElement { const { api } = useApi(); const [isPreimageOpen, togglePreimage] = useToggle(); const [isProposeOpen, togglePropose] = useToggle(); - const referendums = useCall(api.derive.democracy.referendums); + const referendums = useCall(api.derive.democracy.referendums); return (
diff --git a/packages/page-democracy/src/useChangeCalc.ts b/packages/page-democracy/src/useChangeCalc.ts index 8c831b260cf5..7be7799f744a 100644 --- a/packages/page-democracy/src/useChangeCalc.ts +++ b/packages/page-democracy/src/useChangeCalc.ts @@ -18,7 +18,7 @@ interface Result { function useChangeCalcImpl (threshold: VoteThreshold, votedAye: BN, votedNay: BN, votedTotal: BN): Result { const { api } = useApi(); - const sqrtElectorate = useCall(api.derive.democracy.sqrtElectorate); + const sqrtElectorate = useCall(api.derive.democracy.sqrtElectorate); const [result, setResult] = useState({ changeAye: BN_ZERO, changeNay: BN_ZERO }); useEffect((): void => { diff --git a/packages/page-democracy/src/useCounter.ts b/packages/page-democracy/src/useCounter.ts index dbd3dac69e92..a42fa30037ff 100644 --- a/packages/page-democracy/src/useCounter.ts +++ b/packages/page-democracy/src/useCounter.ts @@ -9,8 +9,8 @@ function useCounterImpl (): number { const { hasAccounts } = useAccounts(); const { api, isApiReady } = useApi(); const mountedRef = useIsMountedRef(); - const proposals = useCall(isApiReady && hasAccounts && api.derive.democracy?.proposals); - const referenda = useCall(isApiReady && hasAccounts && api.derive.democracy?.referendumsActive); + const proposals = useCall(isApiReady && hasAccounts && api.derive.democracy?.proposals); + const referenda = useCall(isApiReady && hasAccounts && api.derive.democracy?.referendumsActive); const [counter, setCounter] = useState(0); useEffect((): void => { diff --git a/packages/page-explorer/src/BestHash.tsx b/packages/page-explorer/src/BestHash.tsx index 575ad8284a50..48960440d276 100644 --- a/packages/page-explorer/src/BestHash.tsx +++ b/packages/page-explorer/src/BestHash.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/react-query authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Header } from '@polkadot/types/interfaces'; - import React from 'react'; import { useApi, useCall } from '@polkadot/react-hooks'; @@ -14,7 +12,7 @@ interface Props { function BestHash ({ className = '', label }: Props): React.ReactElement { const { api } = useApi(); - const newHead = useCall
(api.rpc.chain.subscribeNewHeads); + const newHead = useCall(api.rpc.chain.subscribeNewHeads); return (
diff --git a/packages/page-explorer/src/Latency/useLatency.ts b/packages/page-explorer/src/Latency/useLatency.ts index 09e319ce7895..88ba06218bc1 100644 --- a/packages/page-explorer/src/Latency/useLatency.ts +++ b/packages/page-explorer/src/Latency/useLatency.ts @@ -119,7 +119,7 @@ async function getNext (api: ApiPromise, { block: { number: start } }: Detail, { function useLatencyImpl (): Result { const { api } = useApi(); const [details, setDetails] = useState([]); - const signedBlock = useCall(api.derive.chain.subscribeNewBlocks); + const signedBlock = useCall(api.derive.chain.subscribeNewBlocks); const hasHistoric = useRef(false); useEffect((): void => { diff --git a/packages/page-explorer/src/SummarySession.tsx b/packages/page-explorer/src/SummarySession.tsx index f26f4bd968dc..83eaf9a8d83e 100644 --- a/packages/page-explorer/src/SummarySession.tsx +++ b/packages/page-explorer/src/SummarySession.tsx @@ -1,9 +1,6 @@ // Copyright 2017-2023 @polkadot/app-explorer authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveSessionProgress } from '@polkadot/api-derive/types'; -import type { Forcing } from '@polkadot/types/interfaces'; - import React from 'react'; import { CardSummary } from '@polkadot/react-components'; @@ -22,8 +19,8 @@ interface Props { function SummarySession ({ className, withEra = true, withSession = true }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const sessionInfo = useCall(api.derive.session?.progress); - const forcing = useCall(api.query.staking?.forceEra); + const sessionInfo = useCall(api.derive.session?.progress); + const forcing = useCall(api.query.staking?.forceEra); const eraLabel = t('era'); const sessionLabel = api.query.babe diff --git a/packages/page-membership/src/useCounter.ts b/packages/page-membership/src/useCounter.ts index 090b21591c9d..b893c94657ea 100644 --- a/packages/page-membership/src/useCounter.ts +++ b/packages/page-membership/src/useCounter.ts @@ -11,7 +11,7 @@ const OPT = { function useCounterImpl (): number { const { api, isApiReady } = useApi(); - const counter = useCall(isApiReady && api.query.membership?.proposals, undefined, OPT) || 0; + const counter = useCall(isApiReady && api.query.membership?.proposals, undefined, OPT) || 0; return counter; } diff --git a/packages/page-parachains/src/Auctions/Summary.tsx b/packages/page-parachains/src/Auctions/Summary.tsx index f950426c57af..0e24a8c43bec 100644 --- a/packages/page-parachains/src/Auctions/Summary.tsx +++ b/packages/page-parachains/src/Auctions/Summary.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { u32 } from '@polkadot/types'; -import type { Balance, BlockNumber } from '@polkadot/types/interfaces'; +import type { BlockNumber } from '@polkadot/types/interfaces'; import type { AuctionInfo, Winning } from '../types.js'; import React from 'react'; @@ -24,7 +24,7 @@ function Summary ({ auctionInfo, className, lastWinners }: Props): React.ReactEl const { t } = useTranslation(); const { api } = useApi(); const bestNumber = useBestNumber(); - const totalIssuance = useCall(api.query.balances?.totalIssuance); + const totalIssuance = useCall(api.query.balances?.totalIssuance); return ( diff --git a/packages/page-parachains/src/Crowdloan/useContributions.ts b/packages/page-parachains/src/Crowdloan/useContributions.ts index 553def83c8e9..45a2b9effce6 100644 --- a/packages/page-parachains/src/Crowdloan/useContributions.ts +++ b/packages/page-parachains/src/Crowdloan/useContributions.ts @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/app-parachains authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveContributions, DeriveOwnContributions } from '@polkadot/api-derive/types'; +import type { DeriveContributions } from '@polkadot/api-derive/types'; import type { Balance, ParaId } from '@polkadot/types/interfaces'; import { useEffect, useState } from 'react'; @@ -29,8 +29,8 @@ function useContributionsImpl (paraId: ParaId): Result { const { api } = useApi(); const { allAccountsHex } = useAccounts(); const [state, setState] = useState(() => NO_CONTRIB); - const derive = useCall(api.derive.crowdloan.contributions, [paraId]); - const myContributions = useCall(api.derive.crowdloan.ownContributions, [paraId, state.myAccountsHex]); + const derive = useCall(api.derive.crowdloan.contributions, [paraId]); + const myContributions = useCall(api.derive.crowdloan.ownContributions, [paraId, state.myAccountsHex]); useEffect((): void => { derive && setState((prev): Result => { diff --git a/packages/page-parachains/src/Overview/useChainDetails.ts b/packages/page-parachains/src/Overview/useChainDetails.ts index a9e55ac4919b..81cbd4e46931 100644 --- a/packages/page-parachains/src/Overview/useChainDetails.ts +++ b/packages/page-parachains/src/Overview/useChainDetails.ts @@ -19,8 +19,8 @@ function useChainDetailsImpl (id: ParaId): Result { // We are not using the derive here, we keep this queries to the point to not overload return { - bestNumber: useCall(api?.rpc.chain.subscribeNewHeads, undefined, HDR_OPTS), - runtimeVersion: useCall(api?.rpc.state.subscribeRuntimeVersion) + bestNumber: useCall(api?.rpc.chain.subscribeNewHeads, undefined, HDR_OPTS), + runtimeVersion: useCall(api?.rpc.state.subscribeRuntimeVersion) }; } diff --git a/packages/page-parachains/src/Overview/useEvents.ts b/packages/page-parachains/src/Overview/useEvents.ts index 749d541690ad..b3fb3e477d9e 100644 --- a/packages/page-parachains/src/Overview/useEvents.ts +++ b/packages/page-parachains/src/Overview/useEvents.ts @@ -83,7 +83,7 @@ function extractEvents (api: ApiPromise, lastBlock: SignedBlockExtended, prev: R function useEventsImpl (): Result { const { api } = useApi(); - const lastBlock = useCall(api.derive.chain.subscribeNewBlocks); + const lastBlock = useCall(api.derive.chain.subscribeNewBlocks); const [state, setState] = useState(EMPTY_EVENTS); useEffect((): void => { diff --git a/packages/page-parachains/src/Parathreads/Actions.tsx b/packages/page-parachains/src/Parathreads/Actions.tsx index 5da2c7495c33..bc76779e673b 100644 --- a/packages/page-parachains/src/Parathreads/Actions.tsx +++ b/packages/page-parachains/src/Parathreads/Actions.tsx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { ParaId } from '@polkadot/types/interfaces'; -import type { BN } from '@polkadot/util'; import type { OwnedId } from '../types.js'; import React from 'react'; @@ -32,7 +31,7 @@ function Actions ({ className, ownedIds }: Props): React.ReactElement { const { api } = useApi(); const [isRegisterOpen, toggleRegisterOpen] = useToggle(); const [isReserveOpen, toggleReserveOpen] = useToggle(); - const nextParaId = useCall(api.query.registrar.nextFreeParaId, [], OPT_NEXT); + const nextParaId = useCall(api.query.registrar.nextFreeParaId, [], OPT_NEXT); return ( diff --git a/packages/page-parachains/src/Parathreads/useParaMap.ts b/packages/page-parachains/src/Parathreads/useParaMap.ts index 8ebe89a72fd1..7df3dee62725 100644 --- a/packages/page-parachains/src/Parathreads/useParaMap.ts +++ b/packages/page-parachains/src/Parathreads/useParaMap.ts @@ -63,7 +63,7 @@ function useParaMapImpl (ids?: ParaId[]): Result | undefined { [hasLinksMap] ); - return useCall(ids && api.query.slots.leases.multi, [ids], { + return useCall(ids && api.query.slots.leases.multi, [ids], { transform, withParamsTransform: true }); diff --git a/packages/page-parachains/src/useFunds.ts b/packages/page-parachains/src/useFunds.ts index ebe177915ba7..9b55002eb162 100644 --- a/packages/page-parachains/src/useFunds.ts +++ b/packages/page-parachains/src/useFunds.ts @@ -159,8 +159,8 @@ function useFundsImpl (): Campaigns { const mountedRef = useIsMountedRef(); const trigger = useEventTrigger([api.events.crowdloan?.Created]); const paraIds = useMapKeys(api.query.crowdloan?.funds, [], OPT_FUNDS, trigger.blockHash); - const campaigns = useCall(api.query.crowdloan?.funds.multi, [paraIds], OPT_FUNDS_MULTI); - const leases = useCall(api.query.slots.leases.multi, [paraIds], OPT_LEASE); + const campaigns = useCall(api.query.crowdloan?.funds.multi, [paraIds], OPT_FUNDS_MULTI); + const leases = useCall(api.query.slots.leases.multi, [paraIds], OPT_LEASE); const [result, setResult] = useState(EMPTY); // here we manually add the actual ending status and calculate the totals diff --git a/packages/page-referenda/src/Referenda/index.tsx b/packages/page-referenda/src/Referenda/index.tsx index 89d149548721..4eeb9480fc69 100644 --- a/packages/page-referenda/src/Referenda/index.tsx +++ b/packages/page-referenda/src/Referenda/index.tsx @@ -33,8 +33,8 @@ interface Props { function Referenda ({ className, isConvictionVote, members, palletReferenda, palletVote, ranks }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const totalIssuance = useCall(api.query.balances.totalIssuance); - const inactiveIssuance = useCall(api.query.balances.inactiveIssuance); + const totalIssuance = useCall(api.query.balances.totalIssuance); + const inactiveIssuance = useCall(api.query.balances.inactiveIssuance); const { allAccounts } = useAccounts(); const [grouped, tracks] = useReferenda(palletReferenda); const summary = useSummary(palletReferenda, grouped); diff --git a/packages/page-referenda/src/useAccountLocks.ts b/packages/page-referenda/src/useAccountLocks.ts index 8d0842565703..eb13ae4874f2 100644 --- a/packages/page-referenda/src/useAccountLocks.ts +++ b/packages/page-referenda/src/useAccountLocks.ts @@ -147,7 +147,7 @@ function useAccountLocksImpl (palletReferenda: PalletReferenda, palletVote: Pall [accountId] ); - const lockClasses = useCall(lockParams && api.query[palletVote]?.classLocksFor, lockParams, OPT_CLASS); + const lockClasses = useCall(lockParams && api.query[palletVote]?.classLocksFor, lockParams, OPT_CLASS); // retrieve the specific votes casted over the classes & accountId const voteParams = useMemo( @@ -155,7 +155,7 @@ function useAccountLocksImpl (palletReferenda: PalletReferenda, palletVote: Pall [accountId, lockClasses] ); - const votes = useCall<[BN, BN[], PalletConvictionVotingVoteCasting][] | undefined>(voteParams && api.query[palletVote]?.votingFor.multi, voteParams, OPT_VOTES); + const votes = useCall(voteParams && api.query[palletVote]?.votingFor.multi, voteParams, OPT_VOTES); // retrieve the referendums that were voted on const refParams = useMemo( diff --git a/packages/page-referenda/src/useReferenda.ts b/packages/page-referenda/src/useReferenda.ts index 82c6a651b7f2..5a7ab497a4f6 100644 --- a/packages/page-referenda/src/useReferenda.ts +++ b/packages/page-referenda/src/useReferenda.ts @@ -142,7 +142,7 @@ function group (tracks: TrackDescription[], totalIssuance?: BN, referenda?: Refe function useReferendaImpl (palletReferenda: PalletReferenda): [ReferendaGroup[], TrackDescription[]] { const { api, isApiReady } = useApi(); - const totalIssuance = useCall(isApiReady && api.query.balances.totalIssuance); + const totalIssuance = useCall(isApiReady && api.query.balances.totalIssuance); const ids = useReferendaIds(palletReferenda); const tracks = useTracks(palletReferenda); const referenda = useCall(isApiReady && ids && ids.length !== 0 && api.query[palletReferenda as 'referenda'].referendumInfoFor.multi, [ids], OPT_MULTI); diff --git a/packages/page-scheduler/src/DispatchQueue.tsx b/packages/page-scheduler/src/DispatchQueue.tsx index cfa57013983c..85ee6c539381 100644 --- a/packages/page-scheduler/src/DispatchQueue.tsx +++ b/packages/page-scheduler/src/DispatchQueue.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-scheduler authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveDispatch } from '@polkadot/api-derive/types'; - import React, { useMemo, useRef } from 'react'; import { Table } from '@polkadot/react-components'; @@ -19,7 +17,7 @@ function DispatchQueue ({ className }: Props): React.ReactElement | null const { t } = useTranslation(); const { api } = useApi(); const bestNumber = useBestNumber(); - const queued = useCall(api.derive.democracy.dispatchQueue); + const queued = useCall(api.derive.democracy.dispatchQueue); const filtered = useMemo( () => bestNumber && queued && diff --git a/packages/page-scheduler/src/Scheduler.tsx b/packages/page-scheduler/src/Scheduler.tsx index 8716b4a0f37c..4515eba5c70d 100644 --- a/packages/page-scheduler/src/Scheduler.tsx +++ b/packages/page-scheduler/src/Scheduler.tsx @@ -82,7 +82,7 @@ function Schedule ({ className = '' }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const bestNumber = useBestNumber(); - const items = useCall(api.query.scheduler.agenda.entries, undefined, OPT_SCHED); + const items = useCall(api.query.scheduler.agenda.entries, undefined, OPT_SCHED); const filtered = useMemo( () => bestNumber && items && diff --git a/packages/page-society/src/Candidates/Bids.tsx b/packages/page-society/src/Candidates/Bids.tsx index 55e165e7f626..c848bf4da1a6 100644 --- a/packages/page-society/src/Candidates/Bids.tsx +++ b/packages/page-society/src/Candidates/Bids.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-society authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { PalletSocietyBid } from '@polkadot/types/lookup'; - import React, { useRef } from 'react'; import { Table } from '@polkadot/react-components'; @@ -18,7 +16,7 @@ interface Props { function Bids ({ className }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const bids = useCall(api.query.society.bids); + const bids = useCall(api.query.society.bids); const headerRef = useRef<[React.ReactNode?, string?, number?][]>([ [t('bids'), 'start'], diff --git a/packages/page-society/src/Overview/Defender.tsx b/packages/page-society/src/Overview/Defender.tsx index 431bfd47b907..513a1467882b 100644 --- a/packages/page-society/src/Overview/Defender.tsx +++ b/packages/page-society/src/Overview/Defender.tsx @@ -31,7 +31,7 @@ const OPT_VOTES = { function Defender ({ className = '', info, isMember, ownMembers }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const votes = useCall(api.derive.society.members, undefined, OPT_VOTES); + const votes = useCall(api.derive.society.members, undefined, OPT_VOTES); const headerRef = useRef<[React.ReactNode?, string?, number?][]>([ [t('defender'), 'start'], diff --git a/packages/page-society/src/Overview/Summary.tsx b/packages/page-society/src/Overview/Summary.tsx index 47cf3b76282a..73d5072a597c 100644 --- a/packages/page-society/src/Overview/Summary.tsx +++ b/packages/page-society/src/Overview/Summary.tsx @@ -21,7 +21,7 @@ interface Props { function Summary ({ className = '', info, payoutTotal }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const members = useCall(api.derive.society.members); + const members = useCall(api.derive.society.members); const bestNumber = useBestNumber(); const pot = useMemo( diff --git a/packages/page-society/src/Suspended/index.tsx b/packages/page-society/src/Suspended/index.tsx index 0a86d1864862..e9140f394373 100644 --- a/packages/page-society/src/Suspended/index.tsx +++ b/packages/page-society/src/Suspended/index.tsx @@ -46,8 +46,8 @@ const OPT_ACC = { function Suspended ({ className }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const candidates = useCall(api.query.society.suspendedCandidates.entries, undefined, OPT_CAN); - const members = useCall(api.query.society.suspendedMembers.keys, undefined, OPT_ACC); + const candidates = useCall(api.query.society.suspendedCandidates.entries, undefined, OPT_CAN); + const members = useCall(api.query.society.suspendedMembers.keys, undefined, OPT_ACC); const headerRef = useRef({ candidates: [ diff --git a/packages/page-society/src/index.tsx b/packages/page-society/src/index.tsx index 7cdaabf9804a..1e2ee9c608b9 100644 --- a/packages/page-society/src/index.tsx +++ b/packages/page-society/src/index.tsx @@ -84,8 +84,8 @@ function SocietyApp ({ basePath, className }: Props): React.ReactElement const { api } = useApi(); const candidateCount = useCounter(); const { allMembers, isMember, ownMembers } = useMembers(); - const info = useCall(api.derive.society.info); - const members = useCall(api.derive.society.members); + const info = useCall(api.derive.society.info); + const members = useCall(api.derive.society.members); const { candidates, skeptics, voters } = useVoters(); const [mapMembers, payoutTotal] = useMemo( diff --git a/packages/page-society/src/useCounter.ts b/packages/page-society/src/useCounter.ts index 946b5394f719..1df011cdb1fa 100644 --- a/packages/page-society/src/useCounter.ts +++ b/packages/page-society/src/useCounter.ts @@ -1,13 +1,11 @@ // Copyright 2017-2023 @polkadot/app-society authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Bid } from '@polkadot/types/interfaces'; - import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useCounterImpl (): number { const { api } = useApi(); - const bids = useCall(api.query.society?.candidates); + const bids = useCall(api.query.society?.candidates); return bids?.length || 0; } diff --git a/packages/page-society/src/useMembers.ts b/packages/page-society/src/useMembers.ts index 20d4c9ba5cfb..596c90199ea3 100644 --- a/packages/page-society/src/useMembers.ts +++ b/packages/page-society/src/useMembers.ts @@ -23,7 +23,7 @@ function useMembersImpl (): OwnMembers { const { api } = useApi(); const { allAccounts } = useAccounts(); const [state, setState] = useState(EMPTY_MEMBERS); - const members = useCall(api.derive.society.members); + const members = useCall(api.derive.society.members); useEffect((): void => { allAccounts && members && setState( diff --git a/packages/page-society/src/useVoters.ts b/packages/page-society/src/useVoters.ts index e778dc10388c..663229cba4a6 100644 --- a/packages/page-society/src/useVoters.ts +++ b/packages/page-society/src/useVoters.ts @@ -42,7 +42,7 @@ async function getVoters (api: ApiPromise, candidates: DeriveSocietyCandidate[]) function useVotersImpl (): Voters { const { api } = useApi(); const voteTrigger = useEventTrigger([api.events.society.Vote]); - const candidates = useCall(api.derive.society.candidates); + const candidates = useCall(api.derive.society.candidates); const [state, setState] = useState(EMPTY_VOTERS); useEffect((): void => { diff --git a/packages/page-staking/src/Actions/Account/BondExtra.tsx b/packages/page-staking/src/Actions/Account/BondExtra.tsx index d0a66de01e20..a2896d0e9471 100644 --- a/packages/page-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/page-staking/src/Actions/Account/BondExtra.tsx @@ -41,7 +41,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea const { api } = useApi(); const [amountError, setAmountError] = useState(null); const [maxAdditional, setMaxAdditional] = useState(); - const stashBalance = useCall(api.derive.balances?.all, [stashId]); + const stashBalance = useCall(api.derive.balances?.all, [stashId]); const currentAmount = useMemo( () => stakingInfo && stakingInfo.stakingLedger?.active?.unwrap(), [stakingInfo] diff --git a/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx b/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx index 8132dce2b628..0786886eea6b 100644 --- a/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx +++ b/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { AmountValidateState } from '../types.js'; import React, { useEffect, useState } from 'react'; @@ -48,7 +47,7 @@ function formatExistential (value: BN): string { function ValidateAmount ({ currentAmount, isNominating, minNominated, minNominatorBond, minValidatorBond, onError, stashId, value }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const stashBalance = useCall(api.derive.balances?.all, [stashId]); + const stashBalance = useCall(api.derive.balances?.all, [stashId]); const [{ error, warning }, setResult] = useState({ error: null, warning: null }); useEffect((): void => { diff --git a/packages/page-staking/src/Actions/Account/InputValidationController.tsx b/packages/page-staking/src/Actions/Account/InputValidationController.tsx index 2791ebf1ad77..3f22b7420e8e 100644 --- a/packages/page-staking/src/Actions/Account/InputValidationController.tsx +++ b/packages/page-staking/src/Actions/Account/InputValidationController.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { Option } from '@polkadot/types'; import type { AccountId, StakingLedger } from '@polkadot/types/interfaces'; @@ -41,9 +40,9 @@ const OPT_STASH = { function ValidateController ({ accountId, controllerId, defaultController, onError }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const bondedId = useCall(controllerId ? api.query.staking.bonded : null, [controllerId], OPT_BOND); - const stashId = useCall(controllerId ? api.query.staking.ledger : null, [controllerId], OPT_STASH); - const allBalances = useCall(controllerId ? api.derive.balances?.all : null, [controllerId]); + const bondedId = useCall(controllerId ? api.query.staking.bonded : null, [controllerId], OPT_BOND); + const stashId = useCall(controllerId ? api.query.staking.ledger : null, [controllerId], OPT_STASH); + const allBalances = useCall(controllerId ? api.derive.balances?.all : null, [controllerId]); const [{ error, isFatal }, setError] = useState({ error: null, isFatal: false }); useEffect((): void => { diff --git a/packages/page-staking/src/Actions/Account/KickNominees.tsx b/packages/page-staking/src/Actions/Account/KickNominees.tsx index e54924f83b48..fd5c525f07a3 100644 --- a/packages/page-staking/src/Actions/Account/KickNominees.tsx +++ b/packages/page-staking/src/Actions/Account/KickNominees.tsx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { SubmittableExtrinsic } from '@polkadot/api/types'; -import type { DeriveStakingQuery } from '@polkadot/api-derive/types'; import React, { useEffect, useMemo, useState } from 'react'; @@ -31,7 +30,7 @@ function KickNominees ({ className = '', controllerId, nominating, onClose, stas const { api } = useApi(); const [selected, setSelected] = useState([]); const [{ kickTx }, setTx] = useState<{ kickTx?: null | SubmittableExtrinsic<'promise'> }>({}); - const queryInfo = useCall(api.derive.staking.query, [stashId, accountOpts]); + const queryInfo = useCall(api.derive.staking.query, [stashId, accountOpts]); const nominators = useMemo( () => queryInfo?.exposure?.others.map(({ who }) => who.toString()), diff --git a/packages/page-staking/src/Actions/Account/ListNominees.tsx b/packages/page-staking/src/Actions/Account/ListNominees.tsx index 595173bf95e5..34f3c0c930c8 100644 --- a/packages/page-staking/src/Actions/Account/ListNominees.tsx +++ b/packages/page-staking/src/Actions/Account/ListNominees.tsx @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveEraExposure, DeriveSessionIndexes } from '@polkadot/api-derive/types'; +import type { DeriveEraExposure } from '@polkadot/api-derive/types'; import type { BN } from '@polkadot/util'; import React, { useMemo } from 'react'; @@ -69,8 +69,8 @@ function ListNominees ({ nominating, stashId }: Props): React.ReactElement(api.query.staking && api.derive.session?.indexes); - const eraExposure = useCall(isFunction(api.query.staking.erasStakers) && api.derive.staking.eraExposure, [sessionInfo?.activeEra]); + const sessionInfo = useCall(api.query.staking && api.derive.session?.indexes); + const eraExposure = useCall(isFunction(api.query.staking.erasStakers) && api.derive.staking.eraExposure, [sessionInfo?.activeEra]); const [renActive, renChilled, renInactive, renOver, renWaiting] = useMemo( () => [renderNominators(stashId, nomsActive, eraExposure), renderNominators(stashId, nomsChilled), renderNominators(stashId, nomsInactive), renderNominators(stashId, nomsOver), renderNominators(stashId, nomsWaiting)], diff --git a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx index bd86b1da4ee2..89469319a1f1 100644 --- a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx +++ b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { RewardDestination } from '@polkadot/types/interfaces'; import type { DestinationType } from '../types.js'; @@ -26,7 +25,7 @@ function SetRewardDestination ({ controllerId, defaultDestination, onClose, stas const { api } = useApi(); const [destination, setDestination] = useState(() => ((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked'); const [destAccount, setDestAccount] = useState(() => defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null); - const destBalance = useCall(api.derive.balances?.all, [destAccount]); + const destBalance = useCall(api.derive.balances?.all, [destAccount]); const options = useMemo( () => createDestCurr(t), diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index 2d083fdde5cd..ef918b2b836e 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { ApiPromise } from '@polkadot/api'; -import type { DeriveBalancesAll, DeriveStakingAccount } from '@polkadot/api-derive/types'; import type { StakerState } from '@polkadot/react-hooks/types'; import type { PalletStakingUnappliedSlash } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; @@ -54,8 +53,8 @@ function extractSlashes (stashId: string, allSlashes: [BN, PalletStakingUnapplie function useStashCalls (api: ApiPromise, stashId: string) { const params = useMemo(() => [stashId], [stashId]); - const balancesAll = useCall(api.derive.balances?.all, params); - const stakingAccount = useCall(api.derive.staking.account, params); + const balancesAll = useCall(api.derive.balances?.all, params); + const stakingAccount = useCall(api.derive.staking.account, params); const spanCount = useSlashingSpans(stashId); return { balancesAll, spanCount, stakingAccount }; diff --git a/packages/page-staking/src/Actions/Pools.tsx b/packages/page-staking/src/Actions/Pools.tsx index cee49722b912..540ac644c49e 100644 --- a/packages/page-staking/src/Actions/Pools.tsx +++ b/packages/page-staking/src/Actions/Pools.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // 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 { BN } from '@polkadot/util'; @@ -27,7 +26,7 @@ interface Props { function Pools ({ className, list, targets }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const sessionProgress = useCall(api.derive.session.progress); + const sessionProgress = useCall(api.derive.session.progress); const hdrRef = useRef<[React.ReactNode?, string?, number?][]>([ [t('pools'), 'start', 2], diff --git a/packages/page-staking/src/Actions/partials/Bond.tsx b/packages/page-staking/src/Actions/partials/Bond.tsx index 6e17e64a8265..761039aa7713 100644 --- a/packages/page-staking/src/Actions/partials/Bond.tsx +++ b/packages/page-staking/src/Actions/partials/Bond.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { BN } from '@polkadot/util'; import type { AmountValidateState, DestinationType } from '../types.js'; import type { BondInfo } from './types.js'; @@ -46,8 +45,8 @@ function Bond ({ className = '', isNominating, minNominated, minNominatorBond, m const [destAccount, setDestAccount] = useState(null); const [stashId, setStashId] = useState(null); const [startBalance, setStartBalance] = useState(null); - const stashBalance = useCall(api.derive.balances?.all, [stashId]); - const destBalance = useCall(api.derive.balances?.all, [destAccount]); + const stashBalance = useCall(api.derive.balances?.all, [stashId]); + const destBalance = useCall(api.derive.balances?.all, [destAccount]); const bondedBlocks = useUnbondDuration(); const needsController = useMemo( diff --git a/packages/page-staking/src/Actions/useInactives.ts b/packages/page-staking/src/Actions/useInactives.ts index 752772f89168..11d067fb9352 100644 --- a/packages/page-staking/src/Actions/useInactives.ts +++ b/packages/page-staking/src/Actions/useInactives.ts @@ -92,7 +92,7 @@ function useInactivesImpl (stashId: string, nominees?: string[]): Inactives { const { api } = useApi(); const mountedRef = useIsMountedRef(); const [state, setState] = useState({}); - const indexes = useCall(api.derive.session.indexes); + const indexes = useCall(api.derive.session.indexes); useEffect((): () => void => { let unsub: (() => void) | undefined; diff --git a/packages/page-staking/src/Actions/useSlashingSpans.ts b/packages/page-staking/src/Actions/useSlashingSpans.ts index 97dcf5b5469d..89f850d6a7e8 100644 --- a/packages/page-staking/src/Actions/useSlashingSpans.ts +++ b/packages/page-staking/src/Actions/useSlashingSpans.ts @@ -16,7 +16,7 @@ const OPT_SPAN = { function useSlashingSpansImpl (stashId: string): number { const { api } = useApi(); - return useCall(api.query.staking.slashingSpans, [stashId], OPT_SPAN) || 0; + return useCall(api.query.staking.slashingSpans, [stashId], OPT_SPAN) || 0; } export default createNamedHook('useSlashingSpans', useSlashingSpansImpl); diff --git a/packages/page-staking/src/Actions/useUnbondDuration.ts b/packages/page-staking/src/Actions/useUnbondDuration.ts index 3867734f574d..975b95da1b92 100644 --- a/packages/page-staking/src/Actions/useUnbondDuration.ts +++ b/packages/page-staking/src/Actions/useUnbondDuration.ts @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveSessionInfo } from '@polkadot/api-derive/types'; import type { BN } from '@polkadot/util'; import { useMemo } from 'react'; @@ -11,7 +10,7 @@ import { BN_ONE } from '@polkadot/util'; function useUnbondDurationImpl (): BN | undefined { const { api } = useApi(); - const sessionInfo = useCall(api.derive.session.info); + const sessionInfo = useCall(api.derive.session.info); return useMemo( () => (sessionInfo && sessionInfo.sessionLength.gt(BN_ONE)) diff --git a/packages/page-staking/src/Bags/Summary.tsx b/packages/page-staking/src/Bags/Summary.tsx index 54fb2197a545..6d530e6185c1 100644 --- a/packages/page-staking/src/Bags/Summary.tsx +++ b/packages/page-staking/src/Bags/Summary.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BN } from '@polkadot/util'; import type { BagMap } from './types.js'; import React, { useMemo } from 'react'; @@ -22,7 +21,7 @@ interface Props { function Summary ({ bags, className = '', mapOwn }: Props): React.ReactElement { const { t } = useTranslation(); const mod = useQueryModule(); - const total = useCall(mod.counterForListNodes); + const total = useCall(mod.counterForListNodes); const myCount = useMemo( () => mapOwn && Object.values(mapOwn).reduce((count, n) => count + n.length, 0), diff --git a/packages/page-staking/src/Bags/useBagEntries.tsx b/packages/page-staking/src/Bags/useBagEntries.tsx index 5df74b9b5608..72f669b5129a 100644 --- a/packages/page-staking/src/Bags/useBagEntries.tsx +++ b/packages/page-staking/src/Bags/useBagEntries.tsx @@ -1,9 +1,7 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Option } from '@polkadot/types'; import type { AccountId32 } from '@polkadot/types/interfaces'; -import type { PalletBagsListListNode } from '@polkadot/types/lookup'; import { useEffect, useState } from 'react'; @@ -22,7 +20,7 @@ const EMPTY_LIST: AccountId32[] = []; function useBagEntriesImpl (headId: AccountId32 | null, trigger: number): [boolean, AccountId32[]] { const mod = useQueryModule(); const [[currId, { isCompleted, list }], setCurrent] = useState<[AccountId32 | null, Result]>(EMPTY); - const node = useCall>(!!currId && mod.listNodes, [currId]); + const node = useCall(!!currId && mod.listNodes, [currId]); useEffect( () => setCurrent( diff --git a/packages/page-staking/src/Payouts/index.tsx b/packages/page-staking/src/Payouts/index.tsx index e2be50f6ada1..8ac74721fb22 100644 --- a/packages/page-staking/src/Payouts/index.tsx +++ b/packages/page-staking/src/Payouts/index.tsx @@ -163,7 +163,7 @@ function Payouts ({ className = '', historyDepth, isInElection, ownPools, ownVal const [hasOwnValidators] = useState(() => ownValidators.length !== 0); const [myStashesIndex, setMyStashesIndex] = useState(() => hasOwnValidators ? 0 : 1); const [eraSelectionIndex, setEraSelectionIndex] = useState(0); - const eraLength = useCall(api.derive.session.eraLength); + const eraLength = useCall(api.derive.session.eraLength); const blockTime = useBlockInterval(); const poolStashes = useMemo( diff --git a/packages/page-staking/src/Payouts/useEraBlocks.ts b/packages/page-staking/src/Payouts/useEraBlocks.ts index 1cd71747c52f..c7ac86a1ba91 100644 --- a/packages/page-staking/src/Payouts/useEraBlocks.ts +++ b/packages/page-staking/src/Payouts/useEraBlocks.ts @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveSessionProgress } from '@polkadot/api-derive/types'; -import type { Forcing } from '@polkadot/types/interfaces'; import type { BN } from '@polkadot/util'; import { useMemo } from 'react'; @@ -12,8 +10,8 @@ import { BN_ONE } from '@polkadot/util'; function useEraBlocksImpl (historyDepth?: BN, era?: BN): BN | undefined { const { api } = useApi(); - const progress = useCall(api.derive.session.progress); - const forcing = useCall(api.query.staking.forceEra); + const progress = useCall(api.derive.session.progress); + const forcing = useCall(api.query.staking.forceEra); return useMemo( () => (historyDepth && era && forcing && progress && progress.sessionLength.gt(BN_ONE)) diff --git a/packages/page-staking/src/Query/ChartPoints.tsx b/packages/page-staking/src/Query/ChartPoints.tsx index d09d60cf991f..62b2b80b86ed 100644 --- a/packages/page-staking/src/Query/ChartPoints.tsx +++ b/packages/page-staking/src/Query/ChartPoints.tsx @@ -43,8 +43,8 @@ function extractPoints (labels: string[], points: DeriveStakerPoints[]): LineDat function ChartPoints ({ labels, validatorId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const params = useMemo(() => [validatorId, false], [validatorId]); - const stakerPoints = useCall(api.derive.staking.stakerPoints, params); + const params = useMemo(() => [validatorId, false] as const, [validatorId]); + const stakerPoints = useCall(api.derive.staking.stakerPoints, params); const [values, setValues] = useState([]); useEffect( diff --git a/packages/page-staking/src/Query/ChartPrefs.tsx b/packages/page-staking/src/Query/ChartPrefs.tsx index 846920a67cbe..a758b8c2fe39 100644 --- a/packages/page-staking/src/Query/ChartPrefs.tsx +++ b/packages/page-staking/src/Query/ChartPrefs.tsx @@ -48,8 +48,8 @@ function extractPrefs (labels: string[], prefs: DeriveStakerPrefs[]): LineData { function ChartPrefs ({ labels, validatorId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const params = useMemo(() => [validatorId, false], [validatorId]); - const stakerPrefs = useCall(api.derive.staking.stakerPrefs, params); + const params = useMemo(() => [validatorId, false] as const, [validatorId]); + const stakerPrefs = useCall(api.derive.staking.stakerPrefs, params); const [values, setValues] = useState([]); useEffect( diff --git a/packages/page-staking/src/Query/ChartRewards.tsx b/packages/page-staking/src/Query/ChartRewards.tsx index 08b601a7ee51..936a8c413138 100644 --- a/packages/page-staking/src/Query/ChartRewards.tsx +++ b/packages/page-staking/src/Query/ChartRewards.tsx @@ -60,10 +60,10 @@ function extractRewards (labels: string[], erasRewards: DeriveEraRewards[], ownS function ChartRewards ({ labels, validatorId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const params = useMemo(() => [validatorId, false], [validatorId]); - const ownSlashes = useCall(api.derive.staking.ownSlashes, params); - const erasRewards = useCall(api.derive.staking.erasRewards); - const stakerPoints = useCall(api.derive.staking.stakerPoints, params); + const params = useMemo(() => [validatorId, false] as const, [validatorId]); + const ownSlashes = useCall(api.derive.staking.ownSlashes, params); + const erasRewards = useCall(api.derive.staking.erasRewards); + const stakerPoints = useCall(api.derive.staking.stakerPoints, params); const [values, setValues] = useState([]); const { currency, divisor } = useMemo( diff --git a/packages/page-staking/src/Query/ChartStake.tsx b/packages/page-staking/src/Query/ChartStake.tsx index a904590e1fd5..1b9c92362ef7 100644 --- a/packages/page-staking/src/Query/ChartStake.tsx +++ b/packages/page-staking/src/Query/ChartStake.tsx @@ -52,8 +52,8 @@ function extractStake (labels: string[], exposures: DeriveOwnExposure[], divisor function ChartStake ({ labels, validatorId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const params = useMemo(() => [validatorId, false], [validatorId]); - const ownExposures = useCall(api.derive.staking.ownExposures, params); + const params = useMemo(() => [validatorId, false] as const, [validatorId]); + const ownExposures = useCall(api.derive.staking.ownExposures, params); const [values, setValues] = useState([]); const { currency, divisor } = useMemo( diff --git a/packages/page-staking/src/Query/index.tsx b/packages/page-staking/src/Query/index.tsx index 075d30f85868..0ff018c0ed8c 100644 --- a/packages/page-staking/src/Query/index.tsx +++ b/packages/page-staking/src/Query/index.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { INumber } from '@polkadot/types/types'; - import React, { useCallback, useMemo, useState } from 'react'; import { useParams } from 'react-router-dom'; @@ -27,10 +25,10 @@ function Query ({ className }: Props): React.ReactElement { const { api } = useApi(); const { value } = useParams<{ value: string }>(); const [validatorId, setValidatorId] = useState(value || null); - const eras = useCall(api.derive.staking.erasHistoric); + const eras = useCall(api.derive.staking.erasHistoric); const labels = useMemo( - () => eras && eras.map((e) => e.toHuman() as string), + () => eras && eras.map((e) => e.toHuman()), [eras] ); diff --git a/packages/page-staking/src/Query/useBlockCounts.tsx b/packages/page-staking/src/Query/useBlockCounts.tsx index f21b329b4ed5..dc713bebe2d6 100644 --- a/packages/page-staking/src/Query/useBlockCounts.tsx +++ b/packages/page-staking/src/Query/useBlockCounts.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveSessionIndexes } from '@polkadot/api-derive/types'; import type { u32 } from '@polkadot/types'; import type { SessionRewards } from '../types.js'; @@ -13,8 +12,8 @@ import { BN_ONE, BN_ZERO, isFunction } from '@polkadot/util'; function useBlockCountsImpl (accountId: string, sessionRewards: SessionRewards[]): u32[] { const { api } = useApi(); const mountedRef = useIsMountedRef(); - const indexes = useCall(api.derive.session?.indexes); - const current = useCall(api.query.imOnline?.authoredBlocks, [indexes?.currentIndex, accountId]); + const indexes = useCall(api.derive.session?.indexes); + const current = useCall(api.query.imOnline?.authoredBlocks, [indexes?.currentIndex, accountId]); const [counts, setCounts] = useState([]); const [historic, setHistoric] = useState([]); diff --git a/packages/page-staking/src/Slashes/Summary.tsx b/packages/page-staking/src/Slashes/Summary.tsx index c1a3f3f7376e..0ae1067c6541 100644 --- a/packages/page-staking/src/Slashes/Summary.tsx +++ b/packages/page-staking/src/Slashes/Summary.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveSessionProgress } from '@polkadot/api-derive/types'; import type { SlashEra } from './types.js'; import React, { useMemo } from 'react'; @@ -20,7 +19,7 @@ interface Props { function Summary ({ slash: { era, nominators, reporters, total, validators } }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const sessionInfo = useCall(api.derive.session?.progress); + const sessionInfo = useCall(api.derive.session?.progress); const [blockProgress, blockEnd] = useMemo( () => sessionInfo diff --git a/packages/page-staking/src/Targets/Summary.tsx b/packages/page-staking/src/Targets/Summary.tsx index 2dd7a52a8f3c..acab3e5bd8f3 100644 --- a/packages/page-staking/src/Targets/Summary.tsx +++ b/packages/page-staking/src/Targets/Summary.tsx @@ -52,7 +52,7 @@ function getProgressInfo (value?: BN, total?: BN): ProgressInfo { function Summary ({ avgStaked, className, lastEra, lowStaked, minNominated, minNominatorBond, stakedReturn, totalIssuance, totalStaked }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const lastReward = useCall(lastEra && api.query.staking.erasValidatorReward, [lastEra], OPT_REWARD); + const lastReward = useCall(lastEra && api.query.staking.erasValidatorReward, [lastEra], OPT_REWARD); const progressStake = useMemo( () => getProgressInfo(totalStaked, totalIssuance), diff --git a/packages/page-staking/src/Validators/Address/index.tsx b/packages/page-staking/src/Validators/Address/index.tsx index 14327c68b415..363e4b6d633a 100644 --- a/packages/page-staking/src/Validators/Address/index.tsx +++ b/packages/page-staking/src/Validators/Address/index.tsx @@ -83,9 +83,9 @@ const transformSlashes = { }; function useAddressCalls (api: ApiPromise, address: string, isMain?: boolean) { - const params = useMemo(() => [address], [address]); + const params = useMemo(() => [address] as const, [address]); const accountInfo = useDeriveAccountInfo(address); - const slashingSpans = useCall(!isMain && api.query.staking.slashingSpans, params, transformSlashes); + const slashingSpans = useCall(!isMain && api.query.staking.slashingSpans, params, transformSlashes); return { accountInfo, slashingSpans }; } diff --git a/packages/page-staking/src/Validators/index.tsx b/packages/page-staking/src/Validators/index.tsx index 3da98af63dbe..e95aa84c6b9b 100644 --- a/packages/page-staking/src/Validators/index.tsx +++ b/packages/page-staking/src/Validators/index.tsx @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveHeartbeats, DeriveStakingOverview } from '@polkadot/api-derive/types'; +import type { DeriveStakingOverview } from '@polkadot/api-derive/types'; import type { StakerState } from '@polkadot/react-hooks/types'; import type { BN } from '@polkadot/util'; import type { NominatedByMap, SortedTargets } from '../types.js'; @@ -42,7 +42,7 @@ function Overview ({ className = '', favorites, hasAccounts, hasQueries, minComm const { byAuthor, eraPoints } = useBlockAuthors(); const [intentIndex, _setIntentIndex] = useState(0); const [typeIndex, setTypeIndex] = useState(1); - const recentlyOnline = useCall(api.derive.imOnline?.receivedHeartbeats); + const recentlyOnline = useCall(api.derive.imOnline?.receivedHeartbeats); const setIntentIndex = useCallback( (index: number): void => { diff --git a/packages/page-staking/src/index.tsx b/packages/page-staking/src/index.tsx index 928b371de3c7..b6f28e5b2e78 100644 --- a/packages/page-staking/src/index.tsx +++ b/packages/page-staking/src/index.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveStakingOverview } from '@polkadot/api-derive/types'; import type { AppProps as Props } from '@polkadot/react-components/types'; import type { ElectionStatus, ParaValidatorIndex, ValidatorId } from '@polkadot/types/interfaces'; import type { BN } from '@polkadot/util'; @@ -52,7 +51,7 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement(api.derive.staking.overview); + const stakingOverview = useCall(api.derive.staking.overview); const [isInElection, minCommission, paraValidators] = useCallMulti<[boolean, BN | undefined, Record]>([ api.query.staking.eraElectionStatus, api.query.staking.minCommission, diff --git a/packages/page-staking/src/useIdentities.ts b/packages/page-staking/src/useIdentities.ts index e475213f0cde..c66f6648594a 100644 --- a/packages/page-staking/src/useIdentities.ts +++ b/packages/page-staking/src/useIdentities.ts @@ -22,7 +22,7 @@ const OPT_CALL = { function useIdentitiesImpl (validatorIds: string[] = []): Result | undefined { const { api } = useApi(); - const allIdentity = useCall(api.derive.accounts.hasIdentityMulti, [validatorIds], OPT_CALL); + const allIdentity = useCall(api.derive.accounts.hasIdentityMulti, [validatorIds], OPT_CALL); return allIdentity; } diff --git a/packages/page-staking/src/useSortedTargets.ts b/packages/page-staking/src/useSortedTargets.ts index b7d372173f3f..2c6e88ae1f76 100644 --- a/packages/page-staking/src/useSortedTargets.ts +++ b/packages/page-staking/src/useSortedTargets.ts @@ -284,9 +284,9 @@ function useSortedTargetsImpl (favorites: string[], withLedger: boolean): Sorted api.query.staking.minValidatorBond, api.query.balances?.totalIssuance ], OPT_MULTI); - const electedInfo = useCall(api.derive.staking.electedInfo, [{ ...DEFAULT_FLAGS_ELECTED, withLedger }]); - const waitingInfo = useCall(api.derive.staking.waitingInfo, [{ ...DEFAULT_FLAGS_WAITING, withLedger }]); - const lastEraInfo = useCall(api.derive.session.info, undefined, OPT_ERA); + const electedInfo = useCall(api.derive.staking.electedInfo, [{ ...DEFAULT_FLAGS_ELECTED, withLedger }]); + const waitingInfo = useCall(api.derive.staking.waitingInfo, [{ ...DEFAULT_FLAGS_WAITING, withLedger }]); + const lastEraInfo = useCall(api.derive.session.info, undefined, OPT_ERA); const baseInfo = useMemo( () => electedInfo && lastEraInfo && totalIssuance && waitingInfo diff --git a/packages/page-staking2/src/Pools/useAmountError.ts b/packages/page-staking2/src/Pools/useAmountError.ts index aebdca485461..1eda5c0b5af4 100644 --- a/packages/page-staking2/src/Pools/useAmountError.ts +++ b/packages/page-staking2/src/Pools/useAmountError.ts @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { BN } from '@polkadot/util'; import { useMemo } from 'react'; @@ -10,7 +9,7 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useAmountErrorImpl (accountId?: string | null, amount?: BN | null, minAmount?: BN | null): boolean { const { api } = useApi(); - const balances = useCall(!!accountId && api.derive.balances.all, [accountId]); + const balances = useCall(!!accountId && api.derive.balances.all, [accountId]); return useMemo( () => !amount || amount.isZero() || !minAmount || minAmount.gt(amount) || ( diff --git a/packages/page-staking2/src/useSessionInfo.ts b/packages/page-staking2/src/useSessionInfo.ts index 559bbb0f8f09..9f65005909e1 100644 --- a/packages/page-staking2/src/useSessionInfo.ts +++ b/packages/page-staking2/src/useSessionInfo.ts @@ -26,7 +26,7 @@ function useSessionInfoImpl (): SessionInfo { const { api } = useApi(); const activeEra = useCall(api.query.staking.activeEra, undefined, OPT_ACTIVEERA); const currentEra = useCall(api.query.staking.currentEra, undefined, OPT_CURRENTERA); - const currentSession = useCall(api.query.session.currentIndex); + const currentSession = useCall(api.query.session.currentIndex); return useMemo( () => ({ activeEra, currentEra, currentSession }), diff --git a/packages/page-tech-comm/src/App.tsx b/packages/page-tech-comm/src/App.tsx index d28054ec9e4e..c82b68ff7029 100644 --- a/packages/page-tech-comm/src/App.tsx +++ b/packages/page-tech-comm/src/App.tsx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { CollectiveType } from '@polkadot/react-hooks/types'; -import type { Hash } from '@polkadot/types/interfaces'; import React, { useMemo } from 'react'; import { Route, Routes } from 'react-router'; @@ -27,8 +26,8 @@ function TechCommApp ({ basePath, className, type }: Props): React.ReactElement< const { t } = useTranslation(); const { api } = useApi(); const { isMember, members, prime } = useCollectiveMembers(type); - const hasProposals = useCall(api.derive[type].hasProposals); - const proposalHashes = useCall(api.derive[type].proposalHashes); + const hasProposals = useCall(api.derive[type].hasProposals); + const proposalHashes = useCall(api.derive[type].proposalHashes); const items = useMemo(() => [ { diff --git a/packages/page-tech-comm/src/Overview/Summary.tsx b/packages/page-tech-comm/src/Overview/Summary.tsx index 0c501e6eba9f..c362155fb8ca 100644 --- a/packages/page-tech-comm/src/Overview/Summary.tsx +++ b/packages/page-tech-comm/src/Overview/Summary.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-tech-comm authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { u32 } from '@polkadot/types'; import type { ComponentProps as Props } from '../types.js'; import React from 'react'; @@ -15,7 +14,7 @@ import { useTranslation } from '../translate.js'; function Summary ({ className = '', members, proposalHashes, type }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const proposalCount = useCall(api.derive[type].proposalCount); + const proposalCount = useCall(api.derive[type].proposalCount); return ( diff --git a/packages/page-tech-comm/src/Proposals/Proposal.tsx b/packages/page-tech-comm/src/Proposals/Proposal.tsx index 54bd1e0f1490..54fc2acdd63d 100644 --- a/packages/page-tech-comm/src/Proposals/Proposal.tsx +++ b/packages/page-tech-comm/src/Proposals/Proposal.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/app-tech-comm authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types'; import type { CollectiveType } from '@polkadot/react-hooks/types'; import type { Hash } from '@polkadot/types/interfaces'; @@ -27,7 +26,7 @@ interface Props { function Proposal ({ className = '', imageHash, isMember, members, prime, type }: Props): React.ReactElement | null { const { api } = useApi(); - const derive = useCall(api.derive[type as 'technicalCommittee'].proposal, [imageHash]); + const derive = useCall(api.derive[type as 'technicalCommittee'].proposal, [imageHash]); const { hasFailed, isCloseable, isVoteable, remainingBlocks } = useVotingStatus(derive?.votes, members.length, type); const modLocation = useCollectiveInstance(type); diff --git a/packages/page-tech-comm/src/useCounter.ts b/packages/page-tech-comm/src/useCounter.ts index 1c88ed583fc6..666cad638e28 100644 --- a/packages/page-tech-comm/src/useCounter.ts +++ b/packages/page-tech-comm/src/useCounter.ts @@ -11,7 +11,7 @@ const OPT = { function useCounterImpl (): number { const { api, isApiReady } = useApi(); - const counter = useCall(isApiReady && api.derive.technicalCommittee?.proposals, undefined, OPT) || 0; + const counter = useCall(isApiReady && api.derive.technicalCommittee?.proposals, undefined, OPT) || 0; return counter; } diff --git a/packages/page-treasury/src/Overview/Summary.tsx b/packages/page-treasury/src/Overview/Summary.tsx index d43c8f2430b3..d9611a89d8d9 100644 --- a/packages/page-treasury/src/Overview/Summary.tsx +++ b/packages/page-treasury/src/Overview/Summary.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-treasury authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BN } from '@polkadot/util'; - import React, { useMemo } from 'react'; import { CardSummary, SummaryBox } from '@polkadot/react-components'; @@ -21,7 +19,7 @@ function Summary ({ approvalCount, proposalCount }: Props): React.ReactElement

(api.query.treasury.proposalCount); + const totalProposals = useCall(api.query.treasury.proposalCount); const { burn, pendingBounties, pendingProposals, spendPeriod, value } = useTreasury(); const spendable = useMemo( diff --git a/packages/page-treasury/src/Overview/index.tsx b/packages/page-treasury/src/Overview/index.tsx index 58ca0cbfa7a4..29bd82c932ea 100644 --- a/packages/page-treasury/src/Overview/index.tsx +++ b/packages/page-treasury/src/Overview/index.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-treasury authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveTreasuryProposals } from '@polkadot/api-derive/types'; - import React from 'react'; import { Button } from '@polkadot/react-components'; @@ -20,7 +18,7 @@ interface Props { function Overview ({ className, isMember, members }: Props): React.ReactElement { const { api } = useApi(); - const info = useCall(api.derive.treasury.proposals); + const info = useCall(api.derive.treasury.proposals); return (

diff --git a/packages/page-treasury/src/Tips/TipEndorse.tsx b/packages/page-treasury/src/Tips/TipEndorse.tsx index ec22234c44fa..79c0f7783424 100644 --- a/packages/page-treasury/src/Tips/TipEndorse.tsx +++ b/packages/page-treasury/src/Tips/TipEndorse.tsx @@ -32,7 +32,7 @@ function TipEndorse ({ defaultId, hash, isMember, isTipped, median, members, rec const [isOpen, toggleOpen] = useToggle(); const [accountId, setAccountId] = useState(defaultId); const [value, setValue] = useState(); - const totalBalance = useCall(api.derive.balances?.all, [recipient], OPT); + const totalBalance = useCall(api.derive.balances?.all, [recipient], OPT); const tipTx = (api.tx.tips || api.tx.treasury).tip; diff --git a/packages/page-treasury/src/Tips/TipReason.tsx b/packages/page-treasury/src/Tips/TipReason.tsx index 6ce1ff498a75..4e9ee2e9e1c7 100644 --- a/packages/page-treasury/src/Tips/TipReason.tsx +++ b/packages/page-treasury/src/Tips/TipReason.tsx @@ -22,7 +22,7 @@ const OPT = { function TipReason ({ hash }: Props): React.ReactElement { const { api } = useApi(); - const reasonText = useCall((api.query.tips || api.query.treasury).reasons, [hash], OPT); + const reasonText = useCall((api.query.tips || api.query.treasury).reasons, [hash], OPT); return ( {reasonText || hash.toHex()} diff --git a/packages/page-treasury/src/useCounter.ts b/packages/page-treasury/src/useCounter.ts index 655192b7b3b6..b17598dd6f44 100644 --- a/packages/page-treasury/src/useCounter.ts +++ b/packages/page-treasury/src/useCounter.ts @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-treasury authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveTreasuryProposals } from '@polkadot/api-derive/types'; - import { useMemo } from 'react'; import { createNamedHook, useAccounts, useApi, useCall } from '@polkadot/react-hooks'; @@ -10,7 +8,7 @@ import { createNamedHook, useAccounts, useApi, useCall } from '@polkadot/react-h function useCounterImpl (): number { const { hasAccounts } = useAccounts(); const { api, isApiReady } = useApi(); - const proposals = useCall(isApiReady && hasAccounts && api.derive.treasury?.proposals); + const proposals = useCall(isApiReady && hasAccounts && api.derive.treasury?.proposals); return useMemo( () => proposals?.proposals.length || 0, diff --git a/packages/react-components/src/StakingRedeemable.tsx b/packages/react-components/src/StakingRedeemable.tsx index c382fec4a8b5..5bf526bba1f1 100644 --- a/packages/react-components/src/StakingRedeemable.tsx +++ b/packages/react-components/src/StakingRedeemable.tsx @@ -37,7 +37,7 @@ function StakingRedeemable ({ className = '', isPool, stakingInfo }: Props): Rea const { api } = useApi(); const { allAccounts } = useAccounts(); const { t } = useTranslation(); - const spanCount = useCall(api.query.staking.slashingSpans, [stakingInfo?.stashId], OPT_SPAN); + const spanCount = useCall(api.query.staking.slashingSpans, [stakingInfo?.stashId], OPT_SPAN); if (!stakingInfo?.redeemable?.gtn(0)) { return null; diff --git a/packages/react-components/src/StakingUnbonding.tsx b/packages/react-components/src/StakingUnbonding.tsx index 9598ea7c8327..af3af8c2a0e3 100644 --- a/packages/react-components/src/StakingUnbonding.tsx +++ b/packages/react-components/src/StakingUnbonding.tsx @@ -67,7 +67,7 @@ function extractTotals (stakingInfo?: DeriveStakingAccountPartial, progress?: De function StakingUnbonding ({ className = '', iconPosition = 'left', stakingInfo }: Props): React.ReactElement | null { const { api } = useApi(); - const progress = useCall(api.derive.session.progress); + const progress = useCall(api.derive.session.progress); const { t } = useTranslation(); const [mapped, total, isStalled] = useMemo( diff --git a/packages/react-components/src/VoteValue.tsx b/packages/react-components/src/VoteValue.tsx index 04e1de46d25a..d351553e97e8 100644 --- a/packages/react-components/src/VoteValue.tsx +++ b/packages/react-components/src/VoteValue.tsx @@ -85,7 +85,7 @@ function getValues (selectedId: string | null | undefined, noDefault: boolean | function VoteValue ({ accountId, autoFocus, label, noDefault, onChange }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const allBalances = useCall(api.derive.balances?.all, [accountId]); + const allBalances = useCall(api.derive.balances?.all, [accountId]); const [{ defaultValue, maxValue, selectedId, value }, setValue] = useState({ defaultValue: BN_ZERO, maxValue: BN_ZERO, value: BN_ZERO }); useEffect((): void => { diff --git a/packages/react-components/src/modals/Transfer.tsx b/packages/react-components/src/modals/Transfer.tsx index 5efba497a871..f49df95f6756 100644 --- a/packages/react-components/src/modals/Transfer.tsx +++ b/packages/react-components/src/modals/Transfer.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { AccountInfoWithProviders, AccountInfoWithRefCount } from '@polkadot/types/interfaces'; import type { BN } from '@polkadot/util'; @@ -57,8 +56,8 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send const [recipientId, setRecipientId] = useState(null); const [senderId, setSenderId] = useState(null); const [[, recipientPhish], setPhishing] = useState<[string | null, string | null]>([null, null]); - const balances = useCall(api.derive.balances?.all, [propSenderId || senderId]); - const accountInfo = useCall(api.query.system.account, [propSenderId || senderId]); + const balances = useCall(api.derive.balances?.all, [propSenderId || senderId]); + const accountInfo = useCall(api.query.system.account, [propSenderId || senderId]); useEffect((): void => { const fromId = propSenderId || senderId as string; diff --git a/packages/react-hooks/src/ctx/BlockAuthors.tsx b/packages/react-hooks/src/ctx/BlockAuthors.tsx index b601bca7d97e..7279d9b82408 100644 --- a/packages/react-hooks/src/ctx/BlockAuthors.tsx +++ b/packages/react-hooks/src/ctx/BlockAuthors.tsx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { HeaderExtended } from '@polkadot/api-derive/types'; -import type { EraRewardPoints } from '@polkadot/types/interfaces'; import type { BlockAuthors } from './types.js'; import React, { useEffect, useState } from 'react'; @@ -25,7 +24,7 @@ export const BlockAuthorsCtx = React.createContext(EMPTY_STATE); export function BlockAuthorsCtxRoot ({ children }: Props): React.ReactElement { const { api, isApiReady } = useApi(); - const queryPoints = useCall(isApiReady && api.derive.staking?.currentPoints); + const queryPoints = useCall(isApiReady && api.derive.staking?.currentPoints); const [state, setState] = useState(EMPTY_STATE); // No unsub, global context - destroyed on app close diff --git a/packages/react-hooks/src/ctx/BlockEvents.tsx b/packages/react-hooks/src/ctx/BlockEvents.tsx index 789c05f16205..69df17e24598 100644 --- a/packages/react-hooks/src/ctx/BlockEvents.tsx +++ b/packages/react-hooks/src/ctx/BlockEvents.tsx @@ -104,7 +104,7 @@ async function manageEvents (api: ApiPromise, prev: PrevHashes, records: Vec { const { api, isApiReady } = useApi(); const [state, setState] = useState(DEFAULT_EVENTS); - const records = useCall>(isApiReady && api.query.system.events); + const records = useCall(isApiReady && api.query.system.events); const prevHashes = useRef({ block: null, event: null }); useEffect((): void => { diff --git a/packages/react-hooks/src/useAccountInfo.ts b/packages/react-hooks/src/useAccountInfo.ts index 38b5c7d21af7..51e007320c91 100644 --- a/packages/react-hooks/src/useAccountInfo.ts +++ b/packages/react-hooks/src/useAccountInfo.ts @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Nominations, ValidatorPrefs } from '@polkadot/types/interfaces'; import type { KeyringJson$Meta } from '@polkadot/ui-keyring/types'; import type { AddressFlags, AddressIdentity, UseAccountInfo } from './types.js'; @@ -43,8 +42,8 @@ function useAccountInfoImpl (value: string | null, isContract = false): UseAccou const { accounts: { isAccount }, addresses: { isAddress } } = useKeyring(); const accountInfo = useDeriveAccountInfo(value); const accountFlags = useDeriveAccountFlags(value); - const nominator = useCall(api.query.staking?.nominators, [value]); - const validator = useCall(api.query.staking?.validators, [value]); + const nominator = useCall(api.query.staking?.nominators, [value]); + const validator = useCall(api.query.staking?.validators, [value]); const [accountIndex, setAccountIndex] = useState(undefined); const [tags, setSortedTags] = useState([]); const [name, setName] = useState(''); diff --git a/packages/react-hooks/src/useBalancesAll.ts b/packages/react-hooks/src/useBalancesAll.ts index bb9ade1d837d..b052c9e05671 100644 --- a/packages/react-hooks/src/useBalancesAll.ts +++ b/packages/react-hooks/src/useBalancesAll.ts @@ -16,7 +16,7 @@ import { useCall } from './useCall.js'; function useBalancesAllImpl (accountAddress: string): DeriveBalancesAll | undefined { const { api } = useApi(); - return useCall(api.derive.balances?.all, [accountAddress]); + return useCall(api.derive.balances?.all, [accountAddress]); } export const useBalancesAll = createNamedHook('useBalancesAll', useBalancesAllImpl); diff --git a/packages/react-hooks/src/useBestHash.ts b/packages/react-hooks/src/useBestHash.ts index 55f6e3d75bd0..dc07bd441da7 100644 --- a/packages/react-hooks/src/useBestHash.ts +++ b/packages/react-hooks/src/useBestHash.ts @@ -14,7 +14,7 @@ const OPT = { function useBestHashImpl (): string | undefined { const { api } = useApi(); - return useCall(api.rpc.chain.subscribeNewHeads, undefined, OPT); + return useCall(api.rpc.chain.subscribeNewHeads, undefined, OPT); } export const useBestHash = createNamedHook('useBestHash', useBestHashImpl); diff --git a/packages/react-hooks/src/useBestNumber.ts b/packages/react-hooks/src/useBestNumber.ts index 79be7406bd6f..74b4b0121f78 100644 --- a/packages/react-hooks/src/useBestNumber.ts +++ b/packages/react-hooks/src/useBestNumber.ts @@ -1,16 +1,14 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BlockNumber } from '@polkadot/types/interfaces'; - import { createNamedHook } from './createNamedHook.js'; import { useApi } from './useApi.js'; import { useCall } from './useCall.js'; -function useBestNumberImpl (): BlockNumber | undefined { +function useBestNumberImpl () { const { api } = useApi(); - return useCall(api.derive.chain.bestNumber); + return useCall(api.derive.chain.bestNumber); } export const useBestNumber = createNamedHook('useBestNumber', useBestNumberImpl); diff --git a/packages/react-hooks/src/useCall.ts b/packages/react-hooks/src/useCall.ts index a0af3b85ef77..c53f174b068f 100644 --- a/packages/react-hooks/src/useCall.ts +++ b/packages/react-hooks/src/useCall.ts @@ -164,7 +164,7 @@ export function useCall< TFunc extends TrackFn | undefined | null | boolean, TDivergedFunc extends Diverge, StorageEntryPromiseOverloads & QueryableStorageEntry & PromiseResult>, TParams extends TDivergedFunc extends AnyFunction - ? NullablePartial>> + ? Readonly>>> : any[], TFuncResult extends TDivergedFunc extends AnyFunction ? TDivergedFunc extends PromiseResult< (...args: any) => Observable> diff --git a/packages/react-hooks/src/useDelegations.ts b/packages/react-hooks/src/useDelegations.ts index c4758267e30d..6b04b56b999d 100644 --- a/packages/react-hooks/src/useDelegations.ts +++ b/packages/react-hooks/src/useDelegations.ts @@ -7,11 +7,11 @@ import { useAccounts, useApi, useCall } from '@polkadot/react-hooks'; import { createNamedHook } from './createNamedHook.js'; -function useDelegationsImpl (): PalletDemocracyVoteVoting[] | undefined { +function useDelegationsImpl () { const { api } = useApi(); const { allAccounts } = useAccounts(); - return useCall(api.query.democracy?.votingOf?.multi, [allAccounts]); + return useCall(api.query.democracy?.votingOf?.multi, [allAccounts]); } export const useDelegations = createNamedHook('useDelegations', useDelegationsImpl); diff --git a/packages/react-hooks/src/useDeriveAccountInfo.ts b/packages/react-hooks/src/useDeriveAccountInfo.ts index 81628d641148..e98ade4bad73 100644 --- a/packages/react-hooks/src/useDeriveAccountInfo.ts +++ b/packages/react-hooks/src/useDeriveAccountInfo.ts @@ -11,7 +11,7 @@ import { useSystemApi } from './useSystemApi.js'; function useDeriveAccountInfoImpl (value?: AccountId | AccountIndex | Address | Uint8Array | string | null): DeriveAccountInfo | undefined { const api = useSystemApi(); - return useCall(api && api.derive.accounts.info, [value]); + return useCall(api && api.derive.accounts.info, [value]); } export const useDeriveAccountInfo = createNamedHook('useDeriveAccountInfo', useDeriveAccountInfoImpl); diff --git a/packages/react-hooks/src/useEventTrigger.ts b/packages/react-hooks/src/useEventTrigger.ts index b144810403e4..4a40a0bad4c8 100644 --- a/packages/react-hooks/src/useEventTrigger.ts +++ b/packages/react-hooks/src/useEventTrigger.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { AugmentedEvent } from '@polkadot/api/types'; -import type { Vec } from '@polkadot/types'; import type { EventRecord } from '@polkadot/types/interfaces'; import { useEffect, useState } from 'react'; @@ -32,7 +31,7 @@ function useEventTriggerImpl (checks: EventCheck[], filter: (record: EventRecord const [state, setState] = useState(() => EMPTY_RESULT); const memoChecks = useMemoValue(checks); const mountedRef = useIsMountedRef(); - const eventRecords = useCall>(api.query.system.events); + const eventRecords = useCall(api.query.system.events); useEffect((): void => { if (mountedRef.current && eventRecords) { diff --git a/packages/react-hooks/src/useExtrinsicTrigger.ts b/packages/react-hooks/src/useExtrinsicTrigger.ts index df9963de7499..7f4b2ffdd91f 100644 --- a/packages/react-hooks/src/useExtrinsicTrigger.ts +++ b/packages/react-hooks/src/useExtrinsicTrigger.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { SubmittableExtrinsicFunction } from '@polkadot/api/types'; -import type { SignedBlockExtended } from '@polkadot/api-derive/types'; import { useEffect, useState } from 'react'; @@ -19,7 +18,7 @@ function useExtrinsicTriggerImpl (checks: ExtrinsicCheck[]): string { const [trigger, setTrigger] = useState('0'); const mountedRef = useIsMountedRef(); const memoChecks = useMemoValue(checks); - const block = useCall(api.derive.chain.subscribeNewBlocks); + const block = useCall(api.derive.chain.subscribeNewBlocks); useEffect((): void => { mountedRef.current && block && block.extrinsics && block.extrinsics.filter(({ extrinsic }) => diff --git a/packages/react-hooks/src/useProxies.ts b/packages/react-hooks/src/useProxies.ts index 1535f2189827..8a4878ea1db3 100644 --- a/packages/react-hooks/src/useProxies.ts +++ b/packages/react-hooks/src/useProxies.ts @@ -24,11 +24,11 @@ const OPTS = { ) }; -function useProxiesImpl (): [PalletProxyProxyDefinition[], BN][] | undefined { +function useProxiesImpl () { const { api } = useApi(); const { allAccounts } = useAccounts(); - return useCall<[PalletProxyProxyDefinition[], BN][]>(api.query.proxy?.proxies.multi, [allAccounts], OPTS); + return useCall(api.query.proxy?.proxies.multi, [allAccounts], OPTS); } export const useProxies = createNamedHook('useProxies', useProxiesImpl); diff --git a/packages/react-hooks/src/useRegistrars.ts b/packages/react-hooks/src/useRegistrars.ts index 585413e7b40f..9012145b9164 100644 --- a/packages/react-hooks/src/useRegistrars.ts +++ b/packages/react-hooks/src/useRegistrars.ts @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Option } from '@polkadot/types'; -import type { RegistrarInfo } from '@polkadot/types/interfaces'; import type { Registrar } from './types.js'; import { useMemo } from 'react'; @@ -26,7 +24,7 @@ interface State { function useRegistrarsImpl (skipQuery?: boolean): State { const { api } = useApi(); const { allAccounts, hasAccounts } = useAccounts(); - const query = useCall[]>(!skipQuery && api.query.identity?.registrars); + const query = useCall(!skipQuery && api.query.identity?.registrars); // determine if we have a registrar or not - registrars are allowed to approve return useMemo( diff --git a/packages/react-hooks/src/useStakingInfo.ts b/packages/react-hooks/src/useStakingInfo.ts index be7b3c12e7c9..5360b61581aa 100644 --- a/packages/react-hooks/src/useStakingInfo.ts +++ b/packages/react-hooks/src/useStakingInfo.ts @@ -1,16 +1,14 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveStakingAccount } from '@polkadot/api-derive/types'; - import { createNamedHook } from './createNamedHook.js'; import { useApi } from './useApi.js'; import { useCall } from './useCall.js'; -function useStakingInfoImpl (accountId: string | null): DeriveStakingAccount | undefined { +function useStakingInfoImpl (accountId: string | null) { const { api } = useApi(); - return useCall(api.derive.staking?.account, [accountId]); + return useCall(api.derive.staking?.account, [accountId]); } export const useStakingInfo = createNamedHook('useStakingInfo', useStakingInfoImpl); diff --git a/packages/react-hooks/src/useSubidentities.ts b/packages/react-hooks/src/useSubidentities.ts index ff9f5ce54bcf..ac39951b44ee 100644 --- a/packages/react-hooks/src/useSubidentities.ts +++ b/packages/react-hooks/src/useSubidentities.ts @@ -1,16 +1,14 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { AccountId, BalanceOf } from '@polkadot/types/interfaces'; - import { createNamedHook } from './createNamedHook.js'; import { useApi } from './useApi.js'; import { useCall } from './useCall.js'; -function useSubidentitiesImpl (address: string): AccountId[] | undefined { +function useSubidentitiesImpl (address: string) { const { api } = useApi(); - return useCall<[BalanceOf, AccountId[]]>(api.query.identity?.subsOf, [address])?.[1]; + return useCall(api.query.identity?.subsOf, [address])?.[1]; } export const useSubidentities = createNamedHook('useSubidentities', useSubidentitiesImpl); diff --git a/packages/react-hooks/src/useSudo.ts b/packages/react-hooks/src/useSudo.ts index 49bba5b62ac2..0988ceb907d2 100644 --- a/packages/react-hooks/src/useSudo.ts +++ b/packages/react-hooks/src/useSudo.ts @@ -18,7 +18,7 @@ const OPT = { function useSudoImpl (): UseSudo { const { api } = useApi(); const { allAccounts, hasAccounts } = useAccounts(); - const sudoKey = useCall(hasAccounts && api.query.sudo?.key, undefined, OPT); + const sudoKey = useCall(hasAccounts && api.query.sudo?.key, undefined, OPT); const [hasSudoKey, setHasSudoKey] = useState(false); useEffect((): void => { diff --git a/packages/react-query/src/BestFinalized.tsx b/packages/react-query/src/BestFinalized.tsx index 161797da5e12..7b81d88d58ae 100644 --- a/packages/react-query/src/BestFinalized.tsx +++ b/packages/react-query/src/BestFinalized.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/react-query authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BlockNumber } from '@polkadot/types/interfaces'; - import React from 'react'; import { useApi, useCall } from '@polkadot/react-hooks'; @@ -16,7 +14,7 @@ interface Props { function BestFinalized ({ children, className = '', label }: Props): React.ReactElement { const { api } = useApi(); - const bestNumberFinalized = useCall(api.derive.chain.bestNumberFinalized); + const bestNumberFinalized = useCall(api.derive.chain.bestNumberFinalized); return (
diff --git a/packages/react-query/src/BestNumber.tsx b/packages/react-query/src/BestNumber.tsx index 8f8a0fa28359..f1b1859b1f08 100644 --- a/packages/react-query/src/BestNumber.tsx +++ b/packages/react-query/src/BestNumber.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/react-query authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BlockNumber } from '@polkadot/types/interfaces'; - import React from 'react'; import { useApi, useCall } from '@polkadot/react-hooks'; @@ -18,7 +16,7 @@ interface Props { function BestNumber ({ children, className = '', isFinalized, label, withPound }: Props): React.ReactElement { const { api, isApiReady } = useApi(); - const bestNumber = useCall(isApiReady && (isFinalized ? api.derive.chain.bestNumberFinalized : api.derive.chain.bestNumber)); + const bestNumber = useCall(isApiReady && (isFinalized ? api.derive.chain.bestNumberFinalized : api.derive.chain.bestNumber)); return (
diff --git a/packages/react-query/src/Nonce.tsx b/packages/react-query/src/Nonce.tsx index ed223ce5a1f2..ce2bd61c739e 100644 --- a/packages/react-query/src/Nonce.tsx +++ b/packages/react-query/src/Nonce.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/react-query authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { BN } from '@polkadot/util'; import React from 'react'; @@ -19,7 +18,7 @@ interface Props { function Nonce ({ children, className = '', label, params }: Props): React.ReactElement { const { api } = useApi(); - const allBalances = useCall(api.derive.balances?.all, [params]); + const allBalances = useCall(api.derive.balances?.all, [params]); return (
diff --git a/packages/react-query/src/SessionToTime.tsx b/packages/react-query/src/SessionToTime.tsx index 5faafd521e28..f4998ea8f216 100644 --- a/packages/react-query/src/SessionToTime.tsx +++ b/packages/react-query/src/SessionToTime.tsx @@ -1,7 +1,6 @@ // Copyright 2017-2023 @polkadot/react-query authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveSessionProgress } from '@polkadot/api-derive/types'; import type { BN } from '@polkadot/util'; import React, { useMemo } from 'react'; @@ -21,7 +20,7 @@ interface Props { function SessionToTime ({ children, className, isInline, label, value }: Props): React.ReactElement | null { const { api } = useApi(); - const sessionInfo = useCall(api.derive.session.progress); + const sessionInfo = useCall(api.derive.session.progress); const blocks = useMemo( () => sessionInfo && value && sessionInfo.currentIndex.lt(value) diff --git a/packages/react-query/src/TimeNow.tsx b/packages/react-query/src/TimeNow.tsx index 49948156887e..09cd11c3e034 100644 --- a/packages/react-query/src/TimeNow.tsx +++ b/packages/react-query/src/TimeNow.tsx @@ -18,7 +18,7 @@ interface Props { function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement { const { api } = useApi(); - const timestamp = useCall(!value && api.query.timestamp?.now); + const timestamp = useCall(!value && api.query.timestamp?.now); const [now, hasValue] = useMemo( () => [value || timestamp, !!(value || timestamp)], diff --git a/packages/react-query/src/TotalInactive.tsx b/packages/react-query/src/TotalInactive.tsx index b8a09721cd4d..225402e02779 100644 --- a/packages/react-query/src/TotalInactive.tsx +++ b/packages/react-query/src/TotalInactive.tsx @@ -15,7 +15,7 @@ interface Props { function TotalInactive ({ children, className = '', label }: Props): React.ReactElement | null { const { api } = useApi(); - const inactiveIssuance = useCall(api.query.balances?.inactiveIssuance); + const inactiveIssuance = useCall(api.query.balances?.inactiveIssuance); return (
diff --git a/packages/react-query/src/TotalIssuance.tsx b/packages/react-query/src/TotalIssuance.tsx index 64415e582085..de2b072c351a 100644 --- a/packages/react-query/src/TotalIssuance.tsx +++ b/packages/react-query/src/TotalIssuance.tsx @@ -15,7 +15,7 @@ interface Props { function TotalIssuance ({ children, className = '', label }: Props): React.ReactElement | null { const { api } = useApi(); - const totalIssuance = useCall(api.query.balances?.totalIssuance); + const totalIssuance = useCall(api.query.balances?.totalIssuance); return (
diff --git a/packages/react-signer/src/PaymentInfo.tsx b/packages/react-signer/src/PaymentInfo.tsx index 3d4b8bd74599..3059b3873bcc 100644 --- a/packages/react-signer/src/PaymentInfo.tsx +++ b/packages/react-signer/src/PaymentInfo.tsx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { SubmittableExtrinsic } from '@polkadot/api/promise/types'; -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { RuntimeDispatchInfo } from '@polkadot/types/interfaces'; import type { BN } from '@polkadot/util'; @@ -28,7 +27,7 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props) const { t } = useTranslation(); const { api } = useApi(); const [dispatchInfo, setDispatchInfo] = useState(null); - const balances = useCall(api.derive.balances?.all, [accountId]); + const balances = useCall(api.derive.balances?.all, [accountId]); const mountedRef = useIsMountedRef(); useEffect((): void => { From b70881f406e3aaa65c21fbc12089ed17ca50820f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 08:08:32 +1200 Subject: [PATCH 3/8] chore: use manual typing for storage calls that doesn't have type info --- packages/page-accounts/src/modals/IdentitySub.tsx | 2 +- packages/page-alliance/src/useMemberInfo.ts | 6 +++--- packages/page-assets/src/useAssetInfos.ts | 4 ++-- packages/page-calendar/src/useScheduled.ts | 14 +++++++------- packages/page-claims/src/index.tsx | 2 +- packages/page-claims/src/usePolkadotPreclaims.ts | 2 +- packages/page-collator/src/Summary.tsx | 2 +- packages/page-contracts/src/Contracts/Summary.tsx | 2 +- packages/page-democracy/src/Overview/Fasttrack.tsx | 2 +- .../page-nfts/src/AccountItems/useItemsInfos.ts | 2 +- packages/page-nfts/src/useCollectionInfos.ts | 4 ++-- packages/page-parachains/src/Auctions/Auction.tsx | 2 +- .../page-parachains/src/Proposals/useProposal.ts | 2 +- packages/page-parachains/src/index.tsx | 2 +- packages/page-parachains/src/useActionsQueue.ts | 4 ++-- packages/page-parachains/src/useWinningData.ts | 4 ++-- packages/page-referenda/src/useSummary.ts | 2 +- packages/page-society/src/Candidates/Candidate.tsx | 2 +- packages/page-staking/src/useNominations.ts | 2 +- packages/page-treasury/src/Tips/Tips.tsx | 2 +- packages/react-hooks/src/useAvailableSlashes.ts | 4 ++-- packages/react-hooks/src/useInflation.ts | 4 ++-- packages/react-hooks/src/useOwnEraRewards.ts | 8 ++++---- packages/react-hooks/src/useOwnStashes.ts | 4 ++-- packages/react-hooks/src/usePreimage.ts | 4 ++-- packages/react-hooks/src/useTeleport.ts | 2 +- packages/react-hooks/src/useTreasury.ts | 6 +++--- packages/react-query/src/Available.tsx | 2 +- packages/react-query/src/Balance.tsx | 2 +- packages/react-query/src/BalanceFree.tsx | 2 +- packages/react-query/src/BalanceVoting.tsx | 2 +- packages/react-query/src/Bonded.tsx | 4 ++-- packages/react-query/src/LockedVote.tsx | 2 +- 33 files changed, 55 insertions(+), 55 deletions(-) diff --git a/packages/page-accounts/src/modals/IdentitySub.tsx b/packages/page-accounts/src/modals/IdentitySub.tsx index b4d632448cbc..0d420b8be566 100644 --- a/packages/page-accounts/src/modals/IdentitySub.tsx +++ b/packages/page-accounts/src/modals/IdentitySub.tsx @@ -87,7 +87,7 @@ function IdentitySubModal ({ address, className, onClose }: Props): React.ReactE const { api } = useApi(); const { allAccounts } = useAccounts(); const queryIds = useSubidentities(address); - const queryInfos = useCall<[[string[]], Option>[]]>(queryIds && queryIds.length !== 0 && api.query.identity.superOf.multi, [queryIds], transformInfo); + const queryInfos: [[string[]], Option>[]] = useCall(queryIds && queryIds.length !== 0 && api.query.identity.superOf.multi, [queryIds], transformInfo); const [infos, setInfos] = useState<[string, string][] | undefined>(); useEffect((): void => { diff --git a/packages/page-alliance/src/useMemberInfo.ts b/packages/page-alliance/src/useMemberInfo.ts index 07a7b5bb94f1..4786bbf06c8b 100644 --- a/packages/page-alliance/src/useMemberInfo.ts +++ b/packages/page-alliance/src/useMemberInfo.ts @@ -10,9 +10,9 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useMemberInfoImpl (accountId: string): MemberInfo | undefined { const { api } = useApi(); - const upForKicking = useCall(api.query.alliance.upForKicking, [accountId]); - const retiringAt = useCall>(api.query.alliance.retiringMembers, [accountId]); - const depositOf = useCall>(api.query.alliance.depositOf, [accountId]); + const upForKicking: bool = useCall(api.query.alliance.upForKicking, [accountId]); + const retiringAt: Option = useCall(api.query.alliance.retiringMembers, [accountId]); + const depositOf: Option = useCall(api.query.alliance.depositOf, [accountId]); return useMemo( () => depositOf && { diff --git a/packages/page-assets/src/useAssetInfos.ts b/packages/page-assets/src/useAssetInfos.ts index 939bdf6fd4e2..38893c800bc0 100644 --- a/packages/page-assets/src/useAssetInfos.ts +++ b/packages/page-assets/src/useAssetInfos.ts @@ -51,8 +51,8 @@ function extractInfo (allAccounts: string[], id: BN, optDetails: Option(api.query.assets.metadata.multi, [ids], QUERY_OPTS); - const details = useCall<[[BN[]], Option[]]>(api.query.assets.asset.multi, [ids], QUERY_OPTS); + const metadata: [[BN[]], PalletAssetsAssetMetadata[]] = useCall(api.query.assets.metadata.multi, [ids], QUERY_OPTS); + const details: [[BN[]], Option[]] = useCall(api.query.assets.asset.multi, [ids], QUERY_OPTS); const [state, setState] = useState(); useEffect((): void => { diff --git a/packages/page-calendar/src/useScheduled.ts b/packages/page-calendar/src/useScheduled.ts index cc94872234b4..656270ff1a71 100644 --- a/packages/page-calendar/src/useScheduled.ts +++ b/packages/page-calendar/src/useScheduled.ts @@ -202,13 +202,13 @@ function useScheduledImpl (): EntryInfoTyped[] { const blockTime = useBlockInterval(); const bestNumber = useBestNumber(); const leaseRangeMax = useLeaseRangeMax(); - const auctionInfo = useCall>>(api.query.auctions?.auctionInfo); - const councilMotions = useCall(api.derive.council?.proposals); - const dispatches = useCall(api.derive.democracy?.dispatchQueue); - const referendums = useCall(api.derive.democracy?.referendums); - const scheduled = useCall(api.query.scheduler?.agenda?.entries); - const sessionInfo = useCall(api.derive.session?.progress); - const slashes = useCall(api.query.staking?.unappliedSlashes.entries); + const auctionInfo: Option> = useCall(api.query.auctions?.auctionInfo); + const councilMotions: DeriveCollectiveProposal[] = useCall(api.derive.council?.proposals); + const dispatches: DeriveDispatch[] = useCall(api.derive.democracy?.dispatchQueue); + const referendums: DeriveReferendumExt[] = useCall(api.derive.democracy?.referendums); + const scheduled: ScheduleEntry[] = useCall(api.query.scheduler?.agenda?.entries); + const sessionInfo: DeriveSessionProgress = useCall(api.derive.session?.progress); + const slashes: SlashEntry[] = useCall(api.query.staking?.unappliedSlashes.entries); const [state, setState] = useState([]); useEffect((): void => { diff --git a/packages/page-claims/src/index.tsx b/packages/page-claims/src/index.tsx index 04a815728909..3abb79b8e39c 100644 --- a/packages/page-claims/src/index.tsx +++ b/packages/page-claims/src/index.tsx @@ -178,7 +178,7 @@ function ClaimsApp ({ basePath }: Props): React.ReactElement { // If it's 1/ not preclaimed and 2/ not the old claiming process, fetch the // statement kind to sign. - const statementKind = useCall(!isPreclaimed && !isOldClaimProcess && !!ethereumAddress && api.query.claims.signing, [ethereumAddress], transformStatement); + const statementKind: StatementKind | null = useCall(!isPreclaimed && !isOldClaimProcess && !!ethereumAddress && api.query.claims.signing, [ethereumAddress], transformStatement); const statementSentence = getStatement(systemChain, statementKind)?.sentence || ''; const prefix = u8aToString(api.consts.claims.prefix.toU8a(true)); diff --git a/packages/page-claims/src/usePolkadotPreclaims.ts b/packages/page-claims/src/usePolkadotPreclaims.ts index dfd37ad1d7cd..3b3136fe342d 100644 --- a/packages/page-claims/src/usePolkadotPreclaims.ts +++ b/packages/page-claims/src/usePolkadotPreclaims.ts @@ -17,7 +17,7 @@ function usePolkadotPreclaimsImpl (): string[] { const [needsAttest, setNeedsAttest] = useState([]); // find all own preclaims - const preclaims = useCall<[string, EthereumAddress][]>(api.query.claims?.preclaims?.multi, [allAccounts], { + const preclaims: [string, EthereumAddress][] = useCall(api.query.claims?.preclaims?.multi, [allAccounts], { transform: (preclaims: Option[]) => preclaims .map((opt, index): [string, Option] => [allAccounts[index], opt]) diff --git a/packages/page-collator/src/Summary.tsx b/packages/page-collator/src/Summary.tsx index 16c35d4c791f..63c900f81c7d 100644 --- a/packages/page-collator/src/Summary.tsx +++ b/packages/page-collator/src/Summary.tsx @@ -18,7 +18,7 @@ interface Props { function Summary ({ className }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const desiredCandidates = useCall(api.query.collatorSelection.desiredCandidates); + const desiredCandidates: BN = useCall(api.query.collatorSelection.desiredCandidates); return ( diff --git a/packages/page-contracts/src/Contracts/Summary.tsx b/packages/page-contracts/src/Contracts/Summary.tsx index 64ed0eb977cb..e6f65520334c 100644 --- a/packages/page-contracts/src/Contracts/Summary.tsx +++ b/packages/page-contracts/src/Contracts/Summary.tsx @@ -18,7 +18,7 @@ interface Props { function Summary ({ trigger }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const accountCounter = useCall(api.query.contracts.accountCounter); + const accountCounter: BN = useCall(api.query.contracts.accountCounter); const [numContracts, setNumContracts] = useState(0); const [numHashes, setNumHashes] = useState(0); diff --git a/packages/page-democracy/src/Overview/Fasttrack.tsx b/packages/page-democracy/src/Overview/Fasttrack.tsx index dfef796083ed..0cdf2ffee91f 100644 --- a/packages/page-democracy/src/Overview/Fasttrack.tsx +++ b/packages/page-democracy/src/Overview/Fasttrack.tsx @@ -40,7 +40,7 @@ function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElemen const [{ proposal, proposalLength }, setProposal] = useState(() => ({ proposalLength: 0 })); const [withVote, toggleVote] = useToggle(true); const modLocation = useCollectiveInstance('technicalCommittee'); - const proposalCount = useCall(modLocation && api.query[modLocation].proposalCount); + const proposalCount: BN = useCall(modLocation && api.query[modLocation].proposalCount); const memberThreshold = useMemo( () => new BN( diff --git a/packages/page-nfts/src/AccountItems/useItemsInfos.ts b/packages/page-nfts/src/AccountItems/useItemsInfos.ts index 0ac659b96821..942946488ef9 100644 --- a/packages/page-nfts/src/AccountItems/useItemsInfos.ts +++ b/packages/page-nfts/src/AccountItems/useItemsInfos.ts @@ -66,7 +66,7 @@ function useItemsInfosImpl (accountItems: AccountItem[]): ItemInfo[] | undefined [accountItems] ); - const metadata = useCall<[[[BN, BN][]], Option[]]>(api.query.uniques.instanceMetadataOf.multi, [ids], QUERY_OPTS); + const metadata: [[[BN, BN][]], Option[]] = useCall(api.query.uniques.instanceMetadataOf.multi, [ids], QUERY_OPTS); const ipfsHashes = useMemo((): string[] | undefined => { if (metadata && metadata[1].length) { diff --git a/packages/page-nfts/src/useCollectionInfos.ts b/packages/page-nfts/src/useCollectionInfos.ts index 031a5dceca67..b5f667461587 100644 --- a/packages/page-nfts/src/useCollectionInfos.ts +++ b/packages/page-nfts/src/useCollectionInfos.ts @@ -82,8 +82,8 @@ const addIpfsData = (ipfsData: IpfsData) => (collectionInfo: CollectionInfo): Co function useCollectionInfosImpl (ids?: BN[]): CollectionInfo[] | undefined { const { api } = useApi(); const { allAccounts } = useAccounts(); - const metadata = useCall<[[BN[]], Option[]]>(api.query.uniques.classMetadataOf.multi, [ids], QUERY_OPTS); - const details = useCall<[[BN[]], Option[]]>(api.query.uniques.class.multi, [ids], QUERY_OPTS); + const metadata: [[BN[]], Option[]] = useCall(api.query.uniques.classMetadataOf.multi, [ids], QUERY_OPTS); + const details: [[BN[]], Option[]] = useCall(api.query.uniques.class.multi, [ids], QUERY_OPTS); const [state, setState] = useState(); const ipfsHashes = useMemo( diff --git a/packages/page-parachains/src/Auctions/Auction.tsx b/packages/page-parachains/src/Auctions/Auction.tsx index ce2467e2baf9..a88b6eca1eb0 100644 --- a/packages/page-parachains/src/Auctions/Auction.tsx +++ b/packages/page-parachains/src/Auctions/Auction.tsx @@ -24,7 +24,7 @@ function Auction ({ auctionInfo, campaigns, className, winningData }: Props): Re const { t } = useTranslation(); const { api } = useApi(); const rangeMax = useLeaseRangeMax(); - const newRaise = useCall(api.query.crowdloan.newRaise); + const newRaise: ParaId[] = useCall(api.query.crowdloan.newRaise); const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([ [t('bids'), 'start', 3], diff --git a/packages/page-parachains/src/Proposals/useProposal.ts b/packages/page-parachains/src/Proposals/useProposal.ts index 37a2a8662de8..600d9f635b1e 100644 --- a/packages/page-parachains/src/Proposals/useProposal.ts +++ b/packages/page-parachains/src/Proposals/useProposal.ts @@ -11,7 +11,7 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useProposalImpl (id: ParaId, approvedIds: ParaId[], scheduled: ScheduledProposals[]): ProposalExt { const { api } = useApi(); - const opt = useCall>(api.query.proposeParachain.proposals, [id]); + const opt: Option = useCall(api.query.proposeParachain.proposals, [id]); return useMemo( (): ProposalExt => ({ diff --git a/packages/page-parachains/src/index.tsx b/packages/page-parachains/src/index.tsx index aef7186219be..309cc14b44c6 100644 --- a/packages/page-parachains/src/index.tsx +++ b/packages/page-parachains/src/index.tsx @@ -44,7 +44,7 @@ function ParachainsApp ({ basePath, className }: Props): React.ReactElement(api.query.paras.parachains); + const paraIds: ParaId[] = useCall(api.query.paras.parachains); const items = useRef([ { diff --git a/packages/page-parachains/src/useActionsQueue.ts b/packages/page-parachains/src/useActionsQueue.ts index 10ca439e55ef..021dc3cb2962 100644 --- a/packages/page-parachains/src/useActionsQueue.ts +++ b/packages/page-parachains/src/useActionsQueue.ts @@ -18,9 +18,9 @@ const OPT_NEXT = { function useActionsQueueImpl (): QueuedAction[] { const { api } = useApi(); - const currentIndex = useCall(api.query.session.currentIndex); + const currentIndex: SessionIndex = useCall(api.query.session.currentIndex); const queryIndexes = useMemo(() => currentIndex && INC.map((i) => currentIndex.add(i)), [currentIndex]); - const nextActions = useCall<[[BN[]], ParaId[][]]>(queryIndexes && api.query.paras.actionsQueue.multi, [queryIndexes], OPT_NEXT); + const nextActions: [[BN[]], ParaId[][]] = useCall(queryIndexes && api.query.paras.actionsQueue.multi, [queryIndexes], OPT_NEXT); return useMemo( (): QueuedAction[] => diff --git a/packages/page-parachains/src/useWinningData.ts b/packages/page-parachains/src/useWinningData.ts index c06d6ce7bcdc..83bbb9fbb269 100644 --- a/packages/page-parachains/src/useWinningData.ts +++ b/packages/page-parachains/src/useWinningData.ts @@ -128,8 +128,8 @@ function useWinningDataImpl (auctionInfo?: AuctionInfo): Winning[] | undefined { const bestNumber = useBestNumber(); const trigger = useEventTrigger([api.events.auctions?.BidAccepted]); const triggerRef = useRef(trigger); - const initialEntries = useCall<[StorageKey<[BlockNumber]>, Option][]>(api.query.auctions?.winning.entries); - const optFirstData = useCall>(api.query.auctions?.winning, FIRST_PARAM); + const initialEntries: [StorageKey<[BlockNumber]>, Option][] = useCall(api.query.auctions?.winning.entries); + const optFirstData: Option = useCall(api.query.auctions?.winning, FIRST_PARAM); // should be fired once, all entries as an initial round useEffect((): void => { diff --git a/packages/page-referenda/src/useSummary.ts b/packages/page-referenda/src/useSummary.ts index e5f55cc6a5ba..137d1a4ffe4b 100644 --- a/packages/page-referenda/src/useSummary.ts +++ b/packages/page-referenda/src/useSummary.ts @@ -18,7 +18,7 @@ function calcActive (grouped: ReferendaGroup[] = []): number { function useSummaryImpl (palletReferenda: PalletReferenda, grouped?: ReferendaGroup[] | undefined): Summary { const { api } = useApi(); - const refCount = useCall(api.query[palletReferenda].referendumCount); + const refCount: u32 = useCall(api.query[palletReferenda].referendumCount); const refActive = useMemo( () => calcActive(grouped), [grouped] diff --git a/packages/page-society/src/Candidates/Candidate.tsx b/packages/page-society/src/Candidates/Candidate.tsx index a70ee7bd9bd4..27a57dd5785b 100644 --- a/packages/page-society/src/Candidates/Candidate.tsx +++ b/packages/page-society/src/Candidates/Candidate.tsx @@ -28,7 +28,7 @@ function Candidate ({ allMembers, isMember, ownMembers, value: { accountId, kind () => [allMembers.map((memberId): [AccountId, string] => [accountId, memberId])], [accountId, allMembers] ); - const votes = useCall(api.query.society.votes.multi, keys, { + const votes: VoteType[] = useCall(api.query.society.votes.multi, keys, { transform: (voteOpts: Option[]): VoteType[] => voteOpts .map((voteOpt, index): [string, Option] => [allMembers[index], voteOpt]) diff --git a/packages/page-staking/src/useNominations.ts b/packages/page-staking/src/useNominations.ts index 56cbdc64be32..d37c1b41ed86 100644 --- a/packages/page-staking/src/useNominations.ts +++ b/packages/page-staking/src/useNominations.ts @@ -36,7 +36,7 @@ function extractNominators (nominations: [StorageKey, Option][]): N function useNominationsImpl (isActive = true): NominatedByMap | undefined { const { api } = useApi(); - const nominators = useCall<[StorageKey, Option][]>(isActive && api.query.staking.nominators.entries); + const nominators: [StorageKey, Option][] = useCall(isActive && api.query.staking.nominators.entries); return useMemo( () => nominators && extractNominators(nominators), diff --git a/packages/page-treasury/src/Tips/Tips.tsx b/packages/page-treasury/src/Tips/Tips.tsx index 51a21eab33f4..f4de987c6cd0 100644 --- a/packages/page-treasury/src/Tips/Tips.tsx +++ b/packages/page-treasury/src/Tips/Tips.tsx @@ -53,7 +53,7 @@ function Tips ({ className = '', defaultId, hashes, isMember, members, onSelectT const { api } = useApi(); const [onlyUntipped, setOnlyUntipped] = useState(false); const bestNumber = useBestNumber(); - const tipsWithHashes = useCall<[[string[]], Option[]]>(hashes && (api.query.tips || api.query.treasury).tips.multi, [hashes], TIP_OPTS); + const tipsWithHashes: [[string[]], Option[]] = useCall(hashes && (api.query.tips || api.query.treasury).tips.multi, [hashes], TIP_OPTS); const tips = useMemo( () => extractTips(tipsWithHashes, hashes), diff --git a/packages/react-hooks/src/useAvailableSlashes.ts b/packages/react-hooks/src/useAvailableSlashes.ts index 47d24156b91c..3016f53b9b01 100644 --- a/packages/react-hooks/src/useAvailableSlashes.ts +++ b/packages/react-hooks/src/useAvailableSlashes.ts @@ -19,8 +19,8 @@ type Unsub = () => void; function useAvailableSlashesImpl (): [BN, PalletStakingUnappliedSlash[]][] { const { api } = useApi(); - const indexes = useCall(api.derive.session?.indexes); - const earliestSlash = useCall>(api.query.staking?.earliestUnappliedSlash); + const indexes: DeriveSessionIndexes = useCall(api.derive.session?.indexes); + const earliestSlash: Option = useCall(api.query.staking?.earliestUnappliedSlash); const mountedRef = useIsMountedRef(); const [slashes, setSlashes] = useState<[BN, PalletStakingUnappliedSlash[]][]>([]); diff --git a/packages/react-hooks/src/useInflation.ts b/packages/react-hooks/src/useInflation.ts index b9e360c0f9b6..3be47b74fefc 100644 --- a/packages/react-hooks/src/useInflation.ts +++ b/packages/react-hooks/src/useInflation.ts @@ -46,8 +46,8 @@ function calcInflation (api: ApiPromise, totalStaked: BN, totalIssuance: BN, num function useInflationImpl (totalStaked?: BN): Inflation { const { api } = useApi(); - const totalIssuance = useCall(api.query.balances?.totalIssuance); - const auctionCounter = useCall(api.query.auctions?.auctionCounter); + const totalIssuance: BN = useCall(api.query.balances?.totalIssuance); + const auctionCounter: BN = useCall(api.query.auctions?.auctionCounter); const [state, setState] = useState(EMPTY); useEffect((): void => { diff --git a/packages/react-hooks/src/useOwnEraRewards.ts b/packages/react-hooks/src/useOwnEraRewards.ts index 6334716e90a8..4758e9e48410 100644 --- a/packages/react-hooks/src/useOwnEraRewards.ts +++ b/packages/react-hooks/src/useOwnEraRewards.ts @@ -105,12 +105,12 @@ function useOwnEraRewardsImpl (maxEras?: number, ownValidators?: StakerState[], const { api } = useApi(); const mountedRef = useIsMountedRef(); const stashIds = useOwnStashIds(additional); - const allEras = useCall(api.derive.staking?.erasHistoric); + const allEras: EraIndex[] = useCall(api.derive.staking?.erasHistoric); const [{ filteredEras, validatorEras }, setFiltered] = useState(EMPTY_FILTERED); const [state, setState] = useState(EMPTY_STATE); - const stakerRewards = useCall<[[string[]], DeriveStakerReward[][]]>(!ownValidators?.length && !!filteredEras.length && stashIds && api.derive.staking?.stakerRewardsMultiEras, [stashIds, filteredEras], OPT_REWARDS); - const erasPoints = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasPoints, [filteredEras, false]); - const erasRewards = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasRewards, [filteredEras, false]); + const stakerRewards: [[string[]], DeriveStakerReward[][]] = useCall(!ownValidators?.length && !!filteredEras.length && stashIds && api.derive.staking?.stakerRewardsMultiEras, [stashIds, filteredEras], OPT_REWARDS); + const erasPoints: DeriveEraPoints[] = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasPoints, [filteredEras, false]); + const erasRewards: DeriveEraRewards[] = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasRewards, [filteredEras, false]); useEffect((): void => { setState({ allRewards: null, isLoadingRewards: true, rewardCount: 0 }); diff --git a/packages/react-hooks/src/useOwnStashes.ts b/packages/react-hooks/src/useOwnStashes.ts index 66952d41d611..90abb51ba37e 100644 --- a/packages/react-hooks/src/useOwnStashes.ts +++ b/packages/react-hooks/src/useOwnStashes.ts @@ -40,8 +40,8 @@ function useOwnStashesImpl (additional?: string[]): [string, IsInKeyring][] | un [allAccounts, additional] ); - const ownBonded = useCall[]>(ids.length !== 0 && api.query.staking?.bonded.multi, [ids]); - const ownLedger = useCall[]>(ids.length !== 0 && api.query.staking?.ledger.multi, [ids]); + const ownBonded: Option[] = useCall(ids.length !== 0 && api.query.staking?.bonded.multi, [ids]); + const ownLedger: Option[] = useCall(ids.length !== 0 && api.query.staking?.ledger.multi, [ids]); return useMemo( () => ids.length diff --git a/packages/react-hooks/src/usePreimage.ts b/packages/react-hooks/src/usePreimage.ts index c4124a02245b..8d2a67d1109b 100644 --- a/packages/react-hooks/src/usePreimage.ts +++ b/packages/react-hooks/src/usePreimage.ts @@ -207,7 +207,7 @@ function usePreimageImpl (hashOrBounded?: Hash | HexString | FrameSupportPreimag [api, hashOrBounded] ); - const optStatus = useCall>(!inlineData && paramsStatus && api.query.preimage?.statusFor, paramsStatus); + const optStatus: Option = useCall(!inlineData && paramsStatus && api.query.preimage?.statusFor, paramsStatus); // from the retrieved status (if any), get the on-chain stored bytes const { paramsBytes, resultPreimageFor } = useMemo( @@ -217,7 +217,7 @@ function usePreimageImpl (hashOrBounded?: Hash | HexString | FrameSupportPreimag [optStatus, resultPreimageHash] ); - const optBytes = useCall>(paramsBytes && api.query.preimage?.preimageFor, paramsBytes); + const optBytes: Option = useCall(paramsBytes && api.query.preimage?.preimageFor, paramsBytes); // extract all the preimage info we have retrieved return useMemo( diff --git a/packages/react-hooks/src/useTeleport.ts b/packages/react-hooks/src/useTeleport.ts index 9ccb629abc2a..6073929d7d00 100644 --- a/packages/react-hooks/src/useTeleport.ts +++ b/packages/react-hooks/src/useTeleport.ts @@ -64,7 +64,7 @@ function extractRelayDestinations (relayGenesis: string, filter: (l: ExtLinkOpti function useTeleportImpl (): Teleport { const { api, apiUrl, isApiReady } = useApi(); - const paraId = useCall(isApiReady && api.query.parachainInfo?.parachainId); + const paraId: ParaId = useCall(isApiReady && api.query.parachainInfo?.parachainId); const [state, setState] = useState(() => ({ ...DEFAULT_STATE })); useEffect((): void => { diff --git a/packages/react-hooks/src/useTreasury.ts b/packages/react-hooks/src/useTreasury.ts index 1aeeb0b88302..b7b864c7aeb6 100644 --- a/packages/react-hooks/src/useTreasury.ts +++ b/packages/react-hooks/src/useTreasury.ts @@ -40,9 +40,9 @@ function useTreasuryImpl (): Result { EMPTY_U8A_32 ).subarray(0, 32) })); - const bounties = useCall(api.derive.bounties?.bounties); - const treasuryProposals = useCall(api.derive.treasury.proposals); - const treasuryBalance = useCall(api.derive.balances?.account, [result.treasuryAccount]); + const bounties: DeriveBounties = useCall(api.derive.bounties?.bounties); + const treasuryProposals: DeriveTreasuryProposals = useCall(api.derive.treasury.proposals); + const treasuryBalance: DeriveBalancesAccount = useCall(api.derive.balances?.account, [result.treasuryAccount]); useEffect((): void => { treasuryBalance && api.consts.treasury && diff --git a/packages/react-query/src/Available.tsx b/packages/react-query/src/Available.tsx index ff06b7307d72..d2a1f4d13dfc 100644 --- a/packages/react-query/src/Available.tsx +++ b/packages/react-query/src/Available.tsx @@ -19,7 +19,7 @@ interface Props { function AvailableDisplay ({ children, className = '', label, params }: Props): React.ReactElement { const { api } = useApi(); - const allBalances = useCall(api.derive.balances?.all, [params]); + const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const allBalances = useCall(api.derive.balances?.all, [params]); + const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const allBalances = useCall(api.derive.balances?.all, [params]); + const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const allBalances = useCall(api.derive.balances?.all, [params]); + const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const controllerId = useCall(api.query.staking?.bonded, [params], OPT_C); - const stakingLedger = useCall(controllerId && api.query.staking?.ledger, [controllerId], OPT_L); + const controllerId: AccountId | null = useCall(api.query.staking?.bonded, [params], OPT_C); + const stakingLedger: StakingLedger | null = useCall(controllerId && api.query.staking?.ledger, [controllerId], OPT_L); return ( | null { const { api } = useApi(); - const info = useCall(api.derive.council.votesOf, [params]); + const info: DeriveCouncilVote = useCall(api.derive.council.votesOf, [params]); if (!info?.stake.gtn(0)) { return null; From a8e7a063c58ef876875eb716e6a9f6af81be8534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 08:56:46 +1200 Subject: [PATCH 4/8] chore: fix remaining type errors --- packages/react-hooks/src/useCall.ts | 17 +++++++++-------- packages/react-hooks/src/useDelegations.ts | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/react-hooks/src/useCall.ts b/packages/react-hooks/src/useCall.ts index c53f174b068f..1337d8f5038c 100644 --- a/packages/react-hooks/src/useCall.ts +++ b/packages/react-hooks/src/useCall.ts @@ -74,7 +74,7 @@ function isQuery (fn: unknown): fn is QueryableStorageEntry<'promise', []> { } // extract the serialized and mapped params, all ready for use in our call -function extractParams (fn: unknown, params: unknown[], { paramMap = transformIdentity }: CallOptions = {}): [string, CallParams | null] { +function extractParams (fn: unknown, params: readonly unknown[], { paramMap = transformIdentity }: CallOptions = {}): [string, CallParams | null] { return [ JSON.stringify({ f: (fn as { name: string })?.name, p: params }), params.length === 0 || !params.some((param) => isNull(param) || isUndefined(param)) @@ -161,22 +161,23 @@ export function throwOnError (tracker: Tracker): void { // FIXME This is generic, we cannot really use createNamedHook export function useCall< TTransformedResult, - TFunc extends TrackFn | undefined | null | boolean, - TDivergedFunc extends Diverge, StorageEntryPromiseOverloads & QueryableStorageEntry & PromiseResult>, + TFunc extends TrackFn | undefined | null | false, + TDivergedFunc extends Diverge, StorageEntryPromiseOverloads & QueryableStorageEntry & PromiseResult>, TParams extends TDivergedFunc extends AnyFunction ? Readonly>>> - : any[], + : unknown[], TFuncResult extends TDivergedFunc extends AnyFunction ? TDivergedFunc extends PromiseResult< (...args: any) => Observable> ? TResult - : any - : any, + : unknown + : unknown, TResult extends TCallOptions extends CallOptions ? R : TFuncResult, - TCallOptions extends CallOptions | void = void, ->(fn: TFunc, params?: TParams, options?: TCallOptions): TResult { + TCallOptions extends CallOptions | undefined = undefined, +>(fn: TFunc, params?: TParams, options?: TCallOptions): TResult | undefined { const { api } = useApi(); const mountedRef = useIsMountedRef(); const tracker = useRef({ error: null, fn: null, isActive: false, serialized: null, subscriber: null, type: 'useCall' }); + // @ts-expect-error needs better typing for options transform const [value, setValue] = useState((options || {}).defaultValue); // initial effect, we need an un-subscription diff --git a/packages/react-hooks/src/useDelegations.ts b/packages/react-hooks/src/useDelegations.ts index 6b04b56b999d..26b446d47a1a 100644 --- a/packages/react-hooks/src/useDelegations.ts +++ b/packages/react-hooks/src/useDelegations.ts @@ -7,11 +7,11 @@ import { useAccounts, useApi, useCall } from '@polkadot/react-hooks'; import { createNamedHook } from './createNamedHook.js'; -function useDelegationsImpl () { +function useDelegationsImpl (): PalletDemocracyVoteVoting[] { const { api } = useApi(); const { allAccounts } = useAccounts(); - return useCall(api.query.democracy?.votingOf?.multi, [allAccounts]); + return useCall(api.query.democracy?.votingOf?.multi, [allAccounts]) as PalletDemocracyVoteVoting[]; } export const useDelegations = createNamedHook('useDelegations', useDelegationsImpl); From 60ba50e391a15b4e83575e5029e523ff113768b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 17:09:10 +1200 Subject: [PATCH 5/8] chore: rename generics to match existing convention --- packages/react-hooks/src/useCall.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/react-hooks/src/useCall.ts b/packages/react-hooks/src/useCall.ts index 1337d8f5038c..4e5424b05175 100644 --- a/packages/react-hooks/src/useCall.ts +++ b/packages/react-hooks/src/useCall.ts @@ -161,19 +161,19 @@ export function throwOnError (tracker: Tracker): void { // FIXME This is generic, we cannot really use createNamedHook export function useCall< TTransformedResult, - TFunc extends TrackFn | undefined | null | false, - TDivergedFunc extends Diverge, StorageEntryPromiseOverloads & QueryableStorageEntry & PromiseResult>, - TParams extends TDivergedFunc extends AnyFunction - ? Readonly>>> + TFn extends TrackFn | undefined | null | false, + TDivergedFn extends Diverge, StorageEntryPromiseOverloads & QueryableStorageEntry & PromiseResult>, + TParams extends TDivergedFn extends AnyFunction + ? Readonly>>> : unknown[], - TFuncResult extends TDivergedFunc extends AnyFunction - ? TDivergedFunc extends PromiseResult< (...args: any) => Observable> - ? TResult + TFnResult extends TDivergedFn extends AnyFunction + ? TDivergedFn extends PromiseResult< (...args: any) => Observable> + ? R : unknown : unknown, - TResult extends TCallOptions extends CallOptions ? R : TFuncResult, + TResult extends TCallOptions extends CallOptions ? R : TFnResult, TCallOptions extends CallOptions | undefined = undefined, ->(fn: TFunc, params?: TParams, options?: TCallOptions): TResult | undefined { +>(fn: TFn, params?: TParams, options?: TCallOptions): TResult | undefined { const { api } = useApi(); const mountedRef = useIsMountedRef(); const tracker = useRef({ error: null, fn: null, isActive: false, serialized: null, subscriber: null, type: 'useCall' }); From 4aebf629cad9294aeca91180010a9b840be6eb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 17:25:36 +1200 Subject: [PATCH 6/8] chore: remove one unnecessary `AnyFunction` check --- packages/react-hooks/src/useCall.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/react-hooks/src/useCall.ts b/packages/react-hooks/src/useCall.ts index 4e5424b05175..cffd75167e28 100644 --- a/packages/react-hooks/src/useCall.ts +++ b/packages/react-hooks/src/useCall.ts @@ -166,10 +166,8 @@ export function useCall< TParams extends TDivergedFn extends AnyFunction ? Readonly>>> : unknown[], - TFnResult extends TDivergedFn extends AnyFunction - ? TDivergedFn extends PromiseResult< (...args: any) => Observable> - ? R - : unknown + TFnResult extends TDivergedFn extends PromiseResult< (...args: any) => Observable> + ? R : unknown, TResult extends TCallOptions extends CallOptions ? R : TFnResult, TCallOptions extends CallOptions | undefined = undefined, From 379fe3e994d78059cc6e3e8e40d35e0fe64f4954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 17:48:48 +1200 Subject: [PATCH 7/8] chore: fix remaining type errors --- packages/page-accounts/src/modals/IdentitySub.tsx | 2 +- packages/page-alliance/src/useMemberInfo.ts | 6 +++--- packages/page-assets/src/Balances/useBalances.ts | 2 +- packages/page-assets/src/useAssetInfos.ts | 4 ++-- packages/page-calendar/src/useScheduled.ts | 14 +++++++------- packages/page-claims/src/index.tsx | 2 +- packages/page-claims/src/usePolkadotPreclaims.ts | 2 +- packages/page-collator/src/Summary.tsx | 2 +- packages/page-contracts/src/Contracts/Summary.tsx | 2 +- packages/page-democracy/src/Overview/Fasttrack.tsx | 2 +- .../page-nfts/src/AccountItems/useItemsInfos.ts | 2 +- packages/page-nfts/src/useCollectionInfos.ts | 4 ++-- packages/page-parachains/src/Auctions/Auction.tsx | 2 +- .../page-parachains/src/Proposals/useProposal.ts | 2 +- packages/page-parachains/src/index.tsx | 2 +- packages/page-parachains/src/useActionsQueue.ts | 4 ++-- packages/page-parachains/src/useWinningData.ts | 4 ++-- .../src/Referenda/Delegate/useNominators.ts | 2 +- .../src/Referenda/Delegate/useSuperIds.ts | 2 +- .../src/Referenda/Delegate/useVotingFor.ts | 2 +- .../src/Referenda/Delegate/useVotingLocks.ts | 4 ++-- packages/page-referenda/src/useSummary.ts | 2 +- packages/page-society/src/Candidates/Candidate.tsx | 4 ++-- .../page-staking/src/Actions/Account/index.tsx | 2 +- packages/page-staking/src/useNominations.ts | 2 +- .../page-staking2/src/Validators/useExposure.ts | 2 +- .../page-staking2/src/Validators/useHeartbeat.ts | 4 ++-- packages/page-staking2/src/Validators/usePoints.ts | 2 +- packages/page-treasury/src/Tips/Tips.tsx | 2 +- packages/react-hooks/src/types.ts | 2 +- packages/react-hooks/src/useAvailableSlashes.ts | 4 ++-- packages/react-hooks/src/useCall.ts | 4 ++-- packages/react-hooks/src/useDeriveAccountFlags.ts | 4 +++- packages/react-hooks/src/useInflation.ts | 4 ++-- packages/react-hooks/src/useOwnEraRewards.ts | 8 ++++---- packages/react-hooks/src/useOwnStashes.ts | 4 ++-- packages/react-hooks/src/usePreimage.ts | 5 +++-- packages/react-hooks/src/useTeleport.ts | 2 +- packages/react-hooks/src/useTreasury.ts | 7 ++++--- packages/react-query/src/Available.tsx | 3 ++- packages/react-query/src/Balance.tsx | 3 ++- packages/react-query/src/BalanceFree.tsx | 3 ++- packages/react-query/src/BalanceVoting.tsx | 3 ++- packages/react-query/src/Bonded.tsx | 5 +++-- packages/react-query/src/LockedVote.tsx | 3 ++- 45 files changed, 81 insertions(+), 71 deletions(-) diff --git a/packages/page-accounts/src/modals/IdentitySub.tsx b/packages/page-accounts/src/modals/IdentitySub.tsx index 0d420b8be566..ab551b8386a2 100644 --- a/packages/page-accounts/src/modals/IdentitySub.tsx +++ b/packages/page-accounts/src/modals/IdentitySub.tsx @@ -87,7 +87,7 @@ function IdentitySubModal ({ address, className, onClose }: Props): React.ReactE const { api } = useApi(); const { allAccounts } = useAccounts(); const queryIds = useSubidentities(address); - const queryInfos: [[string[]], Option>[]] = useCall(queryIds && queryIds.length !== 0 && api.query.identity.superOf.multi, [queryIds], transformInfo); + const queryInfos: [[string[]], Option>[]] | undefined = useCall(queryIds && queryIds.length !== 0 && api.query.identity.superOf.multi, [queryIds], transformInfo); const [infos, setInfos] = useState<[string, string][] | undefined>(); useEffect((): void => { diff --git a/packages/page-alliance/src/useMemberInfo.ts b/packages/page-alliance/src/useMemberInfo.ts index 4786bbf06c8b..acd6cbab1657 100644 --- a/packages/page-alliance/src/useMemberInfo.ts +++ b/packages/page-alliance/src/useMemberInfo.ts @@ -10,9 +10,9 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useMemberInfoImpl (accountId: string): MemberInfo | undefined { const { api } = useApi(); - const upForKicking: bool = useCall(api.query.alliance.upForKicking, [accountId]); - const retiringAt: Option = useCall(api.query.alliance.retiringMembers, [accountId]); - const depositOf: Option = useCall(api.query.alliance.depositOf, [accountId]); + const upForKicking: bool | undefined = useCall(api.query.alliance.upForKicking, [accountId]); + const retiringAt: Option | undefined = useCall(api.query.alliance.retiringMembers, [accountId]); + const depositOf: Option | undefined = useCall(api.query.alliance.depositOf, [accountId]); return useMemo( () => depositOf && { diff --git a/packages/page-assets/src/Balances/useBalances.ts b/packages/page-assets/src/Balances/useBalances.ts index 91f1850be03c..7c04cdb11573 100644 --- a/packages/page-assets/src/Balances/useBalances.ts +++ b/packages/page-assets/src/Balances/useBalances.ts @@ -49,7 +49,7 @@ function useBalancesImpl (id?: BN | null): AccountResult[] | null { const { api } = useApi(); const { allAccounts } = useAccounts(); const keys = useMemo( - () => [allAccounts.map((a) => [id, a])], + () => [allAccounts.map((a) => [id, a])] as const, [allAccounts, id] ); const query = useCall(keys && api.query.assets.account.multi, keys, OPTS); diff --git a/packages/page-assets/src/useAssetInfos.ts b/packages/page-assets/src/useAssetInfos.ts index 38893c800bc0..82b173b58ae3 100644 --- a/packages/page-assets/src/useAssetInfos.ts +++ b/packages/page-assets/src/useAssetInfos.ts @@ -51,8 +51,8 @@ function extractInfo (allAccounts: string[], id: BN, optDetails: Option[]] = useCall(api.query.assets.asset.multi, [ids], QUERY_OPTS); + const metadata: [[BN[]], PalletAssetsAssetMetadata[]] | undefined = useCall(api.query.assets.metadata.multi, [ids], QUERY_OPTS); + const details: [[BN[]], Option[]] | undefined = useCall(api.query.assets.asset.multi, [ids], QUERY_OPTS); const [state, setState] = useState(); useEffect((): void => { diff --git a/packages/page-calendar/src/useScheduled.ts b/packages/page-calendar/src/useScheduled.ts index 656270ff1a71..36193f75ecec 100644 --- a/packages/page-calendar/src/useScheduled.ts +++ b/packages/page-calendar/src/useScheduled.ts @@ -202,13 +202,13 @@ function useScheduledImpl (): EntryInfoTyped[] { const blockTime = useBlockInterval(); const bestNumber = useBestNumber(); const leaseRangeMax = useLeaseRangeMax(); - const auctionInfo: Option> = useCall(api.query.auctions?.auctionInfo); - const councilMotions: DeriveCollectiveProposal[] = useCall(api.derive.council?.proposals); - const dispatches: DeriveDispatch[] = useCall(api.derive.democracy?.dispatchQueue); - const referendums: DeriveReferendumExt[] = useCall(api.derive.democracy?.referendums); - const scheduled: ScheduleEntry[] = useCall(api.query.scheduler?.agenda?.entries); - const sessionInfo: DeriveSessionProgress = useCall(api.derive.session?.progress); - const slashes: SlashEntry[] = useCall(api.query.staking?.unappliedSlashes.entries); + const auctionInfo: Option> | undefined = useCall(api.query.auctions?.auctionInfo); + const councilMotions: DeriveCollectiveProposal[] | undefined = useCall(api.derive.council?.proposals); + const dispatches: DeriveDispatch[] | undefined = useCall(api.derive.democracy?.dispatchQueue); + const referendums: DeriveReferendumExt[] | undefined = useCall(api.derive.democracy?.referendums); + const scheduled: ScheduleEntry[] | undefined = useCall(api.query.scheduler?.agenda?.entries); + const sessionInfo: DeriveSessionProgress | undefined = useCall(api.derive.session?.progress); + const slashes: SlashEntry[] | undefined = useCall(api.query.staking?.unappliedSlashes.entries); const [state, setState] = useState([]); useEffect((): void => { diff --git a/packages/page-claims/src/index.tsx b/packages/page-claims/src/index.tsx index 3abb79b8e39c..e333cf144577 100644 --- a/packages/page-claims/src/index.tsx +++ b/packages/page-claims/src/index.tsx @@ -178,7 +178,7 @@ function ClaimsApp ({ basePath }: Props): React.ReactElement { // If it's 1/ not preclaimed and 2/ not the old claiming process, fetch the // statement kind to sign. - const statementKind: StatementKind | null = useCall(!isPreclaimed && !isOldClaimProcess && !!ethereumAddress && api.query.claims.signing, [ethereumAddress], transformStatement); + const statementKind: StatementKind | null | undefined = useCall(!isPreclaimed && !isOldClaimProcess && !!ethereumAddress && api.query.claims.signing, [ethereumAddress], transformStatement); const statementSentence = getStatement(systemChain, statementKind)?.sentence || ''; const prefix = u8aToString(api.consts.claims.prefix.toU8a(true)); diff --git a/packages/page-claims/src/usePolkadotPreclaims.ts b/packages/page-claims/src/usePolkadotPreclaims.ts index 3b3136fe342d..690077d63fbd 100644 --- a/packages/page-claims/src/usePolkadotPreclaims.ts +++ b/packages/page-claims/src/usePolkadotPreclaims.ts @@ -17,7 +17,7 @@ function usePolkadotPreclaimsImpl (): string[] { const [needsAttest, setNeedsAttest] = useState([]); // find all own preclaims - const preclaims: [string, EthereumAddress][] = useCall(api.query.claims?.preclaims?.multi, [allAccounts], { + const preclaims: [string, EthereumAddress][] | undefined = useCall(api.query.claims?.preclaims?.multi, [allAccounts], { transform: (preclaims: Option[]) => preclaims .map((opt, index): [string, Option] => [allAccounts[index], opt]) diff --git a/packages/page-collator/src/Summary.tsx b/packages/page-collator/src/Summary.tsx index 63c900f81c7d..34ec4f2253f6 100644 --- a/packages/page-collator/src/Summary.tsx +++ b/packages/page-collator/src/Summary.tsx @@ -18,7 +18,7 @@ interface Props { function Summary ({ className }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const desiredCandidates: BN = useCall(api.query.collatorSelection.desiredCandidates); + const desiredCandidates: BN | undefined = useCall(api.query.collatorSelection.desiredCandidates); return ( diff --git a/packages/page-contracts/src/Contracts/Summary.tsx b/packages/page-contracts/src/Contracts/Summary.tsx index e6f65520334c..5570d3b8f359 100644 --- a/packages/page-contracts/src/Contracts/Summary.tsx +++ b/packages/page-contracts/src/Contracts/Summary.tsx @@ -18,7 +18,7 @@ interface Props { function Summary ({ trigger }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const accountCounter: BN = useCall(api.query.contracts.accountCounter); + const accountCounter: BN | undefined = useCall(api.query.contracts.accountCounter); const [numContracts, setNumContracts] = useState(0); const [numHashes, setNumHashes] = useState(0); diff --git a/packages/page-democracy/src/Overview/Fasttrack.tsx b/packages/page-democracy/src/Overview/Fasttrack.tsx index 0cdf2ffee91f..78cf20f7eb43 100644 --- a/packages/page-democracy/src/Overview/Fasttrack.tsx +++ b/packages/page-democracy/src/Overview/Fasttrack.tsx @@ -40,7 +40,7 @@ function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElemen const [{ proposal, proposalLength }, setProposal] = useState(() => ({ proposalLength: 0 })); const [withVote, toggleVote] = useToggle(true); const modLocation = useCollectiveInstance('technicalCommittee'); - const proposalCount: BN = useCall(modLocation && api.query[modLocation].proposalCount); + const proposalCount: BN | undefined = useCall(modLocation && api.query[modLocation].proposalCount); const memberThreshold = useMemo( () => new BN( diff --git a/packages/page-nfts/src/AccountItems/useItemsInfos.ts b/packages/page-nfts/src/AccountItems/useItemsInfos.ts index 942946488ef9..26dcdadc91d0 100644 --- a/packages/page-nfts/src/AccountItems/useItemsInfos.ts +++ b/packages/page-nfts/src/AccountItems/useItemsInfos.ts @@ -66,7 +66,7 @@ function useItemsInfosImpl (accountItems: AccountItem[]): ItemInfo[] | undefined [accountItems] ); - const metadata: [[[BN, BN][]], Option[]] = useCall(api.query.uniques.instanceMetadataOf.multi, [ids], QUERY_OPTS); + const metadata: [[[BN, BN][]], Option[]] | undefined = useCall(api.query.uniques.instanceMetadataOf.multi, [ids], QUERY_OPTS); const ipfsHashes = useMemo((): string[] | undefined => { if (metadata && metadata[1].length) { diff --git a/packages/page-nfts/src/useCollectionInfos.ts b/packages/page-nfts/src/useCollectionInfos.ts index b5f667461587..5d2e0b143c04 100644 --- a/packages/page-nfts/src/useCollectionInfos.ts +++ b/packages/page-nfts/src/useCollectionInfos.ts @@ -82,8 +82,8 @@ const addIpfsData = (ipfsData: IpfsData) => (collectionInfo: CollectionInfo): Co function useCollectionInfosImpl (ids?: BN[]): CollectionInfo[] | undefined { const { api } = useApi(); const { allAccounts } = useAccounts(); - const metadata: [[BN[]], Option[]] = useCall(api.query.uniques.classMetadataOf.multi, [ids], QUERY_OPTS); - const details: [[BN[]], Option[]] = useCall(api.query.uniques.class.multi, [ids], QUERY_OPTS); + const metadata: [[BN[]], Option[]] | undefined = useCall(api.query.uniques.classMetadataOf.multi, [ids], QUERY_OPTS); + const details: [[BN[]], Option[]] | undefined = useCall(api.query.uniques.class.multi, [ids], QUERY_OPTS); const [state, setState] = useState(); const ipfsHashes = useMemo( diff --git a/packages/page-parachains/src/Auctions/Auction.tsx b/packages/page-parachains/src/Auctions/Auction.tsx index a88b6eca1eb0..27fd6c9dbee0 100644 --- a/packages/page-parachains/src/Auctions/Auction.tsx +++ b/packages/page-parachains/src/Auctions/Auction.tsx @@ -24,7 +24,7 @@ function Auction ({ auctionInfo, campaigns, className, winningData }: Props): Re const { t } = useTranslation(); const { api } = useApi(); const rangeMax = useLeaseRangeMax(); - const newRaise: ParaId[] = useCall(api.query.crowdloan.newRaise); + const newRaise: ParaId[] | undefined = useCall(api.query.crowdloan.newRaise); const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([ [t('bids'), 'start', 3], diff --git a/packages/page-parachains/src/Proposals/useProposal.ts b/packages/page-parachains/src/Proposals/useProposal.ts index 600d9f635b1e..be4d71810cd0 100644 --- a/packages/page-parachains/src/Proposals/useProposal.ts +++ b/packages/page-parachains/src/Proposals/useProposal.ts @@ -11,7 +11,7 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function useProposalImpl (id: ParaId, approvedIds: ParaId[], scheduled: ScheduledProposals[]): ProposalExt { const { api } = useApi(); - const opt: Option = useCall(api.query.proposeParachain.proposals, [id]); + const opt: Option | undefined = useCall(api.query.proposeParachain.proposals, [id]); return useMemo( (): ProposalExt => ({ diff --git a/packages/page-parachains/src/index.tsx b/packages/page-parachains/src/index.tsx index 309cc14b44c6..97ed439c83b8 100644 --- a/packages/page-parachains/src/index.tsx +++ b/packages/page-parachains/src/index.tsx @@ -44,7 +44,7 @@ function ParachainsApp ({ basePath, className }: Props): React.ReactElement currentIndex && INC.map((i) => currentIndex.add(i)), [currentIndex]); - const nextActions: [[BN[]], ParaId[][]] = useCall(queryIndexes && api.query.paras.actionsQueue.multi, [queryIndexes], OPT_NEXT); + const nextActions: [[BN[]], ParaId[][]] | undefined = useCall(queryIndexes && api.query.paras.actionsQueue.multi, [queryIndexes], OPT_NEXT); return useMemo( (): QueuedAction[] => diff --git a/packages/page-parachains/src/useWinningData.ts b/packages/page-parachains/src/useWinningData.ts index 83bbb9fbb269..07bb81c5088f 100644 --- a/packages/page-parachains/src/useWinningData.ts +++ b/packages/page-parachains/src/useWinningData.ts @@ -128,8 +128,8 @@ function useWinningDataImpl (auctionInfo?: AuctionInfo): Winning[] | undefined { const bestNumber = useBestNumber(); const trigger = useEventTrigger([api.events.auctions?.BidAccepted]); const triggerRef = useRef(trigger); - const initialEntries: [StorageKey<[BlockNumber]>, Option][] = useCall(api.query.auctions?.winning.entries); - const optFirstData: Option = useCall(api.query.auctions?.winning, FIRST_PARAM); + const initialEntries: [StorageKey<[BlockNumber]>, Option][] | undefined = useCall(api.query.auctions?.winning.entries); + const optFirstData: Option | undefined = useCall(api.query.auctions?.winning, FIRST_PARAM); // should be fired once, all entries as an initial round useEffect((): void => { diff --git a/packages/page-referenda/src/Referenda/Delegate/useNominators.ts b/packages/page-referenda/src/Referenda/Delegate/useNominators.ts index 74a648cd868f..f7c158372c82 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useNominators.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useNominators.ts @@ -29,7 +29,7 @@ function useNominatorsImpl (): string[] | null | undefined { const { allAccounts } = useAccounts(); const nomineesParam = useMemo( - () => [allAccounts], + () => [allAccounts] as const, [allAccounts] ); diff --git a/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts b/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts index fb2aea282f7d..f9e3a5b2cec4 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts @@ -36,7 +36,7 @@ function useSuperIdsImpl (accountIds?: string[] | null): string[] | null | undef // for the supplied accounts, retrieve the de-dupes parent identity const identityParam = useMemo( - () => accountIds && [accountIds], + () => accountIds && [accountIds] as const, [accountIds] ); diff --git a/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts b/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts index 49ee9418fdea..ffdc3b4e78fd 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts @@ -70,7 +70,7 @@ function useVotingForImpl (palletVote: PalletVote, accountIds?: string[] | null) const locks = useVotingLocks(palletVote, accountIds); const forParam = useMemo( - () => [getParams(locks)], + () => [getParams(locks)] as const, [locks] ); diff --git a/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts b/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts index e8a09e918b60..873c32dc25a6 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts @@ -28,8 +28,8 @@ function useVotingLocksImpl (palletVote: PalletVote, accountIds?: string[] | nul const locksParam = useMemo( () => accountIds ? accountIds.length - ? [accountIds] - : [] + ? [accountIds] as const + : [] as const : undefined, [accountIds] ); diff --git a/packages/page-referenda/src/useSummary.ts b/packages/page-referenda/src/useSummary.ts index 137d1a4ffe4b..7bbc93203bfd 100644 --- a/packages/page-referenda/src/useSummary.ts +++ b/packages/page-referenda/src/useSummary.ts @@ -18,7 +18,7 @@ function calcActive (grouped: ReferendaGroup[] = []): number { function useSummaryImpl (palletReferenda: PalletReferenda, grouped?: ReferendaGroup[] | undefined): Summary { const { api } = useApi(); - const refCount: u32 = useCall(api.query[palletReferenda].referendumCount); + const refCount: u32 | undefined = useCall(api.query[palletReferenda].referendumCount); const refActive = useMemo( () => calcActive(grouped), [grouped] diff --git a/packages/page-society/src/Candidates/Candidate.tsx b/packages/page-society/src/Candidates/Candidate.tsx index 27a57dd5785b..e163613a51d6 100644 --- a/packages/page-society/src/Candidates/Candidate.tsx +++ b/packages/page-society/src/Candidates/Candidate.tsx @@ -25,10 +25,10 @@ interface Props { function Candidate ({ allMembers, isMember, ownMembers, value: { accountId, kind, value } }: Props): React.ReactElement { const { api } = useApi(); const keys = useMemo( - () => [allMembers.map((memberId): [AccountId, string] => [accountId, memberId])], + () => [allMembers.map((memberId): [AccountId, string] => [accountId, memberId])] as const, [accountId, allMembers] ); - const votes: VoteType[] = useCall(api.query.society.votes.multi, keys, { + const votes: VoteType[] | undefined = useCall(api.query.society.votes.multi, keys, { transform: (voteOpts: Option[]): VoteType[] => voteOpts .map((voteOpt, index): [string, Option] => [allMembers[index], voteOpt]) diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index ef918b2b836e..1353aff8a93d 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -52,7 +52,7 @@ function extractSlashes (stashId: string, allSlashes: [BN, PalletStakingUnapplie } function useStashCalls (api: ApiPromise, stashId: string) { - const params = useMemo(() => [stashId], [stashId]); + const params = useMemo(() => [stashId] as const, [stashId]); const balancesAll = useCall(api.derive.balances?.all, params); const stakingAccount = useCall(api.derive.staking.account, params); const spanCount = useSlashingSpans(stashId); diff --git a/packages/page-staking/src/useNominations.ts b/packages/page-staking/src/useNominations.ts index d37c1b41ed86..0b175ed4e883 100644 --- a/packages/page-staking/src/useNominations.ts +++ b/packages/page-staking/src/useNominations.ts @@ -36,7 +36,7 @@ function extractNominators (nominations: [StorageKey, Option][]): N function useNominationsImpl (isActive = true): NominatedByMap | undefined { const { api } = useApi(); - const nominators: [StorageKey, Option][] = useCall(isActive && api.query.staking.nominators.entries); + const nominators: [StorageKey, Option][] | undefined = useCall(isActive && api.query.staking.nominators.entries); return useMemo( () => nominators && extractNominators(nominators), diff --git a/packages/page-staking2/src/Validators/useExposure.ts b/packages/page-staking2/src/Validators/useExposure.ts index 45ec1d0eebeb..7f3fb346c850 100644 --- a/packages/page-staking2/src/Validators/useExposure.ts +++ b/packages/page-staking2/src/Validators/useExposure.ts @@ -48,7 +48,7 @@ function useExposureImpl ({ stashId }: Validator, { activeEra }: SessionInfo): U const { api } = useApi(); const params = useMemo( - () => activeEra && [activeEra, stashId], + () => activeEra && [activeEra, stashId] as const, [activeEra, stashId] ); diff --git a/packages/page-staking2/src/Validators/useHeartbeat.ts b/packages/page-staking2/src/Validators/useHeartbeat.ts index 0ea162144c49..507106cae496 100644 --- a/packages/page-staking2/src/Validators/useHeartbeat.ts +++ b/packages/page-staking2/src/Validators/useHeartbeat.ts @@ -33,8 +33,8 @@ function useHeartbeatImpl ({ stashId, stashIndex }: Validator, { currentSession () => stashIndex === -1 ? undefined : currentSession && ({ - authoredBlocks: [currentSession, stashId], - receivedHeartbeats: [currentSession, stashIndex] + authoredBlocks: [currentSession, stashId] as const, + receivedHeartbeats: [currentSession, stashIndex] as const }), [currentSession, stashId, stashIndex] ); diff --git a/packages/page-staking2/src/Validators/usePoints.ts b/packages/page-staking2/src/Validators/usePoints.ts index 254e47a9e6b0..e1d7dafdddac 100644 --- a/packages/page-staking2/src/Validators/usePoints.ts +++ b/packages/page-staking2/src/Validators/usePoints.ts @@ -27,7 +27,7 @@ function usePointsImpl ({ activeEra }: SessionInfo): UsePoints | undefined { const { api } = useApi(); const queryParams = useMemo( - () => activeEra && [activeEra], + () => activeEra && [activeEra] as const, [activeEra] ); diff --git a/packages/page-treasury/src/Tips/Tips.tsx b/packages/page-treasury/src/Tips/Tips.tsx index f4de987c6cd0..a54a6bb02689 100644 --- a/packages/page-treasury/src/Tips/Tips.tsx +++ b/packages/page-treasury/src/Tips/Tips.tsx @@ -53,7 +53,7 @@ function Tips ({ className = '', defaultId, hashes, isMember, members, onSelectT const { api } = useApi(); const [onlyUntipped, setOnlyUntipped] = useState(false); const bestNumber = useBestNumber(); - const tipsWithHashes: [[string[]], Option[]] = useCall(hashes && (api.query.tips || api.query.treasury).tips.multi, [hashes], TIP_OPTS); + const tipsWithHashes: [[string[]], Option[]] | undefined = useCall(hashes && (api.query.tips || api.query.treasury).tips.multi, [hashes], TIP_OPTS); const tips = useMemo( () => extractTips(tipsWithHashes, hashes), diff --git a/packages/react-hooks/src/types.ts b/packages/react-hooks/src/types.ts index c589dd939351..fb212184f55c 100644 --- a/packages/react-hooks/src/types.ts +++ b/packages/react-hooks/src/types.ts @@ -40,7 +40,7 @@ export type Diverge = TType extends infer TDiverge & TInterse export type Leading = T extends [...infer Leading, any] ? Leading : [] -export type NullablePartial = { [P in keyof T]?: T[P] | null; } +export type FalsifiablePartial = { [P in keyof T]?: T[P] | null | false; } | null | false export type PickKnownKeys = { [P in keyof T as string extends P ? never : number extends P ? never : P]: T[P] diff --git a/packages/react-hooks/src/useAvailableSlashes.ts b/packages/react-hooks/src/useAvailableSlashes.ts index 3016f53b9b01..ee2d605fc68e 100644 --- a/packages/react-hooks/src/useAvailableSlashes.ts +++ b/packages/react-hooks/src/useAvailableSlashes.ts @@ -19,8 +19,8 @@ type Unsub = () => void; function useAvailableSlashesImpl (): [BN, PalletStakingUnappliedSlash[]][] { const { api } = useApi(); - const indexes: DeriveSessionIndexes = useCall(api.derive.session?.indexes); - const earliestSlash: Option = useCall(api.query.staking?.earliestUnappliedSlash); + const indexes: DeriveSessionIndexes | undefined = useCall(api.derive.session?.indexes); + const earliestSlash: Option | undefined = useCall(api.query.staking?.earliestUnappliedSlash); const mountedRef = useIsMountedRef(); const [slashes, setSlashes] = useState<[BN, PalletStakingUnappliedSlash[]][]>([]); diff --git a/packages/react-hooks/src/useCall.ts b/packages/react-hooks/src/useCall.ts index cffd75167e28..4004f5d091bc 100644 --- a/packages/react-hooks/src/useCall.ts +++ b/packages/react-hooks/src/useCall.ts @@ -6,7 +6,7 @@ import type { ApiPromise } from '@polkadot/api'; import type { GenericStorageEntryFunction, PromiseResult, QueryableStorageEntry, StorageEntryPromiseOverloads } from '@polkadot/api/types'; import type { StorageEntryTypeLatest } from '@polkadot/types/interfaces'; import type { AnyFunction, Codec } from '@polkadot/types/types'; -import type { CallOptions, CallParam, CallParams, Diverge, Leading, NullablePartial } from './types.js'; +import type { CallOptions, CallParam, CallParams, Diverge, FalsifiablePartial, Leading } from './types.js'; import type { MountedRef } from './useIsMountedRef.js'; import { useEffect, useRef, useState } from 'react'; @@ -164,7 +164,7 @@ export function useCall< TFn extends TrackFn | undefined | null | false, TDivergedFn extends Diverge, StorageEntryPromiseOverloads & QueryableStorageEntry & PromiseResult>, TParams extends TDivergedFn extends AnyFunction - ? Readonly>>> + ? Readonly>>> : unknown[], TFnResult extends TDivergedFn extends PromiseResult< (...args: any) => Observable> ? R diff --git a/packages/react-hooks/src/useDeriveAccountFlags.ts b/packages/react-hooks/src/useDeriveAccountFlags.ts index f22575939d4a..d29c41c4a40a 100644 --- a/packages/react-hooks/src/useDeriveAccountFlags.ts +++ b/packages/react-hooks/src/useDeriveAccountFlags.ts @@ -11,7 +11,9 @@ import { useSystemApi } from './useSystemApi.js'; function useDeriveAccountFlagsImpl (value?: AccountId | Address | Uint8Array | string | null): DeriveAccountFlags | undefined { const api = useSystemApi(); - return useCall(api && api.derive.accounts.flags, [value]); + return useCall(api && api.derive.accounts.flags, + // @ts-expect-error `api.derive.accounts.flags` doesn't accepts `Uint8Array` + [value]); } export const useDeriveAccountFlags = createNamedHook('useDeriveAccountFlags', useDeriveAccountFlagsImpl); diff --git a/packages/react-hooks/src/useInflation.ts b/packages/react-hooks/src/useInflation.ts index 3be47b74fefc..69bc699bfa69 100644 --- a/packages/react-hooks/src/useInflation.ts +++ b/packages/react-hooks/src/useInflation.ts @@ -46,8 +46,8 @@ function calcInflation (api: ApiPromise, totalStaked: BN, totalIssuance: BN, num function useInflationImpl (totalStaked?: BN): Inflation { const { api } = useApi(); - const totalIssuance: BN = useCall(api.query.balances?.totalIssuance); - const auctionCounter: BN = useCall(api.query.auctions?.auctionCounter); + const totalIssuance: BN | undefined = useCall(api.query.balances?.totalIssuance); + const auctionCounter: BN | undefined = useCall(api.query.auctions?.auctionCounter); const [state, setState] = useState(EMPTY); useEffect((): void => { diff --git a/packages/react-hooks/src/useOwnEraRewards.ts b/packages/react-hooks/src/useOwnEraRewards.ts index 4758e9e48410..6c7a3911e4b8 100644 --- a/packages/react-hooks/src/useOwnEraRewards.ts +++ b/packages/react-hooks/src/useOwnEraRewards.ts @@ -105,12 +105,12 @@ function useOwnEraRewardsImpl (maxEras?: number, ownValidators?: StakerState[], const { api } = useApi(); const mountedRef = useIsMountedRef(); const stashIds = useOwnStashIds(additional); - const allEras: EraIndex[] = useCall(api.derive.staking?.erasHistoric); + const allEras: EraIndex[] | undefined = useCall(api.derive.staking?.erasHistoric); const [{ filteredEras, validatorEras }, setFiltered] = useState(EMPTY_FILTERED); const [state, setState] = useState(EMPTY_STATE); - const stakerRewards: [[string[]], DeriveStakerReward[][]] = useCall(!ownValidators?.length && !!filteredEras.length && stashIds && api.derive.staking?.stakerRewardsMultiEras, [stashIds, filteredEras], OPT_REWARDS); - const erasPoints: DeriveEraPoints[] = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasPoints, [filteredEras, false]); - const erasRewards: DeriveEraRewards[] = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasRewards, [filteredEras, false]); + const stakerRewards: [[string[]], DeriveStakerReward[][]] | undefined = useCall(!ownValidators?.length && !!filteredEras.length && stashIds && api.derive.staking?.stakerRewardsMultiEras, [stashIds, filteredEras], OPT_REWARDS); + const erasPoints: DeriveEraPoints[] | undefined = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasPoints, [filteredEras, false]); + const erasRewards: DeriveEraRewards[] | undefined = useCall(!!validatorEras.length && !!filteredEras.length && api.derive.staking._erasRewards, [filteredEras, false]); useEffect((): void => { setState({ allRewards: null, isLoadingRewards: true, rewardCount: 0 }); diff --git a/packages/react-hooks/src/useOwnStashes.ts b/packages/react-hooks/src/useOwnStashes.ts index 90abb51ba37e..aff06a457e7f 100644 --- a/packages/react-hooks/src/useOwnStashes.ts +++ b/packages/react-hooks/src/useOwnStashes.ts @@ -40,8 +40,8 @@ function useOwnStashesImpl (additional?: string[]): [string, IsInKeyring][] | un [allAccounts, additional] ); - const ownBonded: Option[] = useCall(ids.length !== 0 && api.query.staking?.bonded.multi, [ids]); - const ownLedger: Option[] = useCall(ids.length !== 0 && api.query.staking?.ledger.multi, [ids]); + const ownBonded: Option[] | undefined = useCall(ids.length !== 0 && api.query.staking?.bonded.multi, [ids]); + const ownLedger: Option[] | undefined = useCall(ids.length !== 0 && api.query.staking?.ledger.multi, [ids]); return useMemo( () => ids.length diff --git a/packages/react-hooks/src/usePreimage.ts b/packages/react-hooks/src/usePreimage.ts index 8d2a67d1109b..e04914bd9266 100644 --- a/packages/react-hooks/src/usePreimage.ts +++ b/packages/react-hooks/src/usePreimage.ts @@ -207,7 +207,7 @@ function usePreimageImpl (hashOrBounded?: Hash | HexString | FrameSupportPreimag [api, hashOrBounded] ); - const optStatus: Option = useCall(!inlineData && paramsStatus && api.query.preimage?.statusFor, paramsStatus); + const optStatus: Option | undefined = useCall(!inlineData && paramsStatus && api.query.preimage?.statusFor, paramsStatus); // from the retrieved status (if any), get the on-chain stored bytes const { paramsBytes, resultPreimageFor } = useMemo( @@ -217,7 +217,8 @@ function usePreimageImpl (hashOrBounded?: Hash | HexString | FrameSupportPreimag [optStatus, resultPreimageHash] ); - const optBytes: Option = useCall(paramsBytes && api.query.preimage?.preimageFor, paramsBytes); + // @ts-expect-error mismatch args type with `api.query.preimage?.preimageFor` + const optBytes = useCall(paramsBytes && api.query.preimage?.preimageFor, paramsBytes); // extract all the preimage info we have retrieved return useMemo( diff --git a/packages/react-hooks/src/useTeleport.ts b/packages/react-hooks/src/useTeleport.ts index 6073929d7d00..282fb6779ce9 100644 --- a/packages/react-hooks/src/useTeleport.ts +++ b/packages/react-hooks/src/useTeleport.ts @@ -64,7 +64,7 @@ function extractRelayDestinations (relayGenesis: string, filter: (l: ExtLinkOpti function useTeleportImpl (): Teleport { const { api, apiUrl, isApiReady } = useApi(); - const paraId: ParaId = useCall(isApiReady && api.query.parachainInfo?.parachainId); + const paraId: ParaId | undefined = useCall(isApiReady && api.query.parachainInfo?.parachainId); const [state, setState] = useState(() => ({ ...DEFAULT_STATE })); useEffect((): void => { diff --git a/packages/react-hooks/src/useTreasury.ts b/packages/react-hooks/src/useTreasury.ts index b7b864c7aeb6..45a5aa4b0779 100644 --- a/packages/react-hooks/src/useTreasury.ts +++ b/packages/react-hooks/src/useTreasury.ts @@ -40,9 +40,10 @@ function useTreasuryImpl (): Result { EMPTY_U8A_32 ).subarray(0, 32) })); - const bounties: DeriveBounties = useCall(api.derive.bounties?.bounties); - const treasuryProposals: DeriveTreasuryProposals = useCall(api.derive.treasury.proposals); - const treasuryBalance: DeriveBalancesAccount = useCall(api.derive.balances?.account, [result.treasuryAccount]); + const bounties: DeriveBounties | undefined = useCall(api.derive.bounties?.bounties); + const treasuryProposals: DeriveTreasuryProposals | undefined = useCall(api.derive.treasury.proposals); + // @ts-expect-error `api.derive.balances?.account` doesn't accepts `Uint8Array` + const treasuryBalance: DeriveBalancesAccount | undefined = useCall(api.derive.balances?.account, [result.treasuryAccount]); useEffect((): void => { treasuryBalance && api.consts.treasury && diff --git a/packages/react-query/src/Available.tsx b/packages/react-query/src/Available.tsx index d2a1f4d13dfc..a1963f91f843 100644 --- a/packages/react-query/src/Available.tsx +++ b/packages/react-query/src/Available.tsx @@ -19,7 +19,8 @@ interface Props { function AvailableDisplay ({ children, className = '', label, params }: Props): React.ReactElement { const { api } = useApi(); - const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); + // @ts-expect-error `api.derive.balances?.all` doesn't accepts `Uint8Array` + const allBalances: DeriveBalancesAll | undefined = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); + // @ts-expect-error `api.derive.balances?.all` doesn't accepts `Uint8Array` + const allBalances: DeriveBalancesAll | undefined = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); + // @ts-expect-error `api.derive.balances?.all` doesn't accepts `Uint8Array` + const allBalances: DeriveBalancesAll | undefined = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const allBalances: DeriveBalancesAll = useCall(api.derive.balances?.all, [params]); + // @ts-expect-error `api.derive.balances?.all` doesn't accepts `Uint8Array` + const allBalances: DeriveBalancesAll | undefined = useCall(api.derive.balances?.all, [params]); return ( { const { api } = useApi(); - const controllerId: AccountId | null = useCall(api.query.staking?.bonded, [params], OPT_C); - const stakingLedger: StakingLedger | null = useCall(controllerId && api.query.staking?.ledger, [controllerId], OPT_L); + // @ts-expect-error `api.query.staking.bonded` doesn't accepts `Address` + const controllerId: AccountId | null | undefined = useCall(api.query.staking?.bonded, [params], OPT_C); + const stakingLedger: StakingLedger | null | undefined = useCall(controllerId && api.query.staking?.ledger, [controllerId], OPT_L); return ( | null { const { api } = useApi(); - const info: DeriveCouncilVote = useCall(api.derive.council.votesOf, [params]); + // @ts-expect-error `api.derive.council.votesOf` doesn't accepts `Address` + const info: DeriveCouncilVote | undefined = useCall(api.derive.council.votesOf, [params]); if (!info?.stake.gtn(0)) { return null; From dc45c66e3019899bed237268c7d25c2a9281d5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 3 Jun 2023 20:21:34 +1200 Subject: [PATCH 8/8] chore: remove unnecessary explicit return type --- packages/page-accounts/src/Accounts/useMultisigApprovals.ts | 2 +- packages/page-alliance/src/Members/Member.tsx | 6 +++--- packages/page-alliance/src/useAnnoucements.ts | 2 +- packages/page-alliance/src/useMemberInfo.ts | 3 +-- packages/page-alliance/src/useMembers.ts | 2 +- packages/page-alliance/src/useRule.ts | 2 +- packages/page-alliance/src/useUnscrupulous.ts | 3 +-- packages/page-assets/src/useAssetIds.ts | 2 +- packages/page-assets/src/useAssetInfos.ts | 2 +- packages/page-bounties/src/hooks/useBalance.ts | 4 +--- packages/page-collator/src/useCollators.ts | 2 +- packages/page-nfts/src/AccountItems/useAccountItems.ts | 2 +- packages/page-nfts/src/AccountItems/useItemsInfos.ts | 2 +- packages/page-nfts/src/useCollectionIds.ts | 2 +- packages/page-nfts/src/useCollectionInfos.ts | 2 +- packages/page-parachains/src/Parathreads/useParaMap.ts | 2 +- packages/page-parachains/src/useAuctionInfo.tsx | 2 +- packages/page-parachains/src/useLeasePeriod.ts | 2 +- packages/page-parachains/src/useProposals.ts | 3 +-- packages/page-parachains/src/useUpcomingIds.ts | 2 +- packages/page-parachains/src/useWinningData.ts | 2 +- packages/page-preimages/src/usePreimages.ts | 3 +-- packages/page-ranked/src/useMemberIds.ts | 2 +- packages/page-ranked/src/useMembers.ts | 2 +- .../page-referenda/src/Referenda/Delegate/useActivity.ts | 3 +-- .../src/Referenda/Delegate/useActivityAccount.ts | 3 +-- .../src/Referenda/Delegate/useActivityFellows.ts | 3 +-- .../src/Referenda/Delegate/useActivityNominators.ts | 3 +-- .../page-referenda/src/Referenda/Delegate/useFellows.ts | 2 +- .../page-referenda/src/Referenda/Delegate/useNominators.ts | 2 +- .../page-referenda/src/Referenda/Delegate/useSuperIds.ts | 2 +- .../page-referenda/src/Referenda/Delegate/useVotingFor.ts | 2 +- .../page-referenda/src/Referenda/Delegate/useVotingLocks.ts | 2 +- packages/page-referenda/src/Referenda/useVotes.ts | 2 +- packages/page-referenda/src/useAccountLocks.ts | 2 +- packages/page-referenda/src/useReferendaIds.ts | 3 +-- packages/page-staking/src/Actions/useUnbondDuration.ts | 4 +--- packages/page-staking/src/Bags/useBagsList.ts | 2 +- packages/page-staking/src/Bags/useBagsNodes.tsx | 2 +- packages/page-staking/src/Bags/useBonded.ts | 2 +- packages/page-staking/src/Payouts/useEraBlocks.ts | 2 +- packages/page-staking/src/Targets/useOwnNominators.ts | 2 +- packages/page-staking/src/useIdentities.ts | 4 +--- packages/page-staking/src/useNominations.ts | 2 +- packages/page-staking2/src/Pools/useMembers.ts | 2 +- packages/page-staking2/src/Pools/useOwnPools.ts | 4 ++-- packages/page-staking2/src/Pools/usePoolIds.ts | 2 +- packages/page-staking2/src/Pools/usePoolInfo.ts | 4 ++-- packages/page-staking2/src/Validators/useExposure.ts | 2 +- packages/page-staking2/src/Validators/usePoints.ts | 2 +- packages/page-staking2/src/useElectedValidators.ts | 2 +- packages/page-staking2/src/useTaggedValidators.ts | 2 +- packages/page-staking2/src/useValidatorsActive.ts | 2 +- packages/page-staking2/src/useValidatorsAll.ts | 2 +- packages/page-staking2/src/useValidatorsWaiting.ts | 2 +- packages/page-treasury/src/useTipHashes.ts | 2 +- packages/page-whitelist/src/useHashes.ts | 3 +-- packages/react-hooks/src/useBalancesAll.ts | 4 +--- packages/react-hooks/src/useBestHash.ts | 2 +- packages/react-hooks/src/useDeriveAccountFlags.ts | 3 +-- packages/react-hooks/src/useDeriveAccountInfo.ts | 3 +-- packages/react-hooks/src/useElementPosition.ts | 2 +- packages/react-hooks/src/useOwnStashInfos.ts | 2 +- packages/react-hooks/src/useOwnStashes.ts | 4 ++-- packages/react-hooks/src/useSystemApi.ts | 4 +--- 65 files changed, 70 insertions(+), 92 deletions(-) diff --git a/packages/page-accounts/src/Accounts/useMultisigApprovals.ts b/packages/page-accounts/src/Accounts/useMultisigApprovals.ts index 77f7e951cfae..a1eb18c35e0a 100644 --- a/packages/page-accounts/src/Accounts/useMultisigApprovals.ts +++ b/packages/page-accounts/src/Accounts/useMultisigApprovals.ts @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react'; import { createNamedHook, useApi, useBlockEvents, useIncrement, useIsMountedRef } from '@polkadot/react-hooks'; -function useMultisigApprovalsImpl (address: string): [H256, Multisig][] | undefined { +function useMultisigApprovalsImpl (address: string) { const { events } = useBlockEvents(); const { api } = useApi(); const [multiInfos, setMultiInfos] = useState<[H256, Multisig][] | undefined>(); diff --git a/packages/page-alliance/src/Members/Member.tsx b/packages/page-alliance/src/Members/Member.tsx index 151621687182..5a75cf8ada71 100644 --- a/packages/page-alliance/src/Members/Member.tsx +++ b/packages/page-alliance/src/Members/Member.tsx @@ -54,7 +54,7 @@ function Member ({ bestNumber, className, info: { accountId, role }, isPrime, is
- {(info && info.isRetiringAt && ( + {(info && info.retiringAt && ( ('Is retiring')} @@ -92,7 +92,7 @@ function Member ({ bestNumber, className, info: { accountId, role }, isPrime, is {hasNotice && ( ('Announce retirement')} onClick={doNotice} /> @@ -103,7 +103,7 @@ function Member ({ bestNumber, className, info: { accountId, role }, isPrime, is info.isUpForKicking || ( hasNotice - ? !bestNumber || !info.isRetiringAt || info.isRetiringAt.lt(bestNumber) + ? !bestNumber || !info.retiringAt || info.retiringAt.lt(bestNumber) : false ) ) diff --git a/packages/page-alliance/src/useAnnoucements.ts b/packages/page-alliance/src/useAnnoucements.ts index 0cd93f94a1e9..6f4e85586d05 100644 --- a/packages/page-alliance/src/useAnnoucements.ts +++ b/packages/page-alliance/src/useAnnoucements.ts @@ -13,7 +13,7 @@ const OPT_ANN = { cids.map(createCid) }; -function useAnnouncementsImpl (): Cid[] | undefined { +function useAnnouncementsImpl () { const { api } = useApi(); return useCall(api.query.alliance.announcements, [], OPT_ANN); diff --git a/packages/page-alliance/src/useMemberInfo.ts b/packages/page-alliance/src/useMemberInfo.ts index acd6cbab1657..0727963de05c 100644 --- a/packages/page-alliance/src/useMemberInfo.ts +++ b/packages/page-alliance/src/useMemberInfo.ts @@ -2,13 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import type { bool, Option, UInt } from '@polkadot/types'; -import type { MemberInfo } from './types.js'; import { useMemo } from 'react'; import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; -function useMemberInfoImpl (accountId: string): MemberInfo | undefined { +function useMemberInfoImpl (accountId: string) { const { api } = useApi(); const upForKicking: bool | undefined = useCall(api.query.alliance.upForKicking, [accountId]); const retiringAt: Option | undefined = useCall(api.query.alliance.retiringMembers, [accountId]); diff --git a/packages/page-alliance/src/useMembers.ts b/packages/page-alliance/src/useMembers.ts index f23008da24f9..588dec2ae76a 100644 --- a/packages/page-alliance/src/useMembers.ts +++ b/packages/page-alliance/src/useMembers.ts @@ -34,7 +34,7 @@ function addMembers (prev: Member[], ...query: AccountId32[][]): Member[] { return all.reverse(); } -function useMembersImpl (): Member[] | undefined { +function useMembersImpl () { const { api } = useApi(); const [state, setState] = useState(); const role0 = useCall(api.query.alliance.members, [ROLES[0]]); diff --git a/packages/page-alliance/src/useRule.ts b/packages/page-alliance/src/useRule.ts index afc5c70e72ce..723d9f352a36 100644 --- a/packages/page-alliance/src/useRule.ts +++ b/packages/page-alliance/src/useRule.ts @@ -16,7 +16,7 @@ const OPT_RULE = { : { cid: null, hasRule: false } }; -function useRuleImpl (): Rule | undefined { +function useRuleImpl () { const { api } = useApi(); return useCall(api.query.alliance.rule, [], OPT_RULE); diff --git a/packages/page-alliance/src/useUnscrupulous.ts b/packages/page-alliance/src/useUnscrupulous.ts index 1c53daf9ebbb..b90c712584af 100644 --- a/packages/page-alliance/src/useUnscrupulous.ts +++ b/packages/page-alliance/src/useUnscrupulous.ts @@ -3,7 +3,6 @@ import type { Bytes } from '@polkadot/types'; import type { AccountId32 } from '@polkadot/types/interfaces'; -import type { Unscrupulous } from './types.js'; import { useMemo } from 'react'; @@ -23,7 +22,7 @@ const OPT_WEB = { mapString(websites.filter((b) => b.isAscii)) }; -function useUnscrupulousImpl (): Unscrupulous | undefined { +function useUnscrupulousImpl () { const { api } = useApi(); const accounts = useCall(api.query.alliance.unscrupulousAccounts, [], OPT_ACC); const websites = useCall(api.query.alliance.unscrupulousWebsites, [], OPT_WEB); diff --git a/packages/page-assets/src/useAssetIds.ts b/packages/page-assets/src/useAssetIds.ts index 2eecb7ab427c..4420b002cff8 100644 --- a/packages/page-assets/src/useAssetIds.ts +++ b/packages/page-assets/src/useAssetIds.ts @@ -29,7 +29,7 @@ function filter (records: EventRecord[]): Changes { return { added, removed }; } -function useAssetIdsImpl (): u32[] | undefined { +function useAssetIdsImpl () { const { api } = useApi(); const startValue = useMapKeys(api.query.assets.asset, EMPTY_PARAMS, OPT_KEY); diff --git a/packages/page-assets/src/useAssetInfos.ts b/packages/page-assets/src/useAssetInfos.ts index 82b173b58ae3..eea40a88e348 100644 --- a/packages/page-assets/src/useAssetInfos.ts +++ b/packages/page-assets/src/useAssetInfos.ts @@ -48,7 +48,7 @@ function extractInfo (allAccounts: string[], id: BN, optDetails: Option(); diff --git a/packages/page-nfts/src/AccountItems/useAccountItems.ts b/packages/page-nfts/src/AccountItems/useAccountItems.ts index c762e154b5ae..2c45574edf25 100644 --- a/packages/page-nfts/src/AccountItems/useAccountItems.ts +++ b/packages/page-nfts/src/AccountItems/useAccountItems.ts @@ -24,7 +24,7 @@ function transformResults (results: StorageKey<[AccountId32, u32, u32]>[][]): Ac .flat(); } -function useAccountItemsImpl (): AccountItem[] | undefined { +function useAccountItemsImpl () { const mountedRef = useIsMountedRef(); const { api } = useApi(); const { allAccounts } = useAccounts(); diff --git a/packages/page-nfts/src/AccountItems/useItemsInfos.ts b/packages/page-nfts/src/AccountItems/useItemsInfos.ts index 26dcdadc91d0..63ee9c8d0cc2 100644 --- a/packages/page-nfts/src/AccountItems/useItemsInfos.ts +++ b/packages/page-nfts/src/AccountItems/useItemsInfos.ts @@ -57,7 +57,7 @@ const addIpfsData = (ipfsData: IpfsData) => (itemInfo: ItemInfo): ItemInfo => { }; }; -function useItemsInfosImpl (accountItems: AccountItem[]): ItemInfo[] | undefined { +function useItemsInfosImpl (accountItems: AccountItem[]) { const { api } = useApi(); const [state, setState] = useState(); diff --git a/packages/page-nfts/src/useCollectionIds.ts b/packages/page-nfts/src/useCollectionIds.ts index 89b20954f67c..c541e49bf196 100644 --- a/packages/page-nfts/src/useCollectionIds.ts +++ b/packages/page-nfts/src/useCollectionIds.ts @@ -29,7 +29,7 @@ function filter (records: EventRecord[]): Changes { return { added, removed }; } -function useCollectionIdsImpl (): u32[] | undefined { +function useCollectionIdsImpl () { const { api } = useApi(); const startValue = useMapKeys(api.query.uniques.class, [], OPT_KEYS); diff --git a/packages/page-nfts/src/useCollectionInfos.ts b/packages/page-nfts/src/useCollectionInfos.ts index 5d2e0b143c04..9f766a753b53 100644 --- a/packages/page-nfts/src/useCollectionInfos.ts +++ b/packages/page-nfts/src/useCollectionInfos.ts @@ -79,7 +79,7 @@ const addIpfsData = (ipfsData: IpfsData) => (collectionInfo: CollectionInfo): Co }; }; -function useCollectionInfosImpl (ids?: BN[]): CollectionInfo[] | undefined { +function useCollectionInfosImpl (ids?: BN[]) { const { api } = useApi(); const { allAccounts } = useAccounts(); const metadata: [[BN[]], Option[]] | undefined = useCall(api.query.uniques.classMetadataOf.multi, [ids], QUERY_OPTS); diff --git a/packages/page-parachains/src/Parathreads/useParaMap.ts b/packages/page-parachains/src/Parathreads/useParaMap.ts index 7df3dee62725..e9b7f23ae2c3 100644 --- a/packages/page-parachains/src/Parathreads/useParaMap.ts +++ b/packages/page-parachains/src/Parathreads/useParaMap.ts @@ -54,7 +54,7 @@ function extractParaMap (hasLinksMap: Record, paraIds: ParaId[] }); } -function useParaMapImpl (ids?: ParaId[]): Result | undefined { +function useParaMapImpl (ids?: ParaId[]) { const { api } = useApi(); const hasLinksMap = useIsParasLinked(ids); const transform = useCallback( diff --git a/packages/page-parachains/src/useAuctionInfo.tsx b/packages/page-parachains/src/useAuctionInfo.tsx index 729041ce4d73..deb13034bff0 100644 --- a/packages/page-parachains/src/useAuctionInfo.tsx +++ b/packages/page-parachains/src/useAuctionInfo.tsx @@ -20,7 +20,7 @@ const OPT_MULTI = { } }; -function useAuctionInfoImpl (): AuctionInfo | undefined { +function useAuctionInfoImpl () { const { api } = useApi(); return useCallMulti([ diff --git a/packages/page-parachains/src/useLeasePeriod.ts b/packages/page-parachains/src/useLeasePeriod.ts index 7d8dece01824..115298f4b897 100644 --- a/packages/page-parachains/src/useLeasePeriod.ts +++ b/packages/page-parachains/src/useLeasePeriod.ts @@ -9,7 +9,7 @@ import { useMemo } from 'react'; import { createNamedHook, useApi, useBestNumber } from '@polkadot/react-hooks'; import { BN_ZERO } from '@polkadot/util'; -function useLeasePeriodImpl (): LeasePeriod | undefined { +function useLeasePeriodImpl () { const { api } = useApi(); const bestNumber = useBestNumber(); diff --git a/packages/page-parachains/src/useProposals.ts b/packages/page-parachains/src/useProposals.ts index cae37647d4c9..dc07feb37413 100644 --- a/packages/page-parachains/src/useProposals.ts +++ b/packages/page-parachains/src/useProposals.ts @@ -3,7 +3,6 @@ import type { StorageKey } from '@polkadot/types'; import type { ParaId, SessionIndex } from '@polkadot/types/interfaces'; -import type { Proposals } from './types.js'; import { useMemo } from 'react'; @@ -33,7 +32,7 @@ const OPT_SCHED = { })) }; -function useProposalsImpl (): Proposals | undefined { +function useProposalsImpl () { const { api } = useApi(); const mountedRef = useIsMountedRef(); const trigger = useEventTrigger([api.events.proposeParachain?.ProposeParachain]); diff --git a/packages/page-parachains/src/useUpcomingIds.ts b/packages/page-parachains/src/useUpcomingIds.ts index efe3e54d3460..043455f97010 100644 --- a/packages/page-parachains/src/useUpcomingIds.ts +++ b/packages/page-parachains/src/useUpcomingIds.ts @@ -26,7 +26,7 @@ const OPT_ENTRIES = { .sort((a, b) => a.cmp(b)) }; -function useUpomingIdsImpl (): ParaId[] | undefined { +function useUpomingIdsImpl () { const { api } = useApi(); const trigger = useEventTrigger([ api.events.session.NewSession, diff --git a/packages/page-parachains/src/useWinningData.ts b/packages/page-parachains/src/useWinningData.ts index 07bb81c5088f..05250ebff85b 100644 --- a/packages/page-parachains/src/useWinningData.ts +++ b/packages/page-parachains/src/useWinningData.ts @@ -120,7 +120,7 @@ function mergeFirst (ranges: [number, number][], auctionInfo: AuctionInfo, prev: return prev; } -function useWinningDataImpl (auctionInfo?: AuctionInfo): Winning[] | undefined { +function useWinningDataImpl (auctionInfo?: AuctionInfo) { const { api } = useApi(); const mountedRef = useIsMountedRef(); const ranges = useLeaseRanges(); diff --git a/packages/page-preimages/src/usePreimages.ts b/packages/page-preimages/src/usePreimages.ts index 41e38ffb8fb8..4dea34c4d2cf 100644 --- a/packages/page-preimages/src/usePreimages.ts +++ b/packages/page-preimages/src/usePreimages.ts @@ -4,7 +4,6 @@ import type { Changes } from '@polkadot/react-hooks/useEventChanges'; import type { StorageKey } from '@polkadot/types'; import type { EventRecord, Hash } from '@polkadot/types/interfaces'; -import type { HexString } from '@polkadot/util/types'; import { useMemo } from 'react'; @@ -32,7 +31,7 @@ function filter (records: EventRecord[]): Changes { return { added, removed }; } -function usePreimagesImpl (): HexString[] | undefined { +function usePreimagesImpl () { const { api } = useApi(); const startValue = useMapKeys(api.query.preimage.statusFor, EMPTY_PARAMS, OPT_HASH); const hashes = useEventChanges([ diff --git a/packages/page-ranked/src/useMemberIds.ts b/packages/page-ranked/src/useMemberIds.ts index fc1da5352bff..8c07190aa4b8 100644 --- a/packages/page-ranked/src/useMemberIds.ts +++ b/packages/page-ranked/src/useMemberIds.ts @@ -28,7 +28,7 @@ function filter (records: EventRecord[]): Changes { return { added, removed }; } -function useMemberIdsImpl (collective: PalletColl): AccountId32[] | undefined { +function useMemberIdsImpl (collective: PalletColl) { const { api } = useApi(); const startValue = useMapKeys(api.query[collective].members, [], OPT_ID); diff --git a/packages/page-ranked/src/useMembers.ts b/packages/page-ranked/src/useMembers.ts index 3a6288c1b6c3..fbdd469182c4 100644 --- a/packages/page-ranked/src/useMembers.ts +++ b/packages/page-ranked/src/useMembers.ts @@ -39,7 +39,7 @@ const OPT_MEM = { withParamsTransform: true }; -function useMembersImpl (collective: PalletColl): Result | undefined { +function useMembersImpl (collective: PalletColl) { const { api } = useApi(); const ids = useMembersIds(collective); const result = useCall(ids && ids.length !== 0 && api.query[collective].members.multi, [ids], OPT_MEM); diff --git a/packages/page-referenda/src/Referenda/Delegate/useActivity.ts b/packages/page-referenda/src/Referenda/Delegate/useActivity.ts index 8d209f80e7cc..eede9094a666 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useActivity.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useActivity.ts @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import type { PalletVote } from '../../types.js'; -import type { VoteResult } from './types.js'; import { createNamedHook } from '@polkadot/react-hooks'; import useSuperIds from './useSuperIds.js'; import useVotingFor from './useVotingFor.js'; -function useActivityImpl (palletVote: PalletVote, accountIds?: string[] | null): VoteResult | null | undefined { +function useActivityImpl (palletVote: PalletVote, accountIds?: string[] | null) { const identities = useSuperIds(accountIds); return useVotingFor(palletVote, identities); diff --git a/packages/page-referenda/src/Referenda/Delegate/useActivityAccount.ts b/packages/page-referenda/src/Referenda/Delegate/useActivityAccount.ts index b21b9409511c..cc60de8985c1 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useActivityAccount.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useActivityAccount.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import type { PalletVote } from '../../types.js'; -import type { VoteResultItem } from './types.js'; import { useMemo } from 'react'; @@ -10,7 +9,7 @@ import { createNamedHook } from '@polkadot/react-hooks'; import useVotingFor from './useVotingFor.js'; -function useActivityAccountImpl (palletVote: PalletVote, accountId?: string | null): VoteResultItem[] | null | undefined { +function useActivityAccountImpl (palletVote: PalletVote, accountId?: string | null) { const params = useMemo( () => (accountId && [accountId]) || null, [accountId] diff --git a/packages/page-referenda/src/Referenda/Delegate/useActivityFellows.ts b/packages/page-referenda/src/Referenda/Delegate/useActivityFellows.ts index f8a9977b2620..2fd1ceac3538 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useActivityFellows.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useActivityFellows.ts @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import type { PalletVote } from '../../types.js'; -import type { VoteResult } from './types.js'; import { createNamedHook } from '@polkadot/react-hooks'; import useActivity from './useActivity.js'; import useFellows from './useFellows.js'; -function useActivityFellowsImpl (palletVote: PalletVote): VoteResult | null | undefined { +function useActivityFellowsImpl (palletVote: PalletVote) { const fellows = useFellows(); return useActivity(palletVote, fellows); diff --git a/packages/page-referenda/src/Referenda/Delegate/useActivityNominators.ts b/packages/page-referenda/src/Referenda/Delegate/useActivityNominators.ts index 14416c2692e2..8a7050fc63b9 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useActivityNominators.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useActivityNominators.ts @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import type { PalletVote } from '../../types.js'; -import type { VoteResult } from './types.js'; import { createNamedHook } from '@polkadot/react-hooks'; import useActivity from './useActivity.js'; import useNominators from './useNominators.js'; -function useActivityNominatorsImpl (palletVote: PalletVote): VoteResult | null | undefined { +function useActivityNominatorsImpl (palletVote: PalletVote) { const nominators = useNominators(); return useActivity(palletVote, nominators); diff --git a/packages/page-referenda/src/Referenda/Delegate/useFellows.ts b/packages/page-referenda/src/Referenda/Delegate/useFellows.ts index 2a977d0fb9be..9988b7a82015 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useFellows.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useFellows.ts @@ -14,7 +14,7 @@ const MEMBERS_OPT = { keys.map(({ args: [id] }) => id.toString()) }; -function useFellowsImpl (): string[] | null | undefined { +function useFellowsImpl () { const { api } = useApi(); const members = useMapKeys(api.query.fellowshipCollective?.members, [], MEMBERS_OPT); diff --git a/packages/page-referenda/src/Referenda/Delegate/useNominators.ts b/packages/page-referenda/src/Referenda/Delegate/useNominators.ts index f7c158372c82..6289d0fc22f9 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useNominators.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useNominators.ts @@ -24,7 +24,7 @@ const NOMINATORS_OPT = { // A list of all validators that any of our accounts nominate // (deduped accross accounts) -function useNominatorsImpl (): string[] | null | undefined { +function useNominatorsImpl () { const { api } = useApi(); const { allAccounts } = useAccounts(); diff --git a/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts b/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts index f9e3a5b2cec4..6ffe614308cb 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useSuperIds.ts @@ -31,7 +31,7 @@ const SUPEROF_OPT = { withParamsTransform: true }; -function useSuperIdsImpl (accountIds?: string[] | null): string[] | null | undefined { +function useSuperIdsImpl (accountIds?: string[] | null) { const { api } = useApi(); // for the supplied accounts, retrieve the de-dupes parent identity diff --git a/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts b/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts index ffdc3b4e78fd..012594d3260a 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts @@ -65,7 +65,7 @@ function combineResult (locks: LockResult, votes: VoteResult): VoteResult { }, votes); } -function useVotingForImpl (palletVote: PalletVote, accountIds?: string[] | null): VoteResult | null | undefined { +function useVotingForImpl (palletVote: PalletVote, accountIds?: string[] | null) { const { api } = useApi(); const locks = useVotingLocks(palletVote, accountIds); diff --git a/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts b/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts index 873c32dc25a6..ac5ffc2ba174 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts @@ -22,7 +22,7 @@ const LOCKS_OPT = { withParamsTransform: true }; -function useVotingLocksImpl (palletVote: PalletVote, accountIds?: string[] | null): LockResult | null | undefined { +function useVotingLocksImpl (palletVote: PalletVote, accountIds?: string[] | null) { const { api } = useApi(); const locksParam = useMemo( diff --git a/packages/page-referenda/src/Referenda/useVotes.ts b/packages/page-referenda/src/Referenda/useVotes.ts index 94dbe7c768bb..d68c916bfa86 100644 --- a/packages/page-referenda/src/Referenda/useVotes.ts +++ b/packages/page-referenda/src/Referenda/useVotes.ts @@ -42,7 +42,7 @@ function filterEvents (records: EventRecord[], _: ApiPromise, id?: BN): Changes< return { added }; } -function useVotesImpl (palletVote: PalletVote, id: BN, isConvictionVote: boolean): Record | undefined { +function useVotesImpl (palletVote: PalletVote, id: BN, isConvictionVote: boolean) { const { api } = useApi(); const startAccounts = useMapKeys(isConvictionVote === false && api.query[palletVote].voting, [id], OPT_ACCOUNTID); const allAccounts = useEventChanges([ diff --git a/packages/page-referenda/src/useAccountLocks.ts b/packages/page-referenda/src/useAccountLocks.ts index eb13ae4874f2..ce2c4494e479 100644 --- a/packages/page-referenda/src/useAccountLocks.ts +++ b/packages/page-referenda/src/useAccountLocks.ts @@ -138,7 +138,7 @@ function getLocks (api: ApiPromise, palletVote: PalletVote, votes: [classId: BN, return locks; } -function useAccountLocksImpl (palletReferenda: PalletReferenda, palletVote: PalletVote, accountId: string): Lock[] | undefined { +function useAccountLocksImpl (palletReferenda: PalletReferenda, palletVote: PalletVote, accountId: string) { const { api } = useApi(); // retrieve the locks for the account (all classes) via the accountId diff --git a/packages/page-referenda/src/useReferendaIds.ts b/packages/page-referenda/src/useReferendaIds.ts index 2d630a1badba..d5f326197a75 100644 --- a/packages/page-referenda/src/useReferendaIds.ts +++ b/packages/page-referenda/src/useReferendaIds.ts @@ -4,7 +4,6 @@ import type { Changes } from '@polkadot/react-hooks/useEventChanges'; import type { StorageKey, u32 } from '@polkadot/types'; import type { EventRecord } from '@polkadot/types/interfaces'; -import type { BN } from '@polkadot/util'; import type { PalletReferenda } from './types.js'; import { createNamedHook, useApi, useEventChanges, useMapKeys } from '@polkadot/react-hooks'; @@ -29,7 +28,7 @@ function filter (records: EventRecord[]): Changes { return { added, removed }; } -function useReferendaIdsImpl (palletReferenda: PalletReferenda): BN[] | undefined { +function useReferendaIdsImpl (palletReferenda: PalletReferenda) { const { api } = useApi(); const startValue = useMapKeys(api.query[palletReferenda].referendumInfoFor, [], OPT_ID); diff --git a/packages/page-staking/src/Actions/useUnbondDuration.ts b/packages/page-staking/src/Actions/useUnbondDuration.ts index 975b95da1b92..2f854ff68b50 100644 --- a/packages/page-staking/src/Actions/useUnbondDuration.ts +++ b/packages/page-staking/src/Actions/useUnbondDuration.ts @@ -1,14 +1,12 @@ // Copyright 2017-2023 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BN } from '@polkadot/util'; - import { useMemo } from 'react'; import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; import { BN_ONE } from '@polkadot/util'; -function useUnbondDurationImpl (): BN | undefined { +function useUnbondDurationImpl () { const { api } = useApi(); const sessionInfo = useCall(api.derive.session.info); diff --git a/packages/page-staking/src/Bags/useBagsList.ts b/packages/page-staking/src/Bags/useBagsList.ts index 6a56eeb4b271..a5124b56187c 100644 --- a/packages/page-staking/src/Bags/useBagsList.ts +++ b/packages/page-staking/src/Bags/useBagsList.ts @@ -52,7 +52,7 @@ function merge (prev: BagInfo[] | undefined, curr: BagInfo[]): BagInfo[] { ); } -function useBagsListImpl (): BagInfo[] | undefined { +function useBagsListImpl () { const mod = useQueryModule(); const [result, setResult] = useState(); const ids = useMapKeys(mod.listBags, [], KEY_OPTS); diff --git a/packages/page-staking/src/Bags/useBagsNodes.tsx b/packages/page-staking/src/Bags/useBagsNodes.tsx index c08aebfc32a6..aa615ad95675 100644 --- a/packages/page-staking/src/Bags/useBagsNodes.tsx +++ b/packages/page-staking/src/Bags/useBagsNodes.tsx @@ -41,7 +41,7 @@ function merge (prev: BagMap | undefined, curr: BagMap): BagMap { }, {}); } -function useBagsNodesImpl (stashIds: string[]): BagMap | undefined { +function useBagsNodesImpl (stashIds: string[]) { const mod = useQueryModule(); const [result, setResult] = useState(); const query = useCall(mod.listNodes.multi, [stashIds], MULTI_OPTS); diff --git a/packages/page-staking/src/Bags/useBonded.ts b/packages/page-staking/src/Bags/useBonded.ts index f99e200a0af4..c63609895979 100644 --- a/packages/page-staking/src/Bags/useBonded.ts +++ b/packages/page-staking/src/Bags/useBonded.ts @@ -31,7 +31,7 @@ const DERIVE_OPTS = { } }; -function useBondedImpl (ids?: false | AccountId32[]): ListNode[] | undefined { +function useBondedImpl (ids?: false | AccountId32[]) { const { api } = useApi(); return useCall(ids && ids.length !== 0 && api.derive.staking.accounts, [ids], DERIVE_OPTS); diff --git a/packages/page-staking/src/Payouts/useEraBlocks.ts b/packages/page-staking/src/Payouts/useEraBlocks.ts index c7ac86a1ba91..ef1e1c8e16ea 100644 --- a/packages/page-staking/src/Payouts/useEraBlocks.ts +++ b/packages/page-staking/src/Payouts/useEraBlocks.ts @@ -8,7 +8,7 @@ import { useMemo } from 'react'; import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; import { BN_ONE } from '@polkadot/util'; -function useEraBlocksImpl (historyDepth?: BN, era?: BN): BN | undefined { +function useEraBlocksImpl (historyDepth?: BN, era?: BN) { const { api } = useApi(); const progress = useCall(api.derive.session.progress); const forcing = useCall(api.query.staking.forceEra); diff --git a/packages/page-staking/src/Targets/useOwnNominators.ts b/packages/page-staking/src/Targets/useOwnNominators.ts index 4e931d3716aa..5695b0da047c 100644 --- a/packages/page-staking/src/Targets/useOwnNominators.ts +++ b/packages/page-staking/src/Targets/useOwnNominators.ts @@ -7,7 +7,7 @@ import { useMemo } from 'react'; import { createNamedHook } from '@polkadot/react-hooks'; -function useOwnNominatorsImpl (ownStashes?: StakerState[]): StakerState[] | undefined { +function useOwnNominatorsImpl (ownStashes?: StakerState[]) { return useMemo( () => ownStashes && ownStashes.filter(({ isOwnController, isStashValidating }) => isOwnController && diff --git a/packages/page-staking/src/useIdentities.ts b/packages/page-staking/src/useIdentities.ts index c66f6648594a..198f433de979 100644 --- a/packages/page-staking/src/useIdentities.ts +++ b/packages/page-staking/src/useIdentities.ts @@ -5,8 +5,6 @@ import type { DeriveHasIdentity } from '@polkadot/api-derive/types'; import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; -type Result = Record; - const OPT_CALL = { transform: ([[validatorIds], hasIdentities]: [[string[]], DeriveHasIdentity[]]): Record => { const result: Record = {}; @@ -20,7 +18,7 @@ const OPT_CALL = { withParamsTransform: true }; -function useIdentitiesImpl (validatorIds: string[] = []): Result | undefined { +function useIdentitiesImpl (validatorIds: string[] = []) { const { api } = useApi(); const allIdentity = useCall(api.derive.accounts.hasIdentityMulti, [validatorIds], OPT_CALL); diff --git a/packages/page-staking/src/useNominations.ts b/packages/page-staking/src/useNominations.ts index 0b175ed4e883..84ece795df7a 100644 --- a/packages/page-staking/src/useNominations.ts +++ b/packages/page-staking/src/useNominations.ts @@ -34,7 +34,7 @@ function extractNominators (nominations: [StorageKey, Option][]): N return mapped; } -function useNominationsImpl (isActive = true): NominatedByMap | undefined { +function useNominationsImpl (isActive = true) { const { api } = useApi(); const nominators: [StorageKey, Option][] | undefined = useCall(isActive && api.query.staking.nominators.entries); diff --git a/packages/page-staking2/src/Pools/useMembers.ts b/packages/page-staking2/src/Pools/useMembers.ts index bc4768dfda83..384a065f6532 100644 --- a/packages/page-staking2/src/Pools/useMembers.ts +++ b/packages/page-staking2/src/Pools/useMembers.ts @@ -83,7 +83,7 @@ function interleave (prev: MembersMap, additions: MembersMapEntry[]): MembersMap }, { ...prev }); } -function useMembersImpl (): MembersMap | undefined { +function useMembersImpl () { const { api } = useApi(); const [membersMap, setMembersMap] = useState(); const queryMap = useMapEntries(api.query.nominationPools.poolMembers, [], OPT_ENTRIES); diff --git a/packages/page-staking2/src/Pools/useOwnPools.ts b/packages/page-staking2/src/Pools/useOwnPools.ts index 20910b69aa7b..caeec6399322 100644 --- a/packages/page-staking2/src/Pools/useOwnPools.ts +++ b/packages/page-staking2/src/Pools/useOwnPools.ts @@ -3,7 +3,7 @@ import type { Option } from '@polkadot/types'; import type { PalletNominationPoolsPoolMember } from '@polkadot/types/lookup'; -import type { OwnPool, OwnPoolBase } from './types.js'; +import type { OwnPoolBase } from './types.js'; import { useMemo } from 'react'; @@ -35,7 +35,7 @@ const OPT_MULTI = { withParamsTransform: true }; -function useOwnPoolsImpl (): OwnPool[] | undefined { +function useOwnPoolsImpl () { const { api } = useApi(); const { allAccounts } = useAccounts(); const base = useCall(api.query.nominationPools?.poolMembers.multi, [allAccounts], OPT_MULTI); diff --git a/packages/page-staking2/src/Pools/usePoolIds.ts b/packages/page-staking2/src/Pools/usePoolIds.ts index 2b2aaf80dd54..87ea5be465c5 100644 --- a/packages/page-staking2/src/Pools/usePoolIds.ts +++ b/packages/page-staking2/src/Pools/usePoolIds.ts @@ -29,7 +29,7 @@ function filterEvents (records: EventRecord[]): Changes { return { added, removed }; } -function usePoolIdsImpl (): u32[] | undefined { +function usePoolIdsImpl () { const { api } = useApi(); const startValue = useMapKeys(api.query.nominationPools.bondedPools, [], OPT_KEYS); diff --git a/packages/page-staking2/src/Pools/usePoolInfo.ts b/packages/page-staking2/src/Pools/usePoolInfo.ts index f08dbcd6c562..40a8e151fe8a 100644 --- a/packages/page-staking2/src/Pools/usePoolInfo.ts +++ b/packages/page-staking2/src/Pools/usePoolInfo.ts @@ -4,7 +4,7 @@ import type { Bytes, Option } from '@polkadot/types'; import type { FrameSystemAccountInfo, PalletNominationPoolsBondedPoolInner, PalletNominationPoolsRewardPool, PalletStakingNominations } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; -import type { PoolInfo, PoolInfoBase } from './types.js'; +import type { PoolInfoBase } from './types.js'; import { useMemo } from 'react'; @@ -39,7 +39,7 @@ function transformName (input: string): string { return input.replace(/[^\x20-\x7E]/g, ''); } -function usePoolInfoImpl (poolId: BN): PoolInfo | null | undefined { +function usePoolInfoImpl (poolId: BN) { const { api } = useApi(); const accounts = usePoolAccounts(poolId); const baseInfo = useCallMulti([ diff --git a/packages/page-staking2/src/Validators/useExposure.ts b/packages/page-staking2/src/Validators/useExposure.ts index 7f3fb346c850..3b200546f593 100644 --- a/packages/page-staking2/src/Validators/useExposure.ts +++ b/packages/page-staking2/src/Validators/useExposure.ts @@ -44,7 +44,7 @@ function getResult (exposure: UseExposureExposure, clipped: UseExposureExposure) return { clipped, exposure, waiting }; } -function useExposureImpl ({ stashId }: Validator, { activeEra }: SessionInfo): UseExposure | undefined { +function useExposureImpl ({ stashId }: Validator, { activeEra }: SessionInfo) { const { api } = useApi(); const params = useMemo( diff --git a/packages/page-staking2/src/Validators/usePoints.ts b/packages/page-staking2/src/Validators/usePoints.ts index e1d7dafdddac..9aae59602f74 100644 --- a/packages/page-staking2/src/Validators/usePoints.ts +++ b/packages/page-staking2/src/Validators/usePoints.ts @@ -23,7 +23,7 @@ const OPT_POINTS = { }, {}) }; -function usePointsImpl ({ activeEra }: SessionInfo): UsePoints | undefined { +function usePointsImpl ({ activeEra }: SessionInfo) { const { api } = useApi(); const queryParams = useMemo( diff --git a/packages/page-staking2/src/useElectedValidators.ts b/packages/page-staking2/src/useElectedValidators.ts index 40113197b931..c8bba87fa8b4 100644 --- a/packages/page-staking2/src/useElectedValidators.ts +++ b/packages/page-staking2/src/useElectedValidators.ts @@ -18,7 +18,7 @@ const OPT_ELECTED = { ) }; -function useElectedValidatorsImpl ({ currentEra }: SessionInfo): string[] | undefined { +function useElectedValidatorsImpl ({ currentEra }: SessionInfo) { const { api } = useApi(); const electedParams = useMemo( diff --git a/packages/page-staking2/src/useTaggedValidators.ts b/packages/page-staking2/src/useTaggedValidators.ts index cb8a6b2087d3..62bd8f3d644f 100644 --- a/packages/page-staking2/src/useTaggedValidators.ts +++ b/packages/page-staking2/src/useTaggedValidators.ts @@ -49,7 +49,7 @@ function withSort (allAccounts: string[], favorites: string[], validators: Valid .sort(sort); } -function useTaggedValidatorsImpl (favorites: string[], sessionInfo: SessionInfo, validators?: Validator[]): Validator[] | undefined { +function useTaggedValidatorsImpl (favorites: string[], sessionInfo: SessionInfo, validators?: Validator[]) { const { allAccounts } = useAccounts(); const elected = useElectedValidators(sessionInfo); diff --git a/packages/page-staking2/src/useValidatorsActive.ts b/packages/page-staking2/src/useValidatorsActive.ts index 489814848366..1da868d0eed9 100644 --- a/packages/page-staking2/src/useValidatorsActive.ts +++ b/packages/page-staking2/src/useValidatorsActive.ts @@ -34,7 +34,7 @@ const OPT_INDICES = { indices.map((n) => n.toNumber()) }; -function useValidatorsActiveImpl (favorites: string[], sessionInfo: SessionInfo): Validator[] | undefined { +function useValidatorsActiveImpl (favorites: string[], sessionInfo: SessionInfo) { const { api } = useApi(); const sessionValidators = useCall(api.query.session.validators, undefined, OPT_VALIDATORS); const activeIndices = useCall((api.query.parasShared || api.query.shared)?.activeValidatorIndices, undefined, OPT_INDICES); diff --git a/packages/page-staking2/src/useValidatorsAll.ts b/packages/page-staking2/src/useValidatorsAll.ts index 08b449c26ddf..fcf35ddcc999 100644 --- a/packages/page-staking2/src/useValidatorsAll.ts +++ b/packages/page-staking2/src/useValidatorsAll.ts @@ -50,7 +50,7 @@ function mapValidators (validators?: AccountId32[]): Validator[] | undefined { }); } -function useValidatorsAllImpl (favorites: string[], sessionInfo: SessionInfo): Validator[] | undefined { +function useValidatorsAllImpl (favorites: string[], sessionInfo: SessionInfo) { const { api } = useApi(); const startValue = useMapKeys(api.query.staking.validators, EMPTY_PARAMS, OPT_VALIDATORS); diff --git a/packages/page-staking2/src/useValidatorsWaiting.ts b/packages/page-staking2/src/useValidatorsWaiting.ts index 214ea29b358a..2fc899a066db 100644 --- a/packages/page-staking2/src/useValidatorsWaiting.ts +++ b/packages/page-staking2/src/useValidatorsWaiting.ts @@ -16,7 +16,7 @@ function excludeValidators (from: Validator[], exclude: Validator[]): Validator[ ); } -function useValidatorsWaitingImpl (favorites: string[], sessionInfo: SessionInfo, activeValidators?: Validator[]): Validator[] | undefined { +function useValidatorsWaitingImpl (favorites: string[], sessionInfo: SessionInfo, activeValidators?: Validator[]) { const allValidators = useValidatorsAll(favorites, sessionInfo); // both active and all is already sorted and tagged, so we don't diff --git a/packages/page-treasury/src/useTipHashes.ts b/packages/page-treasury/src/useTipHashes.ts index d2f37b420503..8470c052c512 100644 --- a/packages/page-treasury/src/useTipHashes.ts +++ b/packages/page-treasury/src/useTipHashes.ts @@ -11,7 +11,7 @@ const OPT = { keys.map(({ args: [hash] }) => hash.toHex()) }; -function useTipHashesImpl (): string[] | undefined { +function useTipHashesImpl () { const { api } = useApi(); const trigger = useEventTrigger([ api.events.tips?.NewTip, diff --git a/packages/page-whitelist/src/useHashes.ts b/packages/page-whitelist/src/useHashes.ts index 7b11777ad4d4..0ac4e818fb27 100644 --- a/packages/page-whitelist/src/useHashes.ts +++ b/packages/page-whitelist/src/useHashes.ts @@ -4,7 +4,6 @@ import type { Changes } from '@polkadot/react-hooks/useEventChanges'; import type { StorageKey } from '@polkadot/types'; import type { EventRecord, Hash } from '@polkadot/types/interfaces'; -import type { HexString } from '@polkadot/util/types'; import { useMemo } from 'react'; @@ -30,7 +29,7 @@ function filter (records: EventRecord[]): Changes { return { added, removed }; } -function useHashesImpl (): HexString[] | undefined { +function useHashesImpl () { const { api } = useApi(); const startValue = useMapKeys(api.query.whitelist.whitelistedCall, [], OPT_HASH); const hashes = useEventChanges([ diff --git a/packages/react-hooks/src/useBalancesAll.ts b/packages/react-hooks/src/useBalancesAll.ts index b052c9e05671..ca864ea11663 100644 --- a/packages/react-hooks/src/useBalancesAll.ts +++ b/packages/react-hooks/src/useBalancesAll.ts @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; - import { createNamedHook } from './createNamedHook.js'; import { useApi } from './useApi.js'; import { useCall } from './useCall.js'; @@ -13,7 +11,7 @@ import { useCall } from './useCall.js'; * @param accountAddress The account address of which balance is to be returned * @returns full information about account's balances */ -function useBalancesAllImpl (accountAddress: string): DeriveBalancesAll | undefined { +function useBalancesAllImpl (accountAddress: string) { const { api } = useApi(); return useCall(api.derive.balances?.all, [accountAddress]); diff --git a/packages/react-hooks/src/useBestHash.ts b/packages/react-hooks/src/useBestHash.ts index dc07bd441da7..a4dc44dc78dc 100644 --- a/packages/react-hooks/src/useBestHash.ts +++ b/packages/react-hooks/src/useBestHash.ts @@ -11,7 +11,7 @@ const OPT = { transform: (header: Header) => header.hash.toHex() }; -function useBestHashImpl (): string | undefined { +function useBestHashImpl () { const { api } = useApi(); return useCall(api.rpc.chain.subscribeNewHeads, undefined, OPT); diff --git a/packages/react-hooks/src/useDeriveAccountFlags.ts b/packages/react-hooks/src/useDeriveAccountFlags.ts index d29c41c4a40a..f1b1b94c0ee0 100644 --- a/packages/react-hooks/src/useDeriveAccountFlags.ts +++ b/packages/react-hooks/src/useDeriveAccountFlags.ts @@ -1,14 +1,13 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveAccountFlags } from '@polkadot/api-derive/types'; import type { AccountId, Address } from '@polkadot/types/interfaces'; import { createNamedHook } from './createNamedHook.js'; import { useCall } from './useCall.js'; import { useSystemApi } from './useSystemApi.js'; -function useDeriveAccountFlagsImpl (value?: AccountId | Address | Uint8Array | string | null): DeriveAccountFlags | undefined { +function useDeriveAccountFlagsImpl (value?: AccountId | Address | Uint8Array | string | null) { const api = useSystemApi(); return useCall(api && api.derive.accounts.flags, diff --git a/packages/react-hooks/src/useDeriveAccountInfo.ts b/packages/react-hooks/src/useDeriveAccountInfo.ts index e98ade4bad73..f91f7ff1677d 100644 --- a/packages/react-hooks/src/useDeriveAccountInfo.ts +++ b/packages/react-hooks/src/useDeriveAccountInfo.ts @@ -1,14 +1,13 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeriveAccountInfo } from '@polkadot/api-derive/types'; import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces'; import { createNamedHook } from './createNamedHook.js'; import { useCall } from './useCall.js'; import { useSystemApi } from './useSystemApi.js'; -function useDeriveAccountInfoImpl (value?: AccountId | AccountIndex | Address | Uint8Array | string | null): DeriveAccountInfo | undefined { +function useDeriveAccountInfoImpl (value?: AccountId | AccountIndex | Address | Uint8Array | string | null) { const api = useSystemApi(); return useCall(api && api.derive.accounts.info, [value]); diff --git a/packages/react-hooks/src/useElementPosition.ts b/packages/react-hooks/src/useElementPosition.ts index 2e4853c25890..c2406d0d7cd8 100644 --- a/packages/react-hooks/src/useElementPosition.ts +++ b/packages/react-hooks/src/useElementPosition.ts @@ -11,7 +11,7 @@ import { useIsMountedRef } from './useIsMountedRef.js'; import { useScroll } from './useScroll.js'; import { useWindowSize } from './useWindowSize.js'; -function useElementPositionImpl (ref: React.MutableRefObject): ElementPosition | undefined { +function useElementPositionImpl (ref: React.MutableRefObject) { const [elementPosition, setElementPosition] = useState(); const mountedRef = useIsMountedRef(); const windowSize = useWindowSize(); diff --git a/packages/react-hooks/src/useOwnStashInfos.ts b/packages/react-hooks/src/useOwnStashInfos.ts index bc7a855e3182..25602b279051 100644 --- a/packages/react-hooks/src/useOwnStashInfos.ts +++ b/packages/react-hooks/src/useOwnStashInfos.ts @@ -63,7 +63,7 @@ function getStakerState (stashId: string, allAccounts: string[], [isOwnStash, { }; } -function useOwnStashInfosImpl (): StakerState[] | undefined { +function useOwnStashInfosImpl () { const { api } = useApi(); const { allAccounts } = useAccounts(); const mountedRef = useIsMountedRef(); diff --git a/packages/react-hooks/src/useOwnStashes.ts b/packages/react-hooks/src/useOwnStashes.ts index aff06a457e7f..56f2364023b7 100644 --- a/packages/react-hooks/src/useOwnStashes.ts +++ b/packages/react-hooks/src/useOwnStashes.ts @@ -31,7 +31,7 @@ function getStashes (allAccounts: string[], ownBonded: Option[], ownL return result; } -function useOwnStashesImpl (additional?: string[]): [string, IsInKeyring][] | undefined { +function useOwnStashesImpl (additional?: string[]) { const { allAccounts } = useAccounts(); const { api } = useApi(); @@ -55,7 +55,7 @@ function useOwnStashesImpl (additional?: string[]): [string, IsInKeyring][] | un export const useOwnStashes = createNamedHook('useOwnStashes', useOwnStashesImpl); -function useOwnStashIdsImpl (additional?: string[]): string[] | undefined { +function useOwnStashIdsImpl (additional?: string[]) { const ownStashes = useOwnStashes(additional); return useMemo( diff --git a/packages/react-hooks/src/useSystemApi.ts b/packages/react-hooks/src/useSystemApi.ts index 9bd3340fc44a..4757122cf8ea 100644 --- a/packages/react-hooks/src/useSystemApi.ts +++ b/packages/react-hooks/src/useSystemApi.ts @@ -1,14 +1,12 @@ // Copyright 2017-2023 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ApiPromise } from '@polkadot/api'; - import { useMemo } from 'react'; import { createNamedHook } from './createNamedHook.js'; import { useApi } from './useApi.js'; -function useSystemApiImpl (): ApiPromise | undefined { +function useSystemApiImpl () { const { api, apiRelay } = useApi(); return useMemo(() => apiRelay || api, [apiRelay, api]);