diff --git a/packages/page-accounts/src/Accounts/modals/MultisigApprove.tsx b/packages/page-accounts/src/Accounts/modals/MultisigApprove.tsx index c5ea44eda8..7631ce3b2f 100644 --- a/packages/page-accounts/src/Accounts/modals/MultisigApprove.tsx +++ b/packages/page-accounts/src/Accounts/modals/MultisigApprove.tsx @@ -9,7 +9,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import styled from 'styled-components'; import { registry } from '@polkadot/react-api'; import { Dropdown, InputAddress, Modal, Toggle, TxButton, Input } from '@polkadot/react-components'; -import { useAccounts, useApi } from '@polkadot/react-hooks'; +import { useAccounts, useApi, useWeight } from '@polkadot/react-hooks'; import { assert, isHex } from '@polkadot/util'; import { useTranslation } from '../../translate'; @@ -38,6 +38,7 @@ function MultisigApprove ({ className = '', onClose, ongoing, threshold, who }: const { api } = useApi(); const { allAccounts } = useAccounts(); const [callData, setCallData] = useState(null); + const [callWeight] = useWeight(callData); const [hash, setHash] = useState(ongoing[0][0].toHex()); const [{ isMultiCall, multisig }, setMultisig] = useState({ isMultiCall: false, multisig: null }); const [isCallOverride, setCallOverride] = useState(true); @@ -104,17 +105,21 @@ function MultisigApprove ({ className = '', onClose, ongoing, threshold, who }: ? type === 'aye' ? isMultiCall && isCallOverride ? callData - ? multiMod.asMulti.meta.args.length === 5 + ? multiMod.asMulti.meta.args.length === 6 // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - ? multiMod.asMulti(threshold, others, multisig.when, callData, false) + // @ts-ignore (We are doing toHex here since we have a Vec input) + ? multiMod.asMulti(threshold, others, multisig.when, callData.toHex(), false, callWeight) : multiMod.asMulti(threshold, others, multisig.when, callData) : null - : multiMod.approveAsMulti(threshold, others, multisig.when, hash) + : multiMod.approveAsMulti.meta.args.length === 5 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + ? multiMod.approveAsMulti(threshold, others, multisig.when, hash, callWeight) + : multiMod.approveAsMulti(threshold, others, multisig.when, hash) : multiMod.cancelAsMulti(threshold, others, multisig.when, hash) : null ); - }, [api, callData, hash, isCallOverride, isMultiCall, others, multisig, threshold, type]); + }, [api, callData, callWeight, hash, isCallOverride, isMultiCall, others, multisig, threshold, type]); // when the actual call input changes, create a call and set it const _setCallData = useCallback( diff --git a/packages/page-council/src/Motions/Close.tsx b/packages/page-council/src/Motions/Close.tsx index c7dd92ba14..75caed53b7 100644 --- a/packages/page-council/src/Motions/Close.tsx +++ b/packages/page-council/src/Motions/Close.tsx @@ -24,8 +24,7 @@ function Close ({ hasFailed, hash, idNumber, isDisabled, members, proposal }: Pr const { api } = useApi(); const [isOpen, toggleOpen] = useToggle(); const [accountId, setAccountId] = useState(null); - const [proposalLength] = useState(proposal.encodedLength); - const proposalWeight = useWeight(proposal); + const [proposalWeight, proposalLength] = useWeight(proposal); return ( <> diff --git a/packages/page-tech-comm/src/Proposals/Close.tsx b/packages/page-tech-comm/src/Proposals/Close.tsx index a63588d623..b3200b8590 100644 --- a/packages/page-tech-comm/src/Proposals/Close.tsx +++ b/packages/page-tech-comm/src/Proposals/Close.tsx @@ -24,8 +24,7 @@ function Close ({ hasFailed, hash, idNumber, isDisabled, members, proposal }: Pr const { api } = useApi(); const [isOpen, toggleOpen] = useToggle(); const [accountId, setAccountId] = useState(null); - const [proposalLength] = useState(proposal.encodedLength); - const proposalWeight = useWeight(proposal); + const [proposalWeight, proposalLength] = useWeight(proposal); return ( <> diff --git a/packages/react-hooks/src/useWeight.ts b/packages/react-hooks/src/useWeight.ts index 631196a7fa..6e143f84df 100644 --- a/packages/react-hooks/src/useWeight.ts +++ b/packages/react-hooks/src/useWeight.ts @@ -13,19 +13,24 @@ import useIsMountedRef from './useIsMountedRef'; // a random address that we are using for our queries const ZERO_ACCOUNT = '5CAUdnwecHGxxyr5vABevAfZ34Fi4AaraDRMwfDQXQ52PXqg'; +const EMPTY_STATE: [BN, number] = [BN_ZERO, 0]; // for a given call, calculate the weight -export default function useWeight (call: Call): BN { +export default function useWeight (call?: Call | null): [BN, number] { const { api } = useApi(); const mountedRef = useIsMountedRef(); - const [weight, setWeight] = useState(BN_ZERO); + const [state, setState] = useState(EMPTY_STATE); useEffect((): void => { - api.tx(call) - .paymentInfo(ZERO_ACCOUNT) - .then(({ weight }) => mountedRef.current && setWeight(weight)) - .catch(console.error); + if (call) { + api.tx(call) + .paymentInfo(ZERO_ACCOUNT) + .then(({ weight }) => mountedRef.current && setState([weight, call.encodedLength])) + .catch(console.error); + } else { + setState(EMPTY_STATE); + } }, [api, call, mountedRef]); - return weight; + return state; } diff --git a/packages/react-signer/src/TxSigned.tsx b/packages/react-signer/src/TxSigned.tsx index 4b670d8ed6..d7bdc22a50 100644 --- a/packages/react-signer/src/TxSigned.tsx +++ b/packages/react-signer/src/TxSigned.tsx @@ -108,6 +108,7 @@ async function wrapTx (api: ApiPromise, currentItem: QueueTx, { isMultiCall, mul if (multiRoot) { const multiModule = api.tx.multisig ? 'multisig' : 'utility'; const info = await api.query[multiModule].multisigs>(multiRoot, tx.method.hash); + const { weight } = await tx.paymentInfo(multiRoot); const { threshold, who } = extractExternal(multiRoot); const others = who.filter((w) => w !== signAddress); let timepoint: Timepoint | null = null; @@ -117,12 +118,16 @@ async function wrapTx (api: ApiPromise, currentItem: QueueTx, { isMultiCall, mul } tx = isMultiCall - ? api.tx[multiModule].asMulti.meta.args.length === 5 + ? api.tx[multiModule].asMulti.meta.args.length === 6 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore (We are doing toHex here since we have a Vec input) + ? api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method.toHex(), false, weight) + : api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method) + : api.tx[multiModule].approveAsMulti.meta.args.length === 5 // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - ? api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method, false) - : api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method) - : api.tx[multiModule].approveAsMulti(threshold, others, timepoint, tx.method.hash); + ? api.tx[multiModule].approveAsMulti(threshold, others, timepoint, tx.method.hash, weight) + : api.tx[multiModule].approveAsMulti(threshold, others, timepoint, tx.method.hash); } return tx;