add gasPrice to transactions for contracts

This commit is contained in:
Jonathan Rainville 2018-08-28 15:02:05 -04:00 committed by Iuri Matias
parent 1d841a3d5c
commit 713015811c
4 changed files with 16 additions and 7 deletions

View File

@ -113,14 +113,14 @@ export const contractFile = {
export const CONTRACT_FUNCTION = createRequestTypes('CONTRACT_FUNCTION');
export const contractFunction = {
post: (contractName, method, inputs) => action(CONTRACT_FUNCTION[REQUEST], {contractName, method, inputs}),
post: (contractName, method, inputs, gasPrice) => action(CONTRACT_FUNCTION[REQUEST], {contractName, method, inputs, gasPrice}),
success: (result, payload) => action(CONTRACT_FUNCTION[SUCCESS], {contractFunctions: [{...result, ...payload}]}),
failure: (error) => action(CONTRACT_FUNCTION[FAILURE], {error})
};
export const CONTRACT_DEPLOY = createRequestTypes('CONTRACT_DEPLOY');
export const contractDeploy = {
post: (contractName, method, inputs) => action(CONTRACT_DEPLOY[REQUEST], {contractName, method, inputs}),
post: (contractName, method, inputs, gasPrice) => action(CONTRACT_DEPLOY[REQUEST], {contractName, method, inputs, gasPrice}),
success: (result, payload) => action(CONTRACT_DEPLOY[SUCCESS], {contractDeploys: [{...result, ...payload}]}),
failure: (error) => action(CONTRACT_DEPLOY[FAILURE], {error})
};

View File

@ -15,13 +15,17 @@ class ContractFunction extends Component {
this.state = {inputs: {}};
}
static isPureCall(method) {
return (method.mutability === 'view' || method.mutability === 'pure');
}
buttonTitle() {
const {method} = this.props;
if (method.name === 'constructor') {
return 'Deploy';
}
return (method.mutability === 'view' || method.mutability === 'pure') ? 'Call' : 'Send';
return ContractFunction.isPureCall(method) ? 'Call' : 'Send';
}
inputsAsArray() {
@ -38,7 +42,7 @@ class ContractFunction extends Component {
handleCall(e) {
e.preventDefault();
this.props.postContractFunction(this.props.contractProfile.name, this.props.method.name, this.inputsAsArray());
this.props.postContractFunction(this.props.contractProfile.name, this.props.method.name, this.inputsAsArray(), this.state.inputs.gasPrice * 1000000000);
}
callDisabled() {
@ -59,6 +63,11 @@ class ContractFunction extends Component {
<Form.Input placeholder={input.type} onChange={(e) => this.handleChange(e, input.name)}/>
</Form.Group>
))}
{!ContractFunction.isPureCall(this.props.method) &&
<Form.Group key="gasPrice" label="Gas Price (in GWei)(optional)">
<Form.Input onChange={(e) => this.handleChange(e, 'gasPrice')}/>
</Form.Group>
}
<Button color="primary" disabled={this.callDisabled()} onClick={(e) => this.handleCall(e)}>
{this.buttonTitle()}
</Button>

View File

@ -73,7 +73,7 @@ class GasStation extends Component {
<Grid.Col>
<Card>
<Card.Header>
<Card.Title>Gas Price Estimator</Card.Title>
<Card.Title>Gas Price Estimator (for Mainnet)</Card.Title>
<Card.Options>
<CopyToClipboard text={currentGasStep.price}
onCopy={() => this.setState({copied: true})}

View File

@ -112,7 +112,7 @@ class ContractsManager {
self.events.request("blockchain:contract:create", {abi: contract.abiDefinition, address: contract.deployedAddress}, (contractObj) => {
try {
contractObj.methods[req.body.method].apply(this, req.body.inputs)[funcCall]({from: account}, (error, result) => {
contractObj.methods[req.body.method].apply(this, req.body.inputs)[funcCall]({from: account, gasPrice: req.body.gasPrice}, (error, result) => {
if (error) {
return res.send({result: error.message});
}
@ -148,7 +148,7 @@ class ContractsManager {
try {
const params = {data: `0x${contract.code}`, arguments: req.body.inputs};
let gas = await contractObj.deploy(params).estimateGas();
let newContract = await contractObj.deploy(params).send({from: account, gas});
let newContract = await contractObj.deploy(params).send({from: account, gas, gasPrice: req.body.gasPrice});
res.send({result: newContract._address});
} catch (e) {
res.send({result: e.message});