From 0fae263a9acb1f4023070b37ee1b91815e34de86 Mon Sep 17 00:00:00 2001 From: Frankie Date: Tue, 10 Jan 2017 11:52:25 -0800 Subject: Take some of the tx Logic out of the UI and create a visble state for pending and unaproved transactions --- app/scripts/transaction-manager.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'app/scripts/transaction-manager.js') 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) -- cgit v1.2.3 From bbd2f2738b5b260f0e666b9cfb8d0c843342abb2 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 11 Jan 2017 12:23:00 -0800 Subject: Add to CHANGELOG --- app/scripts/transaction-manager.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/scripts/transaction-manager.js') diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index a279ba23a..f83bc41c9 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -262,12 +262,18 @@ module.exports = class TransactionManager extends EventEmitter { var txHash = tx.hash var txId = tx.id if (!txHash) { - tx.err = { errCode: 'No hash was provided', message: 'Tx could possibly have not been submitted or an error accrued during signing'} + 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) { - tx.err = {errorCode: err, message: 'Tx could possibly have not been submitted to the block chain',} + tx.err = { + errorCode: err, + message: 'Tx could possibly have not been submitted to the block chain', + } this.updateTx(tx) return console.error(err) } -- cgit v1.2.3 From 576e2ad64df293adcc8c2494a3648100ba4b28f5 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 11 Jan 2017 15:44:21 -0800 Subject: Fix wording and icon of failed txs --- app/scripts/transaction-manager.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'app/scripts/transaction-manager.js') diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index f83bc41c9..527899835 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -82,6 +82,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 () { @@ -182,7 +183,6 @@ module.exports = class TransactionManager extends EventEmitter { this.updateTx(metaTx) var rawTx = ethUtil.bufferToHex(tx.serialize()) return Promise.resolve(rawTx) - } /* @@ -242,7 +242,6 @@ module.exports = class TransactionManager extends EventEmitter { setTxStatusConfirmed (txId) { this._setTxStatus(txId, 'confirmed') - this.emit('update') } // merges txParams obj onto txData.txParams @@ -258,26 +257,29 @@ module.exports = class TransactionManager extends EventEmitter { checkForTxInBlock () { var signedTxList = this.getFilteredTxList({status: 'signed'}) if (!signedTxList.length) return - signedTxList.forEach((tx) => { - var txHash = tx.hash - var txId = tx.id + signedTxList.forEach((txMeta) => { + var txHash = txMeta.hash + var txId = txMeta.id if (!txHash) { - tx.err = { + txMeta.err = { errCode: 'No hash was provided', - message: 'Tx could possibly have not been submitted or an error accrued during signing', + message: 'We had an error while submitting this transaction, please try again.', } - return this.updateTx(tx) + this.updateTx(txMeta) + return this._setTxStatus(txId, 'failed') } - this.txProviderUtils.query.getTransactionByHash(txHash, (err, txMeta) => { - if (err) { - tx.err = { + this.txProviderUtils.query.getTransactionByHash(txHash, (err, txParams) => { + if (err || !txParams) { + if (!txParams) return + txMeta.err = { + isWarning: true, errorCode: err, - message: 'Tx could possibly have not been submitted to the block chain', + message: 'There was a problem loading this transaction.', } - this.updateTx(tx) + this.updateTx(txMeta) return console.error(err) } - if (txMeta.blockNumber) { + if (txParams.blockNumber) { this.setTxStatusConfirmed(txId) } }) -- cgit v1.2.3 From 5ed52eed680f503adb0e510320b2610658157d4d Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 13 Jan 2017 10:44:22 -0800 Subject: Clean up code --- app/scripts/transaction-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/scripts/transaction-manager.js') diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index 527899835..f5b57f3c2 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -25,8 +25,9 @@ module.exports = class TransactionManager extends EventEmitter { getState () { var selectedAccount = this.getSelectedAccount() return { + transactions: this.getTxList(), unconfTxs: this.getUnapprovedTxList(), - transactions: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAccount}), + selectedAccountTxList: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAccount}), } } -- cgit v1.2.3