1
0
mirror of https://github.com/dap-ps/discover.git synced 2025-02-07 06:54:49 +00:00

fix: estimate gas

This commit is contained in:
Richard Ramos 2019-08-14 12:44:11 -04:00 committed by Andy Tudhope
parent e2c989dd32
commit 86d1f6cfb2
3 changed files with 16 additions and 14 deletions

View File

@ -259,8 +259,7 @@ class DiscoverService extends BlockchainService {
try {
return broadcastContractFn(
ConnectedDiscoverContract.methods.withdraw(id, tokenAmount.toString())
.send,
ConnectedDiscoverContract.methods.withdraw(id, tokenAmount.toString()),
this.sharedContext.account,
)
} catch (error) {
@ -281,8 +280,7 @@ class DiscoverService extends BlockchainService {
try {
const tx = await broadcastContractFn(
ConnectedDiscoverContract.methods.setMetadata(id, uploadedMetadata)
.send,
ConnectedDiscoverContract.methods.setMetadata(id, uploadedMetadata),
this.sharedContext.account,
)

View File

@ -1,11 +1,15 @@
export const broadcastContractFn = (contractMethod, account) => {
return new Promise((resolve, reject) => {
contractMethod({ from: account })
.on('transactionHash', hash => {
resolve(hash)
})
.on('error', error => {
reject(error)
})
})
return contractMethod
.estimateGas({ from: account })
.then(estimatedGas => {
contractMethod
.send({ from: account, gas: estimatedGas + 1000 })
.on('transactionHash', hash => {
resolve(hash)
})
.on('error', error => {
reject(error)
})
})
.catch(error => reject)
}

View File

@ -44,7 +44,7 @@ class SNTService extends BlockchainService {
spender,
amount.toString(),
callData,
).send,
),
this.sharedContext.account,
)
}