diff --git a/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx b/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx index 8cba5c2d6a..9aa1b810df 100644 --- a/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx +++ b/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx @@ -4,6 +4,7 @@ import React, { useEffect, useState } from 'react'; import { Dropdown, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -24,6 +25,7 @@ const JUDGEMENT_ENUM = [ function RegistrarJudgement ({ address, registrars, toggleJudgement }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [addresses] = useState(registrars.map(({ address }) => address)); const [judgementAccountId, setJudgementAccountId] = useState(null); const [judgementEnum, setJudgementEnum] = useState(2); // Reasonable @@ -73,7 +75,7 @@ function RegistrarJudgement ({ address, registrars, toggleJudgement }: Props): R label={t('Judge')} onStart={toggleJudgement} params={[registrarIndex, address, judgementEnum]} - tx='identity.provideJudgement' + tx={api.tx.identity.provideJudgement} /> diff --git a/packages/page-accounts/src/modals/Delegate.tsx b/packages/page-accounts/src/modals/Delegate.tsx index 40b2836ba6..b706b5d2d4 100644 --- a/packages/page-accounts/src/modals/Delegate.tsx +++ b/packages/page-accounts/src/modals/Delegate.tsx @@ -8,6 +8,7 @@ import BN from 'bn.js'; import React, { useState } from 'react'; import { ConvictionDropdown, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { BalanceFree } from '@polkadot/react-query'; import { BN_ZERO } from '@polkadot/util'; @@ -24,6 +25,7 @@ interface Props { function Delegate ({ onClose, previousAmount, previousConviction, previousDelegatedAccount, previousDelegatingAccount }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [amountError, setAmountError] = useState(null); const [maxBalance] = useState(); const [amount, setAmount] = useState(previousAmount); @@ -111,8 +113,7 @@ function Delegate ({ onClose, previousAmount, previousConviction, previousDelega icon='trash-alt' label={t('Undelegate')} onStart={onClose} - params={[]} - tx='democracy.undelegate' + tx={api.tx.democracy.undelegate} /> )} diff --git a/packages/page-accounts/src/modals/IdentityMain.tsx b/packages/page-accounts/src/modals/IdentityMain.tsx index 8344c75e8d..8d600e4964 100644 --- a/packages/page-accounts/src/modals/IdentityMain.tsx +++ b/packages/page-accounts/src/modals/IdentityMain.tsx @@ -253,8 +253,7 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React isDisabled={!gotPreviousIdentity} label={t('Clear Identity')} onStart={onClose} - params={[]} - tx='identity.clearIdentity' + tx={api.tx.identity.clearIdentity} /> ('Set Identity')} onStart={onClose} params={[info]} - tx='identity.setIdentity' + tx={api.tx.identity.setIdentity} /> diff --git a/packages/page-accounts/src/modals/IdentitySub.tsx b/packages/page-accounts/src/modals/IdentitySub.tsx index 1e1933ce26..a36487795d 100644 --- a/packages/page-accounts/src/modals/IdentitySub.tsx +++ b/packages/page-accounts/src/modals/IdentitySub.tsx @@ -173,7 +173,7 @@ function IdentitySubModal ({ address, className, onClose }: Props): React.ReactE params={[ infos.map(([address, raw]) => [address, { raw }]) ]} - tx='identity.setSubs' + tx={api.tx.identity.setSubs} /> )} diff --git a/packages/page-accounts/src/modals/ProxyOverview.tsx b/packages/page-accounts/src/modals/ProxyOverview.tsx index 72b204083d..c8fb801eb6 100644 --- a/packages/page-accounts/src/modals/ProxyOverview.tsx +++ b/packages/page-accounts/src/modals/ProxyOverview.tsx @@ -324,8 +324,7 @@ function ProxyOverview ({ className, onClose, previousProxy, proxiedAccount }: P icon='trash-alt' label={t('Clear all')} onStart={onClose} - params={[]} - tx='proxy.removeProxies' + tx={api.tx.proxy.removeProxies} /> )} (null); return ( @@ -43,7 +45,7 @@ function RecoverAccount ({ address, className = '', onClose }: Props): React.Rea label={t('Start recovery')} onStart={onClose} params={[recover]} - tx='recovery.initiateRecovery' + tx={api.tx.recovery.initiateRecovery} /> diff --git a/packages/page-accounts/src/modals/RecoverSetup.tsx b/packages/page-accounts/src/modals/RecoverSetup.tsx index 63ea878e2a..8856c8c1de 100644 --- a/packages/page-accounts/src/modals/RecoverSetup.tsx +++ b/packages/page-accounts/src/modals/RecoverSetup.tsx @@ -5,6 +5,7 @@ import BN from 'bn.js'; import React, { useState } from 'react'; import { InputAddress, InputAddressMulti, InputNumber, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { sortAddresses } from '@polkadot/util-crypto'; import useKnownAddresses from '../Accounts/useKnownAddresses'; @@ -20,6 +21,7 @@ const MAX_HELPERS = 16; function RecoverSetup ({ address, className = '', onClose }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const availableHelpers = useKnownAddresses(address); const [delay, setDelay] = useState(); const [helpers, setHelpers] = useState([]); @@ -94,7 +96,7 @@ function RecoverSetup ({ address, className = '', onClose }: Props): React.React label={t('Make recoverable')} onStart={onClose} params={[sortAddresses(helpers), threshold, delay]} - tx='recovery.createRecovery' + tx={api.tx.recovery.createRecovery} /> diff --git a/packages/page-accounts/src/modals/Transfer.tsx b/packages/page-accounts/src/modals/Transfer.tsx index a238e93c75..96458d91d7 100644 --- a/packages/page-accounts/src/modals/Transfer.tsx +++ b/packages/page-accounts/src/modals/Transfer.tsx @@ -185,11 +185,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send ? [recipientId, maxTransfer] : [recipientId, amount] } - tx={ - isProtected && api.tx.balances.transferKeepAlive - ? 'balances.transferKeepAlive' - : 'balances.transfer' - } + tx={(isProtected && api.tx.balances.transferKeepAlive) || api.tx.balances.transfer} /> diff --git a/packages/page-accounts/src/modals/Undelegate.tsx b/packages/page-accounts/src/modals/Undelegate.tsx index bf4ebeea87..b63099a26f 100644 --- a/packages/page-accounts/src/modals/Undelegate.tsx +++ b/packages/page-accounts/src/modals/Undelegate.tsx @@ -4,6 +4,7 @@ import React from 'react'; import { InputAddress, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -14,6 +15,7 @@ interface Props { function Undelegate ({ accountDelegating, onClose }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); return ( ('Undelegate')} onStart={onClose} - params={[]} - tx='democracy.undelegate' + tx={api.tx.democracy.undelegate} /> diff --git a/packages/page-bounties/src/BountyClaim.tsx b/packages/page-bounties/src/BountyClaim.tsx index 514856d82b..b7064fed21 100644 --- a/packages/page-bounties/src/BountyClaim.tsx +++ b/packages/page-bounties/src/BountyClaim.tsx @@ -23,7 +23,10 @@ function BountyClaim ({ beneficiaryId, index, payoutDue }: Props) { const { api } = useApi(); const { allAccounts, hasAccounts } = useAccounts(); - const isBountyClaimable = useMemo(() => isClaimable(allAccounts, beneficiaryId, payoutDue), [allAccounts, beneficiaryId, payoutDue]); + const isBountyClaimable = useMemo( + () => isClaimable(allAccounts, beneficiaryId, payoutDue), + [allAccounts, beneficiaryId, payoutDue] + ); return hasAccounts && isBountyClaimable ? ( @@ -32,11 +35,7 @@ function BountyClaim ({ beneficiaryId, index, payoutDue }: Props) { icon='plus' label={t('Claim Bounty')} params={[index]} - tx={ - api.tx.bounties - ? 'bounties.claimBounty' - : 'treasury.claimBounty' - } + tx={(api.tx.bounties || api.tx.treasury).claimBounty} /> ) : null; diff --git a/packages/page-bounties/src/BountyCreate.tsx b/packages/page-bounties/src/BountyCreate.tsx index 48cc8300ff..43c0520684 100644 --- a/packages/page-bounties/src/BountyCreate.tsx +++ b/packages/page-bounties/src/BountyCreate.tsx @@ -111,11 +111,7 @@ function BountyCreate () { label={t('Add Bounty')} onStart={toggleIsOpen} params={[amount, title]} - tx={ - api.tx.bounties - ? 'bounties.proposeBounty' - : 'treasury.proposeBounty' - } + tx={(api.tx.bounties || api.tx.treasury).proposeBounty} /> diff --git a/packages/page-claims/src/Attest.tsx b/packages/page-claims/src/Attest.tsx index 46e224a8c3..5143e38131 100644 --- a/packages/page-claims/src/Attest.tsx +++ b/packages/page-claims/src/Attest.tsx @@ -94,7 +94,7 @@ function Attest ({ accountId, className, ethereumAddress, onSuccess, statementKi label={t('I agree')} onSuccess={onSuccess} params={[statementSentence]} - tx='claims.attest' + tx={api.tx.claims.attest} /> diff --git a/packages/page-claims/src/Claim.tsx b/packages/page-claims/src/Claim.tsx index 9263c992c3..7adb0a2dcf 100644 --- a/packages/page-claims/src/Claim.tsx +++ b/packages/page-claims/src/Claim.tsx @@ -1,6 +1,8 @@ // Copyright 2017-2020 @polkadot/app-claims authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { ApiPromise } from '@polkadot/api'; +import type { SubmittableExtrinsic } from '@polkadot/api/types'; import type { TxCallback } from '@polkadot/react-components/Status/types'; import type { Option } from '@polkadot/types'; import type { BalanceOf, EthereumAddress, StatementKind } from '@polkadot/types/interfaces'; @@ -24,28 +26,28 @@ interface Props { isOldClaimProcess: boolean; onSuccess?: TxCallback; statementKind?: StatementKind; - systemChain: string; } interface ConstructTx { params?: any[]; - tx?: string; + tx?: (...args: any[]) => SubmittableExtrinsic<'promise'>; } // Depending on isOldClaimProcess, construct the correct tx. -function constructTx (systemChain: string, accountId: string, ethereumSignature: string | null, kind: StatementKind | undefined, isOldClaimProcess: boolean): ConstructTx { +// FIXME We actually want to return the constructed extrinsic here (probably in useMemo) +function constructTx (api: ApiPromise, systemChain: string, accountId: string, ethereumSignature: string | null, kind: StatementKind | undefined, isOldClaimProcess: boolean): ConstructTx { if (!ethereumSignature) { return {}; } return isOldClaimProcess || !kind - ? { params: [accountId, ethereumSignature], tx: 'claims.claim' } - : { params: [accountId, ethereumSignature, getStatement(systemChain, kind)?.sentence], tx: 'claims.claimAttest' }; + ? { params: [accountId, ethereumSignature], tx: api.tx.claims.claim } + : { params: [accountId, ethereumSignature, getStatement(systemChain, kind)?.sentence], tx: api.tx.claims.claimAttest }; } -function Claim ({ accountId, className = '', ethereumAddress, ethereumSignature, isOldClaimProcess, onSuccess, statementKind, systemChain }: Props): React.ReactElement | null { +function Claim ({ accountId, className = '', ethereumAddress, ethereumSignature, isOldClaimProcess, onSuccess, statementKind }: Props): React.ReactElement | null { const { t } = useTranslation(); - const { api } = useApi(); + const { api, systemChain } = useApi(); const [claimValue, setClaimValue] = useState(null); const [isBusy, setIsBusy] = useState(false); @@ -90,7 +92,7 @@ function Claim ({ accountId, className = '', ethereumAddress, ethereumSignature, isUnsigned label={t('Claim')} onSuccess={onSuccess} - {...constructTx(systemChain, accountId, ethereumSignature, statementKind, isOldClaimProcess)} + {...constructTx(api, systemChain, accountId, ethereumSignature, statementKind, isOldClaimProcess)} /> diff --git a/packages/page-claims/src/index.tsx b/packages/page-claims/src/index.tsx index 0662b16165..ce8c89dd7e 100644 --- a/packages/page-claims/src/index.tsx +++ b/packages/page-claims/src/index.tsx @@ -314,7 +314,6 @@ function ClaimsApp ({ basePath }: Props): React.ReactElement { isOldClaimProcess={isOldClaimProcess} onSuccess={goToStepAccount} statementKind={statementKind} - systemChain={systemChain} /> )} diff --git a/packages/page-contracts/src/Contracts/util.tsx b/packages/page-contracts/src/Contracts/util.tsx index f752d304f0..b4dfc69361 100644 --- a/packages/page-contracts/src/Contracts/util.tsx +++ b/packages/page-contracts/src/Contracts/util.tsx @@ -37,14 +37,12 @@ export function getContractForAddress (api: ApiPromise, address: string | null): export function getCallMessageOptions (callContract: Contract | null): any[] { return callContract - ? callContract.abi.messages.map((message, index): { key: string; text: React.ReactNode; value: number } => { - return { - key: message.identifier, - text: ( - - ), - value: index - }; - }) + ? callContract.abi.messages.map((message, index): { key: string; text: React.ReactNode; value: number } => ({ + key: message.identifier, + text: ( + + ), + value: index + })) : []; } diff --git a/packages/page-council/src/Motions/Close.tsx b/packages/page-council/src/Motions/Close.tsx index f1bf24baad..287d06ec6c 100644 --- a/packages/page-council/src/Motions/Close.tsx +++ b/packages/page-council/src/Motions/Close.tsx @@ -75,7 +75,7 @@ function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React. : [hash, idNumber, proposalWeight, proposalLength] : [hash, idNumber] } - tx='council.close' + tx={api.tx.council.close} /> diff --git a/packages/page-council/src/Motions/Motion.tsx b/packages/page-council/src/Motions/Motion.tsx index 24827bc23a..c7bc4aa764 100644 --- a/packages/page-council/src/Motions/Motion.tsx +++ b/packages/page-council/src/Motions/Motion.tsx @@ -133,7 +133,7 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal, : [hash, index, proposalWeight, proposalLength] : [hash, index] } - tx='council.close' + tx={api.tx.council.close} /> ) )} diff --git a/packages/page-council/src/Motions/ProposeExternal.tsx b/packages/page-council/src/Motions/ProposeExternal.tsx index 5911fb6d39..faf30d16ff 100644 --- a/packages/page-council/src/Motions/ProposeExternal.tsx +++ b/packages/page-council/src/Motions/ProposeExternal.tsx @@ -116,7 +116,7 @@ function ProposeExternal ({ className = '', isMember, members }: Props): React.R ? [threshold, proposal, proposalLength] : [threshold, proposal] } - tx='council.propose' + tx={api.tx.council.propose} /> diff --git a/packages/page-council/src/Motions/ProposeMotion.tsx b/packages/page-council/src/Motions/ProposeMotion.tsx index 8a84f6c65f..4686b96d56 100644 --- a/packages/page-council/src/Motions/ProposeMotion.tsx +++ b/packages/page-council/src/Motions/ProposeMotion.tsx @@ -128,7 +128,7 @@ function Propose ({ isMember, members }: Props): React.ReactElement { ? [threshold, proposal, proposalLength] : [threshold, proposal] } - tx='council.propose' + tx={api.tx.council.propose} /> diff --git a/packages/page-council/src/Motions/Slashing.tsx b/packages/page-council/src/Motions/Slashing.tsx index 1c95223830..b08449e4dc 100644 --- a/packages/page-council/src/Motions/Slashing.tsx +++ b/packages/page-council/src/Motions/Slashing.tsx @@ -131,7 +131,7 @@ function Slashing ({ className = '', isMember, members }: Props): React.ReactEle ? [threshold, proposal, proposalLength] : [threshold, proposal] } - tx='council.propose' + tx={api.tx.council.propose} /> diff --git a/packages/page-council/src/Motions/Voting.tsx b/packages/page-council/src/Motions/Voting.tsx index 4f9d501a0f..d0e7e917aa 100644 --- a/packages/page-council/src/Motions/Voting.tsx +++ b/packages/page-council/src/Motions/Voting.tsx @@ -6,7 +6,7 @@ import type { AccountId, Hash, Proposal, ProposalIndex } from '@polkadot/types/i import React, { useState } from 'react'; import { Button, Modal, ProposedAction, TxButton, VoteAccount } from '@polkadot/react-components'; -import { useAccounts, useToggle } from '@polkadot/react-hooks'; +import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -21,6 +21,7 @@ interface Props { function Voting ({ hash, idNumber, isDisabled, members, prime, proposal }: Props): React.ReactElement | null { const { t } = useTranslation(); + const { api } = useApi(); const { hasAccounts } = useAccounts(); const [isVotingOpen, toggleVoting] = useToggle(); const [accountId, setAccountId] = useState(null); @@ -75,7 +76,7 @@ function Voting ({ hash, idNumber, isDisabled, members, prime, proposal }: Props label={t('Vote Nay')} onStart={toggleVoting} params={[hash, idNumber, false]} - tx='council.vote' + tx={api.tx.council.vote} /> ('Vote Aye')} onStart={toggleVoting} params={[hash, idNumber, true]} - tx='council.vote' + tx={api.tx.council.vote} /> diff --git a/packages/page-council/src/Overview/SubmitCandidacy.tsx b/packages/page-council/src/Overview/SubmitCandidacy.tsx index 6917545d0f..a29ef97fb7 100644 --- a/packages/page-council/src/Overview/SubmitCandidacy.tsx +++ b/packages/page-council/src/Overview/SubmitCandidacy.tsx @@ -63,7 +63,7 @@ function SubmitCandidacy ({ electionsInfo }: Props): React.ReactElement { ? [electionsInfo?.candidates.length] : [] } - tx={`${modLocation}.submitCandidacy`} + tx={(api.tx.electionsPhragmen || api.tx.elections).submitCandidacy} /> diff --git a/packages/page-council/src/Overview/Vote.tsx b/packages/page-council/src/Overview/Vote.tsx index f4c9e76ebd..bbeb234222 100644 --- a/packages/page-council/src/Overview/Vote.tsx +++ b/packages/page-council/src/Overview/Vote.tsx @@ -115,12 +115,7 @@ function Vote ({ electionsInfo }: Props): React.ReactElement { isDisabled={!defaultVotes.length} label={t('Unvote all')} onStart={toggleVisible} - params={[]} - tx={ - api.tx.electionsPhragmen - ? 'electionsPhragmen.removeVoter' - : 'elections.removeVoter' - } + tx={(api.tx.electionsPhragmen || api.tx.elections).removeVoter} /> { label={t('Vote')} onStart={toggleVisible} params={[votes, voteValue]} - tx={ - api.tx.electionsPhragmen - ? 'electionsPhragmen.vote' - : 'elections.vote' - } + tx={(api.tx.electionsPhragmen || api.tx.elections).vote} /> diff --git a/packages/page-democracy/src/Overview/Fasttrack.tsx b/packages/page-democracy/src/Overview/Fasttrack.tsx index b71e9e7c95..5199ab9f20 100644 --- a/packages/page-democracy/src/Overview/Fasttrack.tsx +++ b/packages/page-democracy/src/Overview/Fasttrack.tsx @@ -101,7 +101,7 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement ? [memberThreshold, proposal, proposalLength] : [memberThreshold, proposal] } - tx='technicalCommittee.propose' + tx={api.tx.technicalCommittee.propose} /> diff --git a/packages/page-democracy/src/Overview/PreImage.tsx b/packages/page-democracy/src/Overview/PreImage.tsx index 744686017f..4b0edd3d9c 100644 --- a/packages/page-democracy/src/Overview/PreImage.tsx +++ b/packages/page-democracy/src/Overview/PreImage.tsx @@ -123,7 +123,11 @@ function PreImage ({ className = '', imageHash, isImminent = false, onClose }: P label={t('Submit preimage')} onStart={onClose} params={[encodedProposal]} - tx={isImminent ? 'democracy.noteImminentPreimage' : 'democracy.notePreimage'} + tx={ + isImminent + ? api.tx.democracy.noteImminentPreimage + : api.tx.democracy.notePreimage + } /> diff --git a/packages/page-democracy/src/Overview/Propose.tsx b/packages/page-democracy/src/Overview/Propose.tsx index b381b8b4e9..b77d8df31b 100644 --- a/packages/page-democracy/src/Overview/Propose.tsx +++ b/packages/page-democracy/src/Overview/Propose.tsx @@ -109,7 +109,7 @@ function Propose ({ className = '', onClose }: Props): React.ReactElement ? [hash, balance, publicProps?.length] : [hash, balance] } - tx='democracy.propose' + tx={api.tx.democracy.propose} /> diff --git a/packages/page-democracy/src/Overview/Seconding.tsx b/packages/page-democracy/src/Overview/Seconding.tsx index 1c1f190766..21ff6d80ff 100644 --- a/packages/page-democracy/src/Overview/Seconding.tsx +++ b/packages/page-democracy/src/Overview/Seconding.tsx @@ -76,7 +76,7 @@ function Seconding ({ depositors, image, proposalId }: Props): React.ReactElemen ? [proposalId, depositors.length] : [proposalId] } - tx='democracy.second' + tx={api.tx.democracy.second} /> diff --git a/packages/page-democracy/src/Overview/Voting.tsx b/packages/page-democracy/src/Overview/Voting.tsx index 8b94775a33..27364e5837 100644 --- a/packages/page-democracy/src/Overview/Voting.tsx +++ b/packages/page-democracy/src/Overview/Voting.tsx @@ -97,7 +97,7 @@ function Voting ({ proposal, referendumId }: Props): React.ReactElement | ? [referendumId, { Standard: { balance, vote: { aye: false, conviction } } }] : [referendumId, { aye: false, conviction }] } - tx='democracy.vote' + tx={api.tx.democracy.vote} /> | ? [referendumId, { Standard: { balance, vote: { aye: true, conviction } } }] : [referendumId, { aye: true, conviction }] } - tx='democracy.vote' + tx={api.tx.democracy.vote} /> diff --git a/packages/page-extrinsics/src/Selection.tsx b/packages/page-extrinsics/src/Selection.tsx index e9b1d4e604..6eb77e49e0 100644 --- a/packages/page-extrinsics/src/Selection.tsx +++ b/packages/page-extrinsics/src/Selection.tsx @@ -54,7 +54,6 @@ function Selection (): React.ReactElement { ('Submit Unsigned')} withSpinner @@ -63,7 +62,6 @@ function Selection (): React.ReactElement { accountId={accountId} extrinsic={extrinsic} icon='sign-in-alt' - isDisabled={!extrinsic || !accountId} label={t('Submit Transaction')} /> diff --git a/packages/page-parachains/src/Parachain/Deregister.tsx b/packages/page-parachains/src/Parachain/Deregister.tsx index dc24ebc1d4..8f4a9bef5d 100644 --- a/packages/page-parachains/src/Parachain/Deregister.tsx +++ b/packages/page-parachains/src/Parachain/Deregister.tsx @@ -70,7 +70,7 @@ function Deregister ({ id, info, isOpen, onClose, onSubmit, sudoKey }: Props): R { isDisabled={!hasValue} label={t('Vote')} params={[[opt10m, opt100m, opt1b, opt10b]]} - tx='poll.vote' + tx={api.tx.poll.vote} /> diff --git a/packages/page-society/src/Overview/Bid.tsx b/packages/page-society/src/Overview/Bid.tsx index 0b9ee1267f..a4d15d0274 100644 --- a/packages/page-society/src/Overview/Bid.tsx +++ b/packages/page-society/src/Overview/Bid.tsx @@ -6,7 +6,7 @@ import type { Bid } from '@polkadot/types/interfaces'; import React, { useEffect, useState } from 'react'; import { AddressSmall, TxButton } from '@polkadot/react-components'; -import { useAccounts } from '@polkadot/react-hooks'; +import { useAccounts, useApi } from '@polkadot/react-hooks'; import { FormatBalance } from '@polkadot/react-query'; import { useTranslation } from '../translate'; @@ -18,6 +18,7 @@ interface Props { function BidRow ({ index, value: { kind, value, who } }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const { allAccounts } = useAccounts(); const [isBidder, setIsBidder] = useState(false); @@ -45,7 +46,7 @@ function BidRow ({ index, value: { kind, value, who } }: Props): React.ReactElem isDisabled={!isBidder} label={t('Unbid')} params={[index]} - tx='society.unbid' + tx={api.tx.society.unbid} /> diff --git a/packages/page-society/src/Overview/BidNew.tsx b/packages/page-society/src/Overview/BidNew.tsx index 2e9d09d93e..2017ee5e8a 100644 --- a/packages/page-society/src/Overview/BidNew.tsx +++ b/packages/page-society/src/Overview/BidNew.tsx @@ -5,6 +5,7 @@ import BN from 'bn.js'; import React, { useState } from 'react'; import { InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -14,6 +15,7 @@ interface Props { function BidNew ({ onClose }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [amount, setAmount] = useState(); const [accountId, setAccount] = useState(); @@ -58,7 +60,7 @@ function BidNew ({ onClose }: Props): React.ReactElement { label={t('Bid')} onStart={onClose} params={[amount]} - tx='society.bid' + tx={api.tx.society.bid} /> diff --git a/packages/page-society/src/Overview/CandidateVoting.tsx b/packages/page-society/src/Overview/CandidateVoting.tsx index d60ccc3fe0..f3f574fade 100644 --- a/packages/page-society/src/Overview/CandidateVoting.tsx +++ b/packages/page-society/src/Overview/CandidateVoting.tsx @@ -4,7 +4,7 @@ import React, { useRef, useState } from 'react'; import { Button, Dropdown, InputAddress, Modal, TxButton } from '@polkadot/react-components'; -import { useToggle } from '@polkadot/react-hooks'; +import { useApi, useToggle } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -16,6 +16,7 @@ interface Props { function CandidateVoting ({ candidateId, isMember, ownMembers }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [isVisible, toggleVisible] = useToggle(); const [vote, setVote] = useState(true); const [accountId, setAccountId] = useState(null); @@ -51,7 +52,7 @@ function CandidateVoting ({ candidateId, isMember, ownMembers }: Props): React.R label={t('Vote')} onStart={toggleVisible} params={[candidateId, vote]} - tx='society.vote' + tx={api.tx.society.vote} /> diff --git a/packages/page-society/src/Overview/DefenderVoting.tsx b/packages/page-society/src/Overview/DefenderVoting.tsx index 78121e7b74..e19ed99c68 100644 --- a/packages/page-society/src/Overview/DefenderVoting.tsx +++ b/packages/page-society/src/Overview/DefenderVoting.tsx @@ -4,7 +4,7 @@ import React, { useRef, useState } from 'react'; import { Button, Dropdown, InputAddress, Modal, TxButton } from '@polkadot/react-components'; -import { useToggle } from '@polkadot/react-hooks'; +import { useApi, useToggle } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -15,6 +15,7 @@ interface Props { function DefenderVoting ({ isMember, ownMembers }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [isVisible, toggleVisible] = useToggle(); const [vote, setVote] = useState(true); const [accountId, setAccountId] = useState(null); @@ -50,7 +51,7 @@ function DefenderVoting ({ isMember, ownMembers }: Props): React.ReactElement('Vote')} onStart={toggleVisible} params={[vote]} - tx='society.defenderVote' + tx={api.tx.society.defenderVote} /> diff --git a/packages/page-staking/src/Actions/Account/BondExtra.tsx b/packages/page-staking/src/Actions/Account/BondExtra.tsx index 993c489211..4b0e61595b 100644 --- a/packages/page-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/page-staking/src/Actions/Account/BondExtra.tsx @@ -111,7 +111,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea label={t('Bond more')} onStart={onClose} params={[maxAdditional]} - tx='staking.bondExtra' + tx={api.tx.staking.bondExtra} /> diff --git a/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx b/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx index d1a25ee21b..f6a245f946 100644 --- a/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx +++ b/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx @@ -4,6 +4,7 @@ import React, { useCallback, useState } from 'react'; import { InputAddress, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../../translate'; import InputValidationController from './InputValidationController'; @@ -16,6 +17,7 @@ interface Props { function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [isFatal, setIsFatal] = useState(false); const [controllerId, setControllerId] = useState(null); @@ -72,7 +74,7 @@ function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props) label={t('Set controller')} onStart={onClose} params={[controllerId]} - tx='staking.setController' + tx={api.tx.staking.setController} /> diff --git a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx index be3db76c1e..054f652b03 100644 --- a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx +++ b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx @@ -7,6 +7,7 @@ import type { DestinationType } from '../types'; import React, { useMemo, useState } from 'react'; import { Dropdown, InputAddress, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../../translate'; import { createDestCurr } from '../destOptions'; @@ -20,6 +21,7 @@ interface Props { function SetRewardDestination ({ controllerId, defaultDestination, onClose, stashId }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [destination, setDestination] = useState(((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked'); const [destAccount, setDestAccount] = useState(defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null); @@ -91,7 +93,7 @@ function SetRewardDestination ({ controllerId, defaultDestination, onClose, stas ? { Account: destAccount } : destination ]} - tx='staking.setPayee' + tx={api.tx.staking.setPayee} /> diff --git a/packages/page-staking/src/Actions/Account/Unbond.tsx b/packages/page-staking/src/Actions/Account/Unbond.tsx index bfa3e4a2b7..0d1751671e 100644 --- a/packages/page-staking/src/Actions/Account/Unbond.tsx +++ b/packages/page-staking/src/Actions/Account/Unbond.tsx @@ -8,6 +8,7 @@ import React, { useState } from 'react'; import styled from 'styled-components'; import { InputAddress, InputBalance, Modal, Static, Toggle, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { BlockToTime } from '@polkadot/react-query'; import { useTranslation } from '../../translate'; @@ -23,6 +24,7 @@ interface Props { function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const bondedBlocks = useUnbondDuration(); const [maxBalance] = useState(stakingLedger?.active.unwrap() || null); const [maxUnbond, setMaxUnbond] = useState(null); @@ -94,7 +96,7 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId label={t('Unbond')} onStart={onClose} params={[withMax ? maxBalance : maxUnbond]} - tx='staking.unbond' + tx={api.tx.staking.unbond} /> diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index 2bf198d9ab..c3dedf8cb9 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -224,7 +224,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio isDisabled={!isOwnController || isDisabled} key='stop' label={t('Stop')} - tx='staking.chill' + tx={api.tx.staking.chill} /> ) : ( diff --git a/packages/page-staking/src/Actions/NewNominator.tsx b/packages/page-staking/src/Actions/NewNominator.tsx index a8bf95e35c..fe9c9934e5 100644 --- a/packages/page-staking/src/Actions/NewNominator.tsx +++ b/packages/page-staking/src/Actions/NewNominator.tsx @@ -109,11 +109,7 @@ function NewNominator ({ isInElection, targets }: Props): React.ReactElement ) : ( diff --git a/packages/page-staking/src/Actions/NewValidator.tsx b/packages/page-staking/src/Actions/NewValidator.tsx index 16b078d2a4..bd099d1bd3 100644 --- a/packages/page-staking/src/Actions/NewValidator.tsx +++ b/packages/page-staking/src/Actions/NewValidator.tsx @@ -114,11 +114,7 @@ function NewValidator ({ isInElection }: Props): React.ReactElement { ? [bondTx, sessionTx, validateTx] : [bondOwnTx, sessionTx, validateTx, controllerTx] ]} - tx={ - isFunction(api.tx.utility.batchAll) - ? 'utility.batchAll' - : 'utility.batch' - } + tx={api.tx.utility.batchAll || api.tx.utility.batch} /> ) : ( diff --git a/packages/page-staking/src/Targets/Nominate.tsx b/packages/page-staking/src/Targets/Nominate.tsx index 994a8f0e19..ad43883727 100644 --- a/packages/page-staking/src/Targets/Nominate.tsx +++ b/packages/page-staking/src/Targets/Nominate.tsx @@ -7,7 +7,7 @@ import React, { useCallback, useMemo, useState } from 'react'; import styled from 'styled-components'; import { AddressMini, Button, InputAddress, Modal, Static, TxButton } from '@polkadot/react-components'; -import { useToggle } from '@polkadot/react-hooks'; +import { useApi, useToggle } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -25,6 +25,7 @@ interface IdState { function Nominate ({ className = '', isDisabled, ownNominators, targets }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [ids, setIds] = useState(null); const [isOpen, toggleOpen] = useToggle(); @@ -107,7 +108,7 @@ function Nominate ({ className = '', isDisabled, ownNominators, targets }: Props label={t('Nominate')} onStart={toggleOpen} params={[targets]} - tx='staking.nominate' + tx={api.tx.staking.nominate} /> diff --git a/packages/page-sudo/src/SetKey.tsx b/packages/page-sudo/src/SetKey.tsx index 292c6b183b..c5bd355098 100644 --- a/packages/page-sudo/src/SetKey.tsx +++ b/packages/page-sudo/src/SetKey.tsx @@ -5,6 +5,7 @@ import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; import { AddressMini, InputAddress, Labelled, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from './translate'; @@ -17,6 +18,7 @@ interface Props { function SetKey ({ allAccounts, className = '', isMine, sudoKey }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const [selected, setSelected] = useState(null); useEffect((): void => { @@ -48,7 +50,7 @@ function SetKey ({ allAccounts, className = '', isMine, sudoKey }: Props): React isDisabled={!isMine || sudoKey === selected} label={t('Reassign')} params={[selected]} - tx='sudo.setKey' + tx={api.tx.sudo.setKey} /> ) diff --git a/packages/page-sudo/src/Sudo.tsx b/packages/page-sudo/src/Sudo.tsx index db24ff0823..4fdda8558e 100644 --- a/packages/page-sudo/src/Sudo.tsx +++ b/packages/page-sudo/src/Sudo.tsx @@ -80,8 +80,8 @@ function Sudo ({ className, isMine, sudoKey }: Props): React.ReactElement } tx={ withWeight - ? 'sudo.sudoUncheckedWeight' - : 'sudo.sudo' + ? api.tx.sudo.sudoUncheckedWeight + : api.tx.sudo.sudo } /> diff --git a/packages/page-tech-comm/src/Proposals/Close.tsx b/packages/page-tech-comm/src/Proposals/Close.tsx index 708b965d80..c72e64da3c 100644 --- a/packages/page-tech-comm/src/Proposals/Close.tsx +++ b/packages/page-tech-comm/src/Proposals/Close.tsx @@ -74,7 +74,7 @@ function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React. : [hash, idNumber, proposalWeight, proposalLength] : [hash, idNumber] } - tx='technicalCommittee.close' + tx={api.tx.technicalCommittee.close} /> diff --git a/packages/page-tech-comm/src/Proposals/Proposal.tsx b/packages/page-tech-comm/src/Proposals/Proposal.tsx index f705719a5f..e27ade9edd 100644 --- a/packages/page-tech-comm/src/Proposals/Proposal.tsx +++ b/packages/page-tech-comm/src/Proposals/Proposal.tsx @@ -124,7 +124,7 @@ function Proposal ({ className = '', imageHash, members, prime }: Props): React. : [imageHash, index, proposalWeight, proposalLength] : [imageHash, index] } - tx='technicalCommittee.close' + tx={api.tx.technicalCommittee.close} /> ) )} diff --git a/packages/page-tech-comm/src/Proposals/Propose.tsx b/packages/page-tech-comm/src/Proposals/Propose.tsx index 7b5c394df3..e43c847f7d 100644 --- a/packages/page-tech-comm/src/Proposals/Propose.tsx +++ b/packages/page-tech-comm/src/Proposals/Propose.tsx @@ -91,7 +91,7 @@ function Propose ({ isMember, members }: Props): React.ReactElement { ? [threshold, proposal, proposalLength] : [threshold, proposal] } - tx='technicalCommittee.propose' + tx={api.tx.technicalCommittee.propose} /> diff --git a/packages/page-tech-comm/src/Proposals/Voting.tsx b/packages/page-tech-comm/src/Proposals/Voting.tsx index 22629c3345..8b997edb1f 100644 --- a/packages/page-tech-comm/src/Proposals/Voting.tsx +++ b/packages/page-tech-comm/src/Proposals/Voting.tsx @@ -7,7 +7,7 @@ import BN from 'bn.js'; import React, { useState } from 'react'; import { Button, Modal, TxButton, VoteAccount } from '@polkadot/react-components'; -import { useAccounts, useToggle } from '@polkadot/react-hooks'; +import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -20,6 +20,7 @@ interface Props { function Voting ({ hash, members, prime, proposalId }: Props): React.ReactElement | null { const { t } = useTranslation(); + const { api } = useApi(); const { hasAccounts } = useAccounts(); const [accountId, setAccountId] = useState(null); const [isVotingOpen, toggleVoting] = useToggle(); @@ -53,7 +54,7 @@ function Voting ({ hash, members, prime, proposalId }: Props): React.ReactElemen label={t('Vote Nay')} onStart={toggleVoting} params={[hash, proposalId, false]} - tx='technicalCommittee.vote' + tx={api.tx.technicalCommittee.vote} /> ('Vote Aye')} onStart={toggleVoting} params={[hash, proposalId, true]} - tx='technicalCommittee.vote' + tx={api.tx.technicalCommittee.vote} /> diff --git a/packages/page-treasury/src/Overview/Council.tsx b/packages/page-treasury/src/Overview/Council.tsx index a8a92d4726..da2baa0dae 100644 --- a/packages/page-treasury/src/Overview/Council.tsx +++ b/packages/page-treasury/src/Overview/Council.tsx @@ -96,7 +96,7 @@ function Council ({ id, isDisabled, members }: Props): React.ReactElement ? [threshold, proposal, proposalLength] : [threshold, proposal] } - tx='council.propose' + tx={api.tx.council.propose} /> diff --git a/packages/page-treasury/src/Overview/ProposalCreate.tsx b/packages/page-treasury/src/Overview/ProposalCreate.tsx index 0334cbcb0f..248ca53046 100644 --- a/packages/page-treasury/src/Overview/ProposalCreate.tsx +++ b/packages/page-treasury/src/Overview/ProposalCreate.tsx @@ -101,7 +101,7 @@ function Propose ({ className }: Props): React.ReactElement | null { label={t('Submit proposal')} onStart={toggleOpen} params={[value, beneficiary]} - tx='treasury.proposeSpend' + tx={api.tx.treasury.proposeSpend} /> diff --git a/packages/page-treasury/src/Tips/Tip.tsx b/packages/page-treasury/src/Tips/Tip.tsx index aeecae6385..51651aeafb 100644 --- a/packages/page-treasury/src/Tips/Tip.tsx +++ b/packages/page-treasury/src/Tips/Tip.tsx @@ -155,11 +155,7 @@ function Tip ({ bestNumber, className = '', defaultId, hash, isMember, members, label={t('Cancel')} onSuccess={onRefresh} params={[hash]} - tx={ - api.tx.tips - ? 'tips.retractTip' - : 'treasury.retractTip' - } + tx={(api.tx.tips || api.tx.treasury).retractTip} /> ) } @@ -181,11 +177,7 @@ function Tip ({ bestNumber, className = '', defaultId, hash, isMember, members, label={t('Close')} onSuccess={onRefresh} params={[hash]} - tx={ - api.tx.tips - ? 'tips.closeTip' - : 'treasury.closeTip' - } + tx={(api.tx.tips || api.tx.treasury).closeTip} /> ) } diff --git a/packages/page-treasury/src/Tips/TipCreate.tsx b/packages/page-treasury/src/Tips/TipCreate.tsx index 6ac2940a80..5f1397f891 100644 --- a/packages/page-treasury/src/Tips/TipCreate.tsx +++ b/packages/page-treasury/src/Tips/TipCreate.tsx @@ -118,12 +118,8 @@ function TipCreate ({ members, refresh }: Props): React.ReactElement { } tx={ isMember - ? api.tx.tips - ? 'tips.tipNew' - : 'treasury.tipNew' - : api.tx.tips - ? 'tips.reportAwesome' - : 'treasury.reportAwesome' + ? (api.tx.tips || api.tx.treasury).tipNew + : (api.tx.tips || api.tx.treasury).reportAwesome } /> diff --git a/packages/page-treasury/src/Tips/TipEndorse.tsx b/packages/page-treasury/src/Tips/TipEndorse.tsx index 57c751613e..a405c138e1 100644 --- a/packages/page-treasury/src/Tips/TipEndorse.tsx +++ b/packages/page-treasury/src/Tips/TipEndorse.tsx @@ -40,11 +40,7 @@ function TipEndorse ({ defaultId, hash, isMember, isTipped, median, members }: P isDisabled={!isMember || !isTipped} isIcon params={[hash, median]} - tx={ - api.tx.tips - ? 'tips.tip' - : 'treasury.tip' - } + tx={(api.tx.tips || api.tx.treasury).tip} withoutLink /> {isOpen && ( @@ -92,11 +88,7 @@ function TipEndorse ({ defaultId, hash, isMember, isTipped, median, members }: P label={t('Submit tip')} onStart={toggleOpen} params={[hash, value]} - tx={ - api.tx.tips - ? 'tips.tip' - : 'treasury.tip' - } + tx={(api.tx.tips || api.tx.treasury).tip} /> diff --git a/packages/react-components/src/StakingRedeemable.tsx b/packages/react-components/src/StakingRedeemable.tsx index 35a6a3a012..32ea147d48 100644 --- a/packages/react-components/src/StakingRedeemable.tsx +++ b/packages/react-components/src/StakingRedeemable.tsx @@ -50,7 +50,7 @@ function StakingRedeemable ({ className = '', stakingInfo }: Props): React.React : [] } tooltip={t('Withdraw these unbonded funds')} - tx='staking.withdrawUnbonded' + tx={api.tx.staking.withdrawUnbonded} /> )} diff --git a/packages/react-components/src/TxButton.tsx b/packages/react-components/src/TxButton.tsx index bb653a03b4..d01dfd317d 100644 --- a/packages/react-components/src/TxButton.tsx +++ b/packages/react-components/src/TxButton.tsx @@ -7,7 +7,7 @@ import type { TxButtonProps as Props } from './types'; import React, { useCallback, useContext, useEffect, useState } from 'react'; import { SubmittableResult } from '@polkadot/api'; -import { useApi, useIsMountedRef } from '@polkadot/react-hooks'; +import { useIsMountedRef } from '@polkadot/react-hooks'; import { assert, isFunction } from '@polkadot/util'; import Button from './Button'; @@ -16,12 +16,10 @@ import { useTranslation } from './translate'; function TxButton ({ accountId, className = '', extrinsic: propsExtrinsic, icon, isBasic, isBusy, isDisabled, isIcon, isToplevel, isUnsigned, label, onClick, onFailed, onSendRef, onStart, onSuccess, onUpdate, params, tooltip, tx, withSpinner, withoutLink }: Props): React.ReactElement { const { t } = useTranslation(); - const { api } = useApi(); const mountedRef = useIsMountedRef(); const { queueExtrinsic } = useContext(StatusContext); const [isSending, setIsSending] = useState(false); const [isStarted, setIsStarted] = useState(false); - const needsAccount = !isUnsigned && !accountId; useEffect((): void => { (isStarted && onStart) && onStart(); @@ -54,19 +52,15 @@ function TxButton ({ accountId, className = '', extrinsic: propsExtrinsic, icon, const _onSend = useCallback( (): void => { - let extrinsics: SubmittableExtrinsic<'promise'>[]; + let extrinsics: SubmittableExtrinsic<'promise'>[] | undefined; if (propsExtrinsic) { extrinsics = Array.isArray(propsExtrinsic) ? propsExtrinsic : [propsExtrinsic]; - } else { - const [section, method] = (tx || '').split('.'); - - assert(api.tx[section] && api.tx[section][method], `Unable to find api.tx.${section}.${method}`); - + } else if (tx) { extrinsics = [ - api.tx[section][method](...( + tx(...( isFunction(params) ? params() : (params || []) @@ -92,7 +86,7 @@ function TxButton ({ accountId, className = '', extrinsic: propsExtrinsic, icon, onClick && onClick(); }, - [_onFailed, _onStart, _onSuccess, accountId, api.tx, isUnsigned, onClick, onFailed, onSuccess, onUpdate, params, propsExtrinsic, queueExtrinsic, setIsSending, tx, withSpinner, mountedRef] + [_onFailed, _onStart, _onSuccess, accountId, isUnsigned, onClick, onFailed, onSuccess, onUpdate, params, propsExtrinsic, queueExtrinsic, setIsSending, tx, withSpinner, mountedRef] ); if (onSendRef) { @@ -105,7 +99,13 @@ function TxButton ({ accountId, className = '', extrinsic: propsExtrinsic, icon, icon={icon || 'check'} isBasic={isBasic} isBusy={isBusy} - isDisabled={isSending || isDisabled || needsAccount} + isDisabled={isSending || isDisabled || (!isUnsigned && !accountId) || ( + tx + ? false + : Array.isArray(propsExtrinsic) + ? propsExtrinsic.length === 0 + : !propsExtrinsic + )} isIcon={isIcon} isToplevel={isToplevel} label={label || (isIcon ? '' : t('Submit'))} diff --git a/packages/react-components/src/types.ts b/packages/react-components/src/types.ts index 3b47a1158b..a112c81a65 100644 --- a/packages/react-components/src/types.ts +++ b/packages/react-components/src/types.ts @@ -3,7 +3,7 @@ import type { IconName } from '@fortawesome/fontawesome-svg-core'; import type { WithTranslation } from 'react-i18next'; -import type { SubmittableExtrinsic } from '@polkadot/api/promise/types'; +import type { SubmittableExtrinsic } from '@polkadot/api/types'; import type { Abi } from '@polkadot/api-contract'; import type { ActionStatus } from '@polkadot/react-components/Status/types'; import type { AccountId, Index } from '@polkadot/types/interfaces'; @@ -27,7 +27,7 @@ export interface TxButtonProps { accountId?: AccountId | string | null; accountNonce?: Index; className?: string; - extrinsic?: SubmittableExtrinsic | SubmittableExtrinsic[] | null; + extrinsic?: SubmittableExtrinsic<'promise'> | SubmittableExtrinsic<'promise'>[] | null; icon?: IconName; isBasic?: boolean; isBusy?: boolean; @@ -44,7 +44,7 @@ export interface TxButtonProps { onUpdate?: TxCallback; params?: any[] | (() => any[]); tooltip?: string; - tx?: string; + tx?: ((...args: any[]) => SubmittableExtrinsic<'promise'>) | null; withoutLink?: boolean; withSpinner?: boolean; }