diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2018-12-04 07:16:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-04 07:16:19 +0800 |
commit | ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275 (patch) | |
tree | 786b66ff556bc30a7f6136ba130e889408dcebb4 /app/scripts/controllers/transactions | |
parent | be3619cd802536894097d81e7f31d38b0c2b3e9f (diff) | |
parent | 35670e926116b19e66931dace838d785adffac09 (diff) | |
download | tangerine-wallet-browser-ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275.tar tangerine-wallet-browser-ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275.tar.gz tangerine-wallet-browser-ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275.tar.bz2 tangerine-wallet-browser-ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275.tar.lz tangerine-wallet-browser-ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275.tar.xz tangerine-wallet-browser-ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275.tar.zst tangerine-wallet-browser-ed9bfdcebd5eed1d749f275f9d388ea0dd8f8275.zip |
Merge pull request #5879 from MetaMask/develop
Version 5.1.0
Diffstat (limited to 'app/scripts/controllers/transactions')
-rw-r--r-- | app/scripts/controllers/transactions/index.js | 21 | ||||
-rw-r--r-- | app/scripts/controllers/transactions/tx-gas-utils.js | 9 | ||||
-rw-r--r-- | app/scripts/controllers/transactions/tx-state-manager.js | 10 |
3 files changed, 34 insertions, 6 deletions
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index b44f66f14..9cd8429fb 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -96,7 +96,10 @@ class TransactionController extends EventEmitter { // memstore is computed from a few different stores this._updateMemstore() this.txStateManager.store.subscribe(() => this._updateMemstore()) - this.networkStore.subscribe(() => this._updateMemstore()) + this.networkStore.subscribe(() => { + this._onBootCleanUp() + this._updateMemstore() + }) this.preferencesStore.subscribe(() => this._updateMemstore()) // request state update to finalize initialization @@ -191,10 +194,13 @@ class TransactionController extends EventEmitter { txMeta = await this.addTxGasDefaults(txMeta) } catch (error) { log.warn(error) - this.txStateManager.setTxStatusFailed(txMeta.id, error) + txMeta.loadingDefaults = false + this.txStateManager.updateTx(txMeta, 'Failed to calculate gas defaults.') throw error } + txMeta.loadingDefaults = false + // save txMeta this.txStateManager.updateTx(txMeta) @@ -229,7 +235,16 @@ class TransactionController extends EventEmitter { async retryTransaction (originalTxId) { const originalTxMeta = this.txStateManager.getTx(originalTxId) + const { txParams } = originalTxMeta const lastGasPrice = 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 + // dont trust decimals so a round about way of doing that + const lastGasPriceBNBumped = lastGasPriceBN.mul(new ethUtil.BN(110, 10)).div(new ethUtil.BN(100, 10)) + // transactions that are being retried require a >=%10 bump or the clients will throw an error + txParams.gasPrice = suggestedGasPriceBN.gt(lastGasPriceBNBumped) ? `0x${suggestedGasPriceBN.toString(16)}` : `0x${lastGasPriceBNBumped.toString(16)}` + const txMeta = this.txStateManager.generateTxMeta({ txParams: originalTxMeta.txParams, lastGasPrice, @@ -476,6 +491,8 @@ class TransactionController extends EventEmitter { txMeta.loadingDefaults = false this.txStateManager.updateTx(txMeta, 'transactions: gas estimation for tx on boot') }).catch((error) => { + tx.loadingDefaults = false + this.txStateManager.updateTx(tx, 'failed to estimate gas during boot cleanup.') this.txStateManager.setTxStatusFailed(tx.id, error) }) }) diff --git a/app/scripts/controllers/transactions/tx-gas-utils.js b/app/scripts/controllers/transactions/tx-gas-utils.js index def67c2c3..b296dc5eb 100644 --- a/app/scripts/controllers/transactions/tx-gas-utils.js +++ b/app/scripts/controllers/transactions/tx-gas-utils.js @@ -35,7 +35,13 @@ class TxGasUtil { txMeta.simulationFails = { reason: err.message, errorKey: err.errorKey, + debug: { blockNumber: block.number, blockGasLimit: block.gasLimit }, } + + if (err.errorKey === TRANSACTION_NO_CONTRACT_ERROR_KEY) { + txMeta.simulationFails.debug.getCodeResponse = err.getCodeResponse + } + return txMeta } this.setTxGas(txMeta, block.gasLimit, estimatedGasHex) @@ -74,6 +80,9 @@ class TxGasUtil { const err = new Error('TxGasUtil - Trying to call a function on a non-contract address') // set error key so ui can display localized error message err.errorKey = TRANSACTION_NO_CONTRACT_ERROR_KEY + + // set the response on the error so that we can see in logs what the actual response was + err.getCodeResponse = code throw err } diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index 151082452..72d869fa8 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -361,13 +361,15 @@ class TransactionStateManager extends EventEmitter { @param err {erroObject} - error object */ setTxStatusFailed (txId, err) { + const error = !err ? new Error('Internal metamask failure') : err + const txMeta = this.getTx(txId) txMeta.err = { - message: err.toString(), - rpc: err.value, - stack: err.stack, + message: error.toString(), + rpc: error.value, + stack: error.stack, } - this.updateTx(txMeta) + this.updateTx(txMeta, 'transactions:tx-state-manager#fail - add error') this._setTxStatus(txId, 'failed') } |