Fix confirmation popup not always opening

feature/default_network_editable
Alexander Tseung 7 years ago
parent e4eb69dcc2
commit b0a105ce80
  1. 66
      app/scripts/background.js
  2. 9
      app/scripts/lib/enums.js
  3. 10
      app/scripts/lib/environment-type.js
  4. 12
      app/scripts/lib/is-popup-or-notification.js
  5. 32
      app/scripts/lib/util.js
  6. 7
      app/scripts/ui.js
  7. 5
      old-ui/app/conf-tx.js
  8. 11
      ui/app/components/modals/modal.js
  9. 5
      ui/app/components/pages/unlock.js
  10. 5
      ui/app/first-time/init-menu.js
  11. 5
      ui/app/reducers/metamask.js
  12. 5
      ui/app/unlock.js

@ -21,6 +21,11 @@ const setupMetamaskMeshMetrics = require('./lib/setupMetamaskMeshMetrics')
const EdgeEncryptor = require('./edge-encryptor') const EdgeEncryptor = require('./edge-encryptor')
const getFirstPreferredLangCode = require('./lib/get-first-preferred-lang-code') const getFirstPreferredLangCode = require('./lib/get-first-preferred-lang-code')
const getObjStructure = require('./lib/getObjStructure') const getObjStructure = require('./lib/getObjStructure')
const {
ENVIRONMENT_TYPE_POPUP,
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_FULLSCREEN,
} = require('./lib/enums')
const STORAGE_KEY = 'metamask-config' const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = process.env.METAMASK_DEBUG const METAMASK_DEBUG = process.env.METAMASK_DEBUG
@ -43,7 +48,7 @@ const isEdge = !isIE && !!window.StyleMedia
let popupIsOpen = false let popupIsOpen = false
let notificationIsOpen = false let notificationIsOpen = false
let openMetamaskTabsIDs = {} const openMetamaskTabsIDs = {}
// state persistence // state persistence
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
@ -172,7 +177,7 @@ function setupController (initState, initLangCode) {
return versionedData return versionedData
} }
function persistData(state) { function persistData (state) {
if (!state) { if (!state) {
throw new Error('MetaMask - updated state is missing', state) throw new Error('MetaMask - updated state is missing', state)
} }
@ -191,33 +196,53 @@ function setupController (initState, initLangCode) {
// //
// connect to other contexts // connect to other contexts
// //
extension.runtime.onConnect.addListener(connectRemote) extension.runtime.onConnect.addListener(connectRemote)
const metamaskInternalProcessHash = {
[ENVIRONMENT_TYPE_POPUP]: true,
[ENVIRONMENT_TYPE_NOTIFICATION]: true,
[ENVIRONMENT_TYPE_FULLSCREEN]: true,
}
const isClientOpenStatus = () => {
return popupIsOpen || Boolean(Object.keys(openMetamaskTabsIDs).length) || notificationIsOpen
}
function connectRemote (remotePort) { function connectRemote (remotePort) {
const isMetaMaskInternalProcess = remotePort.name === 'popup' || remotePort.name === 'notification' const processName = remotePort.name
const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName]
const portStream = new PortStream(remotePort) const portStream = new PortStream(remotePort)
if (isMetaMaskInternalProcess) { if (isMetaMaskInternalProcess) {
// communication with popup // communication with popup
popupIsOpen = popupIsOpen || (remotePort.name === 'popup')
controller.isClientOpen = true controller.isClientOpen = true
controller.setupTrustedCommunication(portStream, 'MetaMask') controller.setupTrustedCommunication(portStream, 'MetaMask')
// record popup as closed
if (remotePort.sender.url.match(/home.html$/)) { if (processName === ENVIRONMENT_TYPE_POPUP) {
openMetamaskTabsIDs[remotePort.sender.tab.id] = true popupIsOpen = true
}
if (remotePort.name === 'popup') {
endOfStream(portStream, () => { endOfStream(portStream, () => {
popupIsOpen = false popupIsOpen = false
if (remotePort.sender.url.match(/home.html$/)) { controller.isClientOpen = isClientOpenStatus()
openMetamaskTabsIDs[remotePort.sender.tab.id] = false
}
controller.isClientOpen = popupIsOpen ||
Object.keys(openMetamaskTabsIDs).some(key => openMetamaskTabsIDs[key])
}) })
} }
if (remotePort.name === 'notification') {
if (processName === ENVIRONMENT_TYPE_NOTIFICATION) {
notificationIsOpen = true
endOfStream(portStream, () => { endOfStream(portStream, () => {
notificationIsOpen = false notificationIsOpen = false
controller.isClientOpen = isClientOpenStatus()
})
}
if (processName === ENVIRONMENT_TYPE_FULLSCREEN) {
const tabId = remotePort.sender.tab.id
openMetamaskTabsIDs[tabId] = true
endOfStream(portStream, () => {
delete openMetamaskTabsIDs[tabId]
controller.isClientOpen = isClientOpenStatus()
}) })
} }
} else { } else {
@ -260,10 +285,11 @@ function setupController (initState, initLangCode) {
// popup trigger // popup trigger
function triggerUi () { function triggerUi () {
extension.tabs.query({ active: true }, (tabs) => { extension.tabs.query({ active: true }, tabs => {
const currentlyActiveMetamaskTab = tabs.find(tab => openMetamaskTabsIDs[tab.id]) const currentlyActiveMetamaskTab = Boolean(tabs.find(tab => openMetamaskTabsIDs[tab.id]))
if (!popupIsOpen && !currentlyActiveMetamaskTab && !notificationIsOpen) notificationManager.showPopup() if (!popupIsOpen && !currentlyActiveMetamaskTab && !notificationIsOpen) {
notificationIsOpen = true notificationManager.showPopup()
}
}) })
} }

@ -0,0 +1,9 @@
const ENVIRONMENT_TYPE_POPUP = 'popup'
const ENVIRONMENT_TYPE_NOTIFICATION = 'notification'
const ENVIRONMENT_TYPE_FULLSCREEN = 'fullscreen'
module.exports = {
ENVIRONMENT_TYPE_POPUP,
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_FULLSCREEN,
}

@ -1,10 +0,0 @@
module.exports = function environmentType () {
const url = window.location.href
if (url.match(/popup.html$/)) {
return 'popup'
} else if (url.match(/home.html$/)) {
return 'responsive'
} else {
return 'notification'
}
}

@ -1,12 +0,0 @@
module.exports = function isPopupOrNotification () {
const url = window.location.href
// if (url.match(/popup.html$/) || url.match(/home.html$/)) {
// Below regexes needed for feature toggles (e.g. see line ~340 in ui/app/app.js)
// Revert below regexes to above commented out regexes before merge to master
if (url.match(/popup.html(?:\?.+)*$/) ||
url.match(/home.html(?:\?.+)*$/) || url.match(/home.html(?:#.*)*$/)) {
return 'popup'
} else {
return 'notification'
}
}

@ -1,20 +1,27 @@
const ethUtil = require('ethereumjs-util') const ethUtil = require('ethereumjs-util')
const assert = require('assert') const assert = require('assert')
const BN = require('bn.js') const BN = require('bn.js')
const {
module.exports = { ENVIRONMENT_TYPE_POPUP,
getStack, ENVIRONMENT_TYPE_NOTIFICATION,
sufficientBalance, ENVIRONMENT_TYPE_FULLSCREEN,
hexToBn, } = require('./enums')
bnToHex,
BnMultiplyByFraction,
}
function getStack () { function getStack () {
const stack = new Error('Stack trace generator - not an error').stack const stack = new Error('Stack trace generator - not an error').stack
return stack return stack
} }
const getEnvironmentType = (url = window.location.href) => {
if (url.match(/popup.html(?:\?.+)*$/)) {
return ENVIRONMENT_TYPE_POPUP
} else if (url.match(/home.html(?:\?.+)*$/) || url.match(/home.html(?:#.*)*$/)) {
return ENVIRONMENT_TYPE_FULLSCREEN
} else {
return ENVIRONMENT_TYPE_NOTIFICATION
}
}
function sufficientBalance (txParams, hexBalance) { function sufficientBalance (txParams, hexBalance) {
// validate hexBalance is a hex string // validate hexBalance is a hex string
assert.equal(typeof hexBalance, 'string', 'sufficientBalance - hexBalance is not a hex string') assert.equal(typeof hexBalance, 'string', 'sufficientBalance - hexBalance is not a hex string')
@ -42,3 +49,12 @@ function BnMultiplyByFraction (targetBN, numerator, denominator) {
const denomBN = new BN(denominator) const denomBN = new BN(denominator)
return targetBN.mul(numBN).div(denomBN) return targetBN.mul(numBN).div(denomBN)
} }
module.exports = {
getStack,
getEnvironmentType,
sufficientBalance,
hexToBn,
bnToHex,
BnMultiplyByFraction,
}

@ -3,7 +3,8 @@ const OldMetaMaskUiCss = require('../../old-ui/css')
const NewMetaMaskUiCss = require('../../ui/css') const NewMetaMaskUiCss = require('../../ui/css')
const startPopup = require('./popup-core') const startPopup = require('./popup-core')
const PortStream = require('./lib/port-stream.js') const PortStream = require('./lib/port-stream.js')
const isPopupOrNotification = require('./lib/is-popup-or-notification') const { getEnvironmentType } = require('./lib/util')
const { ENVIRONMENT_TYPE_NOTIFICATION } = require('./lib/enums')
const extension = require('extensionizer') const extension = require('extensionizer')
const ExtensionPlatform = require('./platforms/extension') const ExtensionPlatform = require('./platforms/extension')
const NotificationManager = require('./lib/notification-manager') const NotificationManager = require('./lib/notification-manager')
@ -27,7 +28,7 @@ async function start() {
// injectCss(css) // injectCss(css)
// identify window type (popup, notification) // identify window type (popup, notification)
const windowType = isPopupOrNotification() const windowType = getEnvironmentType(window.location.href)
global.METAMASK_UI_TYPE = windowType global.METAMASK_UI_TYPE = windowType
closePopupIfOpen(windowType) closePopupIfOpen(windowType)
@ -69,7 +70,7 @@ async function start() {
function closePopupIfOpen (windowType) { function closePopupIfOpen (windowType) {
if (windowType !== 'notification') { if (windowType !== ENVIRONMENT_TYPE_NOTIFICATION) {
// should close only chrome popup // should close only chrome popup
notificationManager.closePopup() notificationManager.closePopup()
} }

@ -6,8 +6,9 @@ const actions = require('../../ui/app/actions')
const NetworkIndicator = require('./components/network') const NetworkIndicator = require('./components/network')
const LoadingIndicator = require('./components/loading') const LoadingIndicator = require('./components/loading')
const txHelper = require('../lib/tx-helper') const txHelper = require('../lib/tx-helper')
const isPopupOrNotification = require('../../app/scripts/lib/is-popup-or-notification')
const log = require('loglevel') const log = require('loglevel')
const { ENVIRONMENT_TYPE_NOTIFICATION } = require('../../app/scripts/lib/enums')
const { getEnvironmentType } = require('../../app/scripts/lib/util')
const PendingTx = require('./components/pending-tx') const PendingTx = require('./components/pending-tx')
const PendingMsg = require('./components/pending-msg') const PendingMsg = require('./components/pending-msg')
@ -51,7 +52,7 @@ ConfirmTxScreen.prototype.render = function () {
var txData = unconfTxList[props.index] || {} var txData = unconfTxList[props.index] || {}
var txParams = txData.params || {} var txParams = txData.params || {}
var isNotification = isPopupOrNotification() === 'notification' var isNotification = getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
log.info(`rendering a combined ${unconfTxList.length} unconf msg & txs`) log.info(`rendering a combined ${unconfTxList.length} unconf msg & txs`)
if (unconfTxList.length === 0) return h(Loading, { isLoading: true }) if (unconfTxList.length === 0) return h(Loading, { isLoading: true })

@ -5,7 +5,8 @@ const connect = require('react-redux').connect
const FadeModal = require('boron').FadeModal const FadeModal = require('boron').FadeModal
const actions = require('../../actions') const actions = require('../../actions')
const isMobileView = require('../../../lib/is-mobile-view') const isMobileView = require('../../../lib/is-mobile-view')
const isPopupOrNotification = require('../../../../app/scripts/lib/is-popup-or-notification') const { getEnvironmentType } = require('../../../../app/scripts/lib/util')
const { ENVIRONMENT_TYPE_POPUP } = require('../../../../app/scripts/lib/enums')
// Modal Components // Modal Components
const BuyOptions = require('./buy-options-modal') const BuyOptions = require('./buy-options-modal')
@ -162,7 +163,7 @@ const MODALS = {
], ],
mobileModalStyle: { mobileModalStyle: {
width: '95%', width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh', top: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh',
}, },
laptopModalStyle: { laptopModalStyle: {
width: '449px', width: '449px',
@ -179,7 +180,7 @@ const MODALS = {
], ],
mobileModalStyle: { mobileModalStyle: {
width: '95%', width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh', top: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh',
}, },
laptopModalStyle: { laptopModalStyle: {
width: '449px', width: '449px',
@ -196,7 +197,7 @@ const MODALS = {
], ],
mobileModalStyle: { mobileModalStyle: {
width: '95%', width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh', top: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh',
}, },
laptopModalStyle: { laptopModalStyle: {
width: '449px', width: '449px',
@ -208,7 +209,7 @@ const MODALS = {
contents: h(ConfirmResetAccount), contents: h(ConfirmResetAccount),
mobileModalStyle: { mobileModalStyle: {
width: '95%', width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh', top: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh',
}, },
laptopModalStyle: { laptopModalStyle: {
width: '473px', width: '473px',

@ -11,7 +11,8 @@ const {
setNetworkEndpoints, setNetworkEndpoints,
setFeatureFlag, setFeatureFlag,
} = require('../../actions') } = require('../../actions')
const environmentType = require('../../../../app/scripts/lib/environment-type') const { ENVIRONMENT_TYPE_POPUP } = require('../../../../app/scripts/lib/enums')
const { getEnvironmentType } = require('../../../../app/scripts/lib/util')
const getCaretCoordinates = require('textarea-caret') const getCaretCoordinates = require('textarea-caret')
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const Mascot = require('../mascot') const Mascot = require('../mascot')
@ -131,7 +132,7 @@ class UnlockScreen extends Component {
this.props.markPasswordForgotten() this.props.markPasswordForgotten()
this.props.history.push(RESTORE_VAULT_ROUTE) this.props.history.push(RESTORE_VAULT_ROUTE)
if (environmentType() === 'popup') { if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) {
global.platform.openExtensionInBrowser() global.platform.openExtensionInBrowser()
} }
}, },

@ -8,7 +8,8 @@ const actions = require('../actions')
const Tooltip = require('../components/tooltip') const Tooltip = require('../components/tooltip')
const getCaretCoordinates = require('textarea-caret') const getCaretCoordinates = require('textarea-caret')
const { RESTORE_VAULT_ROUTE, DEFAULT_ROUTE } = require('../routes') const { RESTORE_VAULT_ROUTE, DEFAULT_ROUTE } = require('../routes')
const environmentType = require('../../../app/scripts/lib/environment-type') const { getEnvironmentType } = require('../../../app/scripts/lib/util')
const { ENVIRONMENT_TYPE_POPUP } = require('../../../app/scripts/lib/enums')
const { OLD_UI_NETWORK_TYPE } = require('../../../app/scripts/config').enums const { OLD_UI_NETWORK_TYPE } = require('../../../app/scripts/config').enums
class InitializeMenuScreen extends Component { class InitializeMenuScreen extends Component {
@ -180,7 +181,7 @@ class InitializeMenuScreen extends Component {
showRestoreVault () { showRestoreVault () {
this.props.markPasswordForgotten() this.props.markPasswordForgotten()
if (environmentType() === 'popup') { if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) {
global.platform.openExtensionInBrowser() global.platform.openExtensionInBrowser()
} }

@ -1,7 +1,8 @@
const extend = require('xtend') const extend = require('xtend')
const actions = require('../actions') const actions = require('../actions')
const MetamascaraPlatform = require('../../../app/scripts/platforms/window') const MetamascaraPlatform = require('../../../app/scripts/platforms/window')
const environmentType = require('../../../app/scripts/lib/environment-type') const { getEnvironmentType } = require('../../../app/scripts/lib/util')
const { ENVIRONMENT_TYPE_POPUP } = require('../../../app/scripts/lib/enums')
const { OLD_UI_NETWORK_TYPE } = require('../../../app/scripts/config').enums const { OLD_UI_NETWORK_TYPE } = require('../../../app/scripts/config').enums
module.exports = reduceMetamask module.exports = reduceMetamask
@ -15,7 +16,7 @@ function reduceMetamask (state, action) {
isUnlocked: false, isUnlocked: false,
isAccountMenuOpen: false, isAccountMenuOpen: false,
isMascara: window.platform instanceof MetamascaraPlatform, isMascara: window.platform instanceof MetamascaraPlatform,
isPopup: environmentType() === 'popup', isPopup: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP,
rpcTarget: 'https://rawtestrpc.metamask.io/', rpcTarget: 'https://rawtestrpc.metamask.io/',
identities: {}, identities: {},
unapprovedTxs: {}, unapprovedTxs: {},

@ -7,7 +7,8 @@ const actions = require('./actions')
const getCaretCoordinates = require('textarea-caret') const getCaretCoordinates = require('textarea-caret')
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const { OLD_UI_NETWORK_TYPE } = require('../../app/scripts/config').enums const { OLD_UI_NETWORK_TYPE } = require('../../app/scripts/config').enums
const environmentType = require('../../app/scripts/lib/environment-type') const { getEnvironmentType } = require('../../app/scripts/lib/util')
const { ENVIRONMENT_TYPE_POPUP } = require('../../app/scripts/lib/enums')
const Mascot = require('./components/mascot') const Mascot = require('./components/mascot')
@ -77,7 +78,7 @@ UnlockScreen.prototype.render = function () {
h('p.pointer', { h('p.pointer', {
onClick: () => { onClick: () => {
this.props.dispatch(actions.markPasswordForgotten()) this.props.dispatch(actions.markPasswordForgotten())
if (environmentType() === 'popup') { if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) {
global.platform.openExtensionInBrowser() global.platform.openExtensionInBrowser()
} }
}, },

Loading…
Cancel
Save