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

View File

@ -15,8 +15,10 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import ActionDoneAll from 'material-ui/svg-icons/action/done-all'; import ActionDoneAll from 'material-ui/svg-icons/action/done-all';
import ContentClear from 'material-ui/svg-icons/content/clear'; import ContentClear from 'material-ui/svg-icons/content/clear';
import { pick } from 'lodash';
import { BusyStep, CompletedStep, CopyToClipboard, Button, IdentityIcon, Modal, TxHash } from '~/ui'; import { BusyStep, CompletedStep, CopyToClipboard, Button, IdentityIcon, Modal, TxHash } from '~/ui';
import { ERRORS, validateAbi, validateCode, validateName } from '~/util/validation'; import { ERRORS, validateAbi, validateCode, validateName } from '~/util/validation';
@ -36,7 +38,7 @@ const STEPS = {
COMPLETED: { title: 'completed' } COMPLETED: { title: 'completed' }
}; };
export default class DeployContract extends Component { class DeployContract extends Component {
static contextTypes = { static contextTypes = {
api: PropTypes.object.isRequired, api: PropTypes.object.isRequired,
store: PropTypes.object.isRequired store: PropTypes.object.isRequired
@ -45,6 +47,7 @@ export default class DeployContract extends Component {
static propTypes = { static propTypes = {
accounts: PropTypes.object.isRequired, accounts: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired,
balances: PropTypes.object,
abi: PropTypes.string, abi: PropTypes.string,
code: PropTypes.string, code: PropTypes.string,
readOnly: PropTypes.bool, readOnly: PropTypes.bool,
@ -192,7 +195,7 @@ export default class DeployContract extends Component {
} }
renderStep () { renderStep () {
const { accounts, readOnly } = this.props; const { accounts, readOnly, balances } = this.props;
const { address, deployError, step, deployState, txhash, rejected } = this.state; const { address, deployError, step, deployState, txhash, rejected } = this.state;
if (deployError) { if (deployError) {
@ -216,6 +219,7 @@ export default class DeployContract extends Component {
<DetailsStep <DetailsStep
{ ...this.state } { ...this.state }
accounts={ accounts } accounts={ accounts }
balances={ balances }
readOnly={ readOnly } readOnly={ readOnly }
onFromAddressChange={ this.onFromAddressChange } onFromAddressChange={ this.onFromAddressChange }
onDescriptionChange={ this.onDescriptionChange } onDescriptionChange={ this.onDescriptionChange }
@ -394,3 +398,17 @@ export default class DeployContract extends Component {
this.props.onClose(); 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, amount: PropTypes.string,
amountError: PropTypes.string, amountError: PropTypes.string,
onAmountChange: PropTypes.func.isRequired, 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, fromAddress: PropTypes.string,
fromAddressError: PropTypes.string, fromAddressError: PropTypes.string,
gasEdit: PropTypes.bool, gasEdit: PropTypes.bool,
onFromAddressChange: PropTypes.func.isRequired,
func: PropTypes.object, func: PropTypes.object,
funcError: PropTypes.string, funcError: PropTypes.string,
onFuncChange: PropTypes.func, onFuncChange: PropTypes.func,
onGasEditClick: PropTypes.func, onGasEditClick: PropTypes.func,
values: PropTypes.array.isRequired, warning: PropTypes.string
valuesError: PropTypes.array.isRequired,
warning: PropTypes.string,
onValueChange: PropTypes.func.isRequired
} }
render () { 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 ( return (
<Form> <Form>
@ -61,6 +63,7 @@ export default class DetailsStep extends Component {
value={ fromAddress } value={ fromAddress }
error={ fromAddressError } error={ fromAddressError }
accounts={ accounts } accounts={ accounts }
balances={ balances }
onChange={ onFromAddressChange } /> onChange={ onFromAddressChange } />
{ this.renderFunctionSelect() } { this.renderFunctionSelect() }
{ this.renderParameters() } { this.renderParameters() }

View File

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