mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Ensure listener is cleaned up
Also fixed bug when validating a tx with no value.
This commit is contained in:
parent
b1cd7ebc47
commit
bfea26d3e3
@ -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))
|
||||
|
25
app/scripts/lib/listener-manager.js
Normal file
25
app/scripts/lib/listener-manager.js
Normal 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] = []
|
||||
}
|
||||
|
||||
}
|
@ -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…
Reference in New Issue
Block a user