From 2754969b233a52e3c0ec997a914b503f399be59a Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Mon, 26 Aug 2019 15:17:37 +1000 Subject: [PATCH] Ensure one listener and one event for 'secondaryDeviceRegistration' --- js/views/standalone_registration_view.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/views/standalone_registration_view.js b/js/views/standalone_registration_view.js index 4ebc9bac2..c3262cecb 100644 --- a/js/views/standalone_registration_view.js +++ b/js/views/standalone_registration_view.js @@ -126,16 +126,25 @@ const language = this.$('#mnemonic-display-language').val(); this.showProfilePage(mnemonic, language); }, + onSecondaryDeviceRegistered() { + // Ensure the left menu is updated + Whisper.events.trigger('userChanged', { isSecondaryDevice: true }); + this.$el.trigger('openInbox'); + }, async registerSecondaryDevice() { const mnemonic = this.$('#mnemonic-display').text(); const language = this.$('#mnemonic-display-language').val(); const primaryPubKey = this.$('#primary-pubkey').val(); this.$('.standalone-secondary-device #error').hide(); - Whisper.events.on('secondaryDeviceRegistration', () => { - // Ensure the left menu is updated - Whisper.events.trigger('userChanged', { isSecondaryDevice: true }); - this.$el.trigger('openInbox'); - }); + // Ensure only one listener + Whisper.events.off( + 'secondaryDeviceRegistration', + this.onSecondaryDeviceRegistered + ); + Whisper.events.once( + 'secondaryDeviceRegistration', + this.onSecondaryDeviceRegistered + ); clearTimeout(this.pairingTimeout); this.pairingTimeout = setTimeout(() => { this.$('.standalone-secondary-device #error').text(