2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-11-17 13:59:13 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-11-17 13:59:13 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-12-23 16:42:48 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-11-17 13:59:13 +01:00
|
|
|
|
2017-05-09 12:01:44 +02:00
|
|
|
import { parseAbiType } from '@parity/shared/util/abi';
|
|
|
|
|
2016-12-05 11:47:13 +01:00
|
|
|
import { Form, TypedInput } from '~/ui';
|
2016-11-17 13:59:13 +01:00
|
|
|
|
|
|
|
import styles from '../deployContract.css';
|
|
|
|
|
|
|
|
export default class ParametersStep extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accounts: PropTypes.object.isRequired,
|
|
|
|
onParamsChange: PropTypes.func.isRequired,
|
|
|
|
|
2016-11-17 17:45:04 +01:00
|
|
|
inputs: PropTypes.array,
|
2016-11-17 13:59:13 +01:00
|
|
|
params: PropTypes.array,
|
2016-11-17 17:45:04 +01:00
|
|
|
paramsError: PropTypes.array
|
2016-11-17 13:59:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<Form>
|
|
|
|
{ this.renderConstructorInputs() }
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderConstructorInputs () {
|
|
|
|
const { accounts, params, paramsError } = this.props;
|
2016-11-17 17:45:04 +01:00
|
|
|
const { inputs } = this.props;
|
2016-11-17 13:59:13 +01:00
|
|
|
|
|
|
|
if (!inputs || !inputs.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const inputsComponents = inputs.map((input, index) => {
|
|
|
|
const onChange = (value) => this.onParamChange(index, value);
|
|
|
|
|
|
|
|
const label = `${input.name ? `${input.name}: ` : ''}${input.type}`;
|
|
|
|
const value = params[index];
|
|
|
|
const error = paramsError[index];
|
|
|
|
const param = parseAbiType(input.type);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={ index } className={ styles.funcparams }>
|
|
|
|
<TypedInput
|
|
|
|
accounts={ accounts }
|
2016-12-23 16:42:48 +01:00
|
|
|
error={ error }
|
|
|
|
isEth={ false }
|
|
|
|
label={ label }
|
2016-11-17 13:59:13 +01:00
|
|
|
onChange={ onChange }
|
|
|
|
param={ param }
|
2017-01-18 13:05:01 +01:00
|
|
|
value={ value }
|
|
|
|
/>
|
2016-11-17 13:59:13 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2017-02-14 08:29:32 +01:00
|
|
|
<div className={ styles.parameters }>
|
2016-12-23 16:42:48 +01:00
|
|
|
<p>
|
|
|
|
<FormattedMessage
|
|
|
|
id='deployContract.parameters.choose'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Choose the contract parameters'
|
|
|
|
/>
|
2016-12-23 16:42:48 +01:00
|
|
|
</p>
|
2016-11-17 13:59:13 +01:00
|
|
|
{ inputsComponents }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onParamChange = (index, value) => {
|
|
|
|
const { params, onParamsChange } = this.props;
|
|
|
|
|
|
|
|
params[index] = value;
|
|
|
|
onParamsChange(params);
|
|
|
|
}
|
|
|
|
}
|