Skip to content

Commit

Permalink
Use method identifiers to allocat function call results underneath co…
Browse files Browse the repository at this point in the history
…rrect form in ui
  • Loading branch information
ssteiger committed Jun 15, 2019
1 parent 13b0721 commit 80168fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
47 changes: 30 additions & 17 deletions app/components/contract-form/Functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export default class Functions extends Component<Props> {

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 = {}
Expand Down Expand Up @@ -37,7 +43,7 @@ export default class Functions extends Component<Props> {
functionDetails: abiFunc,
inputs: inputValues,
transactionValue,
account: web3.selectedAccount,
account: selectedAccount,
})
}

Expand Down Expand Up @@ -248,33 +254,40 @@ export default class Functions extends Component<Props> {
*/

// 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 (
<React.Fragment>
<Text strong>functions</Text>
{
abi.map((abiPart, key) => {
console.log(abiPart)
if (abiPart.type === 'function') {
return (
<Form
Expand All @@ -289,7 +302,7 @@ export default class Functions extends Component<Props> {
{renderEthInput(abiPart)}
<Button block htmlType='submit'>call</Button>
<Text style={{ color:'#52c41a', overflowWrap:'break-word' }}>
{functionCallResults[this.getEncodeFunctionSignature(abiPart)]}
{this.getFunctionCallResults(abiPart)}
</Text>
</Form>
)
Expand Down
14 changes: 9 additions & 5 deletions app/components/contract-form/SendEther.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ import { Form, InputNumber, Button, Typography, } from 'antd'

export default class SendEther extends Component<Props> {

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)
}
Expand Down

0 comments on commit 80168fd

Please sign in to comment.