From 67ee5b21e6f64ac22e65f2712ae13dd8c09ed113 Mon Sep 17 00:00:00 2001 From: Chi Kei Chan Date: Thu, 28 Sep 2017 17:39:53 -0700 Subject: [PATCH] Query for gas estimates --- package.json | 5 +++-- ui/app/actions.js | 4 ++-- ui/app/components/send-token/index.js | 18 ++++++++++++++++-- ui/app/send.js | 7 ++++++- yarn.lock | 9 ++++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 264c73e06..5763f6e32 100644 --- a/package.json +++ b/package.json @@ -74,8 +74,8 @@ "end-of-stream": "^1.1.0", "ensnare": "^1.0.0", "eth-bin-to-ops": "^1.0.1", - "eth-contract-metadata": "^1.1.5", "eth-block-tracker": "^2.2.0", + "eth-contract-metadata": "^1.1.5", "eth-hd-keyring": "^1.1.1", "eth-json-rpc-filters": "^1.2.1", "eth-keyring-controller": "^2.0.0", @@ -84,6 +84,7 @@ "eth-sig-util": "^1.2.2", "eth-simple-keyring": "^1.1.1", "eth-token-tracker": "^1.1.4", + "ethereumjs-abi": "^0.6.4", "ethereumjs-tx": "^1.3.0", "ethereumjs-util": "github:ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9", "ethereumjs-wallet": "^0.6.0", @@ -216,8 +217,8 @@ "react-addons-test-utils": "^15.5.1", "react-test-renderer": "^15.5.4", "react-testutils-additions": "^15.2.0", - "stylelint-config-standard": "^17.0.0", "sinon": "^4.0.0", + "stylelint-config-standard": "^17.0.0", "tape": "^4.5.1", "testem": "^1.10.3", "uglifyify": "^4.0.2", diff --git a/ui/app/actions.js b/ui/app/actions.js index 0b860ee63..ff3240abf 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -453,10 +453,10 @@ function signTx (txData) { } } -function estimateGas () { +function estimateGas (params = {}) { return (dispatch) => { return new Promise((resolve, reject) => { - global.ethQuery.estimateGas({}, (err, data) => { + global.ethQuery.estimateGas(params, (err, data) => { if (err) { dispatch(actions.displayWarning(err.message)) return reject(err) diff --git a/ui/app/components/send-token/index.js b/ui/app/components/send-token/index.js index 6e4c909be..a95a0a6d8 100644 --- a/ui/app/components/send-token/index.js +++ b/ui/app/components/send-token/index.js @@ -2,6 +2,7 @@ const Component = require('react').Component const connect = require('react-redux').connect const h = require('react-hyperscript') const classnames = require('classnames') +const abi = require('ethereumjs-abi') const inherits = require('util').inherits const actions = require('../../actions') const selectors = require('../../selectors') @@ -57,7 +58,7 @@ function mapDispatchToProps (dispatch) { dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData)) ), updateTokenExchangeRate: token => dispatch(actions.updateTokenExchangeRate(token)), - estimateGas: () => dispatch(actions.estimateGas()), + estimateGas: params => dispatch(actions.estimateGas(params)), getGasPrice: () => dispatch(actions.getGasPrice()), } } @@ -83,15 +84,28 @@ SendTokenScreen.prototype.componentWillMount = function () { selectedToken: { symbol }, getGasPrice, estimateGas, + selectedAddress, } = this.props updateTokenExchangeRate(symbol) + const data = Array.prototype.map.call( + abi.rawEncode(['address', 'uint256'], [selectedAddress, '0x0']), + x => ('00' + x.toString(16)).slice(-2) + ).join('') + + console.log(data) Promise.all([ getGasPrice(), - estimateGas(), + estimateGas({ + from: selectedAddress, + value: '0x0', + gas: '746a528800', + data, + }), ]) .then(([blockGasPrice, estimatedGas]) => { + console.log({ blockGasPrice, estimatedGas}) this.setState({ gasPrice: blockGasPrice, gasLimit: estimatedGas, diff --git a/ui/app/send.js b/ui/app/send.js index d92a6f2d5..2e6409f32 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -100,12 +100,17 @@ function SendTransactionScreen () { SendTransactionScreen.prototype.componentWillMount = function () { const { newTx } = this.state + const { address } = this.props Promise.all([ this.props.dispatch(getGasPrice()), - this.props.dispatch(estimateGas()), + this.props.dispatch(estimateGas({ + from: address, + gas: '746a528800', + })), ]) .then(([blockGasPrice, estimatedGas]) => { + console.log({ blockGasPrice, estimatedGas}) this.setState({ newTx: { ...newTx, diff --git a/yarn.lock b/yarn.lock index 4be3a3684..acd448e6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -397,7 +397,7 @@ async-eventemitter@^0.2.2: dependencies: async "^2.4.0" -"async-eventemitter@github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c": +async-eventemitter@ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c: version "0.2.3" resolved "https://codeload.github.com/ahultgren/async-eventemitter/tar.gz/fa06e39e56786ba541c180061dbf2c0a5bbf951c" dependencies: @@ -3510,6 +3510,13 @@ ethereum-ens-network-map@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/ethereum-ens-network-map/-/ethereum-ens-network-map-1.0.0.tgz#43cd7669ce950a789e151001118d4d65f210eeb7" +ethereumjs-abi@^0.6.4: + version "0.6.4" + resolved "https://registry.yarnpkg.com/ethereumjs-abi/-/ethereumjs-abi-0.6.4.tgz#9ba1bb056492d00c27279f6eccd4d58275912c1a" + dependencies: + bn.js "^4.10.0" + ethereumjs-util "^4.3.0" + "ethereumjs-abi@git+https://github.com/ethereumjs/ethereumjs-abi.git": version "0.6.4" resolved "git+https://github.com/ethereumjs/ethereumjs-abi.git#ee6ded67235a98f3ef4ae2a338aee70a9f68fe20"