Skip to content

Commit bdc7fd7

Browse files
authored
Merge pull request #607 from MetaMask/notif-fix
notif - use standard err-first callback style
2 parents 7583bbf + 822198e commit bdc7fd7

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

app/scripts/lib/notifications.js

+24-18
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@ module.exports = notifications
99
window.METAMASK_NOTIFIER = notifications
1010

1111
function show () {
12-
getWindows((windows) => {
12+
getPopup((err, popup) => {
13+
if (err) throw err
1314

14-
if (windows.length > 0) {
15-
const win = windows[0]
16-
return extension.windows.update(win.id, { focused: true })
17-
}
15+
if (popup) {
16+
17+
// bring focus to existing popup
18+
extension.windows.update(popup.id, { focused: true })
19+
20+
} else {
1821

19-
extension.windows.create({
20-
url: 'notification.html',
21-
type: 'popup',
22-
focused: true,
23-
width: 360,
24-
height: 500,
25-
})
22+
// create new popup
23+
extension.windows.create({
24+
url: 'notification.html',
25+
type: 'popup',
26+
focused: true,
27+
width: 360,
28+
height: 500,
29+
})
30+
31+
}
2632
})
2733
}
2834

@@ -38,19 +44,19 @@ function getWindows(cb) {
3844
}
3945

4046
function getPopup(cb) {
41-
getWindows((windows) => {
42-
cb(getPopupIn(windows))
47+
getWindows((err, windows) => {
48+
if (err) throw err
49+
cb(null, getPopupIn(windows))
4350
})
4451
}
4552

4653
function getPopupIn(windows) {
47-
return windows ? windows.find((win) => {
48-
return win.type === 'popup'
49-
}) : null
54+
return windows ? windows.find((win) => win.type === 'popup') : null
5055
}
5156

5257
function closePopup() {
53-
getPopup((popup) => {
58+
getPopup((err, popup) => {
59+
if (err) throw err
5460
if (!popup) return
5561
extension.windows.remove(popup.id, console.error)
5662
})

0 commit comments

Comments
 (0)