diff --git a/packages/page-accounts/src/Accounts/index.spec.ts b/packages/page-accounts/src/Accounts/index.spec.ts index 2c2cb620f5f..2cb2c30a37f 100644 --- a/packages/page-accounts/src/Accounts/index.spec.ts +++ b/packages/page-accounts/src/Accounts/index.spec.ts @@ -381,6 +381,7 @@ describe('Accounts page', () => { mockApiHooks.setDelegations([{ asDelegating: { target: bob as unknown as AccountId } as unknown as VotingDelegating, isDelegating: true } as Voting]); mockApiHooks.setProxies([[[{ delegate: alice as unknown as AccountId, proxyType: { isAny: true, isGovernance: true, isNonTransfer: true, isStaking: true, toNumber: () => 1 } } as unknown as ProxyDefinition], new BN(1)]]); }); + describe('when genesis hash is not set', () => { beforeEach(async () => { accountsPage.renderAccountsWithDefaultAddresses( diff --git a/packages/page-accounts/src/modals/MultisigApprove.tsx b/packages/page-accounts/src/modals/MultisigApprove.tsx index 06ef79702d8..3a40a1aee2c 100644 --- a/packages/page-accounts/src/modals/MultisigApprove.tsx +++ b/packages/page-accounts/src/modals/MultisigApprove.tsx @@ -51,7 +51,7 @@ function MultisigApprove ({ className = '', onClose, ongoing, threshold, who }: const { allAccounts } = useAccounts(); const [callHex, setCallHex] = useState(''); const [{ callData, callError, callInfo }, setCallData] = useState(EMPTY_CALL); - const { encodedCallLength, v1Weight } = useWeight(callData); + const { encodedCallLength, weight } = useWeight(callData); const [hash, setHash] = useState(() => ongoing[0][0].toHex()); const [{ isMultiCall, multisig }, setMultisig] = useState(() => ({ isMultiCall: false, multisig: null })); const [isCallOverride, setCallOverride] = useState(true); @@ -139,20 +139,22 @@ function MultisigApprove ({ className = '', onClose, ongoing, threshold, who }: ? isMultiCall && isCallOverride ? callData ? multiMod.asMulti.meta.args.length === 6 - ? multiMod.asMulti(threshold, others, multisig.when, callData.toHex(), false, v1Weight) + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + ? multiMod.asMulti(threshold, others, multisig.when, callData.toHex(), false, weight as any) // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore (We are doing toHex here since we have a Vec input) : multiMod.asMulti(threshold, others, multisig.when, callData) : null : multiMod.approveAsMulti.meta.args.length === 5 - ? multiMod.approveAsMulti(threshold, others, multisig.when, hash, v1Weight) + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + ? multiMod.approveAsMulti(threshold, others, multisig.when, hash, weight as any) // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore : multiMod.approveAsMulti(threshold, others, multisig.when, hash) : multiMod.cancelAsMulti(threshold, others, multisig.when, hash) : null ); - }, [api, callData, hash, isCallOverride, isMultiCall, others, multisig, threshold, type, v1Weight]); + }, [api, callData, hash, isCallOverride, isMultiCall, others, multisig, threshold, type, weight]); const isAye = type === 'aye'; diff --git a/packages/page-council/src/Motions/Close.tsx b/packages/page-council/src/Motions/Close.tsx index a48645851c2..bc7f94d93b3 100644 --- a/packages/page-council/src/Motions/Close.tsx +++ b/packages/page-council/src/Motions/Close.tsx @@ -22,7 +22,7 @@ function Close ({ hasFailed, hash, idNumber, proposal }: Props): React.ReactElem const { api } = useApi(); const [isOpen, toggleOpen] = useToggle(); const [accountId, setAccountId] = useState(null); - const { encodedCallLength, v1Weight } = useWeight(proposal); + const { encodedCallLength, weight } = useWeight(proposal); const modLocation = useCollectiveInstance('council'); // protect against older versions @@ -63,7 +63,7 @@ function Close ({ hasFailed, hash, idNumber, proposal }: Props): React.ReactElem api.tx[modLocation].close.meta.args.length === 4 ? hasFailed ? [hash, idNumber, 0, 0] - : [hash, idNumber, v1Weight, encodedCallLength] + : [hash, idNumber, weight, encodedCallLength] : [hash, idNumber] } tx={api.tx[modLocation].closeOperational || api.tx[modLocation].close} diff --git a/packages/page-explorer/src/BlockInfo/ByHash.tsx b/packages/page-explorer/src/BlockInfo/ByHash.tsx index 8844d3fbca0..bd7e30d06b5 100644 --- a/packages/page-explorer/src/BlockInfo/ByHash.tsx +++ b/packages/page-explorer/src/BlockInfo/ByHash.tsx @@ -64,6 +64,11 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme [api, runtimeVersion] ); + const systemEvents = useMemo( + () => events && events.filter(({ record: { phase } }) => !phase.isApplyExtrinsic), + [events] + ); + useEffect((): void => { value && Promise .all([ @@ -162,7 +167,7 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme !phase.isApplyExtrinsic)} + events={systemEvents} label={t('system events')} /> diff --git a/packages/page-explorer/src/BlockInfo/Summary.tsx b/packages/page-explorer/src/BlockInfo/Summary.tsx index f4560e41e13..ab86cf9e61c 100644 --- a/packages/page-explorer/src/BlockInfo/Summary.tsx +++ b/packages/page-explorer/src/BlockInfo/Summary.tsx @@ -30,7 +30,11 @@ function extractEventDetails (events?: KeyedEvent[] | null): [BN?, BN?, BN?] { ? transfers.iadd(data[2] as Balance) : transfers, section === 'system' && ['ExtrinsicFailed', 'ExtrinsicSuccess'].includes(method) - ? weight.iadd(convertWeight(((method === 'ExtrinsicSuccess' ? data[0] : data[1]) as DispatchInfo).weight).v1Weight) + ? weight.iadd( + convertWeight( + ((method === 'ExtrinsicSuccess' ? data[0] : data[1]) as DispatchInfo).weight + ).v1Weight + ) : weight ], [new BN(0), new BN(0), new BN(0)]) : []; diff --git a/packages/page-tech-comm/src/Proposals/Close.tsx b/packages/page-tech-comm/src/Proposals/Close.tsx index 9f5df83c1bd..bcb8dc2ad6b 100644 --- a/packages/page-tech-comm/src/Proposals/Close.tsx +++ b/packages/page-tech-comm/src/Proposals/Close.tsx @@ -24,7 +24,7 @@ function Close ({ hasFailed, hash, idNumber, proposal, type }: Props): React.Rea const { api } = useApi(); const [isOpen, toggleOpen] = useToggle(); const [accountId, setAccountId] = useState(null); - const { encodedCallLength, v1Weight } = useWeight(proposal); + const { encodedCallLength, weight } = useWeight(proposal); const modLocation = useCollectiveInstance(type); if (!modLocation) { @@ -64,7 +64,7 @@ function Close ({ hasFailed, hash, idNumber, proposal, type }: Props): React.Rea api.tx[modLocation].close.meta.args.length === 4 ? hasFailed ? [hash, idNumber, 0, 0] - : [hash, idNumber, v1Weight, encodedCallLength] + : [hash, idNumber, weight, encodedCallLength] : [hash, idNumber] } tx={api.tx[modLocation].closeOperational || api.tx[modLocation].close} diff --git a/packages/react-hooks/src/useTxBatch.ts b/packages/react-hooks/src/useTxBatch.ts index 7c79022b86e..43cc43d054c 100644 --- a/packages/react-hooks/src/useTxBatch.ts +++ b/packages/react-hooks/src/useTxBatch.ts @@ -50,11 +50,8 @@ function useTxBatchImpl (txs?: SubmittableExtrinsic<'promise'>[] | null | false, txs && txs.length && allAccounts[0] && api.call.transactionPaymentApi && nextTick(async (): Promise => { try { - const weight = convertWeight( - ( - await txs[0].paymentInfo(allAccounts[0]) - ).weight - ); + const paymentInfo = await txs[0].paymentInfo(allAccounts[0]); + const weight = convertWeight(paymentInfo.weight); const maxBlock = convertWeight( api.consts.system.blockWeights ? api.consts.system.blockWeights.maxBlock @@ -65,8 +62,7 @@ function useTxBatchImpl (txs?: SubmittableExtrinsic<'promise'>[] | null | false, weight.v1Weight.isZero() ? prev : Math.floor( - maxBlock - .v1Weight + maxBlock.v1Weight .muln(64) // 65% of the block weight on a single extrinsic (64 for safety) .div(weight.v1Weight) .toNumber() / 100 diff --git a/packages/react-hooks/src/useWeight.ts b/packages/react-hooks/src/useWeight.ts index 47f197a52d4..90ae76c8e34 100644 --- a/packages/react-hooks/src/useWeight.ts +++ b/packages/react-hooks/src/useWeight.ts @@ -7,7 +7,7 @@ import type { BN } from '@polkadot/util'; import { useEffect, useState } from 'react'; -import { BN_ZERO, nextTick } from '@polkadot/util'; +import { BN_ZERO, isFunction, nextTick, objectSpread } from '@polkadot/util'; import { createNamedHook } from './createNamedHook'; import { useApi } from './useApi'; @@ -26,16 +26,19 @@ interface V2WeightConstruct { interface Result { encodedCallLength: number; + isWeightV2: boolean; v1Weight: BN; v2Weight: V2WeightConstruct; + weight: BN | V2WeightConstruct; } // a random address that we are using for our queries const ZERO_ACCOUNT = '5CAUdnwecHGxxyr5vABevAfZ34Fi4AaraDRMwfDQXQ52PXqg'; -const EMPTY_STATE: Result = { +const EMPTY_STATE: Partial = { encodedCallLength: 0, v1Weight: BN_ZERO, - v2Weight: { refTime: BN_ZERO } + v2Weight: { refTime: BN_ZERO }, + weight: BN_ZERO }; // return both v1 & v2 weight structures (would depend on actual use) @@ -55,7 +58,9 @@ export function convertWeight (weight: V1Weight | V2Weight): { v1Weight: BN, v2W function useWeightImpl (call?: Call | null): Result { const { api } = useApi(); const mountedRef = useIsMountedRef(); - const [state, setState] = useState(EMPTY_STATE); + const [state, setState] = useState(() => objectSpread({ + isWeightV2: !isFunction(api.registry.createType('Weight').toBn) + }, EMPTY_STATE)); useEffect((): void => { if (call && api.call.transactionPaymentApi) { @@ -65,13 +70,24 @@ function useWeightImpl (call?: Call | null): Result { (await api.tx(call).paymentInfo(ZERO_ACCOUNT)).weight ); - mountedRef.current && setState({ encodedCallLength: call.encodedLength, v1Weight, v2Weight }); + mountedRef.current && setState((prev) => + objectSpread({}, prev, { + encodedCallLength: call.encodedLength, + v1Weight, + v2Weight, + weight: prev.isWeightV2 + ? v2Weight + : v1Weight + }) + ); } catch (error) { console.error(error); } }); } else { - setState(EMPTY_STATE); + setState((prev) => + objectSpread({}, prev, EMPTY_STATE) + ); } }, [api, call, mountedRef]); diff --git a/packages/react-signer/src/TxSigned.tsx b/packages/react-signer/src/TxSigned.tsx index bc1df7d38ad..1bc7fbbef44 100644 --- a/packages/react-signer/src/TxSigned.tsx +++ b/packages/react-signer/src/TxSigned.tsx @@ -120,12 +120,13 @@ async function wrapTx (api: ApiPromise, currentItem: QueueTx, { isMultiCall, mul if (multiRoot) { const multiModule = api.tx.multisig ? 'multisig' : 'utility'; + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const [info, { weight }] = await Promise.all([ api.query[multiModule].multisigs>(multiRoot, tx.method.hash), - tx.paymentInfo(multiRoot) + tx.paymentInfo(multiRoot) as Promise<{ weight: any }> ]); - console.log('multisig max weight=', weight.toString()); + console.log('multisig max weight=', (weight as string).toString()); const { threshold, who } = extractExternal(multiRoot); const others = who.filter((w) => w !== signAddress); @@ -138,11 +139,13 @@ async function wrapTx (api: ApiPromise, currentItem: QueueTx, { isMultiCall, mul tx = isMultiCall ? api.tx[multiModule].asMulti.meta.args.length === 6 // We are doing toHex here since we have a Vec input + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument ? api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method.toHex(), false, weight) // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore : api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method) : api.tx[multiModule].approveAsMulti.meta.args.length === 5 + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument ? api.tx[multiModule].approveAsMulti(threshold, others, timepoint, tx.method.hash, weight) // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore diff --git a/packages/test-support/src/pages/Page.tsx b/packages/test-support/src/pages/Page.tsx index bea1184f8d0..2efcab596e7 100644 --- a/packages/test-support/src/pages/Page.tsx +++ b/packages/test-support/src/pages/Page.tsx @@ -120,6 +120,7 @@ export abstract class Page { }); const noop = () => Promise.resolve(() => { /**/ }); + const registry = new TypeRegistry(); const api = { consts: { babe: { @@ -153,7 +154,7 @@ export abstract class Page { account: noop } }, - genesisHash: new TypeRegistry().createType('Hash', POLKADOT_GENESIS), + genesisHash: registry.createType('Hash', POLKADOT_GENESIS), query: { democracy: { votingOf: noop @@ -165,6 +166,8 @@ export abstract class Page { registry: { chainDecimals: [12], chainTokens: ['Unit'], + createType: (...args: Parameters) => + registry.createType(...args), lookup: { names: [] }