Small fixes to contract (#3751)

* Fix contracts execution will fallback function

* Fix contract execute modal

* Working execute from Contract

* Don't dupliacet events

* Gas * 1.2 in wallet confirmations
This commit is contained in:
Nicolas Gotchac 2016-12-09 01:21:51 +01:00 committed by GitHub
parent 2d6656fc43
commit 09334ca3bd
5 changed files with 30 additions and 72 deletions

View File

@ -17,7 +17,8 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { MenuItem } from 'material-ui'; import { MenuItem } from 'material-ui';
import { AddressSelect, Form, Input, InputAddressSelect, Select } from '~/ui'; import { AddressSelect, Form, Input, Select, TypedInput } from '~/ui';
import { parseAbiType } from '~/util/abi';
import styles from '../executeContract.css'; import styles from '../executeContract.css';
@ -74,7 +75,7 @@ export default class DetailsStep extends Component {
const functions = contract.functions const functions = contract.functions
.filter((func) => !func.constant) .filter((func) => !func.constant)
.sort((a, b) => a.name.localeCompare(b.name)) .sort((a, b) => (a.name || '').localeCompare(b.name || ''))
.map((func) => { .map((func) => {
const params = (func.abi.inputs || []) const params = (func.abi.inputs || [])
.map((input, index) => { .map((input, index) => {
@ -125,56 +126,22 @@ export default class DetailsStep extends Component {
} }
return (func.abi.inputs || []).map((input, index) => { return (func.abi.inputs || []).map((input, index) => {
const onChange = (event, value) => onValueChange(event, index, value); const onChange = (value) => onValueChange(null, index, value);
const onSelect = (event, _index, value) => onValueChange(event, index, value);
const onSubmit = (value) => onValueChange(null, index, value);
const label = `${input.name}: ${input.type}`; const label = `${input.name}: ${input.type}`;
let inputbox;
switch (input.type) {
case 'address':
inputbox = (
<InputAddressSelect
accounts={ accounts }
editing
label={ label }
value={ values[index] }
error={ valuesError[index] }
onChange={ onChange } />
);
break;
case 'bool':
const boolitems = ['false', 'true'].map((bool) => {
return (
<MenuItem
key={ bool }
value={ bool }
label={ bool }>{ bool }</MenuItem>
);
});
inputbox = (
<Select
label={ label }
value={ values[index] ? 'true' : 'false' }
error={ valuesError[index] }
onChange={ onSelect }>{ boolitems }</Select>
);
break;
default:
inputbox = (
<Input
label={ label }
value={ values[index] }
error={ valuesError[index] }
onSubmit={ onSubmit } />
);
}
return ( return (
<div className={ styles.funcparams } key={ index }> <div
{ inputbox } key={ `${index}_${input.name || ''}` }
className={ styles.funcparams }
>
<TypedInput
label={ label }
value={ values[index] }
error={ valuesError[index] }
onChange={ onChange }
accounts={ accounts }
param={ parseAbiType(input.type) }
/>
</div> </div>
); );
}); });

View File

@ -23,6 +23,7 @@ import ContentClear from 'material-ui/svg-icons/content/clear';
import { BusyStep, CompletedStep, Button, IdentityIcon, Modal, TxHash } from '~/ui'; import { BusyStep, CompletedStep, Button, IdentityIcon, Modal, TxHash } from '~/ui';
import { MAX_GAS_ESTIMATION } from '../../util/constants'; import { MAX_GAS_ESTIMATION } from '../../util/constants';
import { validateAddress, validateUint } from '../../util/validation'; import { validateAddress, validateUint } from '../../util/validation';
import { parseAbiType } from '~/util/abi';
import DetailsStep from './DetailsStep'; import DetailsStep from './DetailsStep';
@ -66,7 +67,7 @@ class ExecuteContract extends Component {
const { contract } = this.props; const { contract } = this.props;
const functions = contract.functions const functions = contract.functions
.filter((func) => !func.constant) .filter((func) => !func.constant)
.sort((a, b) => a.name.localeCompare(b.name)); .sort((a, b) => (a.name || '').localeCompare(b.name || ''));
this.onFuncChange(null, functions[0]); this.onFuncChange(null, functions[0]);
} }
@ -111,7 +112,7 @@ class ExecuteContract extends Component {
<Button <Button
key='postTransaction' key='postTransaction'
label='post transaction' label='post transaction'
disabled={ sending || hasError } disabled={ !!(sending || hasError) }
icon={ <IdentityIcon address={ fromAddress } button /> } icon={ <IdentityIcon address={ fromAddress } button /> }
onClick={ this.postTransaction } /> onClick={ this.postTransaction } />
]; ];
@ -174,23 +175,9 @@ class ExecuteContract extends Component {
} }
onFuncChange = (event, func) => { onFuncChange = (event, func) => {
const values = func.inputs.map((input) => { const values = (func.abi.inputs || []).map((input) => {
switch (input.kind.type) { const parsedType = parseAbiType(input.type);
case 'address': return parsedType.default;
return '0x';
case 'bool':
return false;
case 'bytes':
return '0x';
case 'uint':
return '0';
default:
return '';
}
}); });
this.setState({ this.setState({

View File

@ -92,7 +92,7 @@ function findImports (path) {
return { error: 'File not found' }; return { error: 'File not found' };
} }
function compile (data) { function compile (data, optimized = 1) {
const { sourcecode, build } = data; const { sourcecode, build } = data;
const { longVersion } = build; const { longVersion } = build;
@ -109,7 +109,7 @@ function compile (data) {
'': sourcecode '': sourcecode
}; };
const compiled = compiler.compile({ sources: input }, 0, findImports); const compiled = compiler.compile({ sources: input }, optimized, findImports);
self.lastCompile = { self.lastCompile = {
version: longVersion, result: compiled, version: longVersion, result: compiled,

View File

@ -58,7 +58,7 @@ function modifyOperation (method, address, owner, operation) {
contract.instance[method] contract.instance[method]
.estimateGas(options, values) .estimateGas(options, values)
.then((gas) => { .then((gas) => {
options.gas = gas; options.gas = gas.mul(1.2);
return contract.instance[method].postTransaction(options, values); return contract.instance[method].postTransaction(options, values);
}) })
.then((requestId) => { .then((requestId) => {

View File

@ -15,6 +15,7 @@
// 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 { uniq } from 'lodash';
import { Container } from '~/ui'; import { Container } from '~/ui';
@ -38,7 +39,10 @@ export default class Events extends Component {
return null; return null;
} }
const list = events.map((event) => { const eventsKey = uniq(events.map((e) => e.key));
const list = eventsKey.map((eventKey) => {
const event = events.find((e) => e.key === eventKey);
return ( return (
<Event <Event
key={ event.key } key={ event.key }