aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/transaction-manager.js
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-01-11 03:52:25 +0800
committerFrankie <frankie.diamond@gmail.com>2017-01-12 04:16:37 +0800
commit0fae263a9acb1f4023070b37ee1b91815e34de86 (patch)
tree06ce3969f56a2b6d2c5d4316dc6367b79540cb44 /app/scripts/transaction-manager.js
parentaf312bdc90139f99a9a08f9d0f67d63e005e2a20 (diff)
downloadtangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.gz
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.bz2
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.lz
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.xz
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.zst
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.zip
Take some of the tx Logic out of the UI and create a visble state for pending and unaproved transactions
Diffstat (limited to 'app/scripts/transaction-manager.js')
-rw-r--r--app/scripts/transaction-manager.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js
index 6becfa6d1..a279ba23a 100644
--- a/app/scripts/transaction-manager.js
+++ b/app/scripts/transaction-manager.js
@@ -25,9 +25,8 @@ module.exports = class TransactionManager extends EventEmitter {
getState () {
var selectedAccount = this.getSelectedAccount()
return {
- transactions: this.getTxList(),
unconfTxs: this.getUnapprovedTxList(),
- selectedAccountTxList: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAccount}),
+ transactions: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAccount}),
}
}
@@ -113,10 +112,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')
@@ -227,6 +242,7 @@ module.exports = class TransactionManager extends EventEmitter {
setTxStatusConfirmed (txId) {
this._setTxStatus(txId, 'confirmed')
+ this.emit('update')
}
// merges txParams obj onto txData.txParams
@@ -240,17 +256,20 @@ 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
+ if (!txHash) {
+ tx.err = { errCode: 'No hash was provided', message: 'Tx could possibly have not been submitted or an error accrued during signing'}
+ return this.updateTx(tx)
+ }
this.txProviderUtils.query.getTransactionByHash(txHash, (err, txMeta) => {
- if (err || !txMeta) {
- tx.err = err || 'Tx could possibly have not been submitted'
+ if (err) {
+ tx.err = {errorCode: err, message: 'Tx could possibly have not been submitted to the block chain',}
this.updateTx(tx)
- return txMeta ? console.error(err) : console.debug(`txMeta is ${txMeta} for:`, tx)
+ return console.error(err)
}
if (txMeta.blockNumber) {
this.setTxStatusConfirmed(txId)