mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
match other controller patterns
This commit is contained in:
parent
62f26c5ba8
commit
3ad67d1b14
@ -40,9 +40,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.txGasUtil = new TxGasUtil(this.provider)
|
this.txGasUtil = new TxGasUtil(this.provider)
|
||||||
|
|
||||||
this.txStateManager = new TransactionStateManger({
|
this.txStateManager = new TransactionStateManger({
|
||||||
initState: extend({
|
initState: opts.initState,
|
||||||
transactions: [],
|
|
||||||
}, opts.initState),
|
|
||||||
txHistoryLimit: opts.txHistoryLimit,
|
txHistoryLimit: opts.txHistoryLimit,
|
||||||
getNetwork: this.getNetwork.bind(this),
|
getNetwork: this.getNetwork.bind(this),
|
||||||
})
|
})
|
||||||
@ -70,15 +68,12 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
publishTransaction: this.query.sendRawTransaction,
|
publishTransaction: this.query.sendRawTransaction,
|
||||||
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
|
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
|
||||||
giveUpOnTransaction: (txId) => {
|
giveUpOnTransaction: (txId) => {
|
||||||
const msg = `Gave up submitting after 3500 blocks un-mined.`
|
const err = new Error(`Gave up submitting after 3500 blocks un-mined.`)
|
||||||
this.setTxStatusFailed(txId, msg)
|
this.setTxStatusFailed(txId, err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
this.txStateManager.subscribe(() => {
|
this.txStateManager.store.subscribe(() => this.emit('updateBadge'))
|
||||||
this.emit('update')
|
|
||||||
this.emit('updateBadge')
|
|
||||||
})
|
|
||||||
|
|
||||||
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))
|
||||||
@ -94,7 +89,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.blockTracker.on('sync', this.pendingTxTracker.queryPendingTxs.bind(this.pendingTxTracker))
|
this.blockTracker.on('sync', this.pendingTxTracker.queryPendingTxs.bind(this.pendingTxTracker))
|
||||||
// memstore is computed from a few different stores
|
// memstore is computed from a few different stores
|
||||||
this._updateMemstore()
|
this._updateMemstore()
|
||||||
this.txStateManager.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())
|
||||||
}
|
}
|
||||||
@ -250,10 +245,9 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.txStateManager.updateTx(txMeta)
|
this.txStateManager.updateTx(txMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _____________________________________
|
//
|
||||||
| |
|
// PRIVATE METHODS
|
||||||
| PRIVATE METHODS |
|
//
|
||||||
|______________________________________*/
|
|
||||||
|
|
||||||
_updateMemstore () {
|
_updateMemstore () {
|
||||||
const unapprovedTxs = this.txStateManager.getUnapprovedTxList()
|
const unapprovedTxs = this.txStateManager.getUnapprovedTxList()
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
|
const EventEmitter = require('events')
|
||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
const txStateHistoryHelper = require('./tx-state-history-helper')
|
const txStateHistoryHelper = require('./tx-state-history-helper')
|
||||||
|
|
||||||
module.exports = class TransactionStateManger extends ObservableStore {
|
module.exports = class TransactionStateManger extends EventEmitter {
|
||||||
constructor ({initState, txHistoryLimit, getNetwork}) {
|
constructor ({initState, txHistoryLimit, getNetwork}) {
|
||||||
super(initState)
|
super()
|
||||||
|
|
||||||
|
this.store = new ObservableStore(
|
||||||
|
extend({
|
||||||
|
transactions: [],
|
||||||
|
}, initState))
|
||||||
this.txHistoryLimit = txHistoryLimit
|
this.txHistoryLimit = txHistoryLimit
|
||||||
this.getNetwork = getNetwork
|
this.getNetwork = getNetwork
|
||||||
}
|
}
|
||||||
@ -20,7 +26,7 @@ module.exports = class TransactionStateManger extends ObservableStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getFullTxList () {
|
getFullTxList () {
|
||||||
return this.getState().transactions
|
return this.store.getState().transactions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the tx list
|
// Returns the tx list
|
||||||
@ -196,10 +202,9 @@ module.exports = class TransactionStateManger extends ObservableStore {
|
|||||||
this._setTxStatus(txId, 'failed')
|
this._setTxStatus(txId, 'failed')
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _____________________________________
|
//
|
||||||
| |
|
// PRIVATE METHODS
|
||||||
| PRIVATE METHODS |
|
//
|
||||||
|______________________________________*/
|
|
||||||
|
|
||||||
// Should find the tx in the tx list and
|
// Should find the tx in the tx list and
|
||||||
// update it.
|
// update it.
|
||||||
@ -225,6 +230,6 @@ module.exports = class TransactionStateManger extends ObservableStore {
|
|||||||
// Saves the new/updated txList.
|
// Saves the new/updated txList.
|
||||||
// Function is intended only for internal use
|
// Function is intended only for internal use
|
||||||
_saveTxList (transactions) {
|
_saveTxList (transactions) {
|
||||||
this.updateState({ transactions })
|
this.store.updateState({ transactions })
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -133,7 +133,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.subscribe((state) => {
|
this.txController.txStateManager.store.subscribe((state) => {
|
||||||
this.store.updateState({ TransactionController: state })
|
this.store.updateState({ TransactionController: state })
|
||||||
})
|
})
|
||||||
this.keyringController.store.subscribe((state) => {
|
this.keyringController.store.subscribe((state) => {
|
||||||
|
@ -197,7 +197,7 @@ describe('Transaction Controller', function () {
|
|||||||
txParams: {}
|
txParams: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const eventNames = ['update', 'updateBadge', '1:unapproved']
|
const eventNames = ['updateBadge', '1:unapproved']
|
||||||
const listeners = []
|
const listeners = []
|
||||||
eventNames.forEach((eventName) => {
|
eventNames.forEach((eventName) => {
|
||||||
listeners.push(new Promise((resolve) => {
|
listeners.push(new Promise((resolve) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user