mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix persistence of transactions between networks.
This commit is contained in:
parent
b9714b881a
commit
fa0bbd66b6
@ -47,27 +47,39 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
// Returns the tx list
|
// Returns the tx list
|
||||||
getTxList () {
|
getTxList () {
|
||||||
let network = this.getNetwork()
|
let network = this.getNetwork()
|
||||||
let fullTxList = this.store.getState().transactions
|
let fullTxList = this.getFullTxList()
|
||||||
return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network)
|
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
|
// Adds a tx to the txlist
|
||||||
addTx (txMeta) {
|
addTx (txMeta) {
|
||||||
var txList = this.getTxList()
|
let txCount = this.getTxCount()
|
||||||
var txHistoryLimit = this.txHistoryLimit
|
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
|
// longer then desired persistence limit
|
||||||
// and then if it is removes only confirmed
|
// and then if it is removes only confirmed
|
||||||
// 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 (txList.length > txHistoryLimit - 1) {
|
if (txCount > txHistoryLimit - 1) {
|
||||||
var index = txList.findIndex((metaTx) => metaTx.status === 'confirmed' || metaTx.status === 'rejected')
|
var index = fullTxList.findIndex((metaTx) => ((metaTx.status === 'confirmed' || metaTx.status === 'rejected') && network === txMeta.metamaskNetworkId))
|
||||||
txList.splice(index, 1)
|
fullTxList.splice(index, 1)
|
||||||
}
|
}
|
||||||
txList.push(txMeta)
|
fullTxList.push(txMeta)
|
||||||
|
|
||||||
this._saveTxList(txList)
|
this._saveTxList(fullTxList)
|
||||||
this.once(`${txMeta.id}:signed`, function (txId) {
|
this.once(`${txMeta.id}:signed`, function (txId) {
|
||||||
this.removeAllListeners(`${txMeta.id}:rejected`)
|
this.removeAllListeners(`${txMeta.id}:rejected`)
|
||||||
})
|
})
|
||||||
@ -89,7 +101,7 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
//
|
//
|
||||||
updateTx (txMeta) {
|
updateTx (txMeta) {
|
||||||
var txId = txMeta.id
|
var txId = txMeta.id
|
||||||
var txList = this.getTxList()
|
var txList = this.getFullTxList()
|
||||||
var index = txList.findIndex(txData => txData.id === txId)
|
var index = txList.findIndex(txData => txData.id === txId)
|
||||||
txList[index] = txMeta
|
txList[index] = txMeta
|
||||||
this._saveTxList(txList)
|
this._saveTxList(txList)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user