diff --git a/eslint.config.js b/eslint.config.js index e5fe790fb8..7112bc6ba2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/dev authors & contributors +// Copyright 2017-2023 @polkadot/apps authors & contributors // SPDX-License-Identifier: Apache-2.0 import baseConfig from '@polkadot/dev/config/eslint'; diff --git a/package.json b/package.json index 4ec5ecd378..0b368fc5e8 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "devDependencies": { "@crustio/crust-pin": "^1.0.0", "@pinata/sdk": "^1.2.1", - "@polkadot/dev": "^0.75.26", + "@polkadot/dev": "^0.76.16", "@types/chart.js": "^2.9.37", "@types/file-saver": "^2.0.5", "@types/react-beautiful-dnd": "^13.1.4", @@ -99,9 +99,9 @@ "@polkadot/api-base": "^10.9.1", "@polkadot/api-contract": "^10.9.1", "@polkadot/api-derive": "^10.9.1", - "@polkadot/hw-ledger": "^12.3.2", - "@polkadot/keyring": "^12.3.2", - "@polkadot/networks": "^12.3.2", + "@polkadot/hw-ledger": "^12.4.1", + "@polkadot/keyring": "^12.4.1", + "@polkadot/networks": "^12.4.1", "@polkadot/phishing": "^0.21.5", "@polkadot/rpc-augment": "^10.9.1", "@polkadot/rpc-core": "^10.9.1", @@ -112,16 +112,16 @@ "@polkadot/types-create": "^10.9.1", "@polkadot/types-known": "^10.9.1", "@polkadot/types-support": "^10.9.1", - "@polkadot/util": "^12.3.2", - "@polkadot/util-crypto": "^12.3.2", - "@polkadot/wasm-crypto": "^7.2.1", - "@polkadot/x-bigint": "^12.3.2", - "@polkadot/x-fetch": "^12.3.2", - "@polkadot/x-global": "^12.3.2", - "@polkadot/x-randomvalues": "^12.3.2", - "@polkadot/x-textdecoder": "^12.3.2", - "@polkadot/x-textencoder": "^12.3.2", - "@polkadot/x-ws": "^12.3.2", + "@polkadot/util": "^12.4.1", + "@polkadot/util-crypto": "^12.4.1", + "@polkadot/wasm-crypto": "^7.2.2", + "@polkadot/x-bigint": "^12.4.1", + "@polkadot/x-fetch": "^12.4.1", + "@polkadot/x-global": "^12.4.1", + "@polkadot/x-randomvalues": "^12.4.1", + "@polkadot/x-textdecoder": "^12.4.1", + "@polkadot/x-textencoder": "^12.4.1", + "@polkadot/x-ws": "^12.4.1", "styled-components": "^5.3.1", "typescript": "^5.1.6" } diff --git a/packages/apps-config/package.json b/packages/apps-config/package.json index 8ed1504d23..846071d961 100644 --- a/packages/apps-config/package.json +++ b/packages/apps-config/package.json @@ -38,14 +38,14 @@ "@phala/typedefs": "0.2.33", "@polkadot/api": "^10.9.1", "@polkadot/api-derive": "^10.9.1", - "@polkadot/networks": "^12.3.2", + "@polkadot/networks": "^12.4.1", "@polkadot/react-identicon": "^3.5.1", "@polkadot/types": "^10.9.1", "@polkadot/types-codec": "^10.9.1", - "@polkadot/util": "^12.3.2", - "@polkadot/wasm-util": "^7.2.1", - "@polkadot/x-fetch": "^12.3.2", - "@polkadot/x-ws": "^12.3.2", + "@polkadot/util": "^12.4.1", + "@polkadot/wasm-util": "^7.2.2", + "@polkadot/x-fetch": "^12.4.1", + "@polkadot/x-ws": "^12.4.1", "@polymeshassociation/polymesh-types": "5.4.1", "@snowfork/snowbridge-types": "0.2.7", "@sora-substrate/type-definitions": "1.17.16", diff --git a/packages/apps-config/src/api/chain/index.ts b/packages/apps-config/src/api/chain/index.ts index 0c8f8053bc..cc2f9b8b17 100644 --- a/packages/apps-config/src/api/chain/index.ts +++ b/packages/apps-config/src/api/chain/index.ts @@ -6,6 +6,10 @@ import type { OverrideBundleDefinition } from '@polkadot/types/types'; import cere from './cere.js'; import kilt from './kilt.js'; +if (!kilt) { + throw new Error('Unable to retrieve kilt'); +} + // NOTE: The mapping is done from chain name in system.chain const chain: Record = { 'Cere Mainnet Beta': cere, diff --git a/packages/apps-config/src/api/chain/kilt.ts b/packages/apps-config/src/api/chain/kilt.ts index 300b667def..15d6bebd92 100644 --- a/packages/apps-config/src/api/chain/kilt.ts +++ b/packages/apps-config/src/api/chain/kilt.ts @@ -1,8 +1,10 @@ // Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { OverrideBundleDefinition } from '@polkadot/types/types'; - import { typesBundle } from '@kiltprotocol/type-definitions'; -export default typesBundle.chain as Record; +if (!typesBundle.chain) { + throw new Error('Unable to find chain defintions'); +} + +export default typesBundle.chain; diff --git a/packages/apps-config/src/api/constants.ts b/packages/apps-config/src/api/constants.ts index e2a741edca..c3091ca453 100644 --- a/packages/apps-config/src/api/constants.ts +++ b/packages/apps-config/src/api/constants.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-accounts authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { HexString } from '@polkadot/util/types'; @@ -9,7 +9,7 @@ import { assert, BN } from '@polkadot/util'; function getGenesis (name: string): HexString { const network = Object.entries(knownGenesis).find(([network]) => network === name); - assert(network && network[1][0], `Unable to find genesisHash for ${name}`); + assert(network?.[1][0], `Unable to find genesisHash for ${name}`); return network[1][0]; } diff --git a/packages/apps-config/src/api/derives.ts b/packages/apps-config/src/api/derives.ts index 17a3c25556..1ed1b8eae4 100644 --- a/packages/apps-config/src/api/derives.ts +++ b/packages/apps-config/src/api/derives.ts @@ -20,7 +20,7 @@ const mapping: [OverrideBundleDefinition, string[]][] = [ export function applyDerives (typesBundle: OverrideBundleType): OverrideBundleType { mapping.forEach(([{ derives }, chains]): void => { chains.forEach((chain): void => { - if (typesBundle.spec && typesBundle.spec[chain]) { + if (typesBundle.spec?.[chain]) { typesBundle.spec[chain].derives = derives; } }); diff --git a/packages/apps-config/src/api/params/inflation.ts b/packages/apps-config/src/api/params/inflation.ts index c184266325..9bcc187bc2 100644 --- a/packages/apps-config/src/api/params/inflation.ts +++ b/packages/apps-config/src/api/params/inflation.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-config authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { ApiPromise } from '@polkadot/api'; diff --git a/packages/apps-config/src/api/params/teleport.ts b/packages/apps-config/src/api/params/teleport.ts index e78df02ab6..d0f87384cb 100644 --- a/packages/apps-config/src/api/params/teleport.ts +++ b/packages/apps-config/src/api/params/teleport.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-config authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { ApiPromise } from '@polkadot/api'; diff --git a/packages/apps-config/src/api/params/tracks/index.ts b/packages/apps-config/src/api/params/tracks/index.ts index bf32da77fa..74ffbd39aa 100644 --- a/packages/apps-config/src/api/params/tracks/index.ts +++ b/packages/apps-config/src/api/params/tracks/index.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-config authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { ApiPromise } from '@polkadot/api'; @@ -31,5 +31,5 @@ const KNOWN_SPEC_TRACKS: Record> = { export function getGovernanceTracks (api: ApiPromise, specName: string, palletReferenda: string): TrackInfo[] | undefined { const lookup = KNOWN_GENE_TRACKS[api.genesisHash.toHex()] || KNOWN_SPEC_TRACKS[specName]; - return lookup && lookup[palletReferenda]; + return lookup?.[palletReferenda]; } diff --git a/packages/apps-config/src/api/params/tracks/kusama.ts b/packages/apps-config/src/api/params/tracks/kusama.ts index 082a037301..4b74a3bc6d 100644 --- a/packages/apps-config/src/api/params/tracks/kusama.ts +++ b/packages/apps-config/src/api/params/tracks/kusama.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-config authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { TrackInfo } from './types.js'; diff --git a/packages/apps-config/src/api/params/tracks/polkadot.ts b/packages/apps-config/src/api/params/tracks/polkadot.ts index 3cc6ef05cf..f6d113162f 100644 --- a/packages/apps-config/src/api/params/tracks/polkadot.ts +++ b/packages/apps-config/src/api/params/tracks/polkadot.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-config authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { TrackInfo } from './types.js'; diff --git a/packages/apps-config/src/api/params/tracks/types.ts b/packages/apps-config/src/api/params/tracks/types.ts index 88f51321b9..b35941a9cc 100644 --- a/packages/apps-config/src/api/params/tracks/types.ts +++ b/packages/apps-config/src/api/params/tracks/types.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-config authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { BN } from '@polkadot/util'; diff --git a/packages/apps-config/src/api/params/tracks/util.ts b/packages/apps-config/src/api/params/tracks/util.ts index 140e9339a3..03557cac0a 100644 --- a/packages/apps-config/src/api/params/tracks/util.ts +++ b/packages/apps-config/src/api/params/tracks/util.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-config authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { BN } from '@polkadot/util'; diff --git a/packages/apps-config/src/ci/fetch.ts b/packages/apps-config/src/ci/fetch.ts index bce2d80f97..bb8e6dcfc8 100644 --- a/packages/apps-config/src/ci/fetch.ts +++ b/packages/apps-config/src/ci/fetch.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/apps authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import { fetch } from '@polkadot/x-fetch'; @@ -37,9 +37,9 @@ function fetchWithTimeout (url: string, timeout = 2_000): Promise (url: string, timeout?: number): Promise { - return fetchWithTimeout(url, timeout).then((r) => r && r.json()); + return fetchWithTimeout(url, timeout).then((r) => r?.json() || null); } export function fetchText (url: string, timeout?: number): Promise { - return fetchWithTimeout(url, timeout).then((r) => r && r.text()); + return fetchWithTimeout(url, timeout).then((r) => r?.text() || null); } diff --git a/packages/apps-config/src/endpoints/index.spec.ts b/packages/apps-config/src/endpoints/index.spec.ts index 0660c979cd..ba68cd9783 100644 --- a/packages/apps-config/src/endpoints/index.spec.ts +++ b/packages/apps-config/src/endpoints/index.spec.ts @@ -54,21 +54,23 @@ describe('urls are sorted', (): void => { lastHeader = text as string; } else { it(`${lastHeader}:: ${text as string}:: ${textBy}`, (): void => { + const item = filtered[index - 1]; + assert(( - filtered[index - 1].isHeader || - filtered[index - 1].linked || + item.isHeader || + item.linked || ( - isNumber(filtered[index - 1].paraId) && + isNumber(item.paraId) && ( - (filtered[index - 1].paraId as number) < 2000 + item.paraId < 2000 ? isNumber(paraId) && paraId >= 2000 : false ) ) || - filtered[index - 1].text === '' || - text === filtered[index - 1].text || - (text as string).localeCompare(filtered[index - 1].text as string) === 1 - ), `${lastHeader}:: ${text as string} needs to be before ${filtered[index - 1].text as string}`); + item.text === '' || + text === item.text || + (text as string).localeCompare(item.text as string) === 1 + ), `${lastHeader}:: ${text as string} needs to be before ${item.text as string}`); }); } }); diff --git a/packages/apps-config/src/settings/ss58.ts b/packages/apps-config/src/settings/ss58.ts index 0fd3aacba8..2b17d331c1 100644 --- a/packages/apps-config/src/settings/ss58.ts +++ b/packages/apps-config/src/settings/ss58.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/ui-settings authors & contributors +// Copyright 2017-2023 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { TFunction } from '../types.js'; diff --git a/packages/apps-electron/package.json b/packages/apps-electron/package.json index c4404731dc..65406e5b7b 100644 --- a/packages/apps-electron/package.json +++ b/packages/apps-electron/package.json @@ -22,7 +22,7 @@ "electron-updater": "^5.3.0" }, "devDependencies": { - "@polkadot/dev": "^0.75.26", + "@polkadot/dev": "^0.76.16", "@types/tmp": "^0.2.3", "copy-webpack-plugin": "^11.0.0", "electron": "25.0.1", diff --git a/packages/apps-electron/src/main/ipc-main-handler.ts b/packages/apps-electron/src/main/ipc-main-handler.ts index 38193ab4e4..2b875715b0 100644 --- a/packages/apps-electron/src/main/ipc-main-handler.ts +++ b/packages/apps-electron/src/main/ipc-main-handler.ts @@ -1,6 +1,4 @@ // Copyright 2017-2023 @polkadot/apps authors & contributors // SPDX-License-Identifier: Apache-2.0 -export type IpcMainHandler = { - [channel: string]: (...args: any[]) => unknown -} +export type IpcMainHandler = Record unknown>; diff --git a/packages/apps/package.json b/packages/apps/package.json index a9d2963dba..f6b4aeba7f 100644 --- a/packages/apps/package.json +++ b/packages/apps/package.json @@ -18,7 +18,7 @@ "dependencies": { "@polkadot/apps-config": "^0.132.2-55-x", "@polkadot/apps-routing": "^0.132.2-55-x", - "@polkadot/dev": "^0.75.26", + "@polkadot/dev": "^0.76.16", "@polkadot/react-api": "^0.132.2-55-x", "@polkadot/react-components": "^0.132.2-55-x", "@polkadot/react-hooks": "^0.132.2-55-x", diff --git a/packages/page-accounts/package.json b/packages/page-accounts/package.json index f6244a68ca..13ea569656 100644 --- a/packages/page-accounts/package.json +++ b/packages/page-accounts/package.json @@ -16,11 +16,11 @@ "type": "module", "version": "0.132.2-55-x", "dependencies": { - "@polkadot/hw-ledger": "^12.3.2", + "@polkadot/hw-ledger": "^12.4.1", "@polkadot/phishing": "^0.21.5", "@polkadot/react-components": "^0.132.2-55-x", "@polkadot/react-hooks": "^0.132.2-55-x", - "@polkadot/util": "^12.3.2", + "@polkadot/util": "^12.4.1", "@polkadot/vanitygen": "^0.55.3", "detect-browser": "^5.3.0", "file-saver": "^2.0.5" diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index 59fea3275a..9ed4c856eb 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -139,7 +139,7 @@ function createClearReferendaTx (api: ApiPromise, address: string, ids: [BN, BN] async function showLedgerAddress (getLedger: () => Ledger, meta: KeyringJson$Meta): Promise { const ledger = getLedger(); - await ledger.getAddress(true, meta.accountOffset as number || 0, meta.addressOffset as number || 0); + await ledger.getAddress(true, meta.accountOffset || 0, meta.addressOffset || 0); } const transformRecovery = { @@ -405,7 +405,7 @@ function Account ({ account: { address, meta }, className = '', delegation, filt isFunction(api.api.tx.multisig?.asMulti) && isMultisig && createMenuGroup('multisigGroup', [ @@ -549,8 +549,8 @@ function Account ({ account: { address, meta }, className = '', delegation, filt key='multisig-approve' onClose={toggleMultisig} ongoing={multiInfos} - threshold={meta.threshold as number} - who={meta.who as string[]} + threshold={meta.threshold} + who={meta.who} /> )} {isRecoverAccountOpen && ( diff --git a/packages/page-accounts/src/Accounts/index.spec.ts b/packages/page-accounts/src/Accounts/index.spec.ts index 2b1ee837ab..33a504e1ad 100644 --- a/packages/page-accounts/src/Accounts/index.spec.ts +++ b/packages/page-accounts/src/Accounts/index.spec.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/page-accounts authors & contributors +// Copyright 2017-2023 @polkadot/app-accounts authors & contributors // SPDX-License-Identifier: Apache-2.0 /// diff --git a/packages/page-accounts/src/Accounts/index.tsx b/packages/page-accounts/src/Accounts/index.tsx index d08b8e226f..e9a5635fce 100644 --- a/packages/page-accounts/src/Accounts/index.tsx +++ b/packages/page-accounts/src/Accounts/index.tsx @@ -63,7 +63,7 @@ function groupAccounts (accounts: SortedAccount[]): Record testing: [] }; - for (let i = 0; i < accounts.length; i++) { + for (let i = 0, count = accounts.length; i < count; i++) { const { account, address } = accounts[i]; const cryptoType = getAccountCryptoType(address); diff --git a/packages/page-accounts/src/Accounts/useProxies.ts b/packages/page-accounts/src/Accounts/useProxies.ts index 1294eda8ff..0eb0a83f02 100644 --- a/packages/page-accounts/src/Accounts/useProxies.ts +++ b/packages/page-accounts/src/Accounts/useProxies.ts @@ -45,9 +45,9 @@ function useProxiesImpl (address?: string | null): State | null { useEffect((): void => { setState(null); - address && api.query.proxy && + address && api.query.proxy - .proxies | PalletProxyProxyDefinition>, BalanceOf]>>(address) + ?.proxies | PalletProxyProxyDefinition>, BalanceOf]>>(address) .then(([_proxies]): void => { const proxies = api.tx.proxy.addProxy.meta.args.length === 3 ? (_proxies as PalletProxyProxyDefinition[]).map(({ delay, delegate, proxyType }) => diff --git a/packages/page-accounts/src/modals/Create.spec.tsx b/packages/page-accounts/src/modals/Create.spec.tsx index 5ffe4dd2a0..5bed21af6d 100644 --- a/packages/page-accounts/src/modals/Create.spec.tsx +++ b/packages/page-accounts/src/modals/Create.spec.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/page-accounts authors & contributors +// Copyright 2017-2023 @polkadot/app-accounts authors & contributors // SPDX-License-Identifier: Apache-2.0 /// diff --git a/packages/page-accounts/src/modals/CreateConfirmation.tsx b/packages/page-accounts/src/modals/CreateConfirmation.tsx index 1744b92db6..40e4d99b62 100644 --- a/packages/page-accounts/src/modals/CreateConfirmation.tsx +++ b/packages/page-accounts/src/modals/CreateConfirmation.tsx @@ -22,10 +22,10 @@ interface Props { function CreateConfirmation ({ address, derivePath, name, pairType, seed }: Props): React.ReactElement | null { const { t } = useTranslation(); - const splitSeed = seed && seed.split(' '); + const splitSeed = seed?.split(' '); const shortSeed = isHex(seed) ? `${seed.slice(10)} … ${seed.slice(-8)}` - : splitSeed && splitSeed.map((value, index) => (index % 3) ? '…' : value).join(' '); + : splitSeed?.map((value, index) => (index % 3) ? '…' : value).join(' '); return ( diff --git a/packages/page-accounts/src/modals/CreateSuriLedger.tsx b/packages/page-accounts/src/modals/CreateSuriLedger.tsx index 34b1277fb9..5f3e31df13 100644 --- a/packages/page-accounts/src/modals/CreateSuriLedger.tsx +++ b/packages/page-accounts/src/modals/CreateSuriLedger.tsx @@ -41,7 +41,7 @@ function CreateSuriLedger ({ className, onChange, seedType }: Props): React.Reac useEffect((): void => { const network = ledgerNets.find(({ network }) => network === chainType); - onChange(`m/44'/${network?.slip44 as number}'/${accIndex}'/0'/${addIndex}'`); + onChange(`m/44'/${network?.slip44}'/${accIndex}'/0'/${addIndex}'`); }, [accIndex, addIndex, chainType, onChange]); return ( diff --git a/packages/page-accounts/src/modals/IdentitySub.tsx b/packages/page-accounts/src/modals/IdentitySub.tsx index 75e506538e..f9e1829f62 100644 --- a/packages/page-accounts/src/modals/IdentitySub.tsx +++ b/packages/page-accounts/src/modals/IdentitySub.tsx @@ -98,12 +98,12 @@ function IdentitySubModal ({ address, className, onClose }: Props): React.ReactE }, [allAccounts, queryIds, queryInfos]); const _rowAdd = useCallback( - () => setInfos((infos) => infos && infos.concat([[allAccounts[0], '']])), + () => setInfos((infos) => infos?.concat([[allAccounts[0], '']])), [allAccounts] ); const _rowRemove = useCallback( - () => setInfos((infos) => infos && infos.slice(0, infos.length - 1)), + () => setInfos((infos) => infos?.slice(0, infos.length - 1)), [] ); diff --git a/packages/page-accounts/src/modals/Import.tsx b/packages/page-accounts/src/modals/Import.tsx index 31350e39cb..991c0a99c6 100644 --- a/packages/page-accounts/src/modals/Import.tsx +++ b/packages/page-accounts/src/modals/Import.tsx @@ -116,7 +116,7 @@ function Import ({ className = '', onClose, onStatusChange }: Props): React.Reac diff --git a/packages/page-accounts/src/modals/MultisigApprove.tsx b/packages/page-accounts/src/modals/MultisigApprove.tsx index acc8f97965..bbef930e67 100644 --- a/packages/page-accounts/src/modals/MultisigApprove.tsx +++ b/packages/page-accounts/src/modals/MultisigApprove.tsx @@ -19,8 +19,8 @@ interface Props { className?: string; onClose: () => void; ongoing: [H256, Multisig][]; - threshold: number; - who: string[]; + threshold?: number; + who?: string[]; } interface MultiInfo { @@ -45,7 +45,7 @@ const EMPTY_CALL: CallData = { callInfo: null }; -function MultisigApprove ({ className = '', onClose, ongoing, threshold, who }: Props): React.ReactElement { +function MultisigApprove ({ className = '', onClose, ongoing, threshold = 0, who = [] }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const { allAccounts } = useAccounts(); diff --git a/packages/page-accounts/src/modals/PasswordInput.tsx b/packages/page-accounts/src/modals/PasswordInput.tsx index 309c56f17a..cbf934d9f0 100644 --- a/packages/page-accounts/src/modals/PasswordInput.tsx +++ b/packages/page-accounts/src/modals/PasswordInput.tsx @@ -8,7 +8,7 @@ import { keyring } from '@polkadot/ui-keyring'; import { useTranslation } from '../translate.js'; -type Props = { +interface Props { onChange: (password: string, isPasswordValid: boolean) => void; onEnter: () => void; } diff --git a/packages/page-accounts/test/pageElements/AccountRow.tsx b/packages/page-accounts/test/pageElements/AccountRow.tsx index 55cf0cedc1..955b633e54 100644 --- a/packages/page-accounts/test/pageElements/AccountRow.tsx +++ b/packages/page-accounts/test/pageElements/AccountRow.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/page-accounts authors & contributors +// Copyright 2017-2023 @polkadot/app-accounts authors & contributors // SPDX-License-Identifier: Apache-2.0 /* global expect */ diff --git a/packages/page-accounts/test/pages/accountsPage.tsx b/packages/page-accounts/test/pages/accountsPage.tsx index 23c14132ec..aba2438829 100644 --- a/packages/page-accounts/test/pages/accountsPage.tsx +++ b/packages/page-accounts/test/pages/accountsPage.tsx @@ -1,8 +1,6 @@ -// Copyright 2017-2023 @polkadot/page-accounts authors & contributors +// Copyright 2017-2023 @polkadot/app-accounts authors & contributors // SPDX-License-Identifier: Apache-2.0 -/* global expect */ - import type { Sidebar } from '@polkadot/test-support/pagesElements'; import type { AccountOverrides } from '@polkadot/test-support/types'; @@ -98,9 +96,11 @@ export class AccountsPage extends Page { const availableCategories = await within(sortByComponent).findAllByRole('option'); const selectedCategory = availableCategories.find((category) => category.textContent === categoryName); - expect(selectedCategory).not.toBeUndefined(); + if (!selectedCategory) { + throw new Error('No category found'); + } - return selectedCategory as HTMLElement; + return selectedCategory; } private async getSortByComponent (): Promise { diff --git a/packages/page-addresses/src/Contacts/Address.tsx b/packages/page-addresses/src/Contacts/Address.tsx index 8104b48548..485dab58e4 100644 --- a/packages/page-addresses/src/Contacts/Address.tsx +++ b/packages/page-addresses/src/Contacts/Address.tsx @@ -70,7 +70,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite const current = keyring.getAddress(address); setCurrent(current || null); - setGenesisHash((current && current.meta.genesisHash) || null); + setGenesisHash((current?.meta.genesisHash) || null); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -89,7 +89,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite useEffect((): void => { const account = keyring.getAddress(address); - _setTags(account?.meta?.tags as string[] || []); + _setTags(account?.meta?.tags || []); setAccName(account?.meta?.name || ''); }, [_setTags, address]); diff --git a/packages/page-addresses/src/Contacts/index.spec.ts b/packages/page-addresses/src/Contacts/index.spec.ts index df338a607b..68ef039c3f 100644 --- a/packages/page-addresses/src/Contacts/index.spec.ts +++ b/packages/page-addresses/src/Contacts/index.spec.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/page-addresses authors & contributors +// Copyright 2017-2023 @polkadot/app-addresses authors & contributors // SPDX-License-Identifier: Apache-2.0 /// diff --git a/packages/page-addresses/src/Contacts/index.tsx b/packages/page-addresses/src/Contacts/index.tsx index 38e4f9d261..c8a86df7fd 100644 --- a/packages/page-addresses/src/Contacts/index.tsx +++ b/packages/page-addresses/src/Contacts/index.tsx @@ -12,7 +12,7 @@ import CreateModal from '../modals/Create.js'; import { useTranslation } from '../translate.js'; import Address from './Address.js'; -type SortedAddress = { address: string; isFavorite: boolean }; +interface SortedAddress { address: string; isFavorite: boolean } interface Props { className?: string; diff --git a/packages/page-addresses/test/pages/addressesPage.tsx b/packages/page-addresses/test/pages/addressesPage.tsx index 27df23d3fe..704961baed 100644 --- a/packages/page-addresses/test/pages/addressesPage.tsx +++ b/packages/page-addresses/test/pages/addressesPage.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/page-addresses authors & contributors +// Copyright 2017-2023 @polkadot/app-addresses authors & contributors // SPDX-License-Identifier: Apache-2.0 /* global jest */ diff --git a/packages/page-alliance/src/Announcements/index.tsx b/packages/page-alliance/src/Announcements/index.tsx index dedfe5ceac..62162bdeb7 100644 --- a/packages/page-alliance/src/Announcements/index.tsx +++ b/packages/page-alliance/src/Announcements/index.tsx @@ -31,7 +31,7 @@ function Announcements ({ accouncements, className }: Props): React.ReactElement empty={accouncements && t('No annoucements')} header={annRef.current} > - {accouncements && accouncements.map((a) => ( + {accouncements?.map((a) => (
- {(info && info.isRetiringAt && ( + {(info?.isRetiringAt && ( - )) || (info && info.isUpForKicking && ( + )) || (info?.isUpForKicking && ( {hasNotice && ( diff --git a/packages/page-alliance/src/Members/Summary.tsx b/packages/page-alliance/src/Members/Summary.tsx index 65ef3e0590..f3e56da6b9 100644 --- a/packages/page-alliance/src/Members/Summary.tsx +++ b/packages/page-alliance/src/Members/Summary.tsx @@ -19,7 +19,7 @@ interface Props { function Summary ({ className, members, rule }: Props): React.ReactElement { const { t } = useTranslation(); - const ipfsLink = useIpfsLink(rule && rule.cid && rule.cid.ipfs); + const ipfsLink = useIpfsLink(rule?.cid?.ipfs); return ( diff --git a/packages/page-alliance/src/Members/index.tsx b/packages/page-alliance/src/Members/index.tsx index 20a1091d70..1bffb553ef 100644 --- a/packages/page-alliance/src/Members/index.tsx +++ b/packages/page-alliance/src/Members/index.tsx @@ -59,7 +59,7 @@ function Overview ({ className, members, prime, rule, unscrupulous, voters }: Pr isSplit maxColumns={2} > - {members && members.map((m) => ( + {members?.map((m) => ( - {unscrupulous && unscrupulous.accounts.map((m) => ( + {unscrupulous?.accounts.map((m) => (
- {unscrupulous && unscrupulous.websites.map((m) => ( + {unscrupulous?.websites.map((m) => ( }, { name: 'motions', - text: t('Motions ({{count}})', { replace: { count: (proposalHashes && proposalHashes.length) || 0 } }) + text: t('Motions ({{count}})', { replace: { count: proposalHashes?.length || 0 } }) }, { name: 'announcements', - text: t('Announcements ({{count}})', { replace: { count: (accouncements && accouncements.length) || 0 } }) + text: t('Announcements ({{count}})', { replace: { count: accouncements?.length || 0 } }) }, { name: 'unscrupulous', diff --git a/packages/page-alliance/src/useCounter.ts b/packages/page-alliance/src/useCounter.ts index 86b4d9abc1..ae20908767 100644 --- a/packages/page-alliance/src/useCounter.ts +++ b/packages/page-alliance/src/useCounter.ts @@ -10,7 +10,7 @@ function useCounterImpl (): number { const proposalHashes = useCall(isApiReady && api.derive.alliance.proposalHashes); return useMemo( - () => (proposalHashes && proposalHashes.length) || 0, + () => proposalHashes?.length || 0, [proposalHashes] ); } diff --git a/packages/page-alliance/src/useMemberInfo.ts b/packages/page-alliance/src/useMemberInfo.ts index 07a7b5bb94..793c8bc480 100644 --- a/packages/page-alliance/src/useMemberInfo.ts +++ b/packages/page-alliance/src/useMemberInfo.ts @@ -19,7 +19,7 @@ function useMemberInfoImpl (accountId: string): MemberInfo | undefined { accountId, deposit: depositOf.unwrapOr(null), isUpForKicking: upForKicking && upForKicking.isTrue, - retiringAt: retiringAt && retiringAt.unwrapOr(null) + retiringAt: retiringAt?.unwrapOr(null) }, [accountId, depositOf, retiringAt, upForKicking] ); diff --git a/packages/page-alliance/src/useMembers.ts b/packages/page-alliance/src/useMembers.ts index 446ce29541..9c488287a0 100644 --- a/packages/page-alliance/src/useMembers.ts +++ b/packages/page-alliance/src/useMembers.ts @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react'; import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; -const ROLES = ['Retiring', 'Ally', 'Fellow']; +const ROLES = ['Retiring', 'Ally', 'Fellow'] as const; function addMembers (prev: Member[], ...query: AccountId32[][]): Member[] { const all: Member[] = []; @@ -17,7 +17,7 @@ function addMembers (prev: Member[], ...query: AccountId32[][]): Member[] { const role = ROLES[i]; const accountIds = query[i]; - for (let j = 0; j < accountIds.length; j++) { + for (let j = 0, count = accountIds.length; j < count; j++) { const accountId = accountIds[j].toString(); const existing = prev.find((p) => p.accountId === accountId && diff --git a/packages/page-assets/src/index.tsx b/packages/page-assets/src/index.tsx index 4fe14f200a..6f589edfed 100644 --- a/packages/page-assets/src/index.tsx +++ b/packages/page-assets/src/index.tsx @@ -25,7 +25,7 @@ interface Props { } function findOpenId (ids?: BN[]): BN { - if (!ids || !ids.length) { + if (!ids?.length) { return BN_ONE; } diff --git a/packages/page-bounties/src/Bounties.tsx b/packages/page-bounties/src/Bounties.tsx index 956bb008b2..1b257dc1c9 100644 --- a/packages/page-bounties/src/Bounties.tsx +++ b/packages/page-bounties/src/Bounties.tsx @@ -1,8 +1,6 @@ // Copyright 2017-2023 @polkadot/app-bounties authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BN } from '@polkadot/util'; - import React, { useMemo, useRef } from 'react'; import { Button, styled, Table } from '@polkadot/react-components'; @@ -22,7 +20,7 @@ function Bounties ({ className }: Props): React.ReactElement { const info = useBounties(); const sorted = useMemo( - () => info && info.bounties && [...info.bounties].sort((a, b) => b.index.cmp(a.index)), + () => info?.bounties && [...info.bounties].sort((a, b) => b.index.cmp(a.index)), [info] ); @@ -32,6 +30,7 @@ function Bounties ({ className }: Props): React.ReactElement { [t('curator'), 'start'], [t('next action'), 'start', 3] ]); + const bestNumber = info.bestNumber; return ( @@ -44,9 +43,9 @@ function Bounties ({ className }: Props): React.ReactElement { empty={sorted && t('No open bounties')} header={headerRef.current} > - {sorted && info.bestNumber && sorted.map(({ bounty, description, index, proposals }) => ( + {sorted && bestNumber && sorted.map(({ bounty, description, index, proposals }) => ( proposal && proposal.method); + const methods = bountyProposals.map(({ proposal }) => proposal?.method); return validMethods(status).find((method) => methods.includes(method)); } diff --git a/packages/page-bounties/src/hooks/useUserRole.ts b/packages/page-bounties/src/hooks/useUserRole.ts index bb9b21cd06..52f8179488 100644 --- a/packages/page-bounties/src/hooks/useUserRole.ts +++ b/packages/page-bounties/src/hooks/useUserRole.ts @@ -8,7 +8,7 @@ import { useMemo } from 'react'; import { createNamedHook, useAccounts, useCollectiveMembers } from '@polkadot/react-hooks'; -export type UserRolesInfo = { roles: UserRole[], isCurator: boolean }; +export interface UserRolesInfo { roles: UserRole[], isCurator: boolean } function useUserRoleImpl (curatorId?: AccountId): UserRolesInfo { const { allAccounts, hasAccounts } = useAccounts(); diff --git a/packages/page-bounties/src/theme.ts b/packages/page-bounties/src/theme.ts index 6376a7e871..9b834820ec 100644 --- a/packages/page-bounties/src/theme.ts +++ b/packages/page-bounties/src/theme.ts @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/app-bounties authors & contributors // SPDX-License-Identifier: Apache-2.0 -type bountyTheme = { +interface bountyTheme { dark: string; light: string; } diff --git a/packages/page-claims/src/index.tsx b/packages/page-claims/src/index.tsx index 803842f392..4839798c2a 100644 --- a/packages/page-claims/src/index.tsx +++ b/packages/page-claims/src/index.tsx @@ -85,7 +85,7 @@ function ClaimsApp ({ basePath }: Props): React.ReactElement { // - an `EthereumAddress` when there's a preclaim // - null if no preclaim // - `PRECLAIMS_LOADING` if we're fetching the results - const [preclaimEthereumAddress, setPreclaimEthereumAddress] = useState(PRECLAIMS_LOADING); + const [preclaimEthereumAddress, setPreclaimEthereumAddress] = useState(PRECLAIMS_LOADING); const isPreclaimed = !!preclaimEthereumAddress && preclaimEthereumAddress !== PRECLAIMS_LOADING; const itemsRef = useRef([{ diff --git a/packages/page-collator/src/Collators.tsx b/packages/page-collator/src/Collators.tsx index 85d2e4d762..6068369e0a 100644 --- a/packages/page-collator/src/Collators.tsx +++ b/packages/page-collator/src/Collators.tsx @@ -34,7 +34,7 @@ function Collators ({ className }: Props): React.ReactElement { empty={collators && t('No running collators')} header={hdrRef.current} > - {collators && collators.map((c) => ( + {collators?.map((c) => ( (); const accountIds = useMemo( - () => state && state.map(({ accountId }) => accountId), + () => state?.map(({ accountId }) => accountId), [state] ); diff --git a/packages/page-contracts/src/Contracts/Deploy.tsx b/packages/page-contracts/src/Contracts/Deploy.tsx index 5652dfaf06..b024dc0a68 100644 --- a/packages/page-contracts/src/Contracts/Deploy.tsx +++ b/packages/page-contracts/src/Contracts/Deploy.tsx @@ -48,8 +48,8 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex [codeHash] ); - const [name, isNameValid, setName] = useNonEmptyString(code && code.json.name); - const { contractAbi, errorText, isAbiError, isAbiSupplied, isAbiValid, onChangeAbi, onRemoveAbi } = useAbi([code && code.json.abi, code && code.contractAbi], codeHash, true); + const [name, isNameValid, setName] = useNonEmptyString(code?.json.name); + const { contractAbi, errorText, isAbiError, isAbiSupplied, isAbiValid, onChangeAbi, onRemoveAbi } = useAbi([code?.json.abi, code?.contractAbi], codeHash, true); const blueprint = useMemo( () => isAbiValid && codeHash && contractAbi diff --git a/packages/page-contracts/src/Contracts/index.tsx b/packages/page-contracts/src/Contracts/index.tsx index b7c9c27f6b..5166a61a76 100644 --- a/packages/page-contracts/src/Contracts/index.tsx +++ b/packages/page-contracts/src/Contracts/index.tsx @@ -34,7 +34,7 @@ function Contracts ({ className = '' }: Props): React.ReactElement { const _onShowDeploy = useCallback( (codeHash: string, constructorIndex: number): void => { - setCodeHash(codeHash || (allCodes && allCodes[0] ? allCodes[0].json.codeHash : undefined)); + setCodeHash(codeHash || allCodes?.[0]?.json.codeHash || undefined); setConstructorIndex(constructorIndex); toggleDeploy(); }, diff --git a/packages/page-contracts/src/Contracts/util.tsx b/packages/page-contracts/src/Contracts/util.tsx index c5b25121d8..a4404b5d36 100644 --- a/packages/page-contracts/src/Contracts/util.tsx +++ b/packages/page-contracts/src/Contracts/util.tsx @@ -13,13 +13,11 @@ import { getContractAbi } from '@polkadot/react-components/util'; import MessageSignature from '../shared/MessageSignature.js'; export function findCallMethod (callContract: ContractPromise | null, callMethodIndex = 0): AbiMessage | null { - const message = callContract && callContract.abi.messages[callMethodIndex]; - - return message || null; + return callContract?.abi.messages[callMethodIndex] || null; } export function getContractMethodFn (callContract: ContractPromise | null, callMethodIndex: number | null): AbiMessage | null { - const fn = callContract && callContract.abi && callMethodIndex !== null && callContract.abi.messages[callMethodIndex]; + const fn = callMethodIndex !== null && callContract?.abi?.messages[callMethodIndex]; return fn || null; } @@ -37,13 +35,11 @@ export function getContractForAddress (api: ApiPromise, address: string | null): } export function getCallMessageOptions (callContract: ContractPromise | null): DropdownItemProps[] { - return callContract - ? callContract.abi.messages.map((m, index) => ({ - key: m.identifier, - text: ( - - ), - value: index - })) - : []; + return callContract?.abi.messages.map((m, index) => ({ + key: m.identifier, + text: ( + + ), + value: index + })) || []; } diff --git a/packages/page-contracts/src/shared/Message.tsx b/packages/page-contracts/src/shared/Message.tsx index 3069315184..524ec28cf3 100644 --- a/packages/page-contracts/src/shared/Message.tsx +++ b/packages/page-contracts/src/shared/Message.tsx @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { AbiConstructor, AbiMessage, ContractCallOutcome } from '@polkadot/api-contract/types'; +import type { AbiConstructor, ContractCallOutcome } from '@polkadot/api-contract/types'; import React, { useCallback } from 'react'; @@ -15,7 +15,7 @@ export interface Props { className?: string; index: number; lastResult?: ContractCallOutcome; - message: AbiConstructor | AbiMessage; + message: AbiConstructor; onSelect?: (index: number) => void; } diff --git a/packages/page-contracts/src/shared/MessageSignature.tsx b/packages/page-contracts/src/shared/MessageSignature.tsx index 14a8b37229..8b3d32504f 100644 --- a/packages/page-contracts/src/shared/MessageSignature.tsx +++ b/packages/page-contracts/src/shared/MessageSignature.tsx @@ -40,7 +40,7 @@ function MessageSignature ({ className, message: { args, isConstructor, isMutati {name}: {' '} - {params && params[index] + {params?.[index] ? {truncate((params as string[])[index].toString())} : encodeTypeDef(api.registry, type) } diff --git a/packages/page-council/src/Motions/Slashing.tsx b/packages/page-council/src/Motions/Slashing.tsx index 18e2666db4..731a74d2da 100644 --- a/packages/page-council/src/Motions/Slashing.tsx +++ b/packages/page-council/src/Motions/Slashing.tsx @@ -53,7 +53,7 @@ function Slashing ({ className = '', isMember, members }: Props): React.ReactEle ); useEffect((): void => { - const actioned = selectedEra && slashes && slashes.find(([era]) => era.eqn(selectedEra)); + const actioned = selectedEra && slashes?.find(([era]) => era.eqn(selectedEra)); const proposal = actioned ? api.tx.staking.cancelDeferredSlash(actioned[0], actioned[1].map((_, index) => index)) : null; diff --git a/packages/page-council/src/Motions/Voters.tsx b/packages/page-council/src/Motions/Voters.tsx index 89b4fc2aeb..8bcfba2984 100644 --- a/packages/page-council/src/Motions/Voters.tsx +++ b/packages/page-council/src/Motions/Voters.tsx @@ -34,7 +34,7 @@ function Voters ({ isAye, members, threshold, votes }: Props): React.ReactElemen ); const renderVotes = useCallback( - () => votes && votes.map((address): React.ReactNode => ( + () => votes?.map((address): React.ReactNode => ( )} - {electionsInfo && electionsInfo.voteCount && ( + {electionsInfo?.voteCount && (
#{formatNumber(electionsInfo.voteCount)} diff --git a/packages/page-council/src/Overview/Voters.tsx b/packages/page-council/src/Overview/Voters.tsx index a4bc17dee3..0a467855c2 100644 --- a/packages/page-council/src/Overview/Voters.tsx +++ b/packages/page-council/src/Overview/Voters.tsx @@ -15,7 +15,7 @@ interface Props { function Voters ({ balance, voters }: Props): React.ReactElement { const renderVoters = useCallback( - () => voters && voters.map((who): React.ReactNode => + () => voters?.map((who): React.ReactNode => (); useEffect((): void => { - const encodedProposal = (proposal as SubmittableExtrinsic)?.method.toHex() || ''; + const encodedProposal = proposal?.method.toHex() || ''; const storageFee = api.consts.democracy.preimageByteDeposit ? (api.consts.democracy.preimageByteDeposit as unknown as BN).mul( encodedProposal diff --git a/packages/page-explorer/src/BlockInfo/ByHash.tsx b/packages/page-explorer/src/BlockInfo/ByHash.tsx index 04af4687d5..01dd65ac9e 100644 --- a/packages/page-explorer/src/BlockInfo/ByHash.tsx +++ b/packages/page-explorer/src/BlockInfo/ByHash.tsx @@ -37,7 +37,7 @@ const EMPTY_HEADER: [React.ReactNode?, string?, number?][] = [['...', 'start', 6 function transformResult ([[runtimeVersion, events], getBlock, getHeader]: [[RuntimeVersionPartial, EventRecord[] | null], SignedBlock, HeaderExtended?]): State { return { - events: events && events.map((record, index) => ({ + events: events?.map((record, index) => ({ indexes: [index], key: `${Date.now()}-${index}-${record.hash.toHex()}`, record @@ -69,7 +69,7 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme }, [error]); const systemEvents = useMemo( - () => events && events.filter(({ record: { phase } }) => !phase.isApplyExtrinsic), + () => events?.filter(({ record: { phase } }) => !phase.isApplyExtrinsic), [events] ); diff --git a/packages/page-explorer/src/BlockInfo/Extrinsic.tsx b/packages/page-explorer/src/BlockInfo/Extrinsic.tsx index 4b2bf4b3a9..06b4c4f5dc 100644 --- a/packages/page-explorer/src/BlockInfo/Extrinsic.tsx +++ b/packages/page-explorer/src/BlockInfo/Extrinsic.tsx @@ -57,7 +57,7 @@ function filterEvents (index: number, events?: KeyedEvent[] | null, maxBlockWeig return [ dispatchInfo, - weight && weight.v1Weight, + weight?.v1Weight, weight && maxBlockWeight ? weight.v1Weight.mul(BN_TEN_THOUSAND).div(maxBlockWeight).toNumber() / 100 : 0, diff --git a/packages/page-explorer/src/BlockInfo/Extrinsics.tsx b/packages/page-explorer/src/BlockInfo/Extrinsics.tsx index 86a75e389f..d49a26b9bc 100644 --- a/packages/page-explorer/src/BlockInfo/Extrinsics.tsx +++ b/packages/page-explorer/src/BlockInfo/Extrinsics.tsx @@ -42,7 +42,7 @@ function Extrinsics ({ blockNumber, className = '', events, label, maxBlockWeigh header={header} isFixed > - {value && value.map((extrinsic, index): React.ReactNode => + {value?.map((extrinsic, index): React.ReactNode => ) - : events && events.map((e) => renederEvent(eventClassName, e)) + : events?.map((e) => renederEvent(eventClassName, e)) }
); diff --git a/packages/page-explorer/src/Latency/index.tsx b/packages/page-explorer/src/Latency/index.tsx index 05b5b988e1..5fb7d1f5de 100644 --- a/packages/page-explorer/src/Latency/index.tsx +++ b/packages/page-explorer/src/Latency/index.tsx @@ -55,7 +55,7 @@ function getPoints (details: Detail[], timeAvg: number): ChartInfo { const txTotal = details.reduce((a, { extrinsics: { count } }) => a + count, 0); const blockTotal = details.reduce((a, { block: { bytes } }) => a + bytes, 0); - for (let i = 0; i < details.length; i++) { + for (let i = 0, count = details.length; i < count; i++) { const blockNumber = formatNumber(details[i].block.number); blocks.labels.push(blockNumber); @@ -75,7 +75,7 @@ function getPoints (details: Detail[], timeAvg: number): ChartInfo { const filtered = details.filter(({ delay }) => delay); const avgBase = timeAvg * filtered.length; - for (let i = 0; i < filtered.length; i++) { + for (let i = 0, count = filtered.length; i < count; i++) { times.labels.push(formatNumber(filtered[i].block.number)); times.values[0].push(filtered[i].delay / 1000); times.values[1].push(avgBase / filtered.length / 1000); diff --git a/packages/page-explorer/src/NodeInfo/Peers.tsx b/packages/page-explorer/src/NodeInfo/Peers.tsx index 183fd329e6..1a342f8743 100644 --- a/packages/page-explorer/src/NodeInfo/Peers.tsx +++ b/packages/page-explorer/src/NodeInfo/Peers.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-nodeinfo authors & contributors +// Copyright 2017-2023 @polkadot/app-explorer authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { PeerInfo } from '@polkadot/types/interfaces'; diff --git a/packages/page-explorer/src/NodeInfo/Summary.tsx b/packages/page-explorer/src/NodeInfo/Summary.tsx index 58c51f68aa..2447d13eef 100644 --- a/packages/page-explorer/src/NodeInfo/Summary.tsx +++ b/packages/page-explorer/src/NodeInfo/Summary.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-nodeinfo authors & contributors +// Copyright 2017-2023 @polkadot/app-explorer authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Info } from './types.js'; diff --git a/packages/page-explorer/src/NodeInfo/index.tsx b/packages/page-explorer/src/NodeInfo/index.tsx index 5325431e6b..31a69b29cb 100644 --- a/packages/page-explorer/src/NodeInfo/index.tsx +++ b/packages/page-explorer/src/NodeInfo/index.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-nodeinfo authors & contributors +// Copyright 2017-2023 @polkadot/app-explorer authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { ApiPromise } from '@polkadot/api'; diff --git a/packages/page-explorer/src/NodeInfo/types.ts b/packages/page-explorer/src/NodeInfo/types.ts index e3dd6c4fa6..c1ef34698c 100644 --- a/packages/page-explorer/src/NodeInfo/types.ts +++ b/packages/page-explorer/src/NodeInfo/types.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/app-nodeinfo authors & contributors +// Copyright 2017-2023 @polkadot/app-explorer authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Vec } from '@polkadot/types'; diff --git a/packages/page-extrinsics/src/index.tsx b/packages/page-extrinsics/src/index.tsx index defb04b276..03fec8a273 100644 --- a/packages/page-extrinsics/src/index.tsx +++ b/packages/page-extrinsics/src/index.tsx @@ -44,7 +44,7 @@ function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { } diff --git a/packages/page-files/src/CrustFiles.tsx b/packages/page-files/src/CrustFiles.tsx index 782bcf4538..c672fef764 100644 --- a/packages/page-files/src/CrustFiles.tsx +++ b/packages/page-files/src/CrustFiles.tsx @@ -123,9 +123,9 @@ function CrustFiles ({ className }: Props): React.ReactElement { // eslint-disable-next-line @typescript-eslint/no-unsafe-call const dirFiles: DirFile[] = []; - for (let index = 0; index < files.length; index++) { + for (let i = 0, count = files.length; i < count; i++) { // console.info('f:', files[index]); - dirFiles.push(files[index] as DirFile); + dirFiles.push(files[i]); } console.info(dirFiles); @@ -138,6 +138,7 @@ function CrustFiles ({ className }: Props): React.ReactElement { e.target.value = ''; }, [setFile, setShowUpMode, queueAction, t]); + const _onImportResult = useCallback<(m: string, s?: ActionStatusBase['status']) => void>( (message, status = 'queued') => { queueAction && queueAction({ @@ -180,7 +181,7 @@ function CrustFiles ({ className }: Props): React.ReactElement { } const fitter: SaveFile[] = []; - const mapImport: { [key: string]: boolean } = {}; + const mapImport: Record = {}; for (const item of _list) { if (item.Hash && item.Name && item.UpEndpoint && item.PinEndpoint) { diff --git a/packages/page-files/src/UploadModal.tsx b/packages/page-files/src/UploadModal.tsx index 7b3b4bb968..d28fb2da38 100644 --- a/packages/page-files/src/UploadModal.tsx +++ b/packages/page-files/src/UploadModal.tsx @@ -124,10 +124,10 @@ function UploadModal ({ className, file, onClose = NOOP, onSuccess = NOOP }: Pro }, [setAccount, setCurrentPair]); useEffect(() => { - const meta = (currentPair && currentPair.meta) || {}; - const isExternal = (meta.isExternal as boolean) || false; - const isHardware = (meta.isHardware as boolean) || false; - const isInjected = (meta.isInjected as boolean) || false; + const meta = currentPair?.meta || {}; + const isExternal = meta.isExternal || false; + const isHardware = meta.isHardware || false; + const isInjected = meta.isInjected || false; const isUsable = !(isExternal || isHardware || isInjected); setAccountState({ isExternal, isHardware, isInjected }); @@ -305,7 +305,7 @@ function UploadModal ({ className, file, onClose = NOOP, onSuccess = NOOP }: Pro
{file.file && } - {file.files && file.files.map((f, i) => + {file.files?.map((f, i) => { const { info } = useInfo(); const isDisabled = useMemo( - () => !info || !info.activeTotal || info.activeTotal.target.isZero(), + () => !info?.activeTotal || info.activeTotal.target.isZero(), [info] ); diff --git a/packages/page-nfts/src/AccountItems/index.tsx b/packages/page-nfts/src/AccountItems/index.tsx index 13f244f47b..ab3bb5107a 100644 --- a/packages/page-nfts/src/AccountItems/index.tsx +++ b/packages/page-nfts/src/AccountItems/index.tsx @@ -84,7 +84,7 @@ function AccountItems ({ className, infos = [] }: Props): React.ReactElement - {itemsInfos && itemsInfos.map((info) => ( + {itemsInfos?.map((info) => ( ; if (result && typeof result === 'object') { return { @@ -37,10 +37,14 @@ const IPFS_FETCH_OPTIONS = { }; function extractInfo ([, itemId]: [BN, BN], metadata: Option, accountItems: AccountItem[]): ItemInfo { - const { accountId } = accountItems.find(({ itemId: _itemId }) => _itemId.eq(itemId)) as AccountItem; + const item = accountItems.find(({ itemId: _itemId }) => _itemId.eq(itemId)); + + if (!item) { + throw new Error('Unable to extract accountId'); + } return { - account: accountId, + account: item.accountId, id: itemId, ipfsData: null, key: itemId.toString(), @@ -49,7 +53,7 @@ function extractInfo ([, itemId]: [BN, BN], metadata: Option (itemInfo: ItemInfo): ItemInfo => { - const ipfsHash = itemInfo.metadata && itemInfo.metadata.data.toString(); + const ipfsHash = itemInfo.metadata?.data.toString(); return { ...itemInfo, @@ -69,7 +73,7 @@ function useItemsInfosImpl (accountItems: AccountItem[]): ItemInfo[] | undefined const metadata = useCall<[[[BN, BN][]], Option[]]>(api.query.uniques.instanceMetadataOf.multi, [ids], QUERY_OPTS); const ipfsHashes = useMemo((): string[] | undefined => { - if (metadata && metadata[1].length) { + if (metadata?.[1].length) { return metadata[1].map((o) => o.isSome ? o.unwrap().data.toPrimitive() as string @@ -83,7 +87,7 @@ function useItemsInfosImpl (accountItems: AccountItem[]): ItemInfo[] | undefined const ipfsData = useIpfsFetch(ipfsHashes, IPFS_FETCH_OPTIONS); useEffect((): void => { - if (ipfsData && accountItems.length && metadata && metadata[0][0].length) { + if (ipfsData && accountItems.length && metadata?.[0][0].length) { const [collectionId] = metadata[0][0][0]; if (!collectionId.eq(ids[0][0])) { diff --git a/packages/page-nfts/src/useCollectionInfos.ts b/packages/page-nfts/src/useCollectionInfos.ts index ba38f67629..dcc13e8eb0 100644 --- a/packages/page-nfts/src/useCollectionInfos.ts +++ b/packages/page-nfts/src/useCollectionInfos.ts @@ -29,7 +29,7 @@ const IPFS_FETCH_OPTIONS = { } try { - const result = JSON.parse(data) as {[key: string]: any}; + const result = JSON.parse(data) as Record; if (result && typeof result === 'object') { return { @@ -87,7 +87,7 @@ function useCollectionInfosImpl (ids?: BN[]): CollectionInfo[] | undefined { const [state, setState] = useState(); const ipfsHashes = useMemo( - () => metadata && metadata[1].length + () => metadata?.[1].length ? metadata[1].map((o) => o.isSome ? o.unwrap().data.toPrimitive() as string diff --git a/packages/page-nis/src/Overview/index.tsx b/packages/page-nis/src/Overview/index.tsx index b40849bdfd..47113692ab 100644 --- a/packages/page-nis/src/Overview/index.tsx +++ b/packages/page-nis/src/Overview/index.tsx @@ -19,7 +19,7 @@ function Overview ({ className }: Props): React.ReactElement { const proxies = useProxies(); const { info } = useInfo(); - const isDisabled = !info || !info.summary || info.summary.proportionOwed.isZero(); + const isDisabled = !info?.summary || info.summary.proportionOwed.isZero(); return (
diff --git a/packages/page-parachains/src/Auctions/Auction.tsx b/packages/page-parachains/src/Auctions/Auction.tsx index 6e9b75d83c..c38afa4ff5 100644 --- a/packages/page-parachains/src/Auctions/Auction.tsx +++ b/packages/page-parachains/src/Auctions/Auction.tsx @@ -36,7 +36,7 @@ function Auction ({ auctionInfo, campaigns, className, winningData }: Props): Re const loans = useMemo( (): Campaign[] | undefined => { - if (newRaise && auctionInfo && auctionInfo.leasePeriod && campaigns.funds) { + if (newRaise && auctionInfo?.leasePeriod && campaigns.funds) { const leasePeriodStart = auctionInfo.leasePeriod; const leasePeriodEnd = leasePeriodStart.add(rangeMax); @@ -94,7 +94,7 @@ function Auction ({ auctionInfo, campaigns, className, winningData }: Props): Re - {auctionInfo && auctionInfo.leasePeriod && winningData && loans && ( + {auctionInfo?.leasePeriod && winningData && loans && ( winningData.length ? winningData.map(({ blockNumber, winners }, round) => ( diff --git a/packages/page-parachains/src/Auctions/Bid.tsx b/packages/page-parachains/src/Auctions/Bid.tsx index bb3a0dbc3f..b75351c0dc 100644 --- a/packages/page-parachains/src/Auctions/Bid.tsx +++ b/packages/page-parachains/src/Auctions/Bid.tsx @@ -61,7 +61,7 @@ function Bid ({ auctionInfo, className, lastWinners, ownedIds }: Props): React.R ); const currentWinner = useMemo( - () => lastWinners && lastWinners.winners.find(({ firstSlot, lastSlot }) => + () => lastWinners?.winners.find(({ firstSlot, lastSlot }) => firstSlot.eqn(rangeOpts[range].firstSlot) && lastSlot.eqn(rangeOpts[range].lastSlot) ), diff --git a/packages/page-parachains/src/Auctions/index.tsx b/packages/page-parachains/src/Auctions/index.tsx index 700ac57163..0ce85026c7 100644 --- a/packages/page-parachains/src/Auctions/index.tsx +++ b/packages/page-parachains/src/Auctions/index.tsx @@ -20,7 +20,7 @@ interface Props { } function Auctions ({ auctionInfo, campaigns, className, ownedIds, winningData }: Props): React.ReactElement { - const lastWinners = winningData && winningData[0]; + const lastWinners = winningData?.[0]; return (
diff --git a/packages/page-parachains/src/Overview/Parachain.tsx b/packages/page-parachains/src/Overview/Parachain.tsx index 841cf8a4f3..96ad0c4b94 100644 --- a/packages/page-parachains/src/Overview/Parachain.tsx +++ b/packages/page-parachains/src/Overview/Parachain.tsx @@ -60,8 +60,8 @@ function Parachain ({ bestNumber, className = '', id, lastBacked, lastInclusion, const valRender = useCallback( () => renderAddresses( - validators && validators[1].map(({ validatorId }) => validatorId), - validators && validators[1].map(({ indexValidator }) => indexValidator) + validators?.[1].map(({ validatorId }) => validatorId), + validators?.[1].map(({ indexValidator }) => indexValidator) ), [validators] ); diff --git a/packages/page-parachains/src/Overview/Periods.tsx b/packages/page-parachains/src/Overview/Periods.tsx index 295baa8256..990d9fb25f 100644 --- a/packages/page-parachains/src/Overview/Periods.tsx +++ b/packages/page-parachains/src/Overview/Periods.tsx @@ -18,9 +18,9 @@ interface Props { } function getMapped (periods: number[], currentPeriod?: BN): string | undefined { - return currentPeriod && periods && + return currentPeriod && periods - .reduce((all: [BN, BN][], period): [BN, BN][] => { + ?.reduce((all: [BN, BN][], period): [BN, BN][] => { const bnp = currentPeriod.addn(period); if (!all.length || all[all.length - 1][1].add(BN_ONE).lt(bnp)) { diff --git a/packages/page-parachains/src/Overview/useEvents.ts b/packages/page-parachains/src/Overview/useEvents.ts index 749d541690..93887cf526 100644 --- a/packages/page-parachains/src/Overview/useEvents.ts +++ b/packages/page-parachains/src/Overview/useEvents.ts @@ -28,7 +28,7 @@ function includeEntry (map: EventMap, event: Event, blockHash: string, blockNumb try { const { descriptor } = (event as unknown as IEvent<[PolkadotPrimitivesV4CandidateReceipt]>).data[0]; - if (descriptor && descriptor.paraId) { + if (descriptor?.paraId) { map[descriptor.paraId.toString()] = { blockHash, blockNumber, diff --git a/packages/page-parachains/src/Parathreads/Parathread.tsx b/packages/page-parachains/src/Parathreads/Parathread.tsx index d12d8c1ba8..41c29721a9 100644 --- a/packages/page-parachains/src/Parathreads/Parathread.tsx +++ b/packages/page-parachains/src/Parathreads/Parathread.tsx @@ -29,8 +29,7 @@ function Parathread ({ id, leasePeriod, leases, nextAction }: Props): React.Reac const { headHex, lifecycle, manager } = useThreadInfo(id); const periods = useMemo( - () => leasePeriod?.currentPeriod && leases && - leases.map(({ period }) => period), + () => leasePeriod?.currentPeriod && leases?.map(({ period }) => period), [leasePeriod?.currentPeriod, leases] ); diff --git a/packages/page-parachains/src/Proposals/Proposal.tsx b/packages/page-parachains/src/Proposals/Proposal.tsx index 31ce7eba8e..48d00dacc2 100644 --- a/packages/page-parachains/src/Proposals/Proposal.tsx +++ b/packages/page-parachains/src/Proposals/Proposal.tsx @@ -38,7 +38,7 @@ function Proposal ({ approvedIds, id, scheduled }: Props): React.ReactElement api.tx.sudo && api.tx.sudo.sudo(api.tx.proposeParachain.approveProposal(id)), + () => api.tx.sudo?.sudo(api.tx.proposeParachain.approveProposal(id)), [api, id] ); diff --git a/packages/page-parachains/src/Proposals/Proposals.tsx b/packages/page-parachains/src/Proposals/Proposals.tsx index ddcf3273f2..94e6e71a3d 100644 --- a/packages/page-parachains/src/Proposals/Proposals.tsx +++ b/packages/page-parachains/src/Proposals/Proposals.tsx @@ -18,7 +18,7 @@ function Proposals ({ proposals }: Props): React.ReactElement { const { t } = useTranslation(); const sortedIds = useMemo( - () => proposals && proposals.proposalIds.sort((a, b) => a.cmp(b)), + () => proposals?.proposalIds.sort((a, b) => a.cmp(b)), [proposals] ); diff --git a/packages/page-parachains/src/Teleport.tsx b/packages/page-parachains/src/Teleport.tsx index c631cdb105..fcd6853a86 100644 --- a/packages/page-parachains/src/Teleport.tsx +++ b/packages/page-parachains/src/Teleport.tsx @@ -68,7 +68,7 @@ function Teleport ({ onClose }: Props): React.ReactElement | null { recipientParaId === -1 ? index === 0 : recipientParaId === paraId - )?.value as string, + )?.value, [destinations, recipientParaId] ); diff --git a/packages/page-parachains/src/useWinningData.ts b/packages/page-parachains/src/useWinningData.ts index c06d6ce7bc..269770bc6c 100644 --- a/packages/page-parachains/src/useWinningData.ts +++ b/packages/page-parachains/src/useWinningData.ts @@ -83,7 +83,7 @@ function mergeCurrent (ranges: [number, number][], auctionInfo: AuctionInfo, pre const current = createWinning(auctionInfo, blockOffset, extractWinners(ranges, auctionInfo, optCurrent)); if (current.winners.length) { - if (!prev || !prev.length) { + if (!prev?.length) { return [current]; } diff --git a/packages/page-preimages/src/Preimages/Preimage.tsx b/packages/page-preimages/src/Preimages/Preimage.tsx index ac876facfe..813ec53d50 100644 --- a/packages/page-preimages/src/Preimages/Preimage.tsx +++ b/packages/page-preimages/src/Preimages/Preimage.tsx @@ -25,7 +25,7 @@ function Preimage ({ className, value }: Props): React.ReactElement {
diff --git a/packages/page-preimages/src/Preimages/index.tsx b/packages/page-preimages/src/Preimages/index.tsx index 0c84897d5d..1994f18024 100644 --- a/packages/page-preimages/src/Preimages/index.tsx +++ b/packages/page-preimages/src/Preimages/index.tsx @@ -41,7 +41,7 @@ function Hashes ({ className }: Props): React.ReactElement { empty={hashes && t('No hashes found')} header={headerRef.current} > - {hashes && hashes.map((h) => ( + {hashes?.map((h) => ( hashes && hashes.map((h) => h.toHex()), + () => hashes?.map((h) => h.toHex()), [hashes] ); } diff --git a/packages/page-ranked/src/App.tsx b/packages/page-ranked/src/App.tsx index d4a79eeb3b..06d6fea0a3 100644 --- a/packages/page-ranked/src/App.tsx +++ b/packages/page-ranked/src/App.tsx @@ -51,17 +51,17 @@ function App ({ basePath, className, palletColl, palletPoll }: Props): React.Rea } path='referenda' /> + } index /> diff --git a/packages/page-ranked/src/Members/index.tsx b/packages/page-ranked/src/Members/index.tsx index 58220e4216..725ee098dd 100644 --- a/packages/page-ranked/src/Members/index.tsx +++ b/packages/page-ranked/src/Members/index.tsx @@ -32,7 +32,7 @@ function Members ({ className, members }: Props): React.ReactElement { header={headerRef.current} isSplit > - {members && members.map((a): React.ReactNode => ( + {members?.map((a): React.ReactNode => ( (
- {info && info.proposalLength + {info?.proposalLength ? formatNumber(info.proposalLength) : 999,999}
- {(info && info.trackName) || classId.toString()} + {info?.trackName || classId.toString()} { diff --git a/packages/page-referenda/src/Referenda/Delegate/index.tsx b/packages/page-referenda/src/Referenda/Delegate/index.tsx index 6a7ee97869..abe37677f2 100644 --- a/packages/page-referenda/src/Referenda/Delegate/index.tsx +++ b/packages/page-referenda/src/Referenda/Delegate/index.tsx @@ -82,9 +82,9 @@ function Delegate ({ className, palletReferenda, palletVote, tracks }: Props): R () => [ { text: t('Addresses'), value: 'address' }, isFunction(api.query.staking?.nominators) && - { isDisabled: !allVals || !allVals.length, text: t('Validators'), value: 'validators' }, + { isDisabled: !allVals?.length, text: t('Validators'), value: 'validators' }, isFunction(api.query.fellowshipCollective?.members) && - { isDisabled: !allFell || !allFell.length, text: t('Fellows'), value: 'fellows' } + { isDisabled: !allFell?.length, text: t('Fellows'), value: 'fellows' } ], [allFell, allVals, api, t] ); diff --git a/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts b/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts index 49ee9418fd..e603caa8ad 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useVotingFor.ts @@ -74,7 +74,7 @@ function useVotingForImpl (palletVote: PalletVote, accountIds?: string[] | null) [locks] ); - const votes = useCall(forParam && forParam[0] && api.query[palletVote]?.votingFor?.multi, forParam, FOR_OPT); + const votes = useCall(forParam?.[0] && api.query[palletVote]?.votingFor?.multi, forParam, FOR_OPT); return useMemo( () => locks && forParam diff --git a/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts b/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts index e8a09e918b..fa50641c18 100644 --- a/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts +++ b/packages/page-referenda/src/Referenda/Delegate/useVotingLocks.ts @@ -34,7 +34,7 @@ function useVotingLocksImpl (palletVote: PalletVote, accountIds?: string[] | nul [accountIds] ); - const locks = useCall(locksParam && locksParam[0] && api.query[palletVote]?.classLocksFor?.multi, locksParam, LOCKS_OPT); + const locks = useCall(locksParam?.[0] && api.query[palletVote]?.classLocksFor?.multi, locksParam, LOCKS_OPT); return useMemo( () => locksParam diff --git a/packages/page-referenda/src/Referenda/Group.tsx b/packages/page-referenda/src/Referenda/Group.tsx index 6268bb353a..6932edc47a 100644 --- a/packages/page-referenda/src/Referenda/Group.tsx +++ b/packages/page-referenda/src/Referenda/Group.tsx @@ -73,7 +73,7 @@ function Group ({ activeIssuance, className, isMember, members, palletReferenda, isSplit={!trackId} key={key} > - {referenda && referenda.map((r) => ( + {referenda?.map((r) => ( - {preimage && preimage.proposal + {preimage?.proposal ? ( (null); const [trackId, setTrack] = useState(undefined); - const [origin, setOrigin] = useState(null); + const [origin, setOrigin] = useState(null); const [{ imageHash, isImageHashValid }, setImageHash] = useState({ imageHash: null, isImageHashValid: false }); const [{ imageLen, imageLenDefault, isImageLenValid }, setImageLen] = useState({ imageLen: BN_ZERO, isImageLenValid: false }); const [enactIndex, setEnactIndex] = useState(0); diff --git a/packages/page-referenda/src/Referenda/Submit/useTrackOptions.tsx b/packages/page-referenda/src/Referenda/Submit/useTrackOptions.tsx index 9441157dbe..1f40f2302b 100644 --- a/packages/page-referenda/src/Referenda/Submit/useTrackOptions.tsx +++ b/packages/page-referenda/src/Referenda/Submit/useTrackOptions.tsx @@ -14,8 +14,8 @@ import { bnToBn } from '@polkadot/util'; import { getTrackInfo, getTrackName } from '../../util.js'; function getTrackOptions (api: ApiPromise, specName: string, palletReferenda: string, tracks: TrackDescription[], include?: (BN | number)[], exclude?: (BN | number)[]): TrackOption[] { - const includeBn = include && include.map((v) => bnToBn(v)); - const excludeBn = exclude && exclude.map((v) => bnToBn(v)); + const includeBn = include?.map((v) => bnToBn(v)); + const excludeBn = exclude?.map((v) => bnToBn(v)); return tracks .filter(({ id }) => diff --git a/packages/page-referenda/src/Referenda/Vote/index.tsx b/packages/page-referenda/src/Referenda/Vote/index.tsx index 8e0cd59651..af2e5a45a6 100644 --- a/packages/page-referenda/src/Referenda/Vote/index.tsx +++ b/packages/page-referenda/src/Referenda/Vote/index.tsx @@ -33,7 +33,7 @@ function filterMembers (allAccounts: string[], members?: string[], ranks?: BN[], if (members) { const accounts = members.filter((a) => allAccounts.includes(a)); - if (ranks && trackInfo && trackInfo.compare) { + if (ranks && trackInfo?.compare) { const cmp = trackInfo.compare; return accounts.filter((_, i) => cmp(ranks[i])); diff --git a/packages/page-referenda/src/Referenda/Votes.tsx b/packages/page-referenda/src/Referenda/Votes.tsx index 5e55efe61f..5e870200fe 100644 --- a/packages/page-referenda/src/Referenda/Votes.tsx +++ b/packages/page-referenda/src/Referenda/Votes.tsx @@ -38,7 +38,7 @@ function extractVotes (votes: Record = const nays: [string, BN][] = []; const entries = Object.entries(votes); - for (let i = 0; i < entries.length; i++) { + for (let i = 0, count = entries.length; i < count; i++) { const [accountId, vote] = entries[i]; if (vote.isAye) { diff --git a/packages/page-referenda/src/Referenda/index.tsx b/packages/page-referenda/src/Referenda/index.tsx index 1b7268d01e..e97d0ab222 100644 --- a/packages/page-referenda/src/Referenda/index.tsx +++ b/packages/page-referenda/src/Referenda/index.tsx @@ -41,7 +41,7 @@ function Referenda ({ className, isConvictionVote, members, palletReferenda, pal const [trackSelected, setTrackSelected] = useState(-1); const activeIssuance = useMemo( - () => totalIssuance && totalIssuance.sub(inactiveIssuance || BN_ZERO), + () => totalIssuance?.sub(inactiveIssuance || BN_ZERO), [inactiveIssuance, totalIssuance] ); diff --git a/packages/page-referenda/src/useAccountLocks.ts b/packages/page-referenda/src/useAccountLocks.ts index 8d08425657..820ddbcf9a 100644 --- a/packages/page-referenda/src/useAccountLocks.ts +++ b/packages/page-referenda/src/useAccountLocks.ts @@ -58,7 +58,7 @@ function getVoteParams (accountId: string, lockClasses?: BN[]): [[accountId: str } function getRefParams (votes?: [classId: BN, refIds: BN[], casting: PalletConvictionVotingVoteCasting][]): [BN[]] | undefined { - if (votes && votes.length) { + if (votes?.length) { const refIds = votes.reduce((all, [, refIds]) => all.concat(refIds), []); if (refIds.length) { @@ -73,10 +73,10 @@ function getLocks (api: ApiPromise, palletVote: PalletVote, votes: [classId: BN, const lockPeriod = api.consts[palletVote].voteLockingPeriod as BN; const locks: Lock[] = []; - for (let i = 0; i < votes.length; i++) { + for (let i = 0, voteCount = votes.length; i < voteCount; i++) { const [classId,, casting] = votes[i]; - for (let i = 0; i < casting.votes.length; i++) { + for (let i = 0, castCount = casting.votes.length; i < castCount; i++) { const [refId, accountVote] = casting.votes[i]; const refInfo = referenda.find(([id]) => id.eq(refId)); diff --git a/packages/page-referenda/src/useReferenda.ts b/packages/page-referenda/src/useReferenda.ts index 82c6a651b7..96d4cd0765 100644 --- a/packages/page-referenda/src/useReferenda.ts +++ b/packages/page-referenda/src/useReferenda.ts @@ -81,7 +81,7 @@ function group (tracks: TrackDescription[], totalIssuance?: BN, referenda?: Refe const other: ReferendaGroupKnown = { key: 'referenda', referenda: [] }; // sort the referenda by track inside groups - for (let i = 0; i < referenda.length; i++) { + for (let i = 0, count = referenda.length; i < count; i++) { const ref = referenda[i]; // only ongoing have tracks @@ -132,7 +132,7 @@ function group (tracks: TrackDescription[], totalIssuance?: BN, referenda?: Refe } // sort referenda per group - for (let i = 0; i < grouped.length; i++) { + for (let i = 0, count = grouped.length; i < count; i++) { grouped[i].referenda.sort(sortReferenda); } diff --git a/packages/page-scheduler/src/DispatchQueue.tsx b/packages/page-scheduler/src/DispatchQueue.tsx index 15023364ea..54aee08cad 100644 --- a/packages/page-scheduler/src/DispatchQueue.tsx +++ b/packages/page-scheduler/src/DispatchQueue.tsx @@ -22,10 +22,7 @@ function DispatchQueue ({ className }: Props): React.ReactElement | null const queued = useCall(api.derive.democracy.dispatchQueue); const filtered = useMemo( - () => bestNumber && queued && - queued - .filter(({ at }) => at.gte(bestNumber)) - .sort((a, b) => a.at.cmp(b.at)), + () => bestNumber && queued?.filter(({ at }) => at.gte(bestNumber)).sort((a, b) => a.at.cmp(b.at)), [bestNumber, queued] ); diff --git a/packages/page-scheduler/src/Scheduler.tsx b/packages/page-scheduler/src/Scheduler.tsx index 62ac41917c..67e2680280 100644 --- a/packages/page-scheduler/src/Scheduler.tsx +++ b/packages/page-scheduler/src/Scheduler.tsx @@ -85,10 +85,7 @@ function Schedule ({ className = '' }: Props): React.ReactElement { const items = useCall(api.query.scheduler.agenda.entries, undefined, OPT_SCHED); const filtered = useMemo( - () => bestNumber && items && - items - .filter(({ blockNumber }) => blockNumber.gte(bestNumber)) - .sort((a, b) => a.blockNumber.cmp(b.blockNumber)), + () => bestNumber && items?.filter(({ blockNumber }) => blockNumber.gte(bestNumber)).sort((a, b) => a.blockNumber.cmp(b.blockNumber)), [bestNumber, items] ); diff --git a/packages/page-settings/src/I18n/index.tsx b/packages/page-settings/src/I18n/index.tsx index e277545905..429e292e8e 100644 --- a/packages/page-settings/src/I18n/index.tsx +++ b/packages/page-settings/src/I18n/index.tsx @@ -49,7 +49,7 @@ async function retrieveJson (url: string): Promise { } async function retrieveEnglish (): Promise { - const paths = await retrieveJson('en/index.json') as Array; + const paths = await retrieveJson('en/index.json') as string[]; const strings: Strings[] = await Promise.all(paths.map((path) => retrieveJson(`en/${path}`) as Promise)); return strings.reduce((language: StringsMod, strings, index): StringsMod => { diff --git a/packages/page-settings/src/useExtensions.ts b/packages/page-settings/src/useExtensions.ts index 57b7ef13ae..6073a6f71f 100644 --- a/packages/page-settings/src/useExtensions.ts +++ b/packages/page-settings/src/useExtensions.ts @@ -31,9 +31,7 @@ interface ExtensionProperties { ss58Format?: number; } -interface SavedProperties { - [name: string]: ExtensionProperties; -} +type SavedProperties = Record; type TriggerFn = (counter: number) => void; diff --git a/packages/page-signing/src/Sign.tsx b/packages/page-signing/src/Sign.tsx index 393b2c6baa..48d2af557e 100644 --- a/packages/page-signing/src/Sign.tsx +++ b/packages/page-signing/src/Sign.tsx @@ -46,10 +46,10 @@ function Sign ({ className = '' }: Props): React.ReactElement { const [isUnlockVisible, toggleUnlock] = useToggle(); useEffect((): void => { - const meta = (currentPair && currentPair.meta) || {}; - const isExternal = (meta.isExternal as boolean) || false; - const isHardware = (meta.isHardware as boolean) || false; - const isInjected = (meta.isInjected as boolean) || false; + const meta = currentPair?.meta || {}; + const isExternal = meta.isExternal || false; + const isHardware = meta.isHardware || false; + const isInjected = meta.isInjected || false; const isUsable = !(isExternal || isHardware || isInjected); setAccountState({ isExternal, isHardware, isInjected }); diff --git a/packages/page-society/src/Candidates/Bid.tsx b/packages/page-society/src/Candidates/Bid.tsx index 66e36133fd..ebd2768bad 100644 --- a/packages/page-society/src/Candidates/Bid.tsx +++ b/packages/page-society/src/Candidates/Bid.tsx @@ -31,7 +31,7 @@ function BidRow ({ index, value: { kind, value, who } }: Props): React.ReactElem const [isBidder, isVoucher] = useMemo( (): [boolean, boolean] => { const whoSS58 = who.toString(); - const vouchSS58 = voucher && voucher.toString(); + const vouchSS58 = voucher?.toString(); return [ allAccounts.some((accountId) => accountId === whoSS58), diff --git a/packages/page-society/src/Candidates/BidType.tsx b/packages/page-society/src/Candidates/BidType.tsx index bf4dcad98f..54b906c823 100644 --- a/packages/page-society/src/Candidates/BidType.tsx +++ b/packages/page-society/src/Candidates/BidType.tsx @@ -22,7 +22,7 @@ function BidType ({ className, value }: Props): React.ReactElement { return ( -
{value && value.type}
+
{value?.type}
{vouchId && }
); diff --git a/packages/page-society/src/draw/canary.ts b/packages/page-society/src/draw/canary.ts index dfffee0d24..21dd85fcb8 100644 --- a/packages/page-society/src/draw/canary.ts +++ b/packages/page-society/src/draw/canary.ts @@ -81,9 +81,9 @@ function tattooSpiro (ctx: CanvasRenderingContext2D, bits: boolean[]): void { let radius = 0.5 - dot; - for (let i = 0; i < bits.length; i++) { - radius -= 0.5 / bits.length * limit / (radius * 4); - ctx.rotate(Math.PI * 2 / bits.length * cycles / (radius * 4)); + for (let i = 0, count = bits.length; i < count; i++) { + radius -= 0.5 / count * limit / (radius * 4); + ctx.rotate(Math.PI * 2 / count * cycles / (radius * 4)); ctx.save(); ctx.translate(0, -radius); ctx.beginPath(); diff --git a/packages/page-staking/src/Actions/Account/BondExtra.tsx b/packages/page-staking/src/Actions/Account/BondExtra.tsx index 824e63ecd7..1cf618260b 100644 --- a/packages/page-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/page-staking/src/Actions/Account/BondExtra.tsx @@ -23,7 +23,7 @@ interface Props { } function calcBalance (api: ApiPromise, stakingInfo?: DeriveStakingAccount, stashBalance?: DeriveBalancesAll): BN | null { - if (stakingInfo && stakingInfo.stakingLedger && stashBalance) { + if (stakingInfo?.stakingLedger && stashBalance) { const sumUnlocking = (stakingInfo.unlocking || []).reduce((acc, { value }) => acc.iadd(value), new BN(0)); const redeemable = stakingInfo.redeemable || BN_ZERO; const available = stashBalance.freeBalance.sub(stakingInfo.stakingLedger.active?.unwrap() || BN_ZERO).sub(sumUnlocking).sub(redeemable); @@ -43,7 +43,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea const [maxAdditional, setMaxAdditional] = useState(); const stashBalance = useCall(api.derive.balances?.all, [stashId]); const currentAmount = useMemo( - () => stakingInfo && stakingInfo.stakingLedger?.active?.unwrap(), + () => stakingInfo?.stakingLedger?.active?.unwrap(), [stakingInfo] ); diff --git a/packages/page-staking/src/Actions/Account/Rebond.tsx b/packages/page-staking/src/Actions/Account/Rebond.tsx index 7e0087ea0d..1836951ecb 100644 --- a/packages/page-staking/src/Actions/Account/Rebond.tsx +++ b/packages/page-staking/src/Actions/Account/Rebond.tsx @@ -26,7 +26,7 @@ function Rebond ({ controllerId, onClose, stakingInfo, stashId }: Props): React. const [maxAdditional, setMaxAdditional] = useState(); const startBalance = useMemo( - () => stakingInfo && stakingInfo.unlocking + () => stakingInfo?.unlocking ? stakingInfo.unlocking.reduce((total, { value }) => total.iadd(value), new BN(0)) : BN_ZERO, [stakingInfo] diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index 5d8585771c..bb154f22eb 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -294,17 +294,17 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio onClick={toggleBondExtra} /> diff --git a/packages/page-staking/src/Actions/Pool/Account.tsx b/packages/page-staking/src/Actions/Pool/Account.tsx index 5a0ad4958e..3438349684 100644 --- a/packages/page-staking/src/Actions/Pool/Account.tsx +++ b/packages/page-staking/src/Actions/Pool/Account.tsx @@ -73,7 +73,7 @@ function Pool ({ accountId, className, info: { bonded: { roles }, metadata, nomi const accInfo = useAccountInfo(accountId); const stakingInfo = useMemo( - () => sessionProgress && accInfo && accInfo.member.unbondingEras && !accInfo.member.unbondingEras.isEmpty + () => sessionProgress && accInfo?.member.unbondingEras && !accInfo.member.unbondingEras.isEmpty ? calcUnbonding(accountId, stashId, sessionProgress, accInfo.member) : null, [accInfo, accountId, stashId, sessionProgress] diff --git a/packages/page-staking/src/Actions/Pool/useAccountInfo.ts b/packages/page-staking/src/Actions/Pool/useAccountInfo.ts index 9fea2e3191..9844e77fe4 100644 --- a/packages/page-staking/src/Actions/Pool/useAccountInfo.ts +++ b/packages/page-staking/src/Actions/Pool/useAccountInfo.ts @@ -21,9 +21,9 @@ function useAccountInfoImpl (accountId: string): AccountInfo | null { const member = useCall(api.query.nominationPools.poolMembers, [accountId], OPT_DEL); useEffect((): void => { - member && api.call.nominationPoolsApi && + member && api.call.nominationPoolsApi - .pendingRewards(accountId) + ?.pendingRewards(accountId) .then((claimable) => isMountedRef.current && setState({ claimable, member }) ) diff --git a/packages/page-staking/src/Actions/index.tsx b/packages/page-staking/src/Actions/index.tsx index 53680a386c..81e057417b 100644 --- a/packages/page-staking/src/Actions/index.tsx +++ b/packages/page-staking/src/Actions/index.tsx @@ -64,7 +64,7 @@ function extractState (ownStashes?: StakerState[]): State { const bondedTotal = new BN(0); ownStashes.forEach(({ isStashNominating, isStashValidating, stakingLedger }): void => { - const value = stakingLedger && stakingLedger.total + const value = stakingLedger?.total ? stakingLedger.total.unwrap() : BN_ZERO; diff --git a/packages/page-staking/src/Actions/partials/Nominate.tsx b/packages/page-staking/src/Actions/partials/Nominate.tsx index d27486ae92..9ba5efb904 100644 --- a/packages/page-staking/src/Actions/partials/Nominate.tsx +++ b/packages/page-staking/src/Actions/partials/Nominate.tsx @@ -47,7 +47,7 @@ function Nominate ({ className = '', controllerId, nominating, onChange, poolId, useEffect((): void => { try { onChange({ - nominateTx: selected && selected.length + nominateTx: selected?.length ? poolId ? api.tx.nominationPools.nominate(poolId, selected) : api.tx.staking.nominate(selected) diff --git a/packages/page-staking/src/Actions/useInactives.ts b/packages/page-staking/src/Actions/useInactives.ts index 752772f891..3561e39cda 100644 --- a/packages/page-staking/src/Actions/useInactives.ts +++ b/packages/page-staking/src/Actions/useInactives.ts @@ -97,7 +97,7 @@ function useInactivesImpl (stashId: string, nominees?: string[]): Inactives { useEffect((): () => void => { let unsub: (() => void) | undefined; - if (mountedRef.current && nominees && nominees.length && indexes) { + if (mountedRef.current && nominees?.length && indexes) { api .queryMulti( [[api.query.staking.nominators, stashId] as QueryableStorageMultiArg<'promise'>] diff --git a/packages/page-staking/src/Bags/Bag.tsx b/packages/page-staking/src/Bags/Bag.tsx index 3cddd4272a..cb2f1cd4d5 100644 --- a/packages/page-staking/src/Bags/Bag.tsx +++ b/packages/page-staking/src/Bags/Bag.tsx @@ -47,7 +47,7 @@ function Bag ({ bagLower, bagUpper, info, nodesOwn }: Props): React.ReactElement useEffect((): void => { setLoading( - nodesOwn && nodesOwn.length + nodesOwn?.length ? !isCompleted || !bonded : false ); diff --git a/packages/page-staking/src/Bags/Stash.tsx b/packages/page-staking/src/Bags/Stash.tsx index e483ef21fa..584838f21c 100644 --- a/packages/page-staking/src/Bags/Stash.tsx +++ b/packages/page-staking/src/Bags/Stash.tsx @@ -28,7 +28,7 @@ interface Entry { function findEntry (_upper: BN, _bagLower: BN, stashId: string, list: ListNode[] = []): Entry { const stashInfo = list.find((o) => o.stashId === stashId) || null; - const other = (stashInfo && stashInfo.jump && list.find((o) => o.stashId === stashInfo.jump)) || null; + const other = (stashInfo?.jump && list.find((o) => o.stashId === stashInfo.jump)) || null; return { canJump: !!other, diff --git a/packages/page-staking/src/Bags/useBagsNodes.tsx b/packages/page-staking/src/Bags/useBagsNodes.tsx index c08aebfc32..7cccf60fb7 100644 --- a/packages/page-staking/src/Bags/useBagsNodes.tsx +++ b/packages/page-staking/src/Bags/useBagsNodes.tsx @@ -33,7 +33,7 @@ function merge (prev: BagMap | undefined, curr: BagMap): BagMap { return Object .entries(curr) .reduce((all: BagMap, [id, nodes]): BagMap => { - all[id] = prev && prev[id] && JSON.stringify(nodes) === JSON.stringify(prev[id]) + all[id] = prev?.[id] && JSON.stringify(nodes) === JSON.stringify(prev[id]) ? prev[id] : nodes; diff --git a/packages/page-staking/src/Payouts/PayButton.tsx b/packages/page-staking/src/Payouts/PayButton.tsx index 7bc296f81f..26c24f61da 100644 --- a/packages/page-staking/src/Payouts/PayButton.tsx +++ b/packages/page-staking/src/Payouts/PayButton.tsx @@ -131,7 +131,7 @@ function PayButton ({ className, isAll, isDisabled, payout }: Props): React.Reac accountId={accountId} extrinsic={extrinsics} icon='credit-card' - isDisabled={!extrinsics || !extrinsics.length || !accountId} + isDisabled={!extrinsics?.length || !accountId} label={t('Payout')} onStart={togglePayout} /> diff --git a/packages/page-staking/src/Payouts/index.tsx b/packages/page-staking/src/Payouts/index.tsx index d09ca24a22..46613b4e49 100644 --- a/packages/page-staking/src/Payouts/index.tsx +++ b/packages/page-staking/src/Payouts/index.tsx @@ -166,7 +166,7 @@ function Payouts ({ className = '', historyDepth, isInElection, ownPools, ownVal const blockTime = useBlockInterval(); const poolStashes = useMemo( - () => ownPools && ownPools.map(({ stashId }) => stashId), + () => ownPools?.map(({ stashId }) => stashId), [ownPools] ); diff --git a/packages/page-staking/src/Query/Chart.tsx b/packages/page-staking/src/Query/Chart.tsx index 21aac344ed..280bdf29b1 100644 --- a/packages/page-staking/src/Query/Chart.tsx +++ b/packages/page-staking/src/Query/Chart.tsx @@ -18,7 +18,7 @@ interface Props { function ChartDisplay ({ className = '', colors, labels, legends, title, values }: Props): React.ReactElement { const isLoading = useMemo( - () => !labels || labels.length === 0 || !values || values.length === 0 || !values[0] || !values[0].length, + () => !labels || labels.length === 0 || !values || values.length === 0 || !values[0]?.length, [labels, values] ); diff --git a/packages/page-staking/src/Query/index.tsx b/packages/page-staking/src/Query/index.tsx index 32c3cf23cc..7741ffc08e 100644 --- a/packages/page-staking/src/Query/index.tsx +++ b/packages/page-staking/src/Query/index.tsx @@ -30,7 +30,7 @@ function Query ({ className }: Props): React.ReactElement { const eras = useCall(api.derive.staking.erasHistoric); const labels = useMemo( - () => eras && eras.map((e) => e.toHuman() as string), + () => eras?.map((e) => e.toHuman() as string), [eras] ); diff --git a/packages/page-staking/src/Query/useBlockCounts.tsx b/packages/page-staking/src/Query/useBlockCounts.tsx index f21b329b4e..5afac9a56c 100644 --- a/packages/page-staking/src/Query/useBlockCounts.tsx +++ b/packages/page-staking/src/Query/useBlockCounts.tsx @@ -19,7 +19,7 @@ function useBlockCountsImpl (accountId: string, sessionRewards: SessionRewards[] const [historic, setHistoric] = useState([]); useEffect((): void => { - if (isFunction(api.query.imOnline?.authoredBlocks) && sessionRewards && sessionRewards.length) { + if (isFunction(api.query.imOnline?.authoredBlocks) && sessionRewards?.length) { const filtered = sessionRewards.filter(({ sessionIndex }): boolean => sessionIndex.gt(BN_ZERO)); if (filtered.length) { diff --git a/packages/page-staking/src/Targets/Nominate.tsx b/packages/page-staking/src/Targets/Nominate.tsx index 17db6c3a3c..bf471c904e 100644 --- a/packages/page-staking/src/Targets/Nominate.tsx +++ b/packages/page-staking/src/Targets/Nominate.tsx @@ -35,7 +35,7 @@ function Nominate ({ className = '', isDisabled, ownNominators, targets }: Props const _onChangeStash = useCallback( (accountId?: string | null): void => { - const acc = ownNominators && ownNominators.find(({ stashId }) => stashId === accountId); + const acc = ownNominators?.find(({ stashId }) => stashId === accountId); setIds( acc diff --git a/packages/page-staking/src/Targets/index.tsx b/packages/page-staking/src/Targets/index.tsx index dca42fa4ba..d68c437c07 100644 --- a/packages/page-staking/src/Targets/index.tsx +++ b/packages/page-staking/src/Targets/index.tsx @@ -403,7 +403,7 @@ function Targets ({ className = '', isInElection, nominatedBy, ownStashes, targe header={header} legend={} > - {displayList && displayList.map((info): React.ReactNode => + {displayList?.map((info): React.ReactNode => ownStashes && ownStashes.filter(({ isOwnController, isStashValidating }) => + () => ownStashes?.filter(({ isOwnController, isStashValidating }) => isOwnController && !isStashValidating ), diff --git a/packages/page-staking/src/Validators/Address/StakeOther.tsx b/packages/page-staking/src/Validators/Address/StakeOther.tsx index 0cce6b869d..a7b007b358 100644 --- a/packages/page-staking/src/Validators/Address/StakeOther.tsx +++ b/packages/page-staking/src/Validators/Address/StakeOther.tsx @@ -32,7 +32,7 @@ function extractFunction (all: NominatorValue[]): null | [number, () => React.Re function sumValue (all: { value: BN }[]): BN { const total = new BN(0); - for (let i = 0; i < all.length; i++) { + for (let i = 0, count = all.length; i < count; i++) { total.iadd(all[i].value); } @@ -72,7 +72,7 @@ function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement ({ nominatorId: who.toString(), value: value.unwrap() diff --git a/packages/page-staking/src/Validators/CurrentList.tsx b/packages/page-staking/src/Validators/CurrentList.tsx index 98f39b49fa..4d43f38725 100644 --- a/packages/page-staking/src/Validators/CurrentList.tsx +++ b/packages/page-staking/src/Validators/CurrentList.tsx @@ -97,7 +97,7 @@ function getFiltered (isOwn: boolean, stakingOverview: DeriveStakingOverview | u function mapValidators (infos: ValidatorInfo[]): Record { const result: Record = {}; - for (let i = 0; i < infos.length; i++) { + for (let i = 0, count = infos.length; i < count; i++) { const info = infos[i]; result[info.key] = info; @@ -184,7 +184,7 @@ function CurrentList ({ className, favorites, hasQueries, isIntentions, isOwn, m /> } > - {list && list.map(([address, isElected, isFavorite]): React.ReactNode => ( + {list?.map(([address, isElected, isFavorite]): React.ReactNode => (
ownStashes && ownStashes.map(({ stashId }) => stashId), + () => ownStashes?.map(({ stashId }) => stashId), [ownStashes] ); diff --git a/packages/page-staking/src/useNominations.ts b/packages/page-staking/src/useNominations.ts index 56cbdc64be..c9838bfccb 100644 --- a/packages/page-staking/src/useNominations.ts +++ b/packages/page-staking/src/useNominations.ts @@ -12,14 +12,14 @@ import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks'; function extractNominators (nominations: [StorageKey, Option][]): NominatedByMap { const mapped: NominatedByMap = {}; - for (let i = 0; i < nominations.length; i++) { + for (let i = 0, nomCount = nominations.length; i < nomCount; i++) { const [key, optNoms] = nominations[i]; if (optNoms.isSome && key.args.length) { const nominatorId = key.args[0].toString(); const { submittedIn, targets } = optNoms.unwrap(); - for (let j = 0; j < targets.length; j++) { + for (let j = 0, tarCount = targets.length; j < tarCount; j++) { const validatorId = targets[j].toString(); if (!mapped[validatorId]) { diff --git a/packages/page-staking/src/useSortedTargets.ts b/packages/page-staking/src/useSortedTargets.ts index b7d372173f..a4892d3e8a 100644 --- a/packages/page-staking/src/useSortedTargets.ts +++ b/packages/page-staking/src/useSortedTargets.ts @@ -310,7 +310,7 @@ function useSortedTargetsImpl (favorites: string[], withLedger: boolean): Sorted minNominatorBond, minValidatorBond, ...( - inflation && inflation.stakedReturn + inflation?.stakedReturn ? addReturns(inflation, baseInfo) : baseInfo ) diff --git a/packages/page-staking2/src/Pools/Pool.tsx b/packages/page-staking2/src/Pools/Pool.tsx index 7021b02a9e..d421e8df73 100644 --- a/packages/page-staking2/src/Pools/Pool.tsx +++ b/packages/page-staking2/src/Pools/Pool.tsx @@ -41,7 +41,7 @@ function Pool ({ className = '', members, ownAccounts, params, poolId }: Props): ); const renderNominees = useCallback( - () => info && info.nominating.map((stashId, count): React.ReactNode => ( + () => info?.nominating.map((stashId, count): React.ReactNode => ( { const { t } = useTranslation(); const membersMap = useMembers(); - const [typeIndex, setTypeIndex] = useState(() => ownPools && ownPools.length ? 0 : 1); + const [typeIndex, setTypeIndex] = useState(() => ownPools?.length ? 0 : 1); const ownAccounts = useMemo( () => ownPools && arrayFlatten(ownPools.map(({ members }) => Object.keys(members))), @@ -81,7 +81,7 @@ function Pools ({ className, ids, ownPools, params }: Props): React.ReactElement emptySpinner={t('Retrieving nomination pools')} header={header} > - {membersMap && filtered && filtered.map((poolId) => ( + {membersMap && filtered?.map((poolId) => ( base && base.map((base) => ({ + () => base?.map((base) => ({ ...base, ...createAccounts(api, base.poolId) })), diff --git a/packages/page-staking2/src/useValidatorsAll.ts b/packages/page-staking2/src/useValidatorsAll.ts index 08b449c26d..8ced241968 100644 --- a/packages/page-staking2/src/useValidatorsAll.ts +++ b/packages/page-staking2/src/useValidatorsAll.ts @@ -36,7 +36,7 @@ function eventFilter (records: EventRecord[]): Changes { } function mapValidators (validators?: AccountId32[]): Validator[] | undefined { - return validators && validators.map((a) => { + return validators?.map((a) => { const stashId = a.toString(); return { diff --git a/packages/page-storage/src/Queries.tsx b/packages/page-storage/src/Queries.tsx index 61bda49b06..5906288ebe 100644 --- a/packages/page-storage/src/Queries.tsx +++ b/packages/page-storage/src/Queries.tsx @@ -13,7 +13,7 @@ interface Props { } function Queries ({ onRemove, value }: Props): React.ReactElement | null { - if (!value || !value.length) { + if (!value?.length) { return null; } diff --git a/packages/page-storage/src/Query.tsx b/packages/page-storage/src/Query.tsx index 342776bf1c..1bb4cb5784 100644 --- a/packages/page-storage/src/Query.tsx +++ b/packages/page-storage/src/Query.tsx @@ -123,7 +123,7 @@ function getCachedComponent (registry: Registry, query: QueryTypes): CacheInstan }); } - type = key.creator && key.creator.meta + type = key.creator?.meta ? queryTypeToString(registry, key) : 'Raw'; } diff --git a/packages/page-storage/src/Selection/Modules.tsx b/packages/page-storage/src/Selection/Modules.tsx index 3b47ee5eba..9b78c7fc8b 100644 --- a/packages/page-storage/src/Selection/Modules.tsx +++ b/packages/page-storage/src/Selection/Modules.tsx @@ -98,7 +98,7 @@ function expandKey (api: ApiPromise, key: QueryableStorageEntry<'promise'>): Key const isIterable = checkIterable(api.registry, type); return { - defaultValues: section === 'session' && type.isMap && api.consts.session && api.consts.session.dedupKeyPrefix + defaultValues: section === 'session' && type.isMap && api.consts.session?.dedupKeyPrefix ? [{ isValid: true, value: api.consts.session.dedupKeyPrefix.toHex() }] : null, isIterable, diff --git a/packages/page-tech-comm/src/App.tsx b/packages/page-tech-comm/src/App.tsx index ad386769ef..f63f9a2018 100644 --- a/packages/page-tech-comm/src/App.tsx +++ b/packages/page-tech-comm/src/App.tsx @@ -38,7 +38,7 @@ function TechCommApp ({ basePath, className, type }: Props): React.ReactElement< }, { name: 'proposals', - text: t('Proposals ({{count}})', { replace: { count: (proposalHashes && proposalHashes.length) || 0 } }) + text: t('Proposals ({{count}})', { replace: { count: proposalHashes?.length || 0 } }) } ], [proposalHashes, t]); diff --git a/packages/page-tech-comm/src/Proposals/Proposal.tsx b/packages/page-tech-comm/src/Proposals/Proposal.tsx index 54bd1e0f14..e5da23a8ce 100644 --- a/packages/page-tech-comm/src/Proposals/Proposal.tsx +++ b/packages/page-tech-comm/src/Proposals/Proposal.tsx @@ -31,7 +31,7 @@ function Proposal ({ className = '', imageHash, isMember, members, prime, type } const { hasFailed, isCloseable, isVoteable, remainingBlocks } = useVotingStatus(derive?.votes, members.length, type); const modLocation = useCollectiveInstance(type); - if (!modLocation || !derive || !derive.votes) { + if (!modLocation || !derive?.votes) { return null; } diff --git a/packages/page-treasury/src/Overview/Summary.tsx b/packages/page-treasury/src/Overview/Summary.tsx index a28eca02b0..487bed1e7d 100644 --- a/packages/page-treasury/src/Overview/Summary.tsx +++ b/packages/page-treasury/src/Overview/Summary.tsx @@ -25,7 +25,7 @@ function Summary ({ approvalCount, proposalCount }: Props): React.ReactElement

value && value.sub(pendingBounties).sub(pendingProposals), + () => value?.sub(pendingBounties).sub(pendingProposals), [value, pendingBounties, pendingProposals] ); diff --git a/packages/page-treasury/src/Tips/Tips.tsx b/packages/page-treasury/src/Tips/Tips.tsx index 5939e36019..b06dfce664 100644 --- a/packages/page-treasury/src/Tips/Tips.tsx +++ b/packages/page-treasury/src/Tips/Tips.tsx @@ -86,7 +86,7 @@ function Tips ({ className = '', defaultId, hashes, isMember, members, onSelectT )} header={headerRef.current} > - {tips && tips.map(([hash, tip]): React.ReactNode => ( + {tips?.map(([hash, tip]): React.ReactNode => ( { empty={hashes && t('No call hashes found')} header={headerRef.current} > - {hashes && hashes.map((h) => ( + {hashes?.map((h) => (

hashes && hashes.map((h) => h.toHex()), + () => hashes?.map((h) => h.toHex()), [hashes] ); } diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index d3295c4478..2b6fc9ed62 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -178,7 +178,7 @@ async function loadOnReady (api: ApiPromise, endpoint: LinkOption | null, inject const defaultSection = Object.keys(api.tx)[0]; const defaultMethod = Object.keys(api.tx[defaultSection])[0]; const apiDefaultTx = api.tx[defaultSection][defaultMethod]; - const apiDefaultTxSudo = (api.tx.system && api.tx.system.setCode) || apiDefaultTx; + const apiDefaultTxSudo = api.tx.system?.setCode || apiDefaultTx; setDeriveCache(api.genesisHash.toHex(), deriveMapCache); @@ -207,7 +207,7 @@ async function getLightProvider (chain: string): Promise { if (sc !== 'substrate-connect') { throw new Error(`Cannot connect to non substrate-connect protocol ${chain}`); - } else if (!relaySpecs[relayName] || (paraName && (!lightSpecs[relayName] || !lightSpecs[relayName][paraName]))) { + } else if (!relaySpecs[relayName] || (paraName && !lightSpecs[relayName]?.[paraName])) { throw new Error(`Unable to construct light chain ${chain}`); } @@ -264,7 +264,7 @@ export function ApiCtxRoot ({ apiUrl, children, isElectron, store }: Props): Rea const [extensions, setExtensions] = useState(); const apiEndpoint = useEndpoint(apiUrl); const relayUrls = useMemo( - () => (apiEndpoint && apiEndpoint.valueRelay && isNumber(apiEndpoint.paraId) && (apiEndpoint.paraId < 2000)) + () => (apiEndpoint?.valueRelay && isNumber(apiEndpoint.paraId) && (apiEndpoint.paraId < 2000)) ? apiEndpoint.valueRelay : null, [apiEndpoint] diff --git a/packages/react-api/src/hoc/api.tsx b/packages/react-api/src/hoc/api.tsx index 3f2cc1a1a0..9f058a8a77 100644 --- a/packages/react-api/src/hoc/api.tsx +++ b/packages/react-api/src/hoc/api.tsx @@ -17,7 +17,7 @@ export default function withApi

(Inner: React.ComponentType return ( {(apiProps?: ApiProps): React.ReactNode => { - assert(apiProps && apiProps.api, 'Application root must be wrapped inside \'react-api/Api\' to provide API context'); + assert(apiProps?.api, 'Application root must be wrapped inside \'react-api/Api\' to provide API context'); return ( (endpoint: string, { at, at !!apiSection ) || [{}, expanded[0][1], expanded[0][2], expanded[0][3]]; - assert(apiSection && apiSection[method], `Unable to find api.${area}.${section}.${method}`); + assert(apiSection?.[method], `Unable to find api.${area}.${section}.${method}`); const meta = apiSection[method].meta; diff --git a/packages/react-api/src/hoc/observable.tsx b/packages/react-api/src/hoc/observable.tsx index 6e527b6801..8d057a6c3e 100644 --- a/packages/react-api/src/hoc/observable.tsx +++ b/packages/react-api/src/hoc/observable.tsx @@ -82,7 +82,7 @@ export default function withObservable (observable: Observable

, { callO return ( - {render && render(callResult)}{children} + {render?.(callResult)}{children} ); } diff --git a/packages/react-api/src/hoc/types.ts b/packages/react-api/src/hoc/types.ts index 0c8176d309..e5e75a649a 100644 --- a/packages/react-api/src/hoc/types.ts +++ b/packages/react-api/src/hoc/types.ts @@ -29,7 +29,7 @@ export interface Options { export type RenderFn = (value?: any) => any; -export type StorageTransform = (input: any, index: number) => unknown | null; +export type StorageTransform = (input: any, index: number) => unknown; export type HOC = (Component: React.ComponentType, defaultProps?: DefaultProps, render?: RenderFn) => React.ComponentType; diff --git a/packages/react-api/src/util/intervalObservable.ts b/packages/react-api/src/util/intervalObservable.ts index 174b79041f..73b4f67e8a 100644 --- a/packages/react-api/src/util/intervalObservable.ts +++ b/packages/react-api/src/util/intervalObservable.ts @@ -11,7 +11,7 @@ const interval$ = interval(500); export function intervalObservable (that: React.Component): Subscription { return interval$.subscribe((): void => { - const elapsed = Date.now() - ((that.state.callUpdatedAt as number) || 0); + const elapsed = Date.now() - (that.state.callUpdatedAt || 0); const callUpdated = elapsed <= 1500; if (callUpdated !== that.state.callUpdated) { diff --git a/packages/react-api/src/util/triggerChange.ts b/packages/react-api/src/util/triggerChange.ts index 9511f91741..ad8df5c891 100644 --- a/packages/react-api/src/util/triggerChange.ts +++ b/packages/react-api/src/util/triggerChange.ts @@ -6,7 +6,7 @@ import type { OnChangeCb } from '../types.js'; import { isFunction, isObservable } from '@polkadot/util'; export function triggerChange (value?: unknown, ...callOnResult: (OnChangeCb | undefined)[]): void { - if (!callOnResult || !callOnResult.length) { + if (!callOnResult?.length) { return; } diff --git a/packages/react-components/package.json b/packages/react-components/package.json index bc4268af66..b95047510d 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -19,15 +19,15 @@ "@fortawesome/fontawesome-svg-core": "^6.4.0", "@fortawesome/free-solid-svg-icons": "^6.4.0", "@fortawesome/react-fontawesome": "^0.2.0", - "@polkadot/keyring": "^12.3.2", + "@polkadot/keyring": "^12.4.1", "@polkadot/react-api": "^0.132.2-55-x", "@polkadot/react-identicon": "^3.5.1", "@polkadot/react-qr": "^3.5.1", "@polkadot/react-query": "^0.132.2-55-x", "@polkadot/ui-keyring": "^3.5.1", "@polkadot/ui-settings": "^3.5.1", - "@polkadot/util": "^12.3.2", - "@polkadot/util-crypto": "^12.3.2", + "@polkadot/util": "^12.4.1", + "@polkadot/util-crypto": "^12.4.1", "chart.js": "^4.3.0", "chartjs-plugin-annotation": "^3.0.1", "chartjs-plugin-crosshair": "^1.2.0", diff --git a/packages/react-components/src/AccountIndex.tsx b/packages/react-components/src/AccountIndex.tsx index 8dd928277c..d0db7cf011 100644 --- a/packages/react-components/src/AccountIndex.tsx +++ b/packages/react-components/src/AccountIndex.tsx @@ -31,7 +31,7 @@ function AccountIndex ({ children, className = '', defaultValue, label, value }: [info] ); - if (!api || !api.query.indices) { + if (!api?.query.indices) { return null; } diff --git a/packages/react-components/src/AccountSidebar/AddressSection.tsx b/packages/react-components/src/AccountSidebar/AddressSection.tsx index 723cb8414d..fb089437fa 100644 --- a/packages/react-components/src/AccountSidebar/AddressSection.tsx +++ b/packages/react-components/src/AccountSidebar/AddressSection.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/page-accounts authors & contributors +// Copyright 2017-2023 @polkadot/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { AddressFlags } from '@polkadot/react-hooks/types'; diff --git a/packages/react-components/src/AccountSidebar/Multisig.tsx b/packages/react-components/src/AccountSidebar/Multisig.tsx index 5811f2f74c..46c9f57515 100644 --- a/packages/react-components/src/AccountSidebar/Multisig.tsx +++ b/packages/react-components/src/AccountSidebar/Multisig.tsx @@ -37,7 +37,7 @@ function Multisig ({ isMultisig, meta }: Props): React.ReactElement | nul

{t('signatories')}
- {(who as string[])?.map((address) => ( + {who?.map((address) => ( diff --git a/packages/react-components/src/AccountSidebar/SidebarEditableSection.tsx b/packages/react-components/src/AccountSidebar/SidebarEditableSection.tsx index 0de5e73c63..b496873c44 100644 --- a/packages/react-components/src/AccountSidebar/SidebarEditableSection.tsx +++ b/packages/react-components/src/AccountSidebar/SidebarEditableSection.tsx @@ -1,4 +1,4 @@ -// Copyright 2017-2023 @polkadot/page-accounts authors & contributors +// Copyright 2017-2023 @polkadot/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 import React, { useCallback, useEffect, useMemo } from 'react'; diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 33625c895e..9b634a659c 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -158,7 +158,7 @@ function calcBonded (stakingInfo?: DeriveStakingAccount, bonded?: boolean | BN[] .filter((value) => value.gt(BN_ZERO)); own = bonded[0]; - } else if (stakingInfo && stakingInfo.stakingLedger && stakingInfo.stakingLedger.active && stakingInfo.accountId.eq(stakingInfo.stashId)) { + } else if (stakingInfo?.stakingLedger?.active && stakingInfo.accountId.eq(stakingInfo.stashId)) { own = stakingInfo.stakingLedger.active.unwrap(); } @@ -200,7 +200,7 @@ function renderValidatorPrefs ({ stakingInfo, withValidatorPrefs = false }: Prop ? DEFAULT_PREFS : withValidatorPrefs; - if (!validatorPrefsDisplay || !stakingInfo || !stakingInfo.validatorPrefs) { + if (!validatorPrefsDisplay || !stakingInfo?.validatorPrefs) { return null; } @@ -442,7 +442,7 @@ function createBalanceItems (formatIndex: number, lookup: Record ); } - if (bestNumber && convictionLocks && convictionLocks.length) { + if (bestNumber && convictionLocks?.length) { const max = convictionLocks.reduce((max, { total }) => bnMax(max, total), BN_ZERO); allItems.push( @@ -506,7 +506,7 @@ function createBalanceItems (formatIndex: number, lookup: Record summary={ } > @@ -566,7 +566,7 @@ function AddressInfo (props: Props): React.ReactElement {
{renderBalances(props, lookup.current, bestNumber, t)} - {withHexSessionId && withHexSessionId[0] && ( + {withHexSessionId?.[0] && ( <>