From c04d33c6a54dfb5c6ba779a79e19d8f06910ed9f Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Jun 2016 16:59:02 -0700 Subject: hotfix for #236 - chrome notif api not avail --- app/scripts/lib/notifications.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/scripts/lib/notifications.js') diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js index d011d778b..b72939196 100644 --- a/app/scripts/lib/notifications.js +++ b/app/scripts/lib/notifications.js @@ -8,6 +8,9 @@ module.exports = { createMsgNotification: createMsgNotification, } +// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236 +if (!chrome.notifications) return console.error('Chrome notifications API missing...') + // notification button press chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex){ var handlers = notificationHandlers[notificationId] @@ -26,6 +29,8 @@ chrome.notifications.onClosed.addListener(function(notificationId){ // creation helper function createUnlockRequestNotification(opts){ + // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236 + if (!chrome.notifications) return console.error('Chrome notifications API missing...') var message = 'An Ethereum app has requested a signature. Please unlock your account.' var id = createId() @@ -39,6 +44,8 @@ function createUnlockRequestNotification(opts){ } function createTxNotification(opts){ + // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236 + if (!chrome.notifications) return console.error('Chrome notifications API missing...') var message = [ 'Submitted by '+opts.txParams.origin, 'to: '+uiUtils.addressSummary(opts.txParams.to), @@ -67,6 +74,8 @@ function createTxNotification(opts){ } function createMsgNotification(opts){ + // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236 + if (!chrome.notifications) return console.error('Chrome notifications API missing...') var message = [ 'Submitted by '+opts.msgParams.origin, 'to be signed by: '+uiUtils.addressSummary(opts.msgParams.from), -- cgit v1.2.3 From 90f494c9a1f822436d4b3cd5f9ddd52f27e43378 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Jun 2016 17:29:49 -0700 Subject: fix illegal return statement :( --- app/scripts/lib/notifications.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'app/scripts/lib/notifications.js') diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js index b72939196..90edaea12 100644 --- a/app/scripts/lib/notifications.js +++ b/app/scripts/lib/notifications.js @@ -8,24 +8,30 @@ module.exports = { createMsgNotification: createMsgNotification, } -// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236 -if (!chrome.notifications) return console.error('Chrome notifications API missing...') +setupListeners() -// notification button press -chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex){ - var handlers = notificationHandlers[notificationId] - if (buttonIndex === 0) { - handlers.confirm() - } else { - handlers.cancel() - } - chrome.notifications.clear(notificationId) -}) +function setupListeners(){ + + // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236 + if (!chrome.notifications) return console.error('Chrome notifications API missing...') -// notification teardown -chrome.notifications.onClosed.addListener(function(notificationId){ - delete notificationHandlers[notificationId] -}) + // notification button press + chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex){ + var handlers = notificationHandlers[notificationId] + if (buttonIndex === 0) { + handlers.confirm() + } else { + handlers.cancel() + } + chrome.notifications.clear(notificationId) + }) + + // notification teardown + chrome.notifications.onClosed.addListener(function(notificationId){ + delete notificationHandlers[notificationId] + }) + +} // creation helper function createUnlockRequestNotification(opts){ -- cgit v1.2.3