class FunctionForm extends React.Component {
constructor(props) {
super(props);
this.state = {
fields: {},
error: false,
message: null,
receipt: null
};
this.child = React.createRef();
this.showResults = this.showResults.bind(this);
this.handleCopyClick = this.handleCopyClick.bind(this);
}
handleCopyClick(e){
this.child.current.copyCommand(e);
}
_getFunctionParamFields(elem){
if(this.props.abi.type == 'fallback') return '';
return '(' + this.props.abi.inputs
.map((input, i) => )
.join(', ') + ')';
}
_getMethodType(elem){
return (this.props.abi.constant == true || this.props.abi.stateMutability == 'view' || this.props.abi.stateMutability == 'pure') ? 'call' : 'send';
}
render(){
const functionName = this.props.abi.name;
const isDuplicated = this.props.contract.options.jsonInterface.filter(x => x.name == functionName).length > 1;
const contract = this.props.contract;
const receipt = this.state.receipt;
return
{this.props.abi.type == 'function' ? this.props.abi.name : (this.props.abi.type == 'fallback' ? '(fallback)' : this.props.abi.name)}
{
receipt != null || !this.state.error && this.state.message != null
?
{ receipt != null ?
- Status: {receipt.status}
- Transaction Hash: {receipt.transactionHash}
{
receipt.events != null ?
- Events:
{
Object.keys(receipt.events).map(function(ev, index) {
if(!isNaN(ev)) return null;
const eventAbi = contract.options.jsonInterface.filter(x => x.name == ev)[0];
let props = [];
for(let prop in receipt.events[ev].returnValues){
if(isNaN(prop)){
let input = eventAbi.inputs.filter(x => x.name == prop)[0];
props.push(prop + ': '
+ (input.type.indexOf('int') == -1 ? '"' : '')
+ receipt.events[ev].returnValues[prop]
+ (input.type.indexOf('int') == -1 ? '"' : ''));
}
}
return - {ev}({props.join(', ')})
;
})
}
: ''
}
: ""
}
{
!this.state.error && this.state.message != null
?
{
(this.state.message !== null && typeof this.state.message === 'object')
?
(
{
this.props.abi.outputs.filter(x => x.name !== "").length > 0
?
Object.keys(this.state.message).map((key, index) => {
if(isNaN(key)){
return - {key}: {this.state.message[key]}
} else {
return '';
}
})
:
Object.keys(this.state.message).map((key, index) => {
return - {key}: {this.state.message[key]}
})
}
)
:
(typeof this.state.message === "boolean" ?
(this.state.message ? 'true' : 'false')
:
this.state.message)
}
: '' }
: ''
}
;
}
showResults(_error, _message, _receipt){
this.setState({
error: _error,
message: _message,
receipt: _receipt
})
}
}