1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge branch 'i765-gaslimits' of github.com:MetaMask/metamask-plugin into i765-gaslimits

This commit is contained in:
Kevin Serrano 2017-02-28 11:37:05 -08:00
commit 61a19a028b
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
2 changed files with 40 additions and 31 deletions

View File

@ -247,27 +247,55 @@ PTXP.miniAccountPanelForRecipient = function () {
}
}
PTXP.componentDidUpdate = function (prevProps, prevState) {
PTXP.componentDidUpdate = function (prevProps, previousState) {
const state = this.state || {}
const prevState = previousState || {}
const { gas, gasPrice } = state
log.debug(`pending-tx-details componentDidUpdate`)
console.log(arguments)
// Only if gas or gasPrice changed:
if (prevState &&
(state.gas !== prevState.gas ||
state.gasPrice !== prevState.gasPrice)) {
if (!prevState ||
(gas !== prevState.gas ||
gasPrice !== prevState.gasPrice)) {
log.debug(`recalculating gas since prev state change: ${JSON.stringify({ prevState, state })}`)
this.calculateGas()
// Otherwise this was a recalculation,
// so we should inform the parent:
} else {
if (this.props.onTxChange) {
this.props.onTxChange(this.gatherParams)
}
}
}
PTXP.calculateGas = function () {
const txMeta = this.gatherParams()
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
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)
const txFeeHex = '0x' + txFee.toString('hex')
const maxCostHex = '0x' + maxCost.toString('hex')
const gasPriceHex = '0x' + gasPrice.toString('hex')
txMeta.txFee = txFeeHex
txMeta.maxCost = maxCostHex
txMeta.txParams.gasPrice = gasPriceHex
this.setState({
txFee: '0x' + txFee.toString('hex'),
maxCost: '0x' + maxCost.toString('hex'),
})
if (this.props.onTxChange) {
this.props.onTxChange(txMeta)
}
}
// After a customizable state value has been updated,
PTXP.gatherParams = function () {
log.debug(`pending-tx-details#gatherParams`)
const props = this.props
@ -284,29 +312,9 @@ PTXP.gatherParams = function () {
const resultTxMeta = extend(txData, {
txParams: resultTx,
})
log.debug(`gathered params: ${JSON.stringify(resultTxMeta)}`)
return resultTxMeta
}
PTXP.calculateGas = function () {
const txMeta = this.gatherParams()
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
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 forwardCarrat () {
return (

View File

@ -164,6 +164,7 @@ ConfirmTxScreen.prototype.buyEth = function (address, event) {
// Allows the detail view to update the gas calculations,
// for manual gas controls.
ConfirmTxScreen.prototype.onTxChange = function (txData) {
log.debug(`conf-tx onTxChange triggered with ${JSON.stringify(txData)}`)
this.setState({ txData })
}