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

transactions: lint fixes and reveal status-update event for balance controller

This commit is contained in:
frankiebee 2017-09-26 16:52:08 -07:00
parent 8ab23c713d
commit 9fd5458112
6 changed files with 24 additions and 14 deletions

View File

@ -114,7 +114,7 @@ function setupController (initState) {
// //
updateBadge() updateBadge()
controller.txController.on('updateBadge', updateBadge) controller.txController.on('update:badge', updateBadge)
controller.messageManager.on('updateBadge', updateBadge) controller.messageManager.on('updateBadge', updateBadge)
controller.personalMessageManager.on('updateBadge', updateBadge) controller.personalMessageManager.on('updateBadge', updateBadge)

View File

@ -33,9 +33,18 @@ class BalanceController {
_registerUpdates () { _registerUpdates () {
const update = this.updateBalance.bind(this) const update = this.updateBalance.bind(this)
this.txController.on('submitted', update)
this.txController.on('confirmed', update) this.txController.on('tx:status-update', (txId, status) => {
this.txController.on('failed', update) switch (status) {
case 'submitted':
case 'confirmed':
case 'failed':
update()
return
default:
return
}
})
this.accountTracker.store.subscribe(update) this.accountTracker.store.subscribe(update)
this.blockTracker.on('block', update) this.blockTracker.on('block', update)
} }

View File

@ -43,7 +43,8 @@ module.exports = class TransactionController extends EventEmitter {
txHistoryLimit: opts.txHistoryLimit, txHistoryLimit: opts.txHistoryLimit,
getNetwork: this.getNetwork.bind(this), getNetwork: this.getNetwork.bind(this),
}) })
this.store = this.txStateManager.store
this.txStateManager.on('tx:status-update', this.emit.bind(this, 'tx:status-update'))
this.nonceTracker = new NonceTracker({ this.nonceTracker = new NonceTracker({
provider: this.provider, provider: this.provider,
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager), getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
@ -69,7 +70,7 @@ module.exports = class TransactionController extends EventEmitter {
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager), getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
}) })
this.txStateManager.store.subscribe(() => this.emit('updateBadge')) this.txStateManager.store.subscribe(() => this.emit('update:badge'))
this.pendingTxTracker.on('txWarning', this.txStateManager.updateTx.bind(this.txStateManager)) this.pendingTxTracker.on('txWarning', this.txStateManager.updateTx.bind(this.txStateManager))
this.pendingTxTracker.on('txFailed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager)) this.pendingTxTracker.on('txFailed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager))

View File

@ -5,7 +5,7 @@ const ethUtil = require('ethereumjs-util')
const txStateHistoryHelper = require('./tx-state-history-helper') const txStateHistoryHelper = require('./tx-state-history-helper')
module.exports = class TransactionStateManger extends EventEmitter { module.exports = class TransactionStateManger extends EventEmitter {
constructor ({initState, txHistoryLimit, getNetwork}) { constructor ({ initState, txHistoryLimit, getNetwork }) {
super() super()
this.store = new ObservableStore( this.store = new ObservableStore(
@ -15,6 +15,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
this.txHistoryLimit = txHistoryLimit this.txHistoryLimit = txHistoryLimit
this.getNetwork = getNetwork this.getNetwork = getNetwork
} }
// Returns the number of txs for the current network. // Returns the number of txs for the current network.
getTxCount () { getTxCount () {
return this.getTxList().length return this.getTxList().length
@ -31,7 +32,6 @@ module.exports = class TransactionStateManger extends EventEmitter {
} }
// Returns the tx list // Returns the tx list
getUnapprovedTxList () { getUnapprovedTxList () {
const txList = this.getTxsByMetaData('status', 'unapproved') const txList = this.getTxsByMetaData('status', 'unapproved')
return txList.reduce((result, tx) => { return txList.reduce((result, tx) => {
@ -69,7 +69,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
// or rejected tx's. // or rejected tx's.
// not tx's that are pending or unapproved // not tx's that are pending or unapproved
if (txCount > txHistoryLimit - 1) { if (txCount > txHistoryLimit - 1) {
const index = transactions.findIndex((metaTx) => ((metaTx.status === 'confirmed' || metaTx.status === 'rejected'))) const index = transactions.findIndex((metaTx) => metaTx.status === 'confirmed' || metaTx.status === 'rejected')
transactions.splice(index, 1) transactions.splice(index, 1)
} }
transactions.push(txMeta) transactions.push(txMeta)
@ -229,12 +229,12 @@ module.exports = class TransactionStateManger extends EventEmitter {
const txMeta = this.getTx(txId) const txMeta = this.getTx(txId)
txMeta.status = status txMeta.status = status
this.emit(`${txMeta.id}:${status}`, txId) this.emit(`${txMeta.id}:${status}`, txId)
this.emit(`${status}`, txId) this.emit(`tx:status-update`, txId, status)
if (status === 'submitted' || status === 'rejected') { if (status === 'submitted' || status === 'rejected') {
this.emit(`${txMeta.id}:finished`, txMeta) this.emit(`${txMeta.id}:finished`, txMeta)
} }
this.updateTx(txMeta) this.updateTx(txMeta)
this.emit('updateBadge') this.emit('update:badge')
} }
// Saves the new/updated txList. // Saves the new/updated txList.

View File

@ -157,7 +157,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.publicConfigStore = this.initPublicConfigStore() this.publicConfigStore = this.initPublicConfigStore()
// manual disk state subscriptions // manual disk state subscriptions
this.txController.txStateManager.store.subscribe((state) => { this.txController.store.subscribe((state) => {
this.store.updateState({ TransactionController: state }) this.store.updateState({ TransactionController: state })
}) })
this.keyringController.store.subscribe((state) => { this.keyringController.store.subscribe((state) => {

View File

@ -210,7 +210,7 @@ describe('Transaction Controller', function () {
txParams: {} txParams: {}
} }
const eventNames = ['updateBadge', '1:unapproved'] const eventNames = ['update:badge', '1:unapproved']
const listeners = [] const listeners = []
eventNames.forEach((eventName) => { eventNames.forEach((eventName) => {
listeners.push(new Promise((resolve) => { listeners.push(new Promise((resolve) => {