diff options
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/background.js | 1 | ||||
-rw-r--r-- | app/scripts/lib/listener-manager.js | 25 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 21a5eea65..18aaed7bf 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.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)) diff --git a/app/scripts/lib/listener-manager.js b/app/scripts/lib/listener-manager.js new file mode 100644 index 000000000..9e3c71afc --- /dev/null +++ b/app/scripts/lib/listener-manager.js @@ -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] = [] + } + +} diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 83827ec76..5373cf0d9 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -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) } |