Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Fix) Force open notification popup #94

Merged
merged 5 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Current Master

- [#94](https://github.com/poanetwork/metamask-extension/pull/94): (Fix) Force open notification popup
- [#91](https://github.com/poanetwork/metamask-extension/pull/91): (Fix) Confirm tx notification popup: network name
- [#89](https://github.com/poanetwork/metamask-extension/pull/89): (Feature) Support of token per network basis
- [#85](https://github.com/poanetwork/metamask-extension/pull/85): (Upgrade) node, npm packages versions
Expand Down
8 changes: 7 additions & 1 deletion app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,13 @@ function setupController (initState, initLangCode) {
function triggerUi () {
extension.tabs.query({ active: true }, tabs => {
const currentlyActiveMetamaskTab = Boolean(tabs.find(tab => openMetamaskTabsIDs[tab.id]))
if (!popupIsOpen && !currentlyActiveMetamaskTab && !notificationIsOpen) {
/**
* https://github.com/poanetwork/metamask-extension/issues/19
* !notificationIsOpen was removed from the check, because notification can be opened, but it can be behind the DApp
* for some reasons. For example, if notification popup was opened, but user moved focus to DApp.
* New transaction, in this case, will not appear in front of DApp.
*/
if (!popupIsOpen && !currentlyActiveMetamaskTab) {
notificationManager.showPopup()
}
})
Expand Down
5 changes: 4 additions & 1 deletion app/scripts/lib/notification-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class NotificationManager {
// bring focus to existing chrome popup
extension.windows.update(popup.id, { focused: true })
} else {
const cb = (currentPopup) => { this._popupId = currentPopup.id }
const cb = (currentPopup) => {
this._popupId = currentPopup.id
extension.windows.update(currentPopup.id, { focused: true })
}
// create new notification popup
const creation = extension.windows.create({
url: 'notification.html',
Expand Down
21 changes: 21 additions & 0 deletions app/scripts/platforms/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ class ExtensionPlatform {
})
}

/**
* Closes all notifications windows, when action is confirmed in popup
* or closes notification window itself, wheb action is confirmed from it
*/
closeNotificationWindow () {
return extension.windows.getCurrent((curWindowsDetails) => {
if (curWindowsDetails.type === 'popup') {
return extension.windows.remove(curWindowsDetails.id)
} else {
extension.windows.getAll((windowsDetails) => {
const windowsDetailsFiltered = windowsDetails.filter((windowDetails) => windowDetails.id !== curWindowsDetails.id)
return windowsDetailsFiltered.forEach((windowDetails) => {
if (windowDetails.type === 'popup') {
extension.windows.remove(windowDetails.id)
}
})
})
}
})
}

getVersion () {
return extension.runtime.getManifest().version
}
Expand Down
51 changes: 22 additions & 29 deletions ui/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
const ethUtil = require('ethereumjs-util')
const { fetchLocale } = require('../i18n-helper')
const log = require('loglevel')
const { ENVIRONMENT_TYPE_NOTIFICATION } = require('../../app/scripts/lib/enums')
const { hasUnconfirmedTransactions } = require('./helpers/confirm-transaction/util')

var actions = {
Expand Down Expand Up @@ -793,9 +792,8 @@ function signMsg (msgData) {

dispatch(actions.completedTx(msgData.metamaskId))

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return resolve(msgData)
Expand Down Expand Up @@ -824,9 +822,8 @@ function signPersonalMsg (msgData) {

dispatch(actions.completedTx(msgData.metamaskId))

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return resolve(msgData)
Expand Down Expand Up @@ -855,9 +852,8 @@ function signTypedMsg (msgData) {

dispatch(actions.completedTx(msgData.metamaskId))

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return resolve(msgData)
Expand Down Expand Up @@ -1062,9 +1058,8 @@ function sendTx (txData) {
}
dispatch(actions.completedTx(txData.id))

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}
})
}
Expand Down Expand Up @@ -1140,9 +1135,8 @@ function updateAndApproveTx (txData) {
dispatch(actions.completedTx(txData.id))
dispatch(actions.hideLoadingIndication())

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return txData
Expand Down Expand Up @@ -1188,9 +1182,8 @@ function cancelMsg (msgData) {

dispatch(actions.completedTx(msgData.id))

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return resolve(msgData)
Expand All @@ -1215,9 +1208,8 @@ function cancelPersonalMsg (msgData) {

dispatch(actions.completedTx(id))

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return resolve(msgData)
Expand All @@ -1242,9 +1234,8 @@ function cancelTypedMsg (msgData) {

dispatch(actions.completedTx(id))

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return resolve(msgData)
Expand Down Expand Up @@ -1274,9 +1265,8 @@ function cancelTx (txData) {
dispatch(actions.completedTx(txData.id))
dispatch(actions.hideLoadingIndication())

if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
if (!hasUnconfirmedTransactions(getState())) {
return global.platform.closeNotificationWindow()
}

return txData
Expand All @@ -1289,7 +1279,10 @@ function cancelAllTx (txsData) {
txsData.forEach((txData, i) => {
background.cancelTransaction(txData.id, () => {
dispatch(actions.completedTx(txData.id))
i === txsData.length - 1 ? dispatch(actions.goHome()) : null
if (i === txsData.length - 1) {
dispatch(actions.goHome())
global.platform.closeNotificationWindow()
}
})
})
}
Expand Down