1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge pull request #3306 from danjm/MM-805-send-from-tab-popup-fix

[NewUI] Prevents new tx from active tab from opening popup
This commit is contained in:
Thomas Huang 2018-02-21 12:50:45 -08:00 committed by GitHub
commit e27a3823ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,7 @@ const release = platform.getVersion()
const raven = setupRaven({ release })
let popupIsOpen = false
let openMetamaskTabsIDs = {}
// state persistence
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
@ -117,9 +118,15 @@ function setupController (initState) {
popupIsOpen = popupIsOpen || (remotePort.name === 'popup')
controller.setupTrustedCommunication(portStream, 'MetaMask')
// record popup as closed
if (remotePort.sender.url.match(/home.html$/)) {
openMetamaskTabsIDs[remotePort.sender.tab.id] = true
}
if (remotePort.name === 'popup') {
endOfStream(portStream, () => {
popupIsOpen = false
if (remotePort.sender.url.match(/home.html$/)) {
openMetamaskTabsIDs[remotePort.sender.tab.id] = false
}
})
}
} else {
@ -162,7 +169,10 @@ function setupController (initState) {
// popup trigger
function triggerUi () {
if (!popupIsOpen) notificationManager.showPopup()
extension.tabs.query({ active: true }, (tabs) => {
const currentlyActiveMetamaskTab = tabs.find(tab => openMetamaskTabsIDs[tab.id])
if (!popupIsOpen && !currentlyActiveMetamaskTab) notificationManager.showPopup()
})
}
// On first install, open a window to MetaMask website to how-it-works.