Skip to content

Commit

Permalink
Clear AccountTracker accounts and CachedBalances on createNewVaultAnd…
Browse files Browse the repository at this point in the history
…Restore (#9023)
  • Loading branch information
tmashuang authored Jul 17, 2020
1 parent 7b2218a commit f02478e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/scripts/controllers/cached-balances.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ export default class CachedBalancesController {
return balancesToCache
}

/**
* Removes cachedBalances
*/

clearCachedBalances () {
this.store.updateState({ cachedBalances: {} })
}

/**
* Sets up listeners and subscriptions which should trigger an update of cached balances. These updates will
* happen when the current account changes. Which happens on block updates, as well as on network and account
Expand Down
8 changes: 8 additions & 0 deletions app/scripts/lib/account-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ export default class AccountTracker {
this.store.updateState({ accounts })
}

/**
* Removes all addresses and associated balances
*/

clearAccounts () {
this.store.updateState({ accounts: {} })
}

/**
* Given a block, updates this AccountTracker's currentBlockGasLimit, and then updates each local account's balance
* via EthQuery
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ export default class MetamaskController extends EventEmitter {
// clear permissions
this.permissionsController.clearPermissions()

// clear accounts in accountTracker
this.accountTracker.clearAccounts()

// clear cachedBalances
this.cachedBalancesController.clearCachedBalances()

// clear unapproved transactions
this.txController.txStateManager.clearUnapprovedTxs()

Expand Down

0 comments on commit f02478e

Please sign in to comment.