diff --git a/app/components/contract-form/Functions.js b/app/components/contract-form/Functions.js index b362ecc..236ed48 100644 --- a/app/components/contract-form/Functions.js +++ b/app/components/contract-form/Functions.js @@ -9,7 +9,13 @@ export default class Functions extends Component { handleSubmit = (abiFunc) => (event) => { event.preventDefault() - const { file, web3, resetFunctionCallResults, callContractFunction } = this.props + const { + file, + accounts: { all: allAccounts=[], selected: selectedAccount={} }, + resetFunctionCallResults, + callContractFunction, + } = this.props + const formInputFields = $(event.target).find('input') let inputValues = {} @@ -37,7 +43,7 @@ export default class Functions extends Component { functionDetails: abiFunc, inputs: inputValues, transactionValue, - account: web3.selectedAccount, + account: selectedAccount, }) } @@ -248,25 +254,33 @@ export default class Functions extends Component { */ // TODO: - getEncodeFunctionSignature= (abiPart) => { + getFunctionCallResults = (abiPart) => { // https://web3js.readthedocs.io/en/1.0/web3-eth-abi.html#example - const { accounts: { all: allAccounts=[], selected: selectedAccount={} } } = this.props - /* - const encodeFunctionSignature = web3.eth.abi.encodeFunctionSignature({ - name: abiPart.name, - type: abiPart.type, - inputs: abiPart.inputs, - }) - console.log({ encodeFunctionSignature }) - return encodeFunctionSignature - */ - return abiPart + const { + file: { abi, method_identifiers }, + //accounts: { all: allAccounts=[], selected: selectedAccount={} }, + functionCallResults + } = this.props + + // TODO: wow! this seems waaay to complicated + + const identifierPlain = `${abiPart.name}(${abiPart.inputs.map((input, i) => `${input.type}`)})` + + let identifier = method_identifiers[identifierPlain] + + // weird 'method_identifiers' removes 0 values at beginning + while (identifier.length < 10) { // '0x' + 8 + identifier = identifier.slice(0, 2) + '0' + identifier.slice(2) + } + + return functionCallResults[identifier] ? functionCallResults[identifier] : '' } render() { const { Text } = Typography - const { file: { abi } } = this.props + const { renderInputs, renderEthInput, createLabel, handleSubmit } = this + const { file: { abi, method_identifiers } } = this.props const { functionCallResults } = this.props return ( @@ -274,7 +288,6 @@ export default class Functions extends Component { functions { abi.map((abiPart, key) => { - console.log(abiPart) if (abiPart.type === 'function') { return (
{ {renderEthInput(abiPart)} - {functionCallResults[this.getEncodeFunctionSignature(abiPart)]} + {this.getFunctionCallResults(abiPart)}
) diff --git a/app/components/contract-form/SendEther.js b/app/components/contract-form/SendEther.js index 992b307..607e7d5 100644 --- a/app/components/contract-form/SendEther.js +++ b/app/components/contract-form/SendEther.js @@ -7,17 +7,21 @@ import { Form, InputNumber, Button, Typography, } from 'antd' export default class SendEther extends Component { - handleSubmit = (e) => { - e.preventDefault() - const { web3, file, sendEther } = this.props - const inputFields = $(e.target).find('input') + handleSubmit = (event) => { + event.preventDefault() + const { + accounts: { all: allAccounts=[], selected: selectedAccount={} }, + file, + sendEther + } = this.props + const inputFields = $(event.target).find('input') let inputs = {} inputFields.each((index, item) => { inputs[item.name] = item.value }) inputs.file = file - inputs.account = web3.selectedAccount + inputs.account = selectedAccount sendEther(inputs) }