Rework inherent submission (#1123)
This commit is contained in:
parent
bb5cf67d61
commit
08e659aea5
@ -23,6 +23,7 @@ type Props = ApiProps & I18nProps & {
|
||||
|
||||
type State = {
|
||||
isValid: boolean,
|
||||
isValidUnsigned: boolean,
|
||||
method: Method | null,
|
||||
accountNonce: BN,
|
||||
accountId: string
|
||||
@ -30,12 +31,13 @@ type State = {
|
||||
|
||||
class Selection extends React.PureComponent<Props, State> {
|
||||
state: State = {
|
||||
isValid: false
|
||||
isValid: false,
|
||||
isValidUnsigned: false
|
||||
} as State;
|
||||
|
||||
render () {
|
||||
const { apiDefaultTx, api, t } = this.props;
|
||||
const { isValid, accountId } = this.state;
|
||||
const { isValid, isValidUnsigned, accountId } = this.state;
|
||||
const defaultExtrinsic = (() => {
|
||||
try {
|
||||
return api.tx.balances.transfer;
|
||||
@ -78,7 +80,8 @@ class Selection extends React.PureComponent<Props, State> {
|
||||
<br></br>
|
||||
<Button.Group>
|
||||
<TxButton
|
||||
isDisabled={!isValid}
|
||||
isDisabled={!isValidUnsigned}
|
||||
isUnsigned
|
||||
label={t('Submit Inherent')}
|
||||
extrinsic={extrinsic}
|
||||
/>
|
||||
@ -108,6 +111,7 @@ class Selection extends React.PureComponent<Props, State> {
|
||||
return {
|
||||
method,
|
||||
isValid,
|
||||
isValidUnsigned: !!method,
|
||||
accountNonce,
|
||||
accountId
|
||||
};
|
||||
@ -129,13 +133,14 @@ class Selection extends React.PureComponent<Props, State> {
|
||||
|
||||
private getExtrinsic (): SubmittableExtrinsic | null {
|
||||
const { api } = this.props;
|
||||
const { method, isValid } = this.state;
|
||||
const { method } = this.state;
|
||||
|
||||
if (!isValid || !method) {
|
||||
if (!method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const fn = Method.findFunction(method.callIndex);
|
||||
|
||||
return api.tx[fn.section][fn.method](...method.args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ type Props = ApiProps & {
|
||||
isDisabled?: boolean,
|
||||
isNegative?: boolean,
|
||||
isPrimary?: boolean,
|
||||
isUnsigned?: boolean,
|
||||
label: React.ReactNode,
|
||||
onClick?: () => any,
|
||||
onFailed?: TxCallback,
|
||||
@ -56,14 +57,17 @@ class TxButtonInner extends React.PureComponent<InnerProps> {
|
||||
} as State;
|
||||
|
||||
render () {
|
||||
const { accountId, className, icon, iconSize , isDisabled, isNegative, isPrimary, label } = this.props;
|
||||
const { accountId, className, icon, iconSize , isDisabled, isNegative, isPrimary, isUnsigned, label } = this.props;
|
||||
const { isSending } = this.state;
|
||||
const needsAccount = isUnsigned
|
||||
? false
|
||||
: !accountId;
|
||||
|
||||
return (
|
||||
<Button
|
||||
className={className}
|
||||
icon={icon}
|
||||
isDisabled={isSending || isDisabled || !accountId}
|
||||
isDisabled={isSending || isDisabled || needsAccount}
|
||||
isLoading={isSending}
|
||||
isNegative={isNegative}
|
||||
isPrimary={isUndefined(isPrimary) ? !isNegative : isPrimary}
|
||||
@ -75,7 +79,7 @@ class TxButtonInner extends React.PureComponent<InnerProps> {
|
||||
}
|
||||
|
||||
private send = (): void => {
|
||||
const { accountId, api, onClick, onUpdate, params = [], queueExtrinsic, tx = '', extrinsic: propsExtrinsic } = this.props;
|
||||
const { accountId, api, isUnsigned, onClick, onUpdate, params = [], queueExtrinsic, tx = '', extrinsic: propsExtrinsic } = this.props;
|
||||
let extrinsic: any;
|
||||
|
||||
if (propsExtrinsic) {
|
||||
@ -99,6 +103,7 @@ class TxButtonInner extends React.PureComponent<InnerProps> {
|
||||
queueExtrinsic({
|
||||
accountId,
|
||||
extrinsic,
|
||||
isUnsigned,
|
||||
txFailedCb: this.onFailed,
|
||||
txSuccessCb: this.onSuccess,
|
||||
txUpdateCb: onUpdate
|
||||
|
||||
Loading…
Reference in New Issue
Block a user