Fix default values for contract queries (#4819)
This commit is contained in:
parent
f16b53d92a
commit
94a39619b5
@ -14,6 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import LinearProgress from 'material-ui/LinearProgress';
|
import LinearProgress from 'material-ui/LinearProgress';
|
||||||
@ -24,6 +25,7 @@ import { bindActionCreators } from 'redux';
|
|||||||
import { newError } from '~/redux/actions';
|
import { newError } from '~/redux/actions';
|
||||||
import { Button, TypedInput } from '~/ui';
|
import { Button, TypedInput } from '~/ui';
|
||||||
import { arrayOrObjectProptype } from '~/util/proptypes';
|
import { arrayOrObjectProptype } from '~/util/proptypes';
|
||||||
|
import { parseAbiType } from '~/util/abi';
|
||||||
|
|
||||||
import styles from './queries.css';
|
import styles from './queries.css';
|
||||||
|
|
||||||
@ -44,11 +46,35 @@ class InputQuery extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
inputs: [],
|
||||||
isValid: true,
|
isValid: true,
|
||||||
results: [],
|
results: [],
|
||||||
values: {}
|
values: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentWillMount () {
|
||||||
|
this.parseInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps (nextProps) {
|
||||||
|
const prevInputTypes = this.props.inputs.map((input) => input.type);
|
||||||
|
const nextInputTypes = nextProps.inputs.map((input) => input.type);
|
||||||
|
|
||||||
|
if (!isEqual(prevInputTypes, nextInputTypes)) {
|
||||||
|
this.parseInputs(nextProps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parseInputs (props = this.props) {
|
||||||
|
const inputs = props.inputs.map((input) => ({ ...input, parsed: parseAbiType(input.type) }));
|
||||||
|
const values = inputs.reduce((values, input, index) => {
|
||||||
|
values[index] = input.parsed.default;
|
||||||
|
return values;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
this.setState({ inputs, values });
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { name, className } = this.props;
|
const { name, className } = this.props;
|
||||||
|
|
||||||
@ -64,10 +90,9 @@ class InputQuery extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderContent () {
|
renderContent () {
|
||||||
const { inputs } = this.props;
|
const { inputs } = this.state;
|
||||||
|
|
||||||
const { isValid } = this.state;
|
const { isValid } = this.state;
|
||||||
|
|
||||||
const inputsFields = inputs
|
const inputsFields = inputs
|
||||||
.map((input, index) => this.renderInput(input, index));
|
.map((input, index) => this.renderInput(input, index));
|
||||||
|
|
||||||
@ -190,15 +215,15 @@ class InputQuery extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClick = () => {
|
onClick = () => {
|
||||||
const { values } = this.state;
|
const { inputs, values } = this.state;
|
||||||
const { inputs, contract, name, outputs, signature } = this.props;
|
const { contract, name, outputs, signature } = this.props;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
results: []
|
results: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const inputValues = inputs.map((input, index) => values[index] || '');
|
const inputValues = inputs.map((input, index) => values[index]);
|
||||||
|
|
||||||
contract
|
contract
|
||||||
.instance[signature]
|
.instance[signature]
|
||||||
|
Loading…
Reference in New Issue
Block a user