Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #43 from maxme/issue/fix-contract-form-bytes32-submit
Browse files Browse the repository at this point in the history
Fix an issue when strings were sent directly to contract method expecting bytes32
  • Loading branch information
honestbonsai authored Feb 19, 2019
2 parents f411823 + 249b88a commit 3d3e22f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/ContractForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ContractForm extends Component {
this.handleSubmit = this.handleSubmit.bind(this);

this.contracts = context.drizzle.contracts;
this.utils = context.drizzle.web3.utils;

// Get the contract ABI
const abi = this.contracts[this.props.contract].abi;
Expand All @@ -35,15 +36,23 @@ class ContractForm extends Component {

handleSubmit(event) {
event.preventDefault();

const convertedInputs = this.inputs.map((input, index) => {
if (input.type === 'bytes32') {
return this.utils.toHex(this.state[input.name])
}
return this.state[input.name];
})

if (this.props.sendArgs) {
return this.contracts[this.props.contract].methods[
this.props.method
].cacheSend(...Object.values(this.state), this.props.sendArgs);
].cacheSend(...convertedInputs, this.props.sendArgs);
}

this.contracts[this.props.contract].methods[this.props.method].cacheSend(
...Object.values(this.state),
);
return this.contracts[this.props.contract].methods[
this.props.method
].cacheSend(...convertedInputs);
}

handleInputChange(event) {
Expand Down
18 changes: 13 additions & 5 deletions src/new-context-api/ContractForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,25 @@ class ContractForm extends Component {
this.state = initialState;
}

handleSubmit() {
handleSubmit(event) {
event.preventDefault();

const convertedInputs = this.inputs.map((input, index) => {
if (input.type === 'bytes32') {
return this.utils.toHex(this.state[input.name])
}
return this.state[input.name];
})

if (this.props.sendArgs) {
return this.contracts[this.props.contract].methods[
this.props.method
].cacheSend(...Object.values(this.state), this.props.sendArgs);
].cacheSend(...convertedInputs, this.props.sendArgs);
}

this.contracts[this.props.contract].methods[this.props.method].cacheSend(
...Object.values(this.state),
);
return this.contracts[this.props.contract].methods[
this.props.method
].cacheSend(...convertedInputs);
}

handleInputChange(event) {
Expand Down

0 comments on commit 3d3e22f

Please sign in to comment.