mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 21:46:12 +00:00
add gasPrice to transactions for contracts
This commit is contained in:
parent
1d841a3d5c
commit
713015811c
@ -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})
|
||||
};
|
||||
|
@ -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>
|
||||
|
@ -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})}
|
||||
|
@ -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});
|
||||
|
Loading…
x
Reference in New Issue
Block a user