From 918fb71df3079a80102fb77893af69ef3372e75f Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 27 Sep 2018 11:16:24 -0230 Subject: Update gas when hex data changes on send screen --- ui/app/components/send/send.utils.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'ui/app/components/send/send.utils.js') diff --git a/ui/app/components/send/send.utils.js b/ui/app/components/send/send.utils.js index aa255c3d4..ccfdd67c0 100644 --- a/ui/app/components/send/send.utils.js +++ b/ui/app/components/send/send.utils.js @@ -200,16 +200,34 @@ function doesAmountErrorRequireUpdate ({ return amountErrorRequiresUpdate } -async function estimateGas ({ selectedAddress, selectedToken, blockGasLimit, to, value, gasPrice, estimateGasMethod }) { +async function estimateGas ({ + selectedAddress, + selectedToken, + blockGasLimit, + to, + value, + data, + gasPrice, + estimateGasMethod, +}) { const paramsForGasEstimate = { from: selectedAddress, value, gasPrice } if (selectedToken) { paramsForGasEstimate.value = '0x0' paramsForGasEstimate.data = generateTokenTransferData({ toAddress: to, amount: value, selectedToken }) + paramsForGasEstimate.to = selectedToken.address + } else { + if (data) { + paramsForGasEstimate.data = data + } + + if (to) { + paramsForGasEstimate.to = to + } } // if recipient has no code, gas is 21k max: - if (!selectedToken) { + if (!selectedToken && !data) { const code = Boolean(to) && await global.eth.getCode(to) if (!code || code === '0x') { return SIMPLE_GAS_COST @@ -218,8 +236,6 @@ async function estimateGas ({ selectedAddress, selectedToken, blockGasLimit, to, return BASE_TOKEN_GAS_COST } - paramsForGasEstimate.to = selectedToken ? selectedToken.address : to - // if not, fall back to block gasLimit paramsForGasEstimate.gas = ethUtil.addHexPrefix(multiplyCurrencies(blockGasLimit, 0.95, { multiplicandBase: 16, -- cgit v1.2.3 From c9f22916dd026445b2eb0ba343b54cc672fdf6f0 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 27 Sep 2018 12:22:12 -0230 Subject: Rework estimateGas logic The tests still pass! --- ui/app/components/send/send.utils.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ui/app/components/send/send.utils.js') 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, -- cgit v1.2.3