diff options
author | Alexander Tseung <alextsg@gmail.com> | 2018-04-06 14:17:22 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2018-04-06 14:17:22 +0800 |
commit | 4c15c0d3baa15638d75aa5e1a8f336e515d35f95 (patch) | |
tree | 2cdb6ea7faaf39bb577986d62fc2b17bef586def /app/scripts/controllers | |
parent | 2db55cd0de31abacf2d00eba76505fa6b880928d (diff) | |
parent | 77486a23654a7709091f99bc7ef76d894a46113a (diff) | |
download | tangerine-wallet-browser-4c15c0d3baa15638d75aa5e1a8f336e515d35f95.tar tangerine-wallet-browser-4c15c0d3baa15638d75aa5e1a8f336e515d35f95.tar.gz tangerine-wallet-browser-4c15c0d3baa15638d75aa5e1a8f336e515d35f95.tar.bz2 tangerine-wallet-browser-4c15c0d3baa15638d75aa5e1a8f336e515d35f95.tar.lz tangerine-wallet-browser-4c15c0d3baa15638d75aa5e1a8f336e515d35f95.tar.xz tangerine-wallet-browser-4c15c0d3baa15638d75aa5e1a8f336e515d35f95.tar.zst tangerine-wallet-browser-4c15c0d3baa15638d75aa5e1a8f336e515d35f95.zip |
Merge branch 'master' of https://github.com/MetaMask/metamask-extension into cb-254
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/transactions.js | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index a73a8b36d..336b0d8f7 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -185,10 +185,10 @@ module.exports = class TransactionController extends EventEmitter { async addUnapprovedTransaction (txParams) { // validate - this._validateTxParams(txParams) - this._normalizeTxParams(txParams) + const normalizedTxParams = this._normalizeTxParams(txParams) + this._validateTxParams(normalizedTxParams) // construct txMeta - let txMeta = this.txStateManager.generateTxMeta({txParams}) + let txMeta = this.txStateManager.generateTxMeta({ txParams: normalizedTxParams }) this.addTx(txMeta) this.emit('newUnapprovedTx', txMeta) // add default tx params @@ -315,25 +315,24 @@ module.exports = class TransactionController extends EventEmitter { // _normalizeTxParams (txParams) { - delete txParams.chainId - - if ( !txParams.to ) { - delete txParams.to - } else { - txParams.to = ethUtil.addHexPrefix(txParams.to) - } - txParams.from = ethUtil.addHexPrefix(txParams.from).toLowerCase() - - if (!txParams.data) { - delete txParams.data - } else { - txParams.data = ethUtil.addHexPrefix(txParams.data) + // functions that handle normalizing of that key in txParams + const whiteList = { + from: from => ethUtil.addHexPrefix(from).toLowerCase(), + to: to => ethUtil.addHexPrefix(txParams.to).toLowerCase(), + nonce: nonce => ethUtil.addHexPrefix(nonce), + value: value => ethUtil.addHexPrefix(value), + data: data => ethUtil.addHexPrefix(data), + gas: gas => ethUtil.addHexPrefix(gas), + gasPrice: gasPrice => ethUtil.addHexPrefix(gasPrice), } - if (txParams.value) txParams.value = ethUtil.addHexPrefix(txParams.value) + // apply only keys in the whiteList + const normalizedTxParams = {} + Object.keys(whiteList).forEach((key) => { + if (txParams[key]) normalizedTxParams[key] = whiteList[key](txParams[key]) + }) - if (txParams.gas) txParams.gas = ethUtil.addHexPrefix(txParams.gas) - if (txParams.gasPrice) txParams.gas = ethUtil.addHexPrefix(txParams.gas) + return normalizedTxParams } _validateTxParams (txParams) { |