From e6fda855a556a6aa0325556b074612ff76925e5d Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 03:33:15 -0500 Subject: [PATCH 1/7] added reset account feature --- CHANGELOG.md | 1 + app/scripts/controllers/transactions.js | 4 ++++ app/scripts/lib/tx-state-manager.js | 4 ++++ app/scripts/metamask-controller.js | 8 ++++++++ ui/app/actions.js | 16 ++++++++++++++++ ui/app/config.js | 19 +++++++++++++++++++ 6 files changed, 52 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bab6d4062..a415b7359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Current Master +- Add a "reset account" feature to Settings - Add warning for importing some kinds of files. ## 3.13.8 2018-1-29 diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 9c3618e60..7ca04caf1 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -152,6 +152,10 @@ module.exports = class TransactionController extends EventEmitter { } } + wipeTransactions(){ + this.txStateManager.wipeTransactions(); + } + // Adds a tx to the txlist addTx (txMeta) { this.txStateManager.addTx(txMeta) diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index a8ef39891..61ce2024a 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -221,6 +221,10 @@ module.exports = class TransactionStateManger extends EventEmitter { this._setTxStatus(txId, 'failed') } + wipeTransactions(){ + this._saveTxList([]); + } + // // PRIVATE METHODS // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 672ec7403..79e3de4cc 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -348,6 +348,7 @@ module.exports = class MetamaskController extends EventEmitter { addNewAccount: nodeify(this.addNewAccount, this), placeSeedWords: this.placeSeedWords.bind(this), clearSeedWordCache: this.clearSeedWordCache.bind(this), + resetAccount: this.resetAccount.bind(this), importAccountWithStrategy: this.importAccountWithStrategy.bind(this), // vault management @@ -604,6 +605,13 @@ module.exports = class MetamaskController extends EventEmitter { cb(null, this.preferencesController.getSelectedAddress()) } + + resetAccount(cb){ + this.txController.wipeTransactions(); + cb(null, this.preferencesController.getSelectedAddress()) + } + + importAccountWithStrategy (strategy, args, cb) { accountImporter.importAccount(strategy, args) .then((privateKey) => { diff --git a/ui/app/actions.js b/ui/app/actions.js index 52ea899aa..90acdc821 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -47,12 +47,14 @@ var actions = { addNewAccount, NEW_ACCOUNT_SCREEN: 'NEW_ACCOUNT_SCREEN', navigateToNewAccountScreen, + resetAccount, showNewVaultSeed: showNewVaultSeed, showInfoPage: showInfoPage, // seed recovery actions REVEAL_SEED_CONFIRMATION: 'REVEAL_SEED_CONFIRMATION', revealSeedConfirmation: revealSeedConfirmation, requestRevealSeed: requestRevealSeed, + // unlock screen UNLOCK_IN_PROGRESS: 'UNLOCK_IN_PROGRESS', UNLOCK_FAILED: 'UNLOCK_FAILED', @@ -308,6 +310,20 @@ function requestRevealSeed (password) { } } +function resetAccount () { + return (dispatch) => { + background.resetAccount((err, account) => { + dispatch(actions.hideLoadingIndication()) + if (err) { + dispatch(actions.displayWarning(err.message)) + } + + log.info('Transaction history reset for ' + account) + dispatch(actions.showAccountsPage()) + }) + } +} + function addNewKeyring (type, opts) { return (dispatch) => { dispatch(actions.showLoadingIndication()) diff --git a/ui/app/config.js b/ui/app/config.js index 9cb2a0aad..9b9cac4bf 100644 --- a/ui/app/config.js +++ b/ui/app/config.js @@ -55,6 +55,7 @@ ConfigScreen.prototype.render = function () { h('.flex-space-around', { style: { padding: '20px', + overflow: 'auto', }, }, [ @@ -142,6 +143,24 @@ ConfigScreen.prototype.render = function () { }, 'Reveal Seed Words'), ]), + h('hr.horizontal-line'), + + h('div', { + style: { + marginTop: '20px', + }, + }, [ + h('button', { + style: { + alignSelf: 'center', + }, + onClick (event) { + event.preventDefault() + state.dispatch(actions.resetAccount()) + }, + }, 'Reset Account'), + ]), + ]), ]), ]) From 5f39844382fb3106b883efb81f55a6e909f28b01 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 03:36:04 -0500 Subject: [PATCH 2/7] clean up --- app/scripts/lib/tx-state-manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index 61ce2024a..6b4a196f2 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -221,10 +221,10 @@ module.exports = class TransactionStateManger extends EventEmitter { this._setTxStatus(txId, 'failed') } - wipeTransactions(){ - this._saveTxList([]); + wipeTransactions () { + this._saveTxList([]); } - + // // PRIVATE METHODS // From 03d17c75ae47806e9afa562cf664819b83a2b926 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 04:25:32 -0500 Subject: [PATCH 3/7] wipe only transactions for current account --- app/scripts/controllers/transactions.js | 4 ++-- app/scripts/lib/tx-state-manager.js | 12 +++++++++--- app/scripts/metamask-controller.js | 8 ++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 7ca04caf1..a3670155a 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -152,8 +152,8 @@ module.exports = class TransactionController extends EventEmitter { } } - wipeTransactions(){ - this.txStateManager.wipeTransactions(); + wipeTransactions (address) { + this.txStateManager.wipeTransactions(address) } // Adds a tx to the txlist diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index 6b4a196f2..13e645a28 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -221,10 +221,16 @@ module.exports = class TransactionStateManger extends EventEmitter { this._setTxStatus(txId, 'failed') } - wipeTransactions () { - this._saveTxList([]); + wipeTransactions (address) { + // network only tx + const txs = this.getTxList() + + // Filter out the ones from the current account + const otherAccountTxs = txs.filter((txMeta) => txMeta.from !== address) + + // Update state + this._saveTxList(otherAccountTxs) } - // // PRIVATE METHODS // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 79e3de4cc..14ce9c590 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -605,10 +605,10 @@ module.exports = class MetamaskController extends EventEmitter { cb(null, this.preferencesController.getSelectedAddress()) } - - resetAccount(cb){ - this.txController.wipeTransactions(); - cb(null, this.preferencesController.getSelectedAddress()) + resetAccount (cb) { + const selectedAddress = this.preferencesController.getSelectedAddress() + this.txController.wipeTransactions(selectedAddress) + cb(null, selectedAddress) } From 7dc1b09f94003fdac4ed9ea36ecf1c1a14d972a1 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 04:40:32 -0500 Subject: [PATCH 4/7] use txMeta.txParams --- app/scripts/lib/tx-state-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index 13e645a28..f488130a2 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -226,7 +226,7 @@ module.exports = class TransactionStateManger extends EventEmitter { const txs = this.getTxList() // Filter out the ones from the current account - const otherAccountTxs = txs.filter((txMeta) => txMeta.from !== address) + const otherAccountTxs = txs.filter((txMeta) => txMeta.txParams.from !== address) // Update state this._saveTxList(otherAccountTxs) From c1b7cfe91d803c0085afe59d058f2422a0e8dc30 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 13:29:02 -0500 Subject: [PATCH 5/7] preserve other networks TXs --- app/scripts/lib/tx-state-manager.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index f488130a2..051efd247 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -223,10 +223,11 @@ module.exports = class TransactionStateManger extends EventEmitter { wipeTransactions (address) { // network only tx - const txs = this.getTxList() + const txs = this.getFullTxList() + const network = this.getNetwork() - // Filter out the ones from the current account - const otherAccountTxs = txs.filter((txMeta) => txMeta.txParams.from !== address) + // Filter out the ones from the current account and network + const otherAccountTxs = txs.filter((txMeta) => !(txMeta.txParams.from === address && txMeta.metamaskNetworkId === network)) // Update state this._saveTxList(otherAccountTxs) From a70eda36515ee8dc7f0b58bf561dd14c92e70596 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 13:29:30 -0500 Subject: [PATCH 6/7] add test for wipeTransactions --- test/unit/tx-state-manager-test.js | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js index 464e50ee4..3d9641453 100644 --- a/test/unit/tx-state-manager-test.js +++ b/test/unit/tx-state-manager-test.js @@ -238,4 +238,53 @@ describe('TransactionStateManger', function () { assert.equal(txStateManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`) }) }) + + describe('#wipeTransactions', function () { + + const specificAddress = '0xaa'; + + it('should remove only the transactions from a specific address', function () { + + const txMetas = [ + { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: '0xbb' }, metamaskNetworkId: currentNetworkId }, + { id: 1, status: 'confirmed', txParams: { from: '0xbb', to: specificAddress }, metamaskNetworkId: currentNetworkId }, + { id: 2, status: 'confirmed', txParams: { from: '0xcc', to: specificAddress }, metamaskNetworkId: currentNetworkId }, + ] + txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop)) + + txStateManager.wipeTransactions(specificAddress) + + const transactionsFromCurrentAddress = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from === specificAddress) + const transactionsFromOtherAddresses = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from !== specificAddress) + + assert.equal(transactionsFromCurrentAddress.length, 0); + assert.equal(transactionsFromOtherAddresses.length, 2); + + + }) + + it('should not remove the transactions from other networks', function () { + + const txMetas = [ + { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: '0xbb' }, metamaskNetworkId: currentNetworkId }, + { id: 1, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, metamaskNetworkId: otherNetworkId }, + { id: 2, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, metamaskNetworkId: otherNetworkId }, + ] + + txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop)) + + txStateManager.wipeTransactions(specificAddress) + + const txsFromCurrentNetworkAndAddress = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from === specificAddress) + const txFromOtherNetworks= txStateManager.getFullTxList().filter((txMeta) => txMeta.metamaskNetworkId === otherNetworkId) + + console.log('NETWORK TX LIST: ', txStateManager.getTxList()); + console.log('FULL TX LIST: ', txStateManager.getFullTxList()); + + assert.equal(txsFromCurrentNetworkAndAddress.length, 0); + assert.equal(txFromOtherNetworks.length, 2); + + + }) + }) }) \ No newline at end of file From 94dd77d194de97b59c0a191a7439d96ff255bf41 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 13:34:14 -0500 Subject: [PATCH 7/7] clean up --- test/unit/tx-state-manager-test.js | 32 ++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js index 3d9641453..02dc52967 100644 --- a/test/unit/tx-state-manager-test.js +++ b/test/unit/tx-state-manager-test.js @@ -241,14 +241,15 @@ describe('TransactionStateManger', function () { describe('#wipeTransactions', function () { - const specificAddress = '0xaa'; + const specificAddress = '0xaa' + const otherAddress = '0xbb' it('should remove only the transactions from a specific address', function () { const txMetas = [ - { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: '0xbb' }, metamaskNetworkId: currentNetworkId }, - { id: 1, status: 'confirmed', txParams: { from: '0xbb', to: specificAddress }, metamaskNetworkId: currentNetworkId }, - { id: 2, status: 'confirmed', txParams: { from: '0xcc', to: specificAddress }, metamaskNetworkId: currentNetworkId }, + { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: currentNetworkId }, + { id: 1, status: 'confirmed', txParams: { from: otherAddress, to: specificAddress }, metamaskNetworkId: currentNetworkId }, + { id: 2, status: 'confirmed', txParams: { from: otherAddress, to: specificAddress }, metamaskNetworkId: currentNetworkId }, ] txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop)) @@ -257,18 +258,15 @@ describe('TransactionStateManger', function () { const transactionsFromCurrentAddress = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from === specificAddress) const transactionsFromOtherAddresses = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from !== specificAddress) - assert.equal(transactionsFromCurrentAddress.length, 0); - assert.equal(transactionsFromOtherAddresses.length, 2); - - + assert.equal(transactionsFromCurrentAddress.length, 0) + assert.equal(transactionsFromOtherAddresses.length, 2) }) it('should not remove the transactions from other networks', function () { - const txMetas = [ - { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: '0xbb' }, metamaskNetworkId: currentNetworkId }, - { id: 1, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, metamaskNetworkId: otherNetworkId }, - { id: 2, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, metamaskNetworkId: otherNetworkId }, + { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: currentNetworkId }, + { id: 1, status: 'confirmed', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: otherNetworkId }, + { id: 2, status: 'confirmed', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: otherNetworkId }, ] txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop)) @@ -276,14 +274,10 @@ describe('TransactionStateManger', function () { txStateManager.wipeTransactions(specificAddress) const txsFromCurrentNetworkAndAddress = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from === specificAddress) - const txFromOtherNetworks= txStateManager.getFullTxList().filter((txMeta) => txMeta.metamaskNetworkId === otherNetworkId) - - console.log('NETWORK TX LIST: ', txStateManager.getTxList()); - console.log('FULL TX LIST: ', txStateManager.getFullTxList()); - - assert.equal(txsFromCurrentNetworkAndAddress.length, 0); - assert.equal(txFromOtherNetworks.length, 2); + const txFromOtherNetworks = txStateManager.getFullTxList().filter((txMeta) => txMeta.metamaskNetworkId === otherNetworkId) + assert.equal(txsFromCurrentNetworkAndAddress.length, 0) + assert.equal(txFromOtherNetworks.length, 2) }) })