Added gas estimation before send()

This commit is contained in:
Richard Ramos 2018-12-10 15:04:31 -04:00 committed by Barry G
parent 5ce9132830
commit bdf4c373f8
4 changed files with 26 additions and 9 deletions

View File

@ -24,9 +24,13 @@ const CreateFunding = ({ refreshTable }) => (
onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => {
const { funderId, receiverId, tokenAddress, amount } = values
const account = await web3.eth.getCoinbase()
const args = [funderId, receiverId, tokenAddress, web3.utils.toWei(amount, 'ether')]
donate(...args)
.send({ from: account })
const args = [funderId, receiverId, tokenAddress, web3.utils.toWei(amount, 'ether')];
const toSend = donate(...args);
const estimateGas = await toSend.estimateGas();
toSend.send({ from: account, gas: estimateGas + 2000 })
.then(res => {
console.log({res})
setStatus({

View File

@ -64,8 +64,12 @@ class Withdraw extends PureComponent {
const { amount } = values
const args = isPaying ? [rowData.id] : [rowData.id, toWei(amount)]
const sendFn = isPaying ? confirmPayment : withdraw
sendFn(...args)
.send()
const toSend = sendFn(...args);
const estimateGas = await toSend.estimateGas();
toSend.send({gas: estimateGas + 1000})
.then(res => {
console.log({res})
})

View File

@ -4,9 +4,18 @@ import StandardToken from 'Embark/contracts/StandardToken'
import web3 from 'Embark/web3'
export const initVaultAndLP = async () => {
const lpInit = await LiquidPledgingMock.methods.initialize(LPVault._address).send()
let estimateGas;
let toSend;
toSend = LiquidPledgingMock.methods.initialize(LPVault._address);
estimateGas = await toSend.estimateGas();
const lpInit = await toSend.send({gas: estimateGas + 1000})
console.log(lpInit)
const vaultInit = await LPVault.methods.initialize(LiquidPledgingMock._address).send()
toSend = LPVault.methods.initialize(LiquidPledgingMock._address);
estimateGas = await toSend.estimateGas();
const vaultInit = await toSend.send({gas: estimateGas + 1000})
console.log(vaultInit)
}

View File

@ -10,12 +10,12 @@ export const formatPledge = async (pledgePromise, idx) => {
}
export const getAllPledges = async (start = 1) => {
const numPledges = await numberOfPledges().call()
const numPledges = await LiquidPledgingMock.methods.numberOfPledges().call()
const pledges = []
for (let i = start; i <= numPledges; i++) {
pledges.push(getPledge(i).call())
}
return Promise.all(pledges.map(formatPledge))
return Promise.all(pledges.map(formatPledge))
}
export const appendToExistingPledges = async (pledges, setState) => {