1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

controllers - transactions - fix tx status update on boot

This commit is contained in:
kumavis 2018-05-29 00:53:44 -07:00
parent 16d0db15e0
commit 58de5671cc
2 changed files with 13 additions and 2 deletions

View File

@ -83,7 +83,11 @@ class TransactionController extends EventEmitter {
this.txStateManager.store.subscribe(() => this._updateMemstore()) this.txStateManager.store.subscribe(() => this._updateMemstore())
this.networkStore.subscribe(() => this._updateMemstore()) this.networkStore.subscribe(() => this._updateMemstore())
this.preferencesStore.subscribe(() => this._updateMemstore()) this.preferencesStore.subscribe(() => this._updateMemstore())
// request state update to finalize initialization
this._updatePendingTxsAfterFirstBlock()
} }
/** @returns {number} the chainId*/ /** @returns {number} the chainId*/
getChainId () { getChainId () {
const networkState = this.networkStore.getState() const networkState = this.networkStore.getState()
@ -349,6 +353,14 @@ class TransactionController extends EventEmitter {
this.getFilteredTxList = (opts) => this.txStateManager.getFilteredTxList(opts) this.getFilteredTxList = (opts) => this.txStateManager.getFilteredTxList(opts)
} }
// called once on startup
async _updatePendingTxsAfterFirstBlock () {
// wait for first block so we know we're ready
await this.blockTracker.getLatestBlock()
// get status update for all pending transactions (for the current network)
await this.pendingTxTracker.updatePendingTxs()
}
/** /**
If transaction controller was rebooted with transactions that are uncompleted If transaction controller was rebooted with transactions that are uncompleted
in steps of the transaction signing or user confirmation process it will either in steps of the transaction signing or user confirmation process it will either

View File

@ -34,11 +34,10 @@ class PendingTransactionTracker extends EventEmitter {
checks the network for signed txs and releases the nonce global lock if it is checks the network for signed txs and releases the nonce global lock if it is
*/ */
async updatePendingTxs () { async updatePendingTxs () {
const pendingTxs = this.getPendingTransactions()
// in order to keep the nonceTracker accurate we block it while updating pending transactions // in order to keep the nonceTracker accurate we block it while updating pending transactions
console.log('updating pending txs....', pendingTxs)
const nonceGlobalLock = await this.nonceTracker.getGlobalLock() const nonceGlobalLock = await this.nonceTracker.getGlobalLock()
try { try {
const pendingTxs = this.getPendingTransactions()
await Promise.all(pendingTxs.map((txMeta) => this._checkPendingTx(txMeta))) await Promise.all(pendingTxs.map((txMeta) => this._checkPendingTx(txMeta)))
} catch (err) { } catch (err) {
log.error('PendingTransactionTracker - Error updating pending transactions') log.error('PendingTransactionTracker - Error updating pending transactions')