mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1253 from MetaMask/i1210-txdisappearance
Fix transactions disappearing on other networks when creating transactions on a network
This commit is contained in:
commit
1c956bdb62
@ -13,6 +13,7 @@
|
||||
- Fix bug where total gas was sometimes not live-updated.
|
||||
- Fix bug where editing gas value could have some abrupt behaviors (#1233)
|
||||
- Add Kovan as an option on our network list.
|
||||
- Fixed bug where transactions on other networks would disappear when submitting a transaction on another network.
|
||||
|
||||
## 3.4.0 2017-3-8
|
||||
|
||||
|
@ -47,27 +47,39 @@ module.exports = class TransactionManager extends EventEmitter {
|
||||
// Returns the tx list
|
||||
getTxList () {
|
||||
let network = this.getNetwork()
|
||||
let fullTxList = this.store.getState().transactions
|
||||
let fullTxList = this.getFullTxList()
|
||||
return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network)
|
||||
}
|
||||
|
||||
// Returns the number of txs for the current network.
|
||||
getTxCount () {
|
||||
return this.getTxList().length
|
||||
}
|
||||
|
||||
// Returns the full tx list across all networks
|
||||
getFullTxList () {
|
||||
return this.store.getState().transactions
|
||||
}
|
||||
|
||||
// Adds a tx to the txlist
|
||||
addTx (txMeta) {
|
||||
var txList = this.getTxList()
|
||||
var txHistoryLimit = this.txHistoryLimit
|
||||
let txCount = this.getTxCount()
|
||||
let network = this.getNetwork()
|
||||
let fullTxList = this.getFullTxList()
|
||||
let txHistoryLimit = this.txHistoryLimit
|
||||
|
||||
// checks if the length of th tx history is
|
||||
// checks if the length of the tx history is
|
||||
// longer then desired persistence limit
|
||||
// and then if it is removes only confirmed
|
||||
// or rejected tx's.
|
||||
// not tx's that are pending or unapproved
|
||||
if (txList.length > txHistoryLimit - 1) {
|
||||
var index = txList.findIndex((metaTx) => metaTx.status === 'confirmed' || metaTx.status === 'rejected')
|
||||
txList.splice(index, 1)
|
||||
if (txCount > txHistoryLimit - 1) {
|
||||
var index = fullTxList.findIndex((metaTx) => ((metaTx.status === 'confirmed' || metaTx.status === 'rejected') && network === txMeta.metamaskNetworkId))
|
||||
fullTxList.splice(index, 1)
|
||||
}
|
||||
txList.push(txMeta)
|
||||
fullTxList.push(txMeta)
|
||||
|
||||
this._saveTxList(txList)
|
||||
this._saveTxList(fullTxList)
|
||||
this.once(`${txMeta.id}:signed`, function (txId) {
|
||||
this.removeAllListeners(`${txMeta.id}:rejected`)
|
||||
})
|
||||
@ -89,7 +101,7 @@ module.exports = class TransactionManager extends EventEmitter {
|
||||
//
|
||||
updateTx (txMeta) {
|
||||
var txId = txMeta.id
|
||||
var txList = this.getTxList()
|
||||
var txList = this.getFullTxList()
|
||||
var index = txList.findIndex(txData => txData.id === txId)
|
||||
txList[index] = txMeta
|
||||
this._saveTxList(txList)
|
||||
|
@ -59,6 +59,17 @@ describe('Transaction Manager', function() {
|
||||
assert.equal(result[0].id, 1)
|
||||
})
|
||||
|
||||
it('does not override txs from other networks', function() {
|
||||
var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }
|
||||
var tx2 = { id: 2, status: 'confirmed', metamaskNetworkId: 'another net', txParams: {} }
|
||||
txManager.addTx(tx, noop)
|
||||
txManager.addTx(tx2, noop)
|
||||
var result = txManager.getFullTxList()
|
||||
var result2 = txManager.getTxList()
|
||||
assert.equal(result.length, 2, 'txs were deleted')
|
||||
assert.equal(result2.length, 1, 'incorrect number of txs on network.')
|
||||
})
|
||||
|
||||
it('cuts off early txs beyond a limit', function() {
|
||||
const limit = txManager.txHistoryLimit
|
||||
for (let i = 0; i < limit + 1; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user