diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-01-14 03:39:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-14 03:39:32 +0800 |
commit | c1253016fcd678445e860a666ee8c4e04506f01a (patch) | |
tree | 61eca62f325ca5594ffe4c5bbe597e7b4141b0e1 /app/scripts/transaction-manager.js | |
parent | cc5e9aca4fa2a1e78c49be680405d93ac918bccf (diff) | |
parent | 1ffaab1d9b4baa85348f2a366bfff4380b598ce5 (diff) | |
download | tangerine-wallet-browser-c1253016fcd678445e860a666ee8c4e04506f01a.tar tangerine-wallet-browser-c1253016fcd678445e860a666ee8c4e04506f01a.tar.gz tangerine-wallet-browser-c1253016fcd678445e860a666ee8c4e04506f01a.tar.bz2 tangerine-wallet-browser-c1253016fcd678445e860a666ee8c4e04506f01a.tar.lz tangerine-wallet-browser-c1253016fcd678445e860a666ee8c4e04506f01a.tar.xz tangerine-wallet-browser-c1253016fcd678445e860a666ee8c4e04506f01a.tar.zst tangerine-wallet-browser-c1253016fcd678445e860a666ee8c4e04506f01a.zip |
Merge pull request #997 from MetaMask/integrateTxManagerUI
Integrate tx manager ui
Diffstat (limited to 'app/scripts/transaction-manager.js')
-rw-r--r-- | app/scripts/transaction-manager.js | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index 6becfa6d1..f5b57f3c2 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -83,6 +83,7 @@ module.exports = class TransactionManager extends EventEmitter { var index = txList.findIndex(txData => txData.id === txId) txList[index] = txMeta this._saveTxList(txList) + this.emit('update') } get unapprovedTxCount () { @@ -113,10 +114,26 @@ module.exports = class TransactionManager extends EventEmitter { txDidComplete (txMeta, onTxDoneCb, cb, err) { if (err) return cb(err) + var {maxCost, txFee} = this.getMaxTxCostAndFee(txMeta) + txMeta.maxCost = maxCost + txMeta.txFee = txFee this.addTx(txMeta, onTxDoneCb) cb(null, txMeta) } + getMaxTxCostAndFee (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) + return {maxCost, txFee} + } + getUnapprovedTxList () { var txList = this.getTxList() return txList.filter((txMeta) => txMeta.status === 'unapproved') @@ -167,7 +184,6 @@ module.exports = class TransactionManager extends EventEmitter { this.updateTx(metaTx) var rawTx = ethUtil.bufferToHex(tx.serialize()) return Promise.resolve(rawTx) - } /* @@ -240,19 +256,31 @@ module.exports = class TransactionManager extends EventEmitter { // checks if a signed tx is in a block and // if included sets the tx status as 'confirmed' checkForTxInBlock () { - var signedTxList = this.getFilteredTxList({status: 'signed', err: undefined}) + var signedTxList = this.getFilteredTxList({status: 'signed'}) if (!signedTxList.length) return - signedTxList.forEach((tx) => { - var txHash = tx.hash - var txId = tx.id - if (!txHash) return - this.txProviderUtils.query.getTransactionByHash(txHash, (err, txMeta) => { - if (err || !txMeta) { - tx.err = err || 'Tx could possibly have not been submitted' - this.updateTx(tx) - return txMeta ? console.error(err) : console.debug(`txMeta is ${txMeta} for:`, tx) + signedTxList.forEach((txMeta) => { + var txHash = txMeta.hash + var txId = txMeta.id + if (!txHash) { + txMeta.err = { + errCode: 'No hash was provided', + message: 'We had an error while submitting this transaction, please try again.', + } + this.updateTx(txMeta) + return this._setTxStatus(txId, 'failed') + } + this.txProviderUtils.query.getTransactionByHash(txHash, (err, txParams) => { + if (err || !txParams) { + if (!txParams) return + txMeta.err = { + isWarning: true, + errorCode: err, + message: 'There was a problem loading this transaction.', + } + this.updateTx(txMeta) + return console.error(err) } - if (txMeta.blockNumber) { + if (txParams.blockNumber) { this.setTxStatusConfirmed(txId) } }) |