Clear unapprovedTxs on createNewVaultAndRestore (#9026)

Clear unapproved transactions from txStateManager.transactions on createNewVaultAndRestore
feature/default_network_editable
Thomas Huang 4 years ago committed by GitHub
parent fd2e02274a
commit 7b2218ac6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/scripts/controllers/transactions/index.js
  2. 10
      app/scripts/controllers/transactions/tx-state-manager.js
  3. 3
      app/scripts/metamask-controller.js
  4. 19
      test/unit/app/controllers/transactions/tx-state-manager-test.js

@ -793,4 +793,5 @@ export default class TransactionController extends EventEmitter {
const currentNetworkTxList = this.txStateManager.getTxList(MAX_MEMSTORE_TX_LIST_SIZE)
this.memStore.updateState({ unapprovedTxs, currentNetworkTxList })
}
}

@ -508,4 +508,14 @@ export default class TransactionStateManager extends EventEmitter {
const transactionList = this.getFullTxList()
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
this.permissionsController.clearPermissions()
// clear unapproved transactions
this.txController.txStateManager.clearUnapprovedTxs()
// create new vault
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')
})
})
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…
Cancel
Save