diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-06-29 11:48:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-29 11:48:05 +0800 |
commit | a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb (patch) | |
tree | 9a3ada0440a1bef575be3b1e2fd900b4afa99bc4 | |
parent | 218f2e84db71f30858b61938346f913ef71141fd (diff) | |
parent | 696d6261338e96a3a7786e08940ab51cad98cb22 (diff) | |
download | tangerine-wallet-browser-a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb.tar tangerine-wallet-browser-a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb.tar.gz tangerine-wallet-browser-a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb.tar.bz2 tangerine-wallet-browser-a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb.tar.lz tangerine-wallet-browser-a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb.tar.xz tangerine-wallet-browser-a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb.tar.zst tangerine-wallet-browser-a1fb1b8d3e016a3734fb7453e31e7d79c6637bbb.zip |
Merge pull request #4690 from MetaMask/i4662-token-gas-estimate-ux
Set base estimate for token sends to be updated once recipient address specified
-rw-r--r-- | ui/app/components/send_/send.constants.js | 2 | ||||
-rw-r--r-- | ui/app/components/send_/send.utils.js | 3 | ||||
-rw-r--r-- | ui/app/components/send_/tests/send-utils.test.js | 6 |
3 files changed, 11 insertions, 0 deletions
diff --git a/ui/app/components/send_/send.constants.js b/ui/app/components/send_/send.constants.js index df5dee371..8acdf0641 100644 --- a/ui/app/components/send_/send.constants.js +++ b/ui/app/components/send_/send.constants.js @@ -36,6 +36,7 @@ const ONE_GWEI_IN_WEI_HEX = ethUtil.addHexPrefix(conversionUtil('0x1', { })) const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send. +const BASE_TOKEN_GAS_COST = '0x186a0' // Hex for 100000, a base estimate for token transfers. module.exports = { INSUFFICIENT_FUNDS_ERROR, @@ -52,4 +53,5 @@ module.exports = { REQUIRED_ERROR, SIMPLE_GAS_COST, TOKEN_TRANSFER_FUNCTION_SIGNATURE, + BASE_TOKEN_GAS_COST, } diff --git a/ui/app/components/send_/send.utils.js b/ui/app/components/send_/send.utils.js index dfd459731..872df1d2f 100644 --- a/ui/app/components/send_/send.utils.js +++ b/ui/app/components/send_/send.utils.js @@ -10,6 +10,7 @@ const { calcTokenAmount, } = require('../../token-util') const { + BASE_TOKEN_GAS_COST, INSUFFICIENT_FUNDS_ERROR, INSUFFICIENT_TOKENS_ERROR, NEGATIVE_ETH_ERROR, @@ -183,6 +184,8 @@ async function estimateGas ({ selectedAddress, selectedToken, blockGasLimit, to, if (!code || code === '0x') { return SIMPLE_GAS_COST } + } else if (selectedToken && !to) { + return BASE_TOKEN_GAS_COST } paramsForGasEstimate.to = selectedToken ? selectedToken.address : to diff --git a/ui/app/components/send_/tests/send-utils.test.js b/ui/app/components/send_/tests/send-utils.test.js index f3d5674b7..a518a64e9 100644 --- a/ui/app/components/send_/tests/send-utils.test.js +++ b/ui/app/components/send_/tests/send-utils.test.js @@ -2,6 +2,7 @@ import assert from 'assert' import sinon from 'sinon' import proxyquire from 'proxyquire' import { + BASE_TOKEN_GAS_COST, ONE_GWEI_IN_WEI_HEX, SIMPLE_GAS_COST, } from '../send.constants' @@ -336,6 +337,11 @@ describe('send utils', () => { assert.notEqual(result, SIMPLE_GAS_COST) }) + it(`should return ${BASE_TOKEN_GAS_COST} if passed a selectedToken but no to address`, async () => { + const result = await estimateGas(Object.assign({}, baseMockParams, { to: null, selectedToken: { address: '' } })) + assert.equal(result, BASE_TOKEN_GAS_COST) + }) + it(`should return the adjusted blockGasLimit if it fails with a 'Transaction execution error.'`, async () => { const result = await estimateGas(Object.assign({}, baseMockParams, { to: 'isContract willFailBecauseOf:Transaction execution error.', |