diff options
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/controllers/network/network.js | 14 | ||||
-rw-r--r-- | app/scripts/controllers/transactions/enums.js | 2 | ||||
-rw-r--r-- | app/scripts/controllers/transactions/index.js | 29 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 17 | ||||
-rw-r--r-- | app/scripts/platforms/extension.js | 11 |
5 files changed, 60 insertions, 13 deletions
diff --git a/app/scripts/controllers/network/network.js b/app/scripts/controllers/network/network.js index b459b8013..1a251bce1 100644 --- a/app/scripts/controllers/network/network.js +++ b/app/scripts/controllers/network/network.js @@ -105,12 +105,18 @@ module.exports = class NetworkController extends EventEmitter { if (!this._provider) { return log.warn('NetworkController - lookupNetwork aborted due to missing provider') } - var { type } = this.providerStore.getState() + const { type } = this.providerStore.getState() const ethQuery = new EthQuery(this._provider) + const initialNetwork = this.getNetworkState() ethQuery.sendAsync({ method: 'net_version' }, (err, network) => { - if (err) return this.setNetworkState('loading') - log.info('web3.getNetwork returned ' + network) - this.setNetworkState(network, type) + const currentNetwork = this.getNetworkState() + if (initialNetwork === currentNetwork) { + if (err) { + return this.setNetworkState('loading') + } + log.info('web3.getNetwork returned ' + network) + this.setNetworkState(network, type) + } }) } diff --git a/app/scripts/controllers/transactions/enums.js b/app/scripts/controllers/transactions/enums.js index be6f16e0d..d41400b9f 100644 --- a/app/scripts/controllers/transactions/enums.js +++ b/app/scripts/controllers/transactions/enums.js @@ -3,10 +3,12 @@ const TRANSACTION_TYPE_RETRY = 'retry' const TRANSACTION_TYPE_STANDARD = 'standard' const TRANSACTION_STATUS_APPROVED = 'approved' +const TRANSACTION_STATUS_CONFIRMED = 'confirmed' module.exports = { TRANSACTION_TYPE_CANCEL, TRANSACTION_TYPE_RETRY, TRANSACTION_TYPE_STANDARD, TRANSACTION_STATUS_APPROVED, + TRANSACTION_STATUS_CONFIRMED, } diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 9cd8429fb..2ce736beb 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -230,13 +230,15 @@ class TransactionController extends EventEmitter { to allow the user to resign the transaction with a higher gas values @param originalTxId {number} - the id of the txMeta that you want to attempt to retry + @param gasPrice {string=} - Optional gas price to be increased to use as the retry + transaction's gas price @return {txMeta} */ - async retryTransaction (originalTxId) { + async retryTransaction (originalTxId, gasPrice) { const originalTxMeta = this.txStateManager.getTx(originalTxId) const { txParams } = originalTxMeta - const lastGasPrice = originalTxMeta.txParams.gasPrice + const lastGasPrice = gasPrice || originalTxMeta.txParams.gasPrice const suggestedGasPriceBN = new ethUtil.BN(ethUtil.stripHexPrefix(this.getGasPrice()), 16) const lastGasPriceBN = new ethUtil.BN(ethUtil.stripHexPrefix(lastGasPrice), 16) // essentially lastGasPrice * 1.1 but @@ -290,6 +292,29 @@ class TransactionController extends EventEmitter { return newTxMeta } + async createSpeedUpTransaction (originalTxId, customGasPrice) { + const originalTxMeta = this.txStateManager.getTx(originalTxId) + const { txParams } = originalTxMeta + const { gasPrice: lastGasPrice } = txParams + + const newGasPrice = customGasPrice || bnToHex(BnMultiplyByFraction(hexToBn(lastGasPrice), 11, 10)) + + const newTxMeta = this.txStateManager.generateTxMeta({ + txParams: { + ...txParams, + gasPrice: newGasPrice, + }, + lastGasPrice, + loadingDefaults: false, + status: TRANSACTION_STATUS_APPROVED, + type: TRANSACTION_TYPE_RETRY, + }) + + this.addTx(newTxMeta) + await this.approveTransaction(newTxMeta.id) + return newTxMeta + } + /** updates the txMeta in the txStateManager @param txMeta {Object} - the updated txMeta diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index fe806e47e..c7e9cfcc7 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -445,6 +445,7 @@ module.exports = class MetamaskController extends EventEmitter { updateAndApproveTransaction: nodeify(txController.updateAndApproveTransaction, txController), retryTransaction: nodeify(this.retryTransaction, this), createCancelTransaction: nodeify(this.createCancelTransaction, this), + createSpeedUpTransaction: nodeify(this.createSpeedUpTransaction, this), getFilteredTxList: nodeify(txController.getFilteredTxList, txController), isNonceTaken: nodeify(txController.isNonceTaken, txController), estimateGas: nodeify(this.estimateGas, this), @@ -1143,8 +1144,8 @@ module.exports = class MetamaskController extends EventEmitter { * @param {string} txId - The ID of the transaction to speed up. * @param {Function} cb - The callback function called with a full state update. */ - async retryTransaction (txId, cb) { - await this.txController.retryTransaction(txId) + async retryTransaction (txId, gasPrice, cb) { + await this.txController.retryTransaction(txId, gasPrice) const state = await this.getState() return state } @@ -1157,7 +1158,17 @@ module.exports = class MetamaskController extends EventEmitter { * @returns {object} MetaMask state */ async createCancelTransaction (originalTxId, customGasPrice, cb) { - await this.txController.createCancelTransaction(originalTxId, customGasPrice) + try { + await this.txController.createCancelTransaction(originalTxId, customGasPrice) + const state = await this.getState() + return state + } catch (error) { + throw error + } + } + + async createSpeedUpTransaction (originalTxId, customGasPrice, cb) { + await this.txController.createSpeedUpTransaction(originalTxId, customGasPrice) const state = await this.getState() return state } diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index 9ef0d22c9..3f1cb0f27 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -48,10 +48,13 @@ class ExtensionPlatform { } showTransactionNotification (txMeta) { + const { status, txReceipt: { status: receiptStatus } = {} } = txMeta - const status = txMeta.status if (status === 'confirmed') { - this._showConfirmedTransaction(txMeta) + // There was an on-chain failure + receiptStatus === '0x0' + ? this._showFailedTransaction(txMeta, 'Transaction encountered an error.') + : this._showConfirmedTransaction(txMeta) } else if (status === 'failed') { this._showFailedTransaction(txMeta) } @@ -81,11 +84,11 @@ class ExtensionPlatform { this._showNotification(title, message, url) } - _showFailedTransaction (txMeta) { + _showFailedTransaction (txMeta, errorMessage) { const nonce = parseInt(txMeta.txParams.nonce, 16) const title = 'Failed transaction' - const message = `Transaction ${nonce} failed! ${txMeta.err.message}` + const message = `Transaction ${nonce} failed! ${errorMessage || txMeta.err.message}` this._showNotification(title, message) } |