Support undefined input names (#1964)

This commit is contained in:
HenryNguyen5 2018-06-19 13:14:36 -04:00 committed by Daniel Ternyak
parent e761b9d1fb
commit 9f4f50199c
2 changed files with 22 additions and 12 deletions

View File

@ -124,13 +124,20 @@ class InteractExplorerClass extends Component<Props, State> {
{selectedFunction && (
<div key={selectedFunction.name} className="InteractExplorer-func">
{/* TODO: Use reusable components with validation */}
{selectedFunction.contract.inputs.map(input => {
{selectedFunction.contract.inputs.map((input, index) => {
const { type, name } = input;
const inputState = this.state.inputs[name];
// if name is not supplied to arg, use the index instead
// since that's what the contract ABI function factory subsitutes for the name
// if it is undefined
const parsedName = name === '' ? index : name;
const inputState = this.state.inputs[parsedName];
return (
<div key={name} className="input-group-wrapper InteractExplorer-func-in">
<div key={parsedName} className="input-group-wrapper InteractExplorer-func-in">
<label className="input-group">
<div className="input-group-header">{name + ' ' + type}</div>
<div className="input-group-header">
{(parsedName === index ? `Input#${parsedName}` : parsedName) + ' ' + type}
</div>
{type === 'bool' ? (
<Dropdown
options={[{ value: false, label: 'false' }, { value: true, label: 'true' }]}
@ -144,15 +151,15 @@ class InteractExplorerClass extends Component<Props, State> {
}
clearable={false}
onChange={({ value }: { value: boolean }) => {
this.handleBooleanDropdownChange({ value, name });
this.handleBooleanDropdownChange({ value, name: parsedName });
}}
/>
) : (
<Input
className="InteractExplorer-func-in-input"
isValid={!!(inputs[name] && inputs[name].rawData)}
name={name}
value={(inputs[name] && inputs[name].rawData) || ''}
isValid={!!(inputs[parsedName] && inputs[parsedName].rawData)}
name={parsedName}
value={(inputs[parsedName] && inputs[parsedName].rawData) || ''}
onChange={this.handleInputChange}
/>
)}

View File

@ -77,12 +77,12 @@ export default class AbiFunction {
};
private init(outputMappings: FunctionOutputMappings = []) {
this.funcParams = this.makeFuncParams();
//TODO: do this in O(n)
this.inputTypes = this.inputs.map(({ type }) => type);
this.outputTypes = this.outputs.map(({ type }) => type);
this.inputNames = this.inputs.map(({ name }) => name);
this.inputNames = this.inputs.map(({ name }, i) => name || `${i}`);
this.outputNames = this.outputs.map(({ name }, i) => outputMappings[i] || name || `${i}`);
this.funcParams = this.makeFuncParams();
this.methodSelector = abi.methodID(this.name, this.inputTypes).toString('hex');
}
@ -105,8 +105,11 @@ export default class AbiFunction {
};
private makeFuncParams = () =>
this.inputs.reduce((accumulator, currInput) => {
const { name, type } = currInput;
this.inputs.reduce((accumulator, _, idx) => {
// use our properties over this.inputs since the names can be modified
// if the input names are undefined
const name = this.inputNames[idx];
const type = this.inputTypes[idx];
const inputHandler = (inputToParse: any) =>
//TODO: introduce typechecking and typecasting mapping for inputs
({ name, type, value: this.parsePreEncodedValue(type, inputToParse) });