Pass explicit function through to TxButton tx prop (#4251)

* Pass explicit function through to TxButton tx prop

* Updates

* Claim adjust

* Allow null on tx

* Adjust

* Apply suggestions from code review

* Adjustments after merge
This commit is contained in:
Jaco Greeff 2020-12-24 10:01:42 +01:00 committed by GitHub
parent b7dbc59df2
commit 5830e5eab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 133 additions and 156 deletions

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [addresses] = useState(registrars.map(({ address }) => address));
const [judgementAccountId, setJudgementAccountId] = useState<string | null>(null);
const [judgementEnum, setJudgementEnum] = useState(2); // Reasonable
@ -73,7 +75,7 @@ function RegistrarJudgement ({ address, registrars, toggleJudgement }: Props): R
label={t<string>('Judge')}
onStart={toggleJudgement}
params={[registrarIndex, address, judgementEnum]}
tx='identity.provideJudgement'
tx={api.tx.identity.provideJudgement}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [amountError, setAmountError] = useState<AmountValidateState | null>(null);
const [maxBalance] = useState<BN | undefined>();
const [amount, setAmount] = useState<BN | undefined>(previousAmount);
@ -111,8 +113,7 @@ function Delegate ({ onClose, previousAmount, previousConviction, previousDelega
icon='trash-alt'
label={t<string>('Undelegate')}
onStart={onClose}
params={[]}
tx='democracy.undelegate'
tx={api.tx.democracy.undelegate}
/>
)}
<TxButton
@ -125,7 +126,7 @@ function Delegate ({ onClose, previousAmount, previousConviction, previousDelega
}
onStart={onClose}
params={[delegatedAccount, conviction, amount]}
tx='democracy.delegate'
tx={api.tx.democracy.delegate}
/>
</Modal.Actions>
</Modal>

View File

@ -253,8 +253,7 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React
isDisabled={!gotPreviousIdentity}
label={t<string>('Clear Identity')}
onStart={onClose}
params={[]}
tx='identity.clearIdentity'
tx={api.tx.identity.clearIdentity}
/>
<TxButton
accountId={address}
@ -262,7 +261,7 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React
label={t<string>('Set Identity')}
onStart={onClose}
params={[info]}
tx='identity.setIdentity'
tx={api.tx.identity.setIdentity}
/>
</Modal.Actions>
</Modal>

View File

@ -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}
/>
)}
</Modal.Actions>

View File

@ -324,8 +324,7 @@ function ProxyOverview ({ className, onClose, previousProxy, proxiedAccount }: P
icon='trash-alt'
label={t<string>('Clear all')}
onStart={onClose}
params={[]}
tx='proxy.removeProxies'
tx={api.tx.proxy.removeProxies}
/>
)}
<TxButton

View File

@ -4,6 +4,7 @@
import React, { useState } from 'react';
import { InputAddress, Modal, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { useTranslation } from '../translate';
@ -15,6 +16,7 @@ interface Props {
function RecoverAccount ({ address, className = '', onClose }: Props): React.ReactElement {
const { t } = useTranslation();
const { api } = useApi();
const [recover, setRecover] = useState<string | null>(null);
return (
@ -43,7 +45,7 @@ function RecoverAccount ({ address, className = '', onClose }: Props): React.Rea
label={t<string>('Start recovery')}
onStart={onClose}
params={[recover]}
tx='recovery.initiateRecovery'
tx={api.tx.recovery.initiateRecovery}
/>
</Modal.Actions>
</Modal>

View File

@ -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<BN | undefined>();
const [helpers, setHelpers] = useState<string[]>([]);
@ -94,7 +96,7 @@ function RecoverSetup ({ address, className = '', onClose }: Props): React.React
label={t<string>('Make recoverable')}
onStart={onClose}
params={[sortAddresses(helpers), threshold, delay]}
tx='recovery.createRecovery'
tx={api.tx.recovery.createRecovery}
/>
</Modal.Actions>
</Modal>

View File

@ -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}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
return (
<Modal
@ -41,8 +43,7 @@ function Undelegate ({ accountDelegating, onClose }: Props): React.ReactElement<
icon='sign-in-alt'
label={t<string>('Undelegate')}
onStart={onClose}
params={[]}
tx='democracy.undelegate'
tx={api.tx.democracy.undelegate}
/>
</Modal.Actions>
</Modal>

View File

@ -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<string>('Claim Bounty')}
params={[index]}
tx={
api.tx.bounties
? 'bounties.claimBounty'
: 'treasury.claimBounty'
}
tx={(api.tx.bounties || api.tx.treasury).claimBounty}
/>
)
: null;

View File

@ -111,11 +111,7 @@ function BountyCreate () {
label={t<string>('Add Bounty')}
onStart={toggleIsOpen}
params={[amount, title]}
tx={
api.tx.bounties
? 'bounties.proposeBounty'
: 'treasury.proposeBounty'
}
tx={(api.tx.bounties || api.tx.treasury).proposeBounty}
/>
</Modal.Actions>
</Modal>

View File

@ -94,7 +94,7 @@ function Attest ({ accountId, className, ethereumAddress, onSuccess, statementKi
label={t<string>('I agree')}
onSuccess={onSuccess}
params={[statementSentence]}
tx='claims.attest'
tx={api.tx.claims.attest}
/>
</Button.Group>
</div>

View File

@ -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<Props> | null {
function Claim ({ accountId, className = '', ethereumAddress, ethereumSignature, isOldClaimProcess, onSuccess, statementKind }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { api, systemChain } = useApi();
const [claimValue, setClaimValue] = useState<BalanceOf | null>(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)}
/>
</Button.Group>
</>

View File

@ -314,7 +314,6 @@ function ClaimsApp ({ basePath }: Props): React.ReactElement<Props> {
isOldClaimProcess={isOldClaimProcess}
onSuccess={goToStepAccount}
statementKind={statementKind}
systemChain={systemChain}
/>
)}
</Column>

View File

@ -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: (
<MessageSignature message={message} />
),
value: index
};
})
? callContract.abi.messages.map((message, index): { key: string; text: React.ReactNode; value: number } => ({
key: message.identifier,
text: (
<MessageSignature message={message} />
),
value: index
}))
: [];
}

View File

@ -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}
/>
</Modal.Actions>
</Modal>

View File

@ -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}
/>
)
)}

View File

@ -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}
/>
</Modal.Actions>
</Modal>

View File

@ -128,7 +128,7 @@ function Propose ({ isMember, members }: Props): React.ReactElement<Props> {
? [threshold, proposal, proposalLength]
: [threshold, proposal]
}
tx='council.propose'
tx={api.tx.council.propose}
/>
</Modal.Actions>
</Modal>

View File

@ -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}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { hasAccounts } = useAccounts();
const [isVotingOpen, toggleVoting] = useToggle();
const [accountId, setAccountId] = useState<string | null>(null);
@ -75,7 +76,7 @@ function Voting ({ hash, idNumber, isDisabled, members, prime, proposal }: Props
label={t<string>('Vote Nay')}
onStart={toggleVoting}
params={[hash, idNumber, false]}
tx='council.vote'
tx={api.tx.council.vote}
/>
<TxButton
accountId={accountId}
@ -84,7 +85,7 @@ function Voting ({ hash, idNumber, isDisabled, members, prime, proposal }: Props
label={t<string>('Vote Aye')}
onStart={toggleVoting}
params={[hash, idNumber, true]}
tx='council.vote'
tx={api.tx.council.vote}
/>
</Modal.Actions>
</Modal>

View File

@ -63,7 +63,7 @@ function SubmitCandidacy ({ electionsInfo }: Props): React.ReactElement<Props> {
? [electionsInfo?.candidates.length]
: []
}
tx={`${modLocation}.submitCandidacy`}
tx={(api.tx.electionsPhragmen || api.tx.elections).submitCandidacy}
/>
</Modal.Actions>
</Modal>

View File

@ -115,12 +115,7 @@ function Vote ({ electionsInfo }: Props): React.ReactElement<Props> {
isDisabled={!defaultVotes.length}
label={t<string>('Unvote all')}
onStart={toggleVisible}
params={[]}
tx={
api.tx.electionsPhragmen
? 'electionsPhragmen.removeVoter'
: 'elections.removeVoter'
}
tx={(api.tx.electionsPhragmen || api.tx.elections).removeVoter}
/>
<TxButton
accountId={accountId}
@ -128,11 +123,7 @@ function Vote ({ electionsInfo }: Props): React.ReactElement<Props> {
label={t<string>('Vote')}
onStart={toggleVisible}
params={[votes, voteValue]}
tx={
api.tx.electionsPhragmen
? 'electionsPhragmen.vote'
: 'elections.vote'
}
tx={(api.tx.electionsPhragmen || api.tx.elections).vote}
/>
</Modal.Actions>
</Modal>

View File

@ -101,7 +101,7 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement<Props>
? [memberThreshold, proposal, proposalLength]
: [memberThreshold, proposal]
}
tx='technicalCommittee.propose'
tx={api.tx.technicalCommittee.propose}
/>
</Modal.Actions>
</Modal>

View File

@ -123,7 +123,11 @@ function PreImage ({ className = '', imageHash, isImminent = false, onClose }: P
label={t<string>('Submit preimage')}
onStart={onClose}
params={[encodedProposal]}
tx={isImminent ? 'democracy.noteImminentPreimage' : 'democracy.notePreimage'}
tx={
isImminent
? api.tx.democracy.noteImminentPreimage
: api.tx.democracy.notePreimage
}
/>
</Modal.Actions>
</Modal>

View File

@ -109,7 +109,7 @@ function Propose ({ className = '', onClose }: Props): React.ReactElement<Props>
? [hash, balance, publicProps?.length]
: [hash, balance]
}
tx='democracy.propose'
tx={api.tx.democracy.propose}
/>
</Modal.Actions>
</Modal>

View File

@ -76,7 +76,7 @@ function Seconding ({ depositors, image, proposalId }: Props): React.ReactElemen
? [proposalId, depositors.length]
: [proposalId]
}
tx='democracy.second'
tx={api.tx.democracy.second}
/>
</Modal.Actions>
</Modal>

View File

@ -97,7 +97,7 @@ function Voting ({ proposal, referendumId }: Props): React.ReactElement<Props> |
? [referendumId, { Standard: { balance, vote: { aye: false, conviction } } }]
: [referendumId, { aye: false, conviction }]
}
tx='democracy.vote'
tx={api.tx.democracy.vote}
/>
<TxButton
accountId={accountId}
@ -110,7 +110,7 @@ function Voting ({ proposal, referendumId }: Props): React.ReactElement<Props> |
? [referendumId, { Standard: { balance, vote: { aye: true, conviction } } }]
: [referendumId, { aye: true, conviction }]
}
tx='democracy.vote'
tx={api.tx.democracy.vote}
/>
</Modal.Actions>
</Modal>

View File

@ -54,7 +54,6 @@ function Selection (): React.ReactElement {
<TxButton
extrinsic={extrinsic}
icon='sign-in-alt'
isDisabled={!extrinsic}
isUnsigned
label={t<string>('Submit Unsigned')}
withSpinner
@ -63,7 +62,6 @@ function Selection (): React.ReactElement {
accountId={accountId}
extrinsic={extrinsic}
icon='sign-in-alt'
isDisabled={!extrinsic || !accountId}
label={t<string>('Submit Transaction')}
/>
</Button.Group>

View File

@ -70,7 +70,7 @@ function Deregister ({ id, info, isOpen, onClose, onSubmit, sudoKey }: Props): R
<TxButton
accountId={sudoKey}
extrinsic={extrinsic}
isDisabled={!id || !extrinsic}
isDisabled={!id}
onClick={onClose}
onSendRef={onSendRef}
onStart={onStart}

View File

@ -179,7 +179,7 @@ function PollApp ({ basePath, className }: Props): React.ReactElement<Props> {
isDisabled={!hasValue}
label={t('Vote')}
params={[[opt10m, opt100m, opt1b, opt10b]]}
tx='poll.vote'
tx={api.tx.poll.vote}
/>
</Button.Group>
</>

View File

@ -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<Props> {
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<string>('Unbid')}
params={[index]}
tx='society.unbid'
tx={api.tx.society.unbid}
/>
</td>
</tr>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [amount, setAmount] = useState<BN | undefined>();
const [accountId, setAccount] = useState<string | null | undefined>();
@ -58,7 +60,7 @@ function BidNew ({ onClose }: Props): React.ReactElement<Props> {
label={t<string>('Bid')}
onStart={onClose}
params={[amount]}
tx='society.bid'
tx={api.tx.society.bid}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [isVisible, toggleVisible] = useToggle();
const [vote, setVote] = useState(true);
const [accountId, setAccountId] = useState<string | null>(null);
@ -51,7 +52,7 @@ function CandidateVoting ({ candidateId, isMember, ownMembers }: Props): React.R
label={t<string>('Vote')}
onStart={toggleVisible}
params={[candidateId, vote]}
tx='society.vote'
tx={api.tx.society.vote}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [isVisible, toggleVisible] = useToggle();
const [vote, setVote] = useState(true);
const [accountId, setAccountId] = useState<string | null>(null);
@ -50,7 +51,7 @@ function DefenderVoting ({ isMember, ownMembers }: Props): React.ReactElement<Pr
label={t<string>('Vote')}
onStart={toggleVisible}
params={[vote]}
tx='society.defenderVote'
tx={api.tx.society.defenderVote}
/>
</Modal.Actions>
</Modal>

View File

@ -111,7 +111,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea
label={t<string>('Bond more')}
onStart={onClose}
params={[maxAdditional]}
tx='staking.bondExtra'
tx={api.tx.staking.bondExtra}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [isFatal, setIsFatal] = useState(false);
const [controllerId, setControllerId] = useState<string | null>(null);
@ -72,7 +74,7 @@ function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props)
label={t<string>('Set controller')}
onStart={onClose}
params={[controllerId]}
tx='staking.setController'
tx={api.tx.staking.setController}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [destination, setDestination] = useState<DestinationType>(((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked');
const [destAccount, setDestAccount] = useState<string | null>(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}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const bondedBlocks = useUnbondDuration();
const [maxBalance] = useState<BN | null>(stakingLedger?.active.unwrap() || null);
const [maxUnbond, setMaxUnbond] = useState<BN | null>(null);
@ -94,7 +96,7 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId
label={t<string>('Unbond')}
onStart={onClose}
params={[withMax ? maxBalance : maxUnbond]}
tx='staking.unbond'
tx={api.tx.staking.unbond}
/>
</Modal.Actions>
</Modal>

View File

@ -224,7 +224,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio
isDisabled={!isOwnController || isDisabled}
key='stop'
label={t<string>('Stop')}
tx='staking.chill'
tx={api.tx.staking.chill}
/>
)
: (

View File

@ -109,11 +109,7 @@ function NewNominator ({ isInElection, targets }: Props): React.ReactElement<Pro
? [bondTx, nominateTx]
: [bondOwnTx, nominateTx, controllerTx]
]}
tx={
isFunction(api.tx.utility.batchAll)
? 'utility.batchAll'
: 'utility.batch'
}
tx={api.tx.utility.batchAll || api.tx.utility.batch}
/>
)
: (

View File

@ -114,11 +114,7 @@ function NewValidator ({ isInElection }: Props): React.ReactElement<Props> {
? [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}
/>
)
: (

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [ids, setIds] = useState<IdState | null>(null);
const [isOpen, toggleOpen] = useToggle();
@ -107,7 +108,7 @@ function Nominate ({ className = '', isDisabled, ownNominators, targets }: Props
label={t<string>('Nominate')}
onStart={toggleOpen}
params={[targets]}
tx='staking.nominate'
tx={api.tx.staking.nominate}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [selected, setSelected] = useState<string | null>(null);
useEffect((): void => {
@ -48,7 +50,7 @@ function SetKey ({ allAccounts, className = '', isMine, sudoKey }: Props): React
isDisabled={!isMine || sudoKey === selected}
label={t<string>('Reassign')}
params={[selected]}
tx='sudo.setKey'
tx={api.tx.sudo.setKey}
/>
</>
)

View File

@ -80,8 +80,8 @@ function Sudo ({ className, isMine, sudoKey }: Props): React.ReactElement<Props>
}
tx={
withWeight
? 'sudo.sudoUncheckedWeight'
: 'sudo.sudo'
? api.tx.sudo.sudoUncheckedWeight
: api.tx.sudo.sudo
}
/>
</Button.Group>

View File

@ -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}
/>
</Modal.Actions>
</Modal>

View File

@ -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}
/>
)
)}

View File

@ -91,7 +91,7 @@ function Propose ({ isMember, members }: Props): React.ReactElement<Props> {
? [threshold, proposal, proposalLength]
: [threshold, proposal]
}
tx='technicalCommittee.propose'
tx={api.tx.technicalCommittee.propose}
/>
</Modal.Actions>
</Modal>

View File

@ -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<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { hasAccounts } = useAccounts();
const [accountId, setAccountId] = useState<string | null>(null);
const [isVotingOpen, toggleVoting] = useToggle();
@ -53,7 +54,7 @@ function Voting ({ hash, members, prime, proposalId }: Props): React.ReactElemen
label={t<string>('Vote Nay')}
onStart={toggleVoting}
params={[hash, proposalId, false]}
tx='technicalCommittee.vote'
tx={api.tx.technicalCommittee.vote}
/>
<TxButton
accountId={accountId}
@ -61,7 +62,7 @@ function Voting ({ hash, members, prime, proposalId }: Props): React.ReactElemen
label={t<string>('Vote Aye')}
onStart={toggleVoting}
params={[hash, proposalId, true]}
tx='technicalCommittee.vote'
tx={api.tx.technicalCommittee.vote}
/>
</Modal.Actions>
</Modal>

View File

@ -96,7 +96,7 @@ function Council ({ id, isDisabled, members }: Props): React.ReactElement<Props>
? [threshold, proposal, proposalLength]
: [threshold, proposal]
}
tx='council.propose'
tx={api.tx.council.propose}
/>
</Modal.Actions>
</Modal>

View File

@ -101,7 +101,7 @@ function Propose ({ className }: Props): React.ReactElement<Props> | null {
label={t<string>('Submit proposal')}
onStart={toggleOpen}
params={[value, beneficiary]}
tx='treasury.proposeSpend'
tx={api.tx.treasury.proposeSpend}
/>
</Modal.Actions>
</Modal>

View File

@ -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<string>('Close')}
onSuccess={onRefresh}
params={[hash]}
tx={
api.tx.tips
? 'tips.closeTip'
: 'treasury.closeTip'
}
tx={(api.tx.tips || api.tx.treasury).closeTip}
/>
)
}

View File

@ -118,12 +118,8 @@ function TipCreate ({ members, refresh }: Props): React.ReactElement<Props> {
}
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
}
/>
</Modal.Actions>

View File

@ -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<string>('Submit tip')}
onStart={toggleOpen}
params={[hash, value]}
tx={
api.tx.tips
? 'tips.tip'
: 'treasury.tip'
}
tx={(api.tx.tips || api.tx.treasury).tip}
/>
</Modal.Actions>
</Modal>

View File

@ -50,7 +50,7 @@ function StakingRedeemable ({ className = '', stakingInfo }: Props): React.React
: []
}
tooltip={t<string>('Withdraw these unbonded funds')}
tx='staking.withdrawUnbonded'
tx={api.tx.staking.withdrawUnbonded}
/>
)}
</FormatBalance>

View File

@ -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<Props> {
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<string>('Submit'))}

View File

@ -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;
}