1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Ensure listener is cleaned up

Also fixed bug when validating a tx with no value.
This commit is contained in:
Dan Finlay 2016-09-06 18:56:26 -07:00
parent b1cd7ebc47
commit bfea26d3e3
3 changed files with 27 additions and 1 deletions

View File

@ -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))

View File

@ -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] = []
}
}

View File

@ -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)
}