aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-09-27 22:52:12 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-10-01 23:23:32 +0800
commitc9f22916dd026445b2eb0ba343b54cc672fdf6f0 (patch)
tree2fd9d4359da836e35864bc93c9e81043bee8888b
parent918fb71df3079a80102fb77893af69ef3372e75f (diff)
downloadtangerine-wallet-browser-c9f22916dd026445b2eb0ba343b54cc672fdf6f0.tar
tangerine-wallet-browser-c9f22916dd026445b2eb0ba343b54cc672fdf6f0.tar.gz
tangerine-wallet-browser-c9f22916dd026445b2eb0ba343b54cc672fdf6f0.tar.bz2
tangerine-wallet-browser-c9f22916dd026445b2eb0ba343b54cc672fdf6f0.tar.lz
tangerine-wallet-browser-c9f22916dd026445b2eb0ba343b54cc672fdf6f0.tar.xz
tangerine-wallet-browser-c9f22916dd026445b2eb0ba343b54cc672fdf6f0.tar.zst
tangerine-wallet-browser-c9f22916dd026445b2eb0ba343b54cc672fdf6f0.zip
Rework estimateGas logic
The tests still pass!
-rw-r--r--ui/app/components/send/send.utils.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/ui/app/components/send/send.utils.js b/ui/app/components/send/send.utils.js
index ccfdd67c0..a18a9e4b3 100644
--- a/ui/app/components/send/send.utils.js
+++ b/ui/app/components/send/send.utils.js
@@ -212,6 +212,16 @@ async function estimateGas ({
}) {
const paramsForGasEstimate = { from: selectedAddress, value, gasPrice }
+ // if recipient has no code, gas is 21k max:
+ if (!selectedToken && !data) {
+ const code = Boolean(to) && await global.eth.getCode(to)
+ if (!code || code === '0x') {
+ return SIMPLE_GAS_COST
+ }
+ } else if (selectedToken && !to) {
+ return BASE_TOKEN_GAS_COST
+ }
+
if (selectedToken) {
paramsForGasEstimate.value = '0x0'
paramsForGasEstimate.data = generateTokenTransferData({ toAddress: to, amount: value, selectedToken })
@@ -226,16 +236,6 @@ async function estimateGas ({
}
}
- // if recipient has no code, gas is 21k max:
- if (!selectedToken && !data) {
- const code = Boolean(to) && await global.eth.getCode(to)
- if (!code || code === '0x') {
- return SIMPLE_GAS_COST
- }
- } else if (selectedToken && !to) {
- return BASE_TOKEN_GAS_COST
- }
-
// if not, fall back to block gasLimit
paramsForGasEstimate.gas = ethUtil.addHexPrefix(multiplyCurrencies(blockGasLimit, 0.95, {
multiplicandBase: 16,