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:
commit
61a19a028b
@ -247,27 +247,55 @@ PTXP.miniAccountPanelForRecipient = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PTXP.componentDidUpdate = function (prevProps, prevState) {
|
PTXP.componentDidUpdate = function (prevProps, previousState) {
|
||||||
const state = this.state || {}
|
const state = this.state || {}
|
||||||
|
const prevState = previousState || {}
|
||||||
|
const { gas, gasPrice } = state
|
||||||
|
|
||||||
log.debug(`pending-tx-details componentDidUpdate`)
|
log.debug(`pending-tx-details componentDidUpdate`)
|
||||||
console.log(arguments)
|
console.log(arguments)
|
||||||
|
|
||||||
// Only if gas or gasPrice changed:
|
// Only if gas or gasPrice changed:
|
||||||
if (prevState &&
|
if (!prevState ||
|
||||||
(state.gas !== prevState.gas ||
|
(gas !== prevState.gas ||
|
||||||
state.gasPrice !== prevState.gasPrice)) {
|
gasPrice !== prevState.gasPrice)) {
|
||||||
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.calculateGas()
|
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 () {
|
PTXP.gatherParams = function () {
|
||||||
log.debug(`pending-tx-details#gatherParams`)
|
log.debug(`pending-tx-details#gatherParams`)
|
||||||
const props = this.props
|
const props = this.props
|
||||||
@ -284,29 +312,9 @@ PTXP.gatherParams = function () {
|
|||||||
const resultTxMeta = extend(txData, {
|
const resultTxMeta = extend(txData, {
|
||||||
txParams: resultTx,
|
txParams: resultTx,
|
||||||
})
|
})
|
||||||
log.debug(`gathered params: ${JSON.stringify(resultTxMeta)}`)
|
|
||||||
return 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 () {
|
function forwardCarrat () {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
@ -164,6 +164,7 @@ ConfirmTxScreen.prototype.buyEth = function (address, event) {
|
|||||||
// Allows the detail view to update the gas calculations,
|
// Allows the detail view to update the gas calculations,
|
||||||
// for manual gas controls.
|
// for manual gas controls.
|
||||||
ConfirmTxScreen.prototype.onTxChange = function (txData) {
|
ConfirmTxScreen.prototype.onTxChange = function (txData) {
|
||||||
|
log.debug(`conf-tx onTxChange triggered with ${JSON.stringify(txData)}`)
|
||||||
this.setState({ txData })
|
this.setState({ txData })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user