aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send.utils.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-05-24 00:43:25 +0800
committerDan <danjm.com@gmail.com>2018-05-31 07:24:31 +0800
commit0f20fce9b761fc0aa16d61b2b739fa7f9b9f6a7d (patch)
treed3c566fdb0485a690da5048264372514661e3830 /ui/app/components/send_/send.utils.js
parent3d597cd1d2bfe74abdb945f8ec3ffe96853ed90a (diff)
downloadtangerine-wallet-browser-0f20fce9b761fc0aa16d61b2b739fa7f9b9f6a7d.tar.gz
tangerine-wallet-browser-0f20fce9b761fc0aa16d61b2b739fa7f9b9f6a7d.tar.zst
tangerine-wallet-browser-0f20fce9b761fc0aa16d61b2b739fa7f9b9f6a7d.zip
Auto update gas estimate when to changes.
Diffstat (limited to 'ui/app/components/send_/send.utils.js')
-rw-r--r--ui/app/components/send_/send.utils.js30
1 files changed, 17 insertions, 13 deletions
diff --git a/ui/app/components/send_/send.utils.js b/ui/app/components/send_/send.utils.js
index 4c731c91b..750411908 100644
--- a/ui/app/components/send_/send.utils.js
+++ b/ui/app/components/send_/send.utils.js
@@ -15,8 +15,8 @@ const {
ONE_GWEI_IN_WEI_HEX,
SIMPLE_GAS_COST,
} = require('./send.constants')
-const EthQuery = require('ethjs-query')
const abi = require('ethereumjs-abi')
+const ethUtil = require('ethereumjs-util')
module.exports = {
calcGasTotal,
@@ -165,40 +165,44 @@ function doesAmountErrorRequireUpdate ({
return amountErrorRequiresUpdate
}
-async function estimateGas ({ selectedAddress, selectedToken, data, blockGasLimit, to }) {
- const ethQuery = new EthQuery(global.ethereumProvider)
+async function estimateGas ({ selectedAddress, selectedToken, data, blockGasLimit, to, value, gasPrice, estimateGasMethod }) {
const { symbol } = selectedToken || {}
- const estimatedGasParams = { from: selectedAddress }
+ const paramsForGasEstimate = { from: selectedAddress, value, gasPrice }
if (symbol) {
- Object.assign(estimatedGasParams, { value: '0x0' })
+ Object.assign(paramsForGasEstimate, { value: '0x0' })
}
if (data) {
- Object.assign(estimatedGasParams, { data })
+ Object.assign(paramsForGasEstimate, { data })
}
// if recipient has no code, gas is 21k max:
const hasRecipient = Boolean(to)
let code
- if (hasRecipient) code = await ethQuery.getCode(to)
-
+ if (hasRecipient) code = await global.eth.getCode(to)
if (hasRecipient && (!code || code === '0x')) {
return SIMPLE_GAS_COST
}
- estimatedGasParams.to = to
+ paramsForGasEstimate.to = to
// if not, fall back to block gasLimit
- estimatedGasParams.gas = multiplyCurrencies(blockGasLimit, 0.95, {
+ paramsForGasEstimate.gas = ethUtil.addHexPrefix(multiplyCurrencies(blockGasLimit, 0.95, {
multiplicandBase: 16,
multiplierBase: 10,
roundDown: '0',
toNumericBase: 'hex',
- })
+ }))
// run tx
- const estimatedGas = await ethQuery.estimateGas(estimatedGasParams)
- return estimatedGas.toString(16)
+ return new Promise((resolve, reject) => {
+ estimateGasMethod(paramsForGasEstimate, (err, estimatedGas) => {
+ if (err) {
+ reject(err)
+ }
+ resolve(estimatedGas.toString(16))
+ })
+ })
}
function generateTokenTransferData (selectedAddress, selectedToken) {