Ensure listener is cleaned up

Also fixed bug when validating a tx with no value.
feature/default_network_editable
Dan Finlay 8 years ago
parent b1cd7ebc47
commit bfea26d3e3
  1. 1
      app/scripts/background.js
  2. 25
      app/scripts/lib/listener-manager.js
  3. 2
      app/scripts/metamask-controller.js

@ -86,6 +86,7 @@ function setupControllerConnection (stream) {
stream.pipe(dnode).pipe(stream)
dnode.on('remote', (remote) => {
// push updates to popup
controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller))
controller.ethStore.on('update', controller.sendUpdate.bind(controller))
controller.listeners.push(remote)
idStore.on('update', controller.sendUpdate.bind(controller))

@ -0,0 +1,25 @@
module.exports = class ListenerManager {
constructor() {
this.cleaners = {}
}
setup (name) {
if (!(name in this.cleaners)) {
this.cleaners[name] = []
}
}
addCleanup (name, cleaner) {
this.setup(name)
}
cleanupOldListeners (name) {
this.setup(name)
this.cleaners[name].forEach((cleaner) => {
cleaner()
})
this.cleaners[name] = []
}
}

@ -220,7 +220,7 @@ module.exports = class MetamaskController {
}
enforceTxValidations (txParams) {
if (txParams.value.indexOf('-') === 0) {
if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
const msg = `Invalid transaction value of ${txParams.value} not a positive number.`
return new Error(msg)
}

Loading…
Cancel
Save