Small contracts fixes & adjustments (#1092)

* Adjust code deploy redirection (w & wo contracts)

* Allow contract call with 0 value

* TxButton to calculate all on click

* Stray logging
This commit is contained in:
Jaco Greeff 2019-05-07 10:00:53 +02:00 committed by GitHub
parent 653fd09d2b
commit f461c84642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 37 deletions

View File

@ -40,7 +40,7 @@ class Call extends React.PureComponent<Props, State> {
render () {
const { t } = this.props;
const { accountId, address, contractAbi, endowment, gasLimit, isAddressValid, method } = this.state;
const { accountId, address, contractAbi, gasLimit, isAddressValid, method } = this.state;
const contractOptions = store.getAllContracts().map(({ json: { address, name } }) => ({
text: `${name} (${address})`,
value: address
@ -62,7 +62,7 @@ class Call extends React.PureComponent<Props, State> {
const defaultContract = contractOptions.length
? contractOptions[contractOptions.length - 1].value
: undefined;
const isEndowValid = !endowment.isZero();
const isEndowValid = true; // !endowment.isZero();
const isGasValid = !gasLimit.isZero();
const isValid = !!accountId && isEndowValid && isGasValid && isAddressValid;

View File

@ -271,7 +271,9 @@ class Deploy extends React.PureComponent<Props, State> {
}
private redirect () {
window.location.hash = this.props.basePath;
window.location.hash = store.hasContracts
? `${this.props.basePath}/instantiate`
: this.props.basePath;
}
}

View File

@ -9,6 +9,7 @@ import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { QueueTx, QueueTx$ExtrinsicAdd, TxCallback } from './Status/types';
import React from 'react';
import { SubmittableResult } from '@polkadot/api';
import { withApi } from '@polkadot/ui-api';
import { assert, isFunction, isUndefined } from '@polkadot/util';
@ -50,36 +51,6 @@ class TxButtonInner extends React.PureComponent<InnerProps> {
isSending: false
} as State;
static getDerivedStateFromProps ({ api, isDisabled, params = [], txqueue = [], tx = '', extrinsic: propsExtrinsic }: InnerProps): State | null {
if (isDisabled || !propsExtrinsic && (!tx || tx.length === 0)) {
return null;
}
let extrinsic: any;
if (propsExtrinsic) {
extrinsic = propsExtrinsic;
} else {
const [section, method] = tx.split('.');
assert(api.tx[section] && api.tx[section][method], `Unable to find api.tx.${section}.${method}`);
extrinsic = api.tx[section][method](
...(isFunction(params) ? params() : params)
);
}
let isSending = false;
const queuedTx = txqueue.find(({ extrinsic: ex }) => ex === extrinsic);
if (queuedTx) {
isSending = ['broadcast', 'sending'].includes(queuedTx.status);
}
return {
extrinsic,
isSending
};
}
render () {
const { accountId, isDisabled, isNegative, isPrimary, label } = this.props;
const { isSending } = this.state;
@ -97,21 +68,53 @@ class TxButtonInner extends React.PureComponent<InnerProps> {
}
private send = (): void => {
const { accountId, onClick, onFailed, onSuccess, onUpdate, queueExtrinsic } = this.props;
const { extrinsic } = this.state;
const { accountId, api, onClick, onUpdate, params = [], queueExtrinsic, tx = '', extrinsic: propsExtrinsic } = this.props;
let extrinsic: any;
if (propsExtrinsic) {
extrinsic = propsExtrinsic;
} else {
const [section, method] = tx.split('.');
assert(api.tx[section] && api.tx[section][method], `Unable to find api.tx.${section}.${method}`);
extrinsic = api.tx[section][method](...(
isFunction(params)
? params()
: params
));
}
assert(extrinsic, 'Expected generated extrinsic passed to TxButton');
this.setState({ isSending: true });
queueExtrinsic({
accountId,
extrinsic,
txFailedCb: onFailed,
txSuccessCb: onSuccess,
txFailedCb: this.onFailed,
txSuccessCb: this.onSuccess,
txUpdateCb: onUpdate
});
onClick && onClick();
}
private onFailed = (result: SubmittableResult): void => {
const { onFailed } = this.props;
this.setState({ isSending: false });
onFailed && onFailed(result);
}
private onSuccess = (result: SubmittableResult): void => {
const { onSuccess } = this.props;
this.setState({ isSending: false });
onSuccess && onSuccess(result);
}
}
class TxButton extends React.PureComponent<Props> {