Check for buffer type and decode to hex instead of utf8 (#1469)

* Check for buffer type and decode to hex instead of utf8

* Fix typo
This commit is contained in:
HenryNguyen5 2018-04-06 17:34:43 -04:00 committed by Daniel Ternyak
parent 307e941684
commit 08a7cb1f2b
1 changed files with 7 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import { setDataField, TSetDataField } from 'actions/transaction';
import { Data } from 'libs/units'; import { Data } from 'libs/units';
import { Input, Dropdown } from 'components/ui'; import { Input, Dropdown } from 'components/ui';
import { INode } from 'libs/nodes'; import { INode } from 'libs/nodes';
import { bufferToHex } from 'ethereumjs-util';
interface StateProps { interface StateProps {
nodeLib: INode; nodeLib: INode;
@ -126,6 +127,10 @@ class InteractExplorerClass extends Component<Props, State> {
{selectedFunction.contract.outputs.map((output: any, index: number) => { {selectedFunction.contract.outputs.map((output: any, index: number) => {
const { type, name } = output; const { type, name } = output;
const parsedName = name === '' ? index : name; const parsedName = name === '' ? index : name;
const rawFieldValue = outputs[parsedName] || '';
const decodedFieldValue = Buffer.isBuffer(rawFieldValue)
? bufferToHex(rawFieldValue)
: rawFieldValue;
return ( return (
<div key={parsedName} className="input-group-wrapper InteractExplorer-func-out"> <div key={parsedName} className="input-group-wrapper InteractExplorer-func-out">
@ -133,7 +138,7 @@ class InteractExplorerClass extends Component<Props, State> {
<div className="input-group-header"> {name + ' ' + type}</div> <div className="input-group-header"> {name + ' ' + type}</div>
<Input <Input
className="InteractExplorer-func-out-input " className="InteractExplorer-func-out-input "
value={outputs[parsedName] || ''} value={decodedFieldValue}
disabled={true} disabled={true}
/> />
</label> </label>
@ -187,6 +192,7 @@ class InteractExplorerClass extends Component<Props, State> {
const results = await nodeLib.sendCallRequest(callData); const results = await nodeLib.sendCallRequest(callData);
const parsedResult = selectedFunction!.contract.decodeOutput(results); const parsedResult = selectedFunction!.contract.decodeOutput(results);
this.setState({ outputs: parsedResult }); this.setState({ outputs: parsedResult });
} catch (e) { } catch (e) {
this.props.showNotification( this.props.showNotification(