aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-28 10:18:39 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-28 10:19:05 +0800
commit4370ca0cef1f58e78b7d596c0976d6b18fe998f8 (patch)
tree26630dd1a28d7f0267468797d6c5d595ad384d8c /ui
parent2b0e939abdfe8207d47cce863aab48898dbf4e8c (diff)
downloadtangerine-wallet-browser-4370ca0cef1f58e78b7d596c0976d6b18fe998f8.tar
tangerine-wallet-browser-4370ca0cef1f58e78b7d596c0976d6b18fe998f8.tar.gz
tangerine-wallet-browser-4370ca0cef1f58e78b7d596c0976d6b18fe998f8.tar.bz2
tangerine-wallet-browser-4370ca0cef1f58e78b7d596c0976d6b18fe998f8.tar.lz
tangerine-wallet-browser-4370ca0cef1f58e78b7d596c0976d6b18fe998f8.tar.xz
tangerine-wallet-browser-4370ca0cef1f58e78b7d596c0976d6b18fe998f8.tar.zst
tangerine-wallet-browser-4370ca0cef1f58e78b7d596c0976d6b18fe998f8.zip
Got gas live re-estimating
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/hex-as-decimal-input.js1
-rw-r--r--ui/app/components/pending-tx-details.js42
2 files changed, 23 insertions, 20 deletions
diff --git a/ui/app/components/hex-as-decimal-input.js b/ui/app/components/hex-as-decimal-input.js
index 95d805335..254232a0a 100644
--- a/ui/app/components/hex-as-decimal-input.js
+++ b/ui/app/components/hex-as-decimal-input.js
@@ -43,6 +43,7 @@ HexAsDecimalInput.prototype.render = function () {
display: 'block',
textAlign: 'right',
backgroundColor: 'transparent',
+ border: '1px solid #bdbdbd',
}, style),
value: decimalValue,
onChange: (event) => {
diff --git a/ui/app/components/pending-tx-details.js b/ui/app/components/pending-tx-details.js
index d6ae8b85f..d94d65d5b 100644
--- a/ui/app/components/pending-tx-details.js
+++ b/ui/app/components/pending-tx-details.js
@@ -1,10 +1,10 @@
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
-const debounce = require('debounce')
const extend = require('xtend')
+const ethUtil = require('ethereumjs-util')
+const BN = ethUtil.BN
-const TxUtils = require('../../../app/scripts/lib/tx-utils')
const MiniAccountPanel = require('./mini-account-panel')
const EthBalance = require('./eth-balance')
const util = require('../util')
@@ -242,11 +242,6 @@ PTXP.miniAccountPanelForRecipient = function () {
}
}
-PTXP.componentDidMount = function () {
- this.txUtils = new TxUtils(web3.currentProvider)
- this.recalculateGas = debounce(this.calculateGas.bind(this), 300)
-}
-
PTXP.componentDidUpdate = function (prevProps, prevState) {
const state = this.state || {}
log.debug(`pending-tx-details componentDidUpdate`)
@@ -255,10 +250,9 @@ PTXP.componentDidUpdate = function (prevProps, prevState) {
// Only if gas or gasPrice changed:
if (prevState &&
(state.gas !== prevState.gas ||
- state.gasPrice !== prevState.gasPrice) &&
- this.recalculateGas) {
+ state.gasPrice !== prevState.gasPrice)) {
log.debug(`recalculating gas since prev state change: ${JSON.stringify({ prevState, state })}`)
- this.recalculateGas()
+ this.calculateGas()
}
}
@@ -285,19 +279,27 @@ PTXP.gatherParams = function () {
PTXP.calculateGas = function () {
const txMeta = this.gatherParams()
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
- this.txUtils.analyzeGasUsage(txMeta, (err, result) => {
- if (err) {
- return this.setState({ error: err })
- }
- const { txFee, maxCost } = result || txMeta
- if (txFee === txMeta.txFee && maxCost === txMeta.maxCost) {
- log.warn(`Recalculating gas resulted in no change.`)
- }
- log.debug(`pending-tx-details calculated tx fee: ${txFee} and max cost: ${maxCost}`)
- this.setState({ txFee, maxCost })
+
+ var txParams = txMeta.txParams
+ var gasMultiplier = txMeta.gasMultiplier
+ var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
+ var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
+ gasPrice = gasPrice.mul(new BN(gasMultiplier * 100), 10).div(new BN(100, 10))
+ var txFee = gasCost.mul(gasPrice)
+ var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
+ var maxCost = txValue.add(txFee)
+
+ this.setState({
+ txFee: '0x' + txFee.toString('hex'),
+ maxCost: '0x' + maxCost.toString('hex'),
})
}
+function bnFromHex (hex) {
+ var bn = new BN(ethUtil.stripHexPrefix(hex), 16)
+ return bn
+}
+
function forwardCarrat () {
return (