mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Got gas live re-estimating
This commit is contained in:
parent
2b0e939abd
commit
4370ca0cef
@ -43,6 +43,7 @@ HexAsDecimalInput.prototype.render = function () {
|
|||||||
display: 'block',
|
display: 'block',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
backgroundColor: 'transparent',
|
backgroundColor: 'transparent',
|
||||||
|
border: '1px solid #bdbdbd',
|
||||||
}, style),
|
}, style),
|
||||||
value: decimalValue,
|
value: decimalValue,
|
||||||
onChange: (event) => {
|
onChange: (event) => {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
const Component = require('react').Component
|
const Component = require('react').Component
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const debounce = require('debounce')
|
|
||||||
const extend = require('xtend')
|
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 MiniAccountPanel = require('./mini-account-panel')
|
||||||
const EthBalance = require('./eth-balance')
|
const EthBalance = require('./eth-balance')
|
||||||
const util = require('../util')
|
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) {
|
PTXP.componentDidUpdate = function (prevProps, prevState) {
|
||||||
const state = this.state || {}
|
const state = this.state || {}
|
||||||
log.debug(`pending-tx-details componentDidUpdate`)
|
log.debug(`pending-tx-details componentDidUpdate`)
|
||||||
@ -255,10 +250,9 @@ PTXP.componentDidUpdate = function (prevProps, prevState) {
|
|||||||
// Only if gas or gasPrice changed:
|
// Only if gas or gasPrice changed:
|
||||||
if (prevState &&
|
if (prevState &&
|
||||||
(state.gas !== prevState.gas ||
|
(state.gas !== prevState.gas ||
|
||||||
state.gasPrice !== prevState.gasPrice) &&
|
state.gasPrice !== prevState.gasPrice)) {
|
||||||
this.recalculateGas) {
|
|
||||||
log.debug(`recalculating gas since prev state change: ${JSON.stringify({ prevState, state })}`)
|
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 () {
|
PTXP.calculateGas = function () {
|
||||||
const txMeta = this.gatherParams()
|
const txMeta = this.gatherParams()
|
||||||
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
|
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
|
||||||
this.txUtils.analyzeGasUsage(txMeta, (err, result) => {
|
|
||||||
if (err) {
|
var txParams = txMeta.txParams
|
||||||
return this.setState({ error: err })
|
var gasMultiplier = txMeta.gasMultiplier
|
||||||
}
|
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
|
||||||
const { txFee, maxCost } = result || txMeta
|
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
|
||||||
if (txFee === txMeta.txFee && maxCost === txMeta.maxCost) {
|
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100), 10).div(new BN(100, 10))
|
||||||
log.warn(`Recalculating gas resulted in no change.`)
|
var txFee = gasCost.mul(gasPrice)
|
||||||
}
|
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
|
||||||
log.debug(`pending-tx-details calculated tx fee: ${txFee} and max cost: ${maxCost}`)
|
var maxCost = txValue.add(txFee)
|
||||||
this.setState({ txFee, maxCost })
|
|
||||||
|
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 () {
|
function forwardCarrat () {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user