Add sender balances to contract (exec/deploy)

This commit is contained in:
Nicolas Gotchac 2016-12-10 16:58:03 +01:00
parent d9da8a48ff
commit 84116130f6
4 changed files with 43 additions and 11 deletions

View File

@ -37,6 +37,7 @@ export default class DetailsStep extends Component {
onParamsChange: PropTypes.func.isRequired,
onInputsChange: PropTypes.func.isRequired,
balances: PropTypes.object,
fromAddress: PropTypes.string,
fromAddressError: PropTypes.string,
name: PropTypes.string,
@ -77,6 +78,7 @@ export default class DetailsStep extends Component {
render () {
const {
accounts,
balances,
readOnly,
fromAddress, fromAddressError,
@ -97,6 +99,7 @@ export default class DetailsStep extends Component {
value={ fromAddress }
error={ fromAddressError }
accounts={ accounts }
balances={ balances }
onChange={ this.onFromAddressChange } />
<Input

View File

@ -15,8 +15,10 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import ActionDoneAll from 'material-ui/svg-icons/action/done-all';
import ContentClear from 'material-ui/svg-icons/content/clear';
import { pick } from 'lodash';
import { BusyStep, CompletedStep, CopyToClipboard, Button, IdentityIcon, Modal, TxHash } from '~/ui';
import { ERRORS, validateAbi, validateCode, validateName } from '~/util/validation';
@ -36,7 +38,7 @@ const STEPS = {
COMPLETED: { title: 'completed' }
};
export default class DeployContract extends Component {
class DeployContract extends Component {
static contextTypes = {
api: PropTypes.object.isRequired,
store: PropTypes.object.isRequired
@ -45,6 +47,7 @@ export default class DeployContract extends Component {
static propTypes = {
accounts: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
balances: PropTypes.object,
abi: PropTypes.string,
code: PropTypes.string,
readOnly: PropTypes.bool,
@ -192,7 +195,7 @@ export default class DeployContract extends Component {
}
renderStep () {
const { accounts, readOnly } = this.props;
const { accounts, readOnly, balances } = this.props;
const { address, deployError, step, deployState, txhash, rejected } = this.state;
if (deployError) {
@ -216,6 +219,7 @@ export default class DeployContract extends Component {
<DetailsStep
{ ...this.state }
accounts={ accounts }
balances={ balances }
readOnly={ readOnly }
onFromAddressChange={ this.onFromAddressChange }
onDescriptionChange={ this.onDescriptionChange }
@ -394,3 +398,17 @@ export default class DeployContract extends Component {
this.props.onClose();
}
}
function mapStateToProps (initState, initProps) {
const fromAddresses = Object.keys(initProps.accounts);
return (state) => {
const balances = pick(state.balances.balances, fromAddresses);
return { balances };
};
}
export default connect(
mapStateToProps
)(DeployContract);

View File

@ -35,22 +35,24 @@ export default class DetailsStep extends Component {
amount: PropTypes.string,
amountError: PropTypes.string,
onAmountChange: PropTypes.func.isRequired,
onFromAddressChange: PropTypes.func.isRequired,
onValueChange: PropTypes.func.isRequired,
values: PropTypes.array.isRequired,
valuesError: PropTypes.array.isRequired,
balances: PropTypes.object,
fromAddress: PropTypes.string,
fromAddressError: PropTypes.string,
gasEdit: PropTypes.bool,
onFromAddressChange: PropTypes.func.isRequired,
func: PropTypes.object,
funcError: PropTypes.string,
onFuncChange: PropTypes.func,
onGasEditClick: PropTypes.func,
values: PropTypes.array.isRequired,
valuesError: PropTypes.array.isRequired,
warning: PropTypes.string,
onValueChange: PropTypes.func.isRequired
warning: PropTypes.string
}
render () {
const { accounts, amount, amountError, fromAddress, fromAddressError, gasEdit, onGasEditClick, onFromAddressChange, onAmountChange } = this.props;
const { accounts, amount, amountError, balances, fromAddress, fromAddressError, gasEdit, onGasEditClick, onFromAddressChange, onAmountChange } = this.props;
return (
<Form>
@ -61,6 +63,7 @@ export default class DetailsStep extends Component {
value={ fromAddress }
error={ fromAddressError }
accounts={ accounts }
balances={ balances }
onChange={ onFromAddressChange } />
{ this.renderFunctionSelect() }
{ this.renderParameters() }

View File

@ -18,6 +18,8 @@ import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { observer } from 'mobx-react';
import { pick } from 'lodash';
import ActionDoneAll from 'material-ui/svg-icons/action/done-all';
import ContentClear from 'material-ui/svg-icons/content/clear';
import NavigationArrowBack from 'material-ui/svg-icons/navigation/arrow-back';
@ -57,6 +59,7 @@ class ExecuteContract extends Component {
isTest: PropTypes.bool,
fromAddress: PropTypes.string,
accounts: PropTypes.object,
balances: PropTypes.object,
contract: PropTypes.object,
gasLimit: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
@ -362,10 +365,15 @@ class ExecuteContract extends Component {
}
}
function mapStateToProps (state) {
const { gasLimit } = state.nodeStatus;
function mapStateToProps (initState, initProps) {
const fromAddresses = Object.keys(initProps.accounts);
return { gasLimit };
return (state) => {
const balances = pick(state.balances.balances, fromAddresses);
const { gasLimit } = state.nodeStatus;
return { gasLimit, balances };
};
}
function mapDispatchToProps (dispatch) {