mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1154 from MetaMask/i765-gaslimits
Add ability to customize gas and gasPrice on tx confirmation screen
This commit is contained in:
commit
f162a11585
@ -3,6 +3,7 @@
|
|||||||
## Current Master
|
## Current Master
|
||||||
|
|
||||||
- Add personal_sign method support.
|
- Add personal_sign method support.
|
||||||
|
- Add ability to customize gas and gasPrice on the transaction approval screen.
|
||||||
|
|
||||||
## 3.3.0 2017-2-20
|
## 3.3.0 2017-2-20
|
||||||
|
|
||||||
|
@ -228,18 +228,6 @@ ConfigManager.prototype._emitUpdates = function (state) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager.prototype.getGasMultiplier = function () {
|
|
||||||
var data = this.getData()
|
|
||||||
return data.gasMultiplier
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigManager.prototype.setGasMultiplier = function (gasMultiplier) {
|
|
||||||
var data = this.getData()
|
|
||||||
|
|
||||||
data.gasMultiplier = gasMultiplier
|
|
||||||
this.setData(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigManager.prototype.setLostAccounts = function (lostAccounts) {
|
ConfigManager.prototype.setLostAccounts = function (lostAccounts) {
|
||||||
var data = this.getData()
|
var data = this.getData()
|
||||||
data.lostAccounts = lostAccounts
|
data.lostAccounts = lostAccounts
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const BN = ethUtil.BN
|
|
||||||
const Transaction = require('ethereumjs-tx')
|
const Transaction = require('ethereumjs-tx')
|
||||||
|
|
||||||
module.exports = IdManagement
|
module.exports = IdManagement
|
||||||
@ -25,13 +24,9 @@ function IdManagement (opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.signTx = function (txParams) {
|
this.signTx = function (txParams) {
|
||||||
// calculate gas with custom gas multiplier
|
|
||||||
var gasMultiplier = this.configManager.getGasMultiplier() || 1
|
|
||||||
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16)
|
|
||||||
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100, 10)).div(new BN(100, 10))
|
|
||||||
txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber())
|
|
||||||
// normalize values
|
|
||||||
|
|
||||||
|
// normalize values
|
||||||
|
txParams.gasPrice = ethUtil.intToHex(txParams.gasPrice)
|
||||||
txParams.to = ethUtil.addHexPrefix(txParams.to)
|
txParams.to = ethUtil.addHexPrefix(txParams.to)
|
||||||
txParams.from = ethUtil.addHexPrefix(txParams.from.toLowerCase())
|
txParams.from = ethUtil.addHexPrefix(txParams.from.toLowerCase())
|
||||||
txParams.value = ethUtil.addHexPrefix(txParams.value)
|
txParams.value = ethUtil.addHexPrefix(txParams.value)
|
||||||
|
@ -95,7 +95,6 @@ IdentityStore.prototype.getState = function () {
|
|||||||
isUnlocked: this._isUnlocked(),
|
isUnlocked: this._isUnlocked(),
|
||||||
seedWords: seedWords,
|
seedWords: seedWords,
|
||||||
selectedAddress: configManager.getSelectedAccount(),
|
selectedAddress: configManager.getSelectedAccount(),
|
||||||
gasMultiplier: configManager.getGasMultiplier(),
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,11 +92,10 @@ module.exports = class txProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// builds ethTx from txParams object
|
// builds ethTx from txParams object
|
||||||
buildEthTxFromParams (txParams, gasMultiplier = 1) {
|
buildEthTxFromParams (txParams) {
|
||||||
// apply gas multiplyer
|
// apply gas multiplyer
|
||||||
let gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16)
|
let gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16)
|
||||||
// multiply and divide by 100 so as to add percision to integer mul
|
// multiply and divide by 100 so as to add percision to integer mul
|
||||||
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100, 10)).div(new BN(100, 10))
|
|
||||||
txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber())
|
txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber())
|
||||||
// normalize values
|
// normalize values
|
||||||
txParams.to = normalize(txParams.to)
|
txParams.to = normalize(txParams.to)
|
||||||
@ -106,6 +105,7 @@ module.exports = class txProviderUtils {
|
|||||||
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
|
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
|
||||||
txParams.nonce = normalize(txParams.nonce)
|
txParams.nonce = normalize(txParams.nonce)
|
||||||
// build ethTx
|
// build ethTx
|
||||||
|
log.info(`Prepared tx for signing: ${JSON.stringify(txParams)}`)
|
||||||
const ethTx = new Transaction(txParams)
|
const ethTx = new Transaction(txParams)
|
||||||
return ethTx
|
return ethTx
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
setProviderType: this.setProviderType.bind(this),
|
setProviderType: this.setProviderType.bind(this),
|
||||||
useEtherscanProvider: this.useEtherscanProvider.bind(this),
|
useEtherscanProvider: this.useEtherscanProvider.bind(this),
|
||||||
setCurrentCurrency: this.setCurrentCurrency.bind(this),
|
setCurrentCurrency: this.setCurrentCurrency.bind(this),
|
||||||
setGasMultiplier: this.setGasMultiplier.bind(this),
|
|
||||||
markAccountsFound: this.markAccountsFound.bind(this),
|
markAccountsFound: this.markAccountsFound.bind(this),
|
||||||
// coinbase
|
// coinbase
|
||||||
buyEth: this.buyEth.bind(this),
|
buyEth: this.buyEth.bind(this),
|
||||||
@ -278,6 +277,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// txManager
|
// txManager
|
||||||
approveTransaction: txManager.approveTransaction.bind(txManager),
|
approveTransaction: txManager.approveTransaction.bind(txManager),
|
||||||
cancelTransaction: txManager.cancelTransaction.bind(txManager),
|
cancelTransaction: txManager.cancelTransaction.bind(txManager),
|
||||||
|
updateAndApproveTransaction: this.updateAndApproveTx.bind(this),
|
||||||
|
|
||||||
// messageManager
|
// messageManager
|
||||||
signMessage: nodeify(this.signMessage).bind(this),
|
signMessage: nodeify(this.signMessage).bind(this),
|
||||||
@ -407,6 +407,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
//
|
//
|
||||||
|
|
||||||
newUnapprovedTransaction (txParams, cb) {
|
newUnapprovedTransaction (txParams, cb) {
|
||||||
|
log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
|
||||||
const self = this
|
const self = this
|
||||||
self.txManager.addUnapprovedTransaction(txParams, (err, txMeta) => {
|
self.txManager.addUnapprovedTransaction(txParams, (err, txMeta) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
@ -462,6 +463,13 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateAndApproveTx(txMeta, cb) {
|
||||||
|
log.debug(`MetaMaskController - updateAndApproveTx: ${JSON.stringify(txMeta)}`)
|
||||||
|
const txManager = this.txManager
|
||||||
|
txManager.updateTx(txMeta)
|
||||||
|
txManager.approveTransaction(txMeta.id, cb)
|
||||||
|
}
|
||||||
|
|
||||||
signMessage (msgParams, cb) {
|
signMessage (msgParams, cb) {
|
||||||
log.info('MetaMaskController - signMessage')
|
log.info('MetaMaskController - signMessage')
|
||||||
const msgId = msgParams.metamaskId
|
const msgId = msgParams.metamaskId
|
||||||
@ -644,15 +652,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
this.shapeshiftController.createShapeShiftTx(depositAddress, depositType)
|
this.shapeshiftController.createShapeShiftTx(depositAddress, depositType)
|
||||||
}
|
}
|
||||||
|
|
||||||
setGasMultiplier (gasMultiplier, cb) {
|
|
||||||
try {
|
|
||||||
this.txManager.setGasMultiplier(gasMultiplier)
|
|
||||||
cb()
|
|
||||||
} catch (err) {
|
|
||||||
cb(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// network
|
// network
|
||||||
//
|
//
|
||||||
|
@ -13,7 +13,6 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
super()
|
super()
|
||||||
this.store = new ObservableStore(extend({
|
this.store = new ObservableStore(extend({
|
||||||
transactions: [],
|
transactions: [],
|
||||||
gasMultiplier: 1,
|
|
||||||
}, opts.initState))
|
}, opts.initState))
|
||||||
this.memStore = new ObservableStore({})
|
this.memStore = new ObservableStore({})
|
||||||
this.networkStore = opts.networkStore || new ObservableStore({})
|
this.networkStore = opts.networkStore || new ObservableStore({})
|
||||||
@ -52,14 +51,6 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network)
|
return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network)
|
||||||
}
|
}
|
||||||
|
|
||||||
getGasMultiplier () {
|
|
||||||
return this.store.getState().gasMultiplier
|
|
||||||
}
|
|
||||||
|
|
||||||
setGasMultiplier (gasMultiplier) {
|
|
||||||
return this.store.updateState({ gasMultiplier })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds a tx to the txlist
|
// Adds a tx to the txlist
|
||||||
addTx (txMeta) {
|
addTx (txMeta) {
|
||||||
var txList = this.getTxList()
|
var txList = this.getTxList()
|
||||||
@ -129,7 +120,6 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
id: txId,
|
id: txId,
|
||||||
time: time,
|
time: time,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
gasMultiplier: this.getGasMultiplier(),
|
|
||||||
metamaskNetworkId: this.getNetwork(),
|
metamaskNetworkId: this.getNetwork(),
|
||||||
txParams: txParams,
|
txParams: txParams,
|
||||||
}
|
}
|
||||||
@ -147,16 +137,15 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
|
|
||||||
setMaxTxCostAndFee (txMeta) {
|
setMaxTxCostAndFee (txMeta) {
|
||||||
var txParams = txMeta.txParams
|
var txParams = txMeta.txParams
|
||||||
var gasMultiplier = txMeta.gasMultiplier
|
|
||||||
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
|
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
|
||||||
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 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 txFee = gasCost.mul(gasPrice)
|
||||||
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
|
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
|
||||||
var maxCost = txValue.add(txFee)
|
var maxCost = txValue.add(txFee)
|
||||||
txMeta.txFee = txFee
|
txMeta.txFee = txFee
|
||||||
txMeta.txValue = txValue
|
txMeta.txValue = txValue
|
||||||
txMeta.maxCost = maxCost
|
txMeta.maxCost = maxCost
|
||||||
|
txMeta.gasPrice = gasPrice
|
||||||
this.updateTx(txMeta)
|
this.updateTx(txMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +198,7 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
let txMeta = this.getTx(txId)
|
let txMeta = this.getTx(txId)
|
||||||
let txParams = txMeta.txParams
|
let txParams = txMeta.txParams
|
||||||
let fromAddress = txParams.from
|
let fromAddress = txParams.from
|
||||||
let ethTx = this.txProviderUtils.buildEthTxFromParams(txParams, txMeta.gasMultiplier)
|
let ethTx = this.txProviderUtils.buildEthTxFromParams(txParams)
|
||||||
this.signEthTx(ethTx, fromAddress).then(() => {
|
this.signEthTx(ethTx, fromAddress).then(() => {
|
||||||
this.setTxStatusSigned(txMeta.id)
|
this.setTxStatusSigned(txMeta.id)
|
||||||
cb(null, ethUtil.bufferToHex(ethTx.serialize()))
|
cb(null, ethUtil.bufferToHex(ethTx.serialize()))
|
||||||
|
211
development/states/conf-tx.json
Normal file
211
development/states/conf-tx.json
Normal file
File diff suppressed because one or more lines are too long
@ -94,6 +94,7 @@ var actions = {
|
|||||||
cancelPersonalMsg,
|
cancelPersonalMsg,
|
||||||
sendTx: sendTx,
|
sendTx: sendTx,
|
||||||
signTx: signTx,
|
signTx: signTx,
|
||||||
|
updateAndApproveTx,
|
||||||
cancelTx: cancelTx,
|
cancelTx: cancelTx,
|
||||||
completedTx: completedTx,
|
completedTx: completedTx,
|
||||||
txError: txError,
|
txError: txError,
|
||||||
@ -387,9 +388,6 @@ function signPersonalMsg (msgData) {
|
|||||||
|
|
||||||
function signTx (txData) {
|
function signTx (txData) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
log.debug(`background.setGasMultiplier`)
|
|
||||||
background.setGasMultiplier(txData.gasMultiplier, (err) => {
|
|
||||||
if (err) return dispatch(actions.displayWarning(err.message))
|
|
||||||
web3.eth.sendTransaction(txData, (err, data) => {
|
web3.eth.sendTransaction(txData, (err, data) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
if (err) return dispatch(actions.displayWarning(err.message))
|
if (err) return dispatch(actions.displayWarning(err.message))
|
||||||
@ -397,12 +395,11 @@ function signTx (txData) {
|
|||||||
dispatch(actions.goHome())
|
dispatch(actions.goHome())
|
||||||
})
|
})
|
||||||
dispatch(this.showConfTxPage())
|
dispatch(this.showConfTxPage())
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendTx (txData) {
|
function sendTx (txData) {
|
||||||
log.info('actions: sendTx')
|
log.info(`actions - sendTx: ${JSON.stringify(txData.txParams)}`)
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
log.debug(`actions calling background.approveTransaction`)
|
log.debug(`actions calling background.approveTransaction`)
|
||||||
background.approveTransaction(txData.id, (err) => {
|
background.approveTransaction(txData.id, (err) => {
|
||||||
@ -415,6 +412,20 @@ function sendTx (txData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateAndApproveTx (txData) {
|
||||||
|
log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
|
||||||
|
return (dispatch) => {
|
||||||
|
log.debug(`actions calling background.updateAndApproveTx`)
|
||||||
|
background.updateAndApproveTransaction(txData, (err) => {
|
||||||
|
if (err) {
|
||||||
|
dispatch(actions.txError(err))
|
||||||
|
return console.error(err.message)
|
||||||
|
}
|
||||||
|
dispatch(actions.completedTx(txData.id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function completedTx (id) {
|
function completedTx (id) {
|
||||||
return {
|
return {
|
||||||
type: actions.COMPLETED_TX,
|
type: actions.COMPLETED_TX,
|
||||||
|
76
ui/app/components/hex-as-decimal-input.js
Normal file
76
ui/app/components/hex-as-decimal-input.js
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
const Component = require('react').Component
|
||||||
|
const h = require('react-hyperscript')
|
||||||
|
const inherits = require('util').inherits
|
||||||
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
const BN = ethUtil.BN
|
||||||
|
const extend = require('xtend')
|
||||||
|
|
||||||
|
module.exports = HexAsDecimalInput
|
||||||
|
|
||||||
|
inherits(HexAsDecimalInput, Component)
|
||||||
|
function HexAsDecimalInput () {
|
||||||
|
Component.call(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hex as Decimal Input
|
||||||
|
*
|
||||||
|
* A component for allowing easy, decimal editing
|
||||||
|
* of a passed in hex string value.
|
||||||
|
*
|
||||||
|
* On change, calls back its `onChange` function parameter
|
||||||
|
* and passes it an updated hex string.
|
||||||
|
*/
|
||||||
|
|
||||||
|
HexAsDecimalInput.prototype.render = function () {
|
||||||
|
const props = this.props
|
||||||
|
const { value, onChange } = props
|
||||||
|
const toEth = props.toEth
|
||||||
|
const suffix = props.suffix
|
||||||
|
const decimalValue = decimalize(value, toEth)
|
||||||
|
const style = props.style
|
||||||
|
|
||||||
|
return (
|
||||||
|
h('.flex-row', {
|
||||||
|
style: {
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
lineHeight: '13px',
|
||||||
|
fontFamily: 'Montserrat Light',
|
||||||
|
textRendering: 'geometricPrecision',
|
||||||
|
},
|
||||||
|
}, [
|
||||||
|
h('input.ether-balance.ether-balance-amount', {
|
||||||
|
style: extend({
|
||||||
|
display: 'block',
|
||||||
|
textAlign: 'right',
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
border: '1px solid #bdbdbd',
|
||||||
|
}, style),
|
||||||
|
value: decimalValue,
|
||||||
|
onChange: (event) => {
|
||||||
|
const hexString = hexify(event.target.value)
|
||||||
|
onChange(hexString)
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
h('div', {
|
||||||
|
style: {
|
||||||
|
color: ' #AEAEAE',
|
||||||
|
fontSize: '12px',
|
||||||
|
marginLeft: '5px',
|
||||||
|
marginRight: '6px',
|
||||||
|
width: '20px',
|
||||||
|
},
|
||||||
|
}, suffix),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function hexify (decimalString) {
|
||||||
|
const hexBN = new BN(decimalString, 10)
|
||||||
|
return '0x' + hexBN.toString('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
function decimalize (input, toEth) {
|
||||||
|
const strippedInput = ethUtil.stripHexPrefix(input)
|
||||||
|
const inputBN = new BN(strippedInput, 'hex')
|
||||||
|
return inputBN.toString(10)
|
||||||
|
}
|
@ -1,12 +1,16 @@
|
|||||||
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 extend = require('xtend')
|
||||||
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
const BN = ethUtil.BN
|
||||||
|
|
||||||
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')
|
||||||
const addressSummary = util.addressSummary
|
const addressSummary = util.addressSummary
|
||||||
const nameForAddress = require('../../lib/contract-namer')
|
const nameForAddress = require('../../lib/contract-namer')
|
||||||
|
const HexInput = require('./hex-as-decimal-input')
|
||||||
|
|
||||||
module.exports = PendingTxDetails
|
module.exports = PendingTxDetails
|
||||||
|
|
||||||
@ -19,7 +23,8 @@ const PTXP = PendingTxDetails.prototype
|
|||||||
|
|
||||||
PTXP.render = function () {
|
PTXP.render = function () {
|
||||||
var props = this.props
|
var props = this.props
|
||||||
var txData = props.txData
|
var state = this.state || {}
|
||||||
|
var txData = state.txMeta || props.txData
|
||||||
|
|
||||||
var txParams = txData.txParams || {}
|
var txParams = txData.txParams || {}
|
||||||
var address = txParams.from || props.selectedAddress
|
var address = txParams.from || props.selectedAddress
|
||||||
@ -27,11 +32,18 @@ PTXP.render = function () {
|
|||||||
var account = props.accounts[address]
|
var account = props.accounts[address]
|
||||||
var balance = account ? account.balance : '0x0'
|
var balance = account ? account.balance : '0x0'
|
||||||
|
|
||||||
var txFee = txData.txFee || ''
|
const gas = state.gas || txParams.gas
|
||||||
var maxCost = txData.maxCost || ''
|
const gasPrice = state.gasPrice || txData.gasPrice
|
||||||
|
const gasDefault = txParams.gas
|
||||||
|
const gasPriceDefault = txData.gasPrice
|
||||||
|
|
||||||
|
var txFee = state.txFee || txData.txFee || ''
|
||||||
|
var maxCost = state.maxCost || txData.maxCost || ''
|
||||||
var dataLength = txParams.data ? (txParams.data.length - 2) / 2 : 0
|
var dataLength = txParams.data ? (txParams.data.length - 2) / 2 : 0
|
||||||
var imageify = props.imageifyIdenticons === undefined ? true : props.imageifyIdenticons
|
var imageify = props.imageifyIdenticons === undefined ? true : props.imageifyIdenticons
|
||||||
|
|
||||||
|
log.debug(`rendering gas: ${gas}, gasPrice: ${gasPrice}, txFee: ${txFee}, maxCost: ${maxCost}`)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('div', [
|
h('div', [
|
||||||
|
|
||||||
@ -97,11 +109,63 @@ PTXP.render = function () {
|
|||||||
|
|
||||||
h('.table-box', [
|
h('.table-box', [
|
||||||
|
|
||||||
|
// Ether Value
|
||||||
|
// Currently not customizable, but easily modified
|
||||||
|
// in the way that gas and gasLimit currently are.
|
||||||
h('.row', [
|
h('.row', [
|
||||||
h('.cell.label', 'Amount'),
|
h('.cell.label', 'Amount'),
|
||||||
h(EthBalance, { value: txParams.value }),
|
h(EthBalance, { value: txParams.value }),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
// Gas Limit (customizable)
|
||||||
|
h('.cell.row', [
|
||||||
|
h('.cell.label', 'Gas Limit'),
|
||||||
|
h('.cell.value', {
|
||||||
|
}, [
|
||||||
|
h(HexInput, {
|
||||||
|
value: gas,
|
||||||
|
suffix: 'UNITS',
|
||||||
|
style: {
|
||||||
|
position: 'relative',
|
||||||
|
top: '5px',
|
||||||
|
},
|
||||||
|
onChange: (newHex) => {
|
||||||
|
log.info(`Gas limit changed to ${newHex}`)
|
||||||
|
if (newHex === '0x0') {
|
||||||
|
this.setState({gas: gasDefault})
|
||||||
|
} else {
|
||||||
|
this.setState({ gas: newHex })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
|
||||||
|
// Gas Price (customizable)
|
||||||
|
h('.cell.row', [
|
||||||
|
h('.cell.label', 'Gas Price'),
|
||||||
|
h('.cell.value', {
|
||||||
|
}, [
|
||||||
|
h(HexInput, {
|
||||||
|
value: gasPrice,
|
||||||
|
suffix: 'WEI',
|
||||||
|
style: {
|
||||||
|
position: 'relative',
|
||||||
|
top: '5px',
|
||||||
|
},
|
||||||
|
onChange: (newHex) => {
|
||||||
|
log.info(`Gas price changed to: ${newHex}`)
|
||||||
|
if (newHex === '0x0') {
|
||||||
|
this.setState({gasPrice: gasPriceDefault})
|
||||||
|
} else {
|
||||||
|
this.setState({ gasPrice: newHex })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
|
||||||
|
// Max Transaction Fee (calculated)
|
||||||
h('.cell.row', [
|
h('.cell.row', [
|
||||||
h('.cell.label', 'Max Transaction Fee'),
|
h('.cell.label', 'Max Transaction Fee'),
|
||||||
h(EthBalance, { value: txFee.toString(16) }),
|
h(EthBalance, { value: txFee.toString(16) }),
|
||||||
@ -130,6 +194,7 @@ PTXP.render = function () {
|
|||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
// Data size row:
|
||||||
h('.cell.row', {
|
h('.cell.row', {
|
||||||
style: {
|
style: {
|
||||||
background: '#f7f7f7',
|
background: '#f7f7f7',
|
||||||
@ -191,6 +256,80 @@ PTXP.miniAccountPanelForRecipient = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PTXP.componentDidUpdate = function (prevProps, previousState) {
|
||||||
|
log.debug(`pending-tx-details componentDidUpdate`)
|
||||||
|
const state = this.state || {}
|
||||||
|
const prevState = previousState || {}
|
||||||
|
const { gas, gasPrice } = state
|
||||||
|
|
||||||
|
// Only if gas or gasPrice changed:
|
||||||
|
if (!prevState ||
|
||||||
|
(gas !== prevState.gas ||
|
||||||
|
gasPrice !== prevState.gasPrice)) {
|
||||||
|
log.debug(`recalculating gas since prev state change: ${JSON.stringify({ prevState, state })}`)
|
||||||
|
this.calculateGas()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PTXP.calculateGas = function () {
|
||||||
|
const txMeta = this.gatherParams()
|
||||||
|
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
|
||||||
|
|
||||||
|
var txParams = txMeta.txParams
|
||||||
|
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
|
||||||
|
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PTXP.resetGasFields = function () {
|
||||||
|
log.debug(`pending-tx-details#resetGasFields`)
|
||||||
|
const txData = this.props.txData
|
||||||
|
this.setState({
|
||||||
|
gas: txData.txParams.gas,
|
||||||
|
gasPrice: txData.gasPrice,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// After a customizable state value has been updated,
|
||||||
|
PTXP.gatherParams = function () {
|
||||||
|
log.debug(`pending-tx-details#gatherParams`)
|
||||||
|
const props = this.props
|
||||||
|
const state = this.state || {}
|
||||||
|
const txData = state.txData || props.txData
|
||||||
|
const txParams = txData.txParams
|
||||||
|
|
||||||
|
const gas = state.gas || txParams.gas
|
||||||
|
const gasPrice = state.gasPrice || txParams.gasPrice
|
||||||
|
const resultTx = extend(txParams, {
|
||||||
|
gas,
|
||||||
|
gasPrice,
|
||||||
|
})
|
||||||
|
const resultTxMeta = extend(txData, {
|
||||||
|
txParams: resultTx,
|
||||||
|
})
|
||||||
|
log.debug(`UI has computed tx params ${JSON.stringify(resultTx)}`)
|
||||||
|
return resultTxMeta
|
||||||
|
}
|
||||||
|
|
||||||
function forwardCarrat () {
|
function forwardCarrat () {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ 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 PendingTxDetails = require('./pending-tx-details')
|
const PendingTxDetails = require('./pending-tx-details')
|
||||||
|
const extend = require('xtend')
|
||||||
|
|
||||||
module.exports = PendingTx
|
module.exports = PendingTx
|
||||||
|
|
||||||
@ -11,8 +12,9 @@ function PendingTx () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PendingTx.prototype.render = function () {
|
PendingTx.prototype.render = function () {
|
||||||
var state = this.props
|
const props = this.props
|
||||||
var txData = state.txData
|
const newProps = extend(props, {ref: 'details'})
|
||||||
|
const txData = props.txData
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
@ -21,7 +23,7 @@ PendingTx.prototype.render = function () {
|
|||||||
}, [
|
}, [
|
||||||
|
|
||||||
// tx info
|
// tx info
|
||||||
h(PendingTxDetails, state),
|
h(PendingTxDetails, newProps),
|
||||||
|
|
||||||
h('style', `
|
h('style', `
|
||||||
.conf-buttons button {
|
.conf-buttons button {
|
||||||
@ -39,7 +41,7 @@ PendingTx.prototype.render = function () {
|
|||||||
}, 'Transaction Error. Exception thrown in contract code.')
|
}, 'Transaction Error. Exception thrown in contract code.')
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
state.insufficientBalance ?
|
props.insufficientBalance ?
|
||||||
h('span.error', {
|
h('span.error', {
|
||||||
style: {
|
style: {
|
||||||
marginLeft: 50,
|
marginLeft: 50,
|
||||||
@ -57,20 +59,26 @@ PendingTx.prototype.render = function () {
|
|||||||
},
|
},
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
state.insufficientBalance ?
|
props.insufficientBalance ?
|
||||||
h('button.btn-green', {
|
h('button.btn-green', {
|
||||||
onClick: state.buyEth,
|
onClick: props.buyEth,
|
||||||
}, 'Buy Ether')
|
}, 'Buy Ether')
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
h('button.confirm', {
|
h('button.confirm', {
|
||||||
disabled: state.insufficientBalance,
|
disabled: props.insufficientBalance,
|
||||||
onClick: state.sendTransaction,
|
onClick: props.sendTransaction,
|
||||||
}, 'Accept'),
|
}, 'Accept'),
|
||||||
|
|
||||||
h('button.cancel.btn-red', {
|
h('button.cancel.btn-red', {
|
||||||
onClick: state.cancelTransaction,
|
onClick: props.cancelTransaction,
|
||||||
}, 'Reject'),
|
}, 'Reject'),
|
||||||
|
|
||||||
|
h('button', {
|
||||||
|
onClick: () => {
|
||||||
|
this.refs.details.resetGasFields()
|
||||||
|
},
|
||||||
|
}, 'Reset'),
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,7 @@ const BN = ethUtil.BN
|
|||||||
const PendingTx = require('./components/pending-tx')
|
const PendingTx = require('./components/pending-tx')
|
||||||
const PendingMsg = require('./components/pending-msg')
|
const PendingMsg = require('./components/pending-msg')
|
||||||
const PendingPersonalMsg = require('./components/pending-personal-msg')
|
const PendingPersonalMsg = require('./components/pending-personal-msg')
|
||||||
|
const Loading = require('./components/loading')
|
||||||
|
|
||||||
module.exports = connect(mapStateToProps)(ConfirmTxScreen)
|
module.exports = connect(mapStateToProps)(ConfirmTxScreen)
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ ConfirmTxScreen.prototype.render = function () {
|
|||||||
var isNotification = isPopupOrNotification() === 'notification'
|
var isNotification = isPopupOrNotification() === 'notification'
|
||||||
|
|
||||||
log.info(`rendering a combined ${unconfTxList.length} unconf msg & txs`)
|
log.info(`rendering a combined ${unconfTxList.length} unconf msg & txs`)
|
||||||
if (unconfTxList.length === 0) return null
|
if (unconfTxList.length === 0) return h(Loading)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
@ -104,6 +105,8 @@ ConfirmTxScreen.prototype.render = function () {
|
|||||||
accounts: props.accounts,
|
accounts: props.accounts,
|
||||||
identities: props.identities,
|
identities: props.identities,
|
||||||
insufficientBalance: this.checkBalanceAgainstTx(txData),
|
insufficientBalance: this.checkBalanceAgainstTx(txData),
|
||||||
|
// State actions
|
||||||
|
onTxChange: this.onTxChange.bind(this),
|
||||||
// Actions
|
// Actions
|
||||||
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress),
|
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress),
|
||||||
sendTransaction: this.sendTransaction.bind(this, txData),
|
sendTransaction: this.sendTransaction.bind(this, txData),
|
||||||
@ -141,6 +144,7 @@ function currentTxView (opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfirmTxScreen.prototype.checkBalanceAgainstTx = function (txData) {
|
ConfirmTxScreen.prototype.checkBalanceAgainstTx = function (txData) {
|
||||||
if (!txData.txParams) return false
|
if (!txData.txParams) return false
|
||||||
var props = this.props
|
var props = this.props
|
||||||
@ -158,9 +162,20 @@ ConfirmTxScreen.prototype.buyEth = function (address, event) {
|
|||||||
this.props.dispatch(actions.buyEthView(address))
|
this.props.dispatch(actions.buyEthView(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must default to any local state txData,
|
||||||
|
// to allow manual override of gas calculations.
|
||||||
ConfirmTxScreen.prototype.sendTransaction = function (txData, event) {
|
ConfirmTxScreen.prototype.sendTransaction = function (txData, event) {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
this.props.dispatch(actions.sendTx(txData))
|
const state = this.state || {}
|
||||||
|
const txMeta = state.txData
|
||||||
|
this.props.dispatch(actions.updateAndApproveTx(txMeta || txData))
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfirmTxScreen.prototype.cancelTransaction = function (txData, event) {
|
ConfirmTxScreen.prototype.cancelTransaction = function (txData, event) {
|
||||||
|
@ -291,7 +291,7 @@ function reduceApp (state, action) {
|
|||||||
case actions.SHOW_CONF_TX_PAGE:
|
case actions.SHOW_CONF_TX_PAGE:
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
currentView: {
|
currentView: {
|
||||||
name: pendingTxs ? 'confTx' : 'account-detail',
|
name: 'confTx',
|
||||||
context: 0,
|
context: 0,
|
||||||
},
|
},
|
||||||
transForward: action.transForward,
|
transForward: action.transForward,
|
||||||
|
@ -10,8 +10,6 @@ const addressSummary = require('./util').addressSummary
|
|||||||
const isHex = require('./util').isHex
|
const isHex = require('./util').isHex
|
||||||
const EthBalance = require('./components/eth-balance')
|
const EthBalance = require('./components/eth-balance')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const RangeSlider = require('./components/range-slider')
|
|
||||||
const Tooltip = require('./components/tooltip')
|
|
||||||
module.exports = connect(mapStateToProps)(SendTransactionScreen)
|
module.exports = connect(mapStateToProps)(SendTransactionScreen)
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
@ -208,73 +206,6 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
// custom gasPrice field
|
|
||||||
h('h3.flex-center.text-transform-uppercase', {
|
|
||||||
style: {
|
|
||||||
background: '#EBEBEB',
|
|
||||||
color: '#AEAEAE',
|
|
||||||
marginBottom: '5px',
|
|
||||||
},
|
|
||||||
}, [
|
|
||||||
'Transaction Fee (optional)',
|
|
||||||
h(Tooltip, {
|
|
||||||
title: `
|
|
||||||
This is used to set the transaction's gas price.
|
|
||||||
Setting it to 100% will use the full recommended value. `,
|
|
||||||
}, [
|
|
||||||
h('i.fa.fa-question-circle', {
|
|
||||||
style: {
|
|
||||||
marginLeft: '5px',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
]),
|
|
||||||
|
|
||||||
h('section.flex-column.flex-center', [
|
|
||||||
h('.flex-row', [
|
|
||||||
h(RangeSlider, {
|
|
||||||
name: 'gasInput',
|
|
||||||
options: {
|
|
||||||
mirrorInput: true,
|
|
||||||
defaultValue: 100,
|
|
||||||
min: 80,
|
|
||||||
max: 220,
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
container: {
|
|
||||||
marginBottom: '16px',
|
|
||||||
},
|
|
||||||
range: {
|
|
||||||
width: '68vw',
|
|
||||||
},
|
|
||||||
input: {
|
|
||||||
width: '5em',
|
|
||||||
marginLeft: '5px',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
h('div', {
|
|
||||||
style: {
|
|
||||||
fontSize: '12px',
|
|
||||||
paddingTop: '8px',
|
|
||||||
paddingLeft: '5px',
|
|
||||||
},
|
|
||||||
}, '%'),
|
|
||||||
]),
|
|
||||||
h('.flex-row', {
|
|
||||||
style: {
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
width: '243px',
|
|
||||||
position: 'relative',
|
|
||||||
fontSize: '12px',
|
|
||||||
right: '42px',
|
|
||||||
bottom: '30px',
|
|
||||||
},
|
|
||||||
}, [
|
|
||||||
h('span', 'Cheaper'), h('span', 'Faster'),
|
|
||||||
]),
|
|
||||||
]),
|
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -289,12 +220,11 @@ SendTransactionScreen.prototype.back = function () {
|
|||||||
this.props.dispatch(actions.backToAccountDetail(address))
|
this.props.dispatch(actions.backToAccountDetail(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.onSubmit = function (gasPrice) {
|
SendTransactionScreen.prototype.onSubmit = function () {
|
||||||
const recipient = document.querySelector('input[name="address"]').value
|
const recipient = document.querySelector('input[name="address"]').value
|
||||||
const input = document.querySelector('input[name="amount"]').value
|
const input = document.querySelector('input[name="amount"]').value
|
||||||
const value = util.normalizeEthStringToWei(input)
|
const value = util.normalizeEthStringToWei(input)
|
||||||
const txData = document.querySelector('input[name="txData"]').value
|
const txData = document.querySelector('input[name="txData"]').value
|
||||||
const gasMultiplier = document.querySelector('input[name="gasInput"]').value
|
|
||||||
const balance = this.props.balance
|
const balance = this.props.balance
|
||||||
let message
|
let message
|
||||||
|
|
||||||
@ -323,7 +253,6 @@ SendTransactionScreen.prototype.onSubmit = function (gasPrice) {
|
|||||||
var txParams = {
|
var txParams = {
|
||||||
from: this.props.address,
|
from: this.props.address,
|
||||||
value: '0x' + value.toString(16),
|
value: '0x' + value.toString(16),
|
||||||
gasMultiplier: gasMultiplier * 0.01,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipient) txParams.to = ethUtil.addHexPrefix(recipient)
|
if (recipient) txParams.to = ethUtil.addHexPrefix(recipient)
|
||||||
|
@ -37,7 +37,7 @@ function startApp (metamaskState, accountManager, opts) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// if unconfirmed txs, start on txConf page
|
// if unconfirmed txs, start on txConf page
|
||||||
var unapprovedTxsAll = txHelper(metamaskState.unapprovedTxs, metamaskState.unapprovedMsgs, metamaskState.network)
|
var unapprovedTxsAll = txHelper(metamaskState.unapprovedTxs, metamaskState.unapprovedMsgs, metamaskState.unapprovedPersonalMsgs, metamaskState.network)
|
||||||
if (unapprovedTxsAll.length > 0) {
|
if (unapprovedTxsAll.length > 0) {
|
||||||
store.dispatch(actions.showConfTxPage())
|
store.dispatch(actions.showConfTxPage())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user