Support undefined input names (#1964)
This commit is contained in:
parent
e761b9d1fb
commit
9f4f50199c
|
@ -124,13 +124,20 @@ class InteractExplorerClass extends Component<Props, State> {
|
||||||
{selectedFunction && (
|
{selectedFunction && (
|
||||||
<div key={selectedFunction.name} className="InteractExplorer-func">
|
<div key={selectedFunction.name} className="InteractExplorer-func">
|
||||||
{/* TODO: Use reusable components with validation */}
|
{/* TODO: Use reusable components with validation */}
|
||||||
{selectedFunction.contract.inputs.map(input => {
|
{selectedFunction.contract.inputs.map((input, index) => {
|
||||||
const { type, name } = input;
|
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 (
|
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">
|
<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' ? (
|
{type === 'bool' ? (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
options={[{ value: false, label: 'false' }, { value: true, label: 'true' }]}
|
options={[{ value: false, label: 'false' }, { value: true, label: 'true' }]}
|
||||||
|
@ -144,15 +151,15 @@ class InteractExplorerClass extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
clearable={false}
|
clearable={false}
|
||||||
onChange={({ value }: { value: boolean }) => {
|
onChange={({ value }: { value: boolean }) => {
|
||||||
this.handleBooleanDropdownChange({ value, name });
|
this.handleBooleanDropdownChange({ value, name: parsedName });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Input
|
<Input
|
||||||
className="InteractExplorer-func-in-input"
|
className="InteractExplorer-func-in-input"
|
||||||
isValid={!!(inputs[name] && inputs[name].rawData)}
|
isValid={!!(inputs[parsedName] && inputs[parsedName].rawData)}
|
||||||
name={name}
|
name={parsedName}
|
||||||
value={(inputs[name] && inputs[name].rawData) || ''}
|
value={(inputs[parsedName] && inputs[parsedName].rawData) || ''}
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -77,12 +77,12 @@ export default class AbiFunction {
|
||||||
};
|
};
|
||||||
|
|
||||||
private init(outputMappings: FunctionOutputMappings = []) {
|
private init(outputMappings: FunctionOutputMappings = []) {
|
||||||
this.funcParams = this.makeFuncParams();
|
|
||||||
//TODO: do this in O(n)
|
//TODO: do this in O(n)
|
||||||
this.inputTypes = this.inputs.map(({ type }) => type);
|
this.inputTypes = this.inputs.map(({ type }) => type);
|
||||||
this.outputTypes = this.outputs.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.outputNames = this.outputs.map(({ name }, i) => outputMappings[i] || name || `${i}`);
|
||||||
|
this.funcParams = this.makeFuncParams();
|
||||||
|
|
||||||
this.methodSelector = abi.methodID(this.name, this.inputTypes).toString('hex');
|
this.methodSelector = abi.methodID(this.name, this.inputTypes).toString('hex');
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,11 @@ export default class AbiFunction {
|
||||||
};
|
};
|
||||||
|
|
||||||
private makeFuncParams = () =>
|
private makeFuncParams = () =>
|
||||||
this.inputs.reduce((accumulator, currInput) => {
|
this.inputs.reduce((accumulator, _, idx) => {
|
||||||
const { name, type } = currInput;
|
// 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) =>
|
const inputHandler = (inputToParse: any) =>
|
||||||
//TODO: introduce typechecking and typecasting mapping for inputs
|
//TODO: introduce typechecking and typecasting mapping for inputs
|
||||||
({ name, type, value: this.parsePreEncodedValue(type, inputToParse) });
|
({ name, type, value: this.parsePreEncodedValue(type, inputToParse) });
|
||||||
|
|
Loading…
Reference in New Issue