diff options
author | Akshit Kr Nagpal <nagpalkrakshit@gmail.com> | 2019-06-29 06:51:51 +0800 |
---|---|---|
committer | Frankie <frankie.diamond@gmail.com> | 2019-06-29 06:51:51 +0800 |
commit | d16d6f483c28c07aedcaa0bc69228109fa5fbade (patch) | |
tree | 007c42ba91000b13dcf590c0cca564e4ea0fbbd4 /app/scripts/controllers | |
parent | 90eb5c44406aaf0be68a1bb366cf98023a2214b2 (diff) | |
download | tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar.gz tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar.bz2 tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar.lz tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar.xz tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar.zst tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.zip |
Validate txParams in TransactionStateManager.addTx (#6713)
* Normalize and Validate txParams in TransactionStateManager.addTx too
* Added Tests
* Updated normalizeAndValidateParams to return the new txParams
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/transactions/tx-state-manager.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index 9504f43a5..2aa28c270 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -125,6 +125,11 @@ class TransactionStateManager extends EventEmitter { @returns {object} the txMeta */ addTx (txMeta) { + // normalize and validate txParams if present + if (txMeta.txParams) { + txMeta.txParams = this.normalizeAndValidateTxParams(txMeta.txParams) + } + this.once(`${txMeta.id}:signed`, function () { this.removeAllListeners(`${txMeta.id}:rejected`) }) @@ -174,13 +179,9 @@ class TransactionStateManager extends EventEmitter { @param [note] {string} - a note about the update for history */ updateTx (txMeta, note) { - // validate txParams + // normalize and validate txParams if present if (txMeta.txParams) { - if (typeof txMeta.txParams.data === 'undefined') { - delete txMeta.txParams.data - } - txMeta.txParams = normalizeTxParams(txMeta.txParams, false) - this.validateTxParams(txMeta.txParams) + txMeta.txParams = this.normalizeAndValidateTxParams(txMeta.txParams) } // create txMeta snapshot for history @@ -213,6 +214,19 @@ class TransactionStateManager extends EventEmitter { } /** + * normalize and validate txParams members + * @param txParams {object} - txParams + */ + normalizeAndValidateTxParams (txParams) { + if (typeof txParams.data === 'undefined') { + delete txParams.data + } + txParams = normalizeTxParams(txParams, false) + this.validateTxParams(txParams) + return txParams + } + + /** validates txParams members by type @param txParams {object} - txParams to validate */ |