mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Clear unapprovedTxs on createNewVaultAndRestore (#9026)
Clear unapproved transactions from txStateManager.transactions on createNewVaultAndRestore
This commit is contained in:
parent
fd2e02274a
commit
7b2218ac6e
@ -793,4 +793,5 @@ export default class TransactionController extends EventEmitter {
|
|||||||
const currentNetworkTxList = this.txStateManager.getTxList(MAX_MEMSTORE_TX_LIST_SIZE)
|
const currentNetworkTxList = this.txStateManager.getTxList(MAX_MEMSTORE_TX_LIST_SIZE)
|
||||||
this.memStore.updateState({ unapprovedTxs, currentNetworkTxList })
|
this.memStore.updateState({ unapprovedTxs, currentNetworkTxList })
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -508,4 +508,14 @@ export default class TransactionStateManager extends EventEmitter {
|
|||||||
const transactionList = this.getFullTxList()
|
const transactionList = this.getFullTxList()
|
||||||
this._saveTxList(transactionList.filter((txMeta) => txMeta.id !== txId))
|
this._saveTxList(transactionList.filter((txMeta) => txMeta.id !== txId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters out the unapproved transactions
|
||||||
|
*/
|
||||||
|
|
||||||
|
clearUnapprovedTxs () {
|
||||||
|
const transactions = this.getFullTxList()
|
||||||
|
const nonUnapprovedTxs = transactions.filter((tx) => tx.status !== 'unapproved')
|
||||||
|
this._saveTxList(nonUnapprovedTxs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,6 +631,9 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
// clear permissions
|
// clear permissions
|
||||||
this.permissionsController.clearPermissions()
|
this.permissionsController.clearPermissions()
|
||||||
|
|
||||||
|
// clear unapproved transactions
|
||||||
|
this.txController.txStateManager.clearUnapprovedTxs()
|
||||||
|
|
||||||
// create new vault
|
// create new vault
|
||||||
const vault = await keyringController.createNewVaultAndRestore(password, seed)
|
const vault = await keyringController.createNewVaultAndRestore(password, seed)
|
||||||
|
|
||||||
|
@ -598,4 +598,23 @@ describe('TransactionStateManager', function () {
|
|||||||
assert.equal(txStateManager.getFullTxList()[0].id, 2, 'txList should have a id of 2')
|
assert.equal(txStateManager.getFullTxList()[0].id, 2, 'txList should have a id of 2')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('#clearUnapprovedTxs', function () {
|
||||||
|
it('removes unapproved transactions', function () {
|
||||||
|
const txMetas = [
|
||||||
|
{ id: 0, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
|
||||||
|
{ id: 1, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
|
||||||
|
{ id: 2, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: otherNetworkId },
|
||||||
|
{ id: 3, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: otherNetworkId },
|
||||||
|
]
|
||||||
|
|
||||||
|
txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop))
|
||||||
|
|
||||||
|
txStateManager.clearUnapprovedTxs()
|
||||||
|
|
||||||
|
const unapprovedTxList = txStateManager.getFullTxList().filter((tx) => tx.status === 'unapproved')
|
||||||
|
|
||||||
|
assert.equal(unapprovedTxList.length, 0)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user