From 5815de33fbef617625d8350ec8e88aa4dbff6156 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 14:04:33 -0700 Subject: build - rename 'popup.js' to 'ui.js' --- app/scripts/popup.js | 84 ---------------------------------------------------- app/scripts/ui.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 app/scripts/popup.js create mode 100644 app/scripts/ui.js (limited to 'app/scripts') diff --git a/app/scripts/popup.js b/app/scripts/popup.js deleted file mode 100644 index 13c7ac5ec..000000000 --- a/app/scripts/popup.js +++ /dev/null @@ -1,84 +0,0 @@ -const injectCss = require('inject-css') -const OldMetaMaskUiCss = require('../../old-ui/css') -const NewMetaMaskUiCss = require('../../ui/css') -const startPopup = require('./popup-core') -const PortStream = require('./lib/port-stream.js') -const isPopupOrNotification = require('./lib/is-popup-or-notification') -const extension = require('extensionizer') -const ExtensionPlatform = require('./platforms/extension') -const NotificationManager = require('./lib/notification-manager') -const notificationManager = new NotificationManager() -const setupRaven = require('./lib/setupRaven') - -start().catch(log.error) - -async function start() { - - // create platform global - global.platform = new ExtensionPlatform() - - // setup sentry error reporting - const release = global.platform.getVersion() - setupRaven({ release }) - - // inject css - // const css = MetaMaskUiCss() - // injectCss(css) - - // identify window type (popup, notification) - const windowType = isPopupOrNotification() - global.METAMASK_UI_TYPE = windowType - closePopupIfOpen(windowType) - - // setup stream to background - const extensionPort = extension.runtime.connect({ name: windowType }) - const connectionStream = new PortStream(extensionPort) - - // start ui - const container = document.getElementById('app-content') - startPopup({ container, connectionStream }, (err, store) => { - if (err) return displayCriticalError(err) - - // Code commented out until we begin auto adding users to NewUI - // const { isMascara, identities = {}, featureFlags = {} } = store.getState().metamask - // const firstTime = Object.keys(identities).length === 0 - const { isMascara, featureFlags = {} } = store.getState().metamask - let betaUIState = featureFlags.betaUI - - // Code commented out until we begin auto adding users to NewUI - // const useBetaCss = isMascara || firstTime || betaUIState - const useBetaCss = isMascara || betaUIState - - let css = useBetaCss ? NewMetaMaskUiCss() : OldMetaMaskUiCss() - let deleteInjectedCss = injectCss(css) - let newBetaUIState - - store.subscribe(() => { - const state = store.getState() - newBetaUIState = state.metamask.featureFlags.betaUI - if (newBetaUIState !== betaUIState) { - deleteInjectedCss() - betaUIState = newBetaUIState - css = betaUIState ? NewMetaMaskUiCss() : OldMetaMaskUiCss() - deleteInjectedCss = injectCss(css) - } - if (state.appState.shouldClose) notificationManager.closePopup() - }) - }) - - - function closePopupIfOpen (windowType) { - if (windowType !== 'notification') { - // should close only chrome popup - notificationManager.closePopup() - } - } - - function displayCriticalError (err) { - container.innerHTML = '
The MetaMask app failed to load: please open and close MetaMask again to restart.
' - container.style.height = '80px' - log.error(err.stack) - throw err - } - -} diff --git a/app/scripts/ui.js b/app/scripts/ui.js new file mode 100644 index 000000000..13c7ac5ec --- /dev/null +++ b/app/scripts/ui.js @@ -0,0 +1,84 @@ +const injectCss = require('inject-css') +const OldMetaMaskUiCss = require('../../old-ui/css') +const NewMetaMaskUiCss = require('../../ui/css') +const startPopup = require('./popup-core') +const PortStream = require('./lib/port-stream.js') +const isPopupOrNotification = require('./lib/is-popup-or-notification') +const extension = require('extensionizer') +const ExtensionPlatform = require('./platforms/extension') +const NotificationManager = require('./lib/notification-manager') +const notificationManager = new NotificationManager() +const setupRaven = require('./lib/setupRaven') + +start().catch(log.error) + +async function start() { + + // create platform global + global.platform = new ExtensionPlatform() + + // setup sentry error reporting + const release = global.platform.getVersion() + setupRaven({ release }) + + // inject css + // const css = MetaMaskUiCss() + // injectCss(css) + + // identify window type (popup, notification) + const windowType = isPopupOrNotification() + global.METAMASK_UI_TYPE = windowType + closePopupIfOpen(windowType) + + // setup stream to background + const extensionPort = extension.runtime.connect({ name: windowType }) + const connectionStream = new PortStream(extensionPort) + + // start ui + const container = document.getElementById('app-content') + startPopup({ container, connectionStream }, (err, store) => { + if (err) return displayCriticalError(err) + + // Code commented out until we begin auto adding users to NewUI + // const { isMascara, identities = {}, featureFlags = {} } = store.getState().metamask + // const firstTime = Object.keys(identities).length === 0 + const { isMascara, featureFlags = {} } = store.getState().metamask + let betaUIState = featureFlags.betaUI + + // Code commented out until we begin auto adding users to NewUI + // const useBetaCss = isMascara || firstTime || betaUIState + const useBetaCss = isMascara || betaUIState + + let css = useBetaCss ? NewMetaMaskUiCss() : OldMetaMaskUiCss() + let deleteInjectedCss = injectCss(css) + let newBetaUIState + + store.subscribe(() => { + const state = store.getState() + newBetaUIState = state.metamask.featureFlags.betaUI + if (newBetaUIState !== betaUIState) { + deleteInjectedCss() + betaUIState = newBetaUIState + css = betaUIState ? NewMetaMaskUiCss() : OldMetaMaskUiCss() + deleteInjectedCss = injectCss(css) + } + if (state.appState.shouldClose) notificationManager.closePopup() + }) + }) + + + function closePopupIfOpen (windowType) { + if (windowType !== 'notification') { + // should close only chrome popup + notificationManager.closePopup() + } + } + + function displayCriticalError (err) { + container.innerHTML = '
The MetaMask app failed to load: please open and close MetaMask again to restart.
' + container.style.height = '80px' + log.error(err.stack) + throw err + } + +} -- cgit From f50a7a8fe891a803e50cc256200e8ce8c903ea2e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 28 Mar 2018 14:09:45 -0700 Subject: Rename variable to be more understandable --- app/scripts/lib/nonce-tracker.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js index ed9dd3f11..5b1cd7f43 100644 --- a/app/scripts/lib/nonce-tracker.js +++ b/app/scripts/lib/nonce-tracker.js @@ -31,14 +31,13 @@ class NonceTracker { const networkNonceResult = await this._getNetworkNextNonce(address) const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address) const nextNetworkNonce = networkNonceResult.nonce - const highestLocalNonce = highestLocallyConfirmed - const highestSuggested = Math.max(nextNetworkNonce, highestLocalNonce) + const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed) const pendingTxs = this.getPendingTransactions(address) const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0 nonceDetails.params = { - highestLocalNonce, + highestLocallyConfirmed, highestSuggested, nextNetworkNonce, } -- cgit From 253abd60fca5a6efb1a2e0ecbe305989a852ec32 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 21:29:57 -0700 Subject: build - extension - move js files to toplevel --- app/scripts/contentscript.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 7abbc60e7..2098fae27 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -7,8 +7,8 @@ const ObjectMultiplex = require('obj-multiplex') const extension = require('extensionizer') const PortStream = require('./lib/port-stream.js') -const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'scripts', 'inpage.js')).toString() -const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('scripts/inpage.js') + '\n' +const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString() +const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n' const inpageBundle = inpageContent + inpageSuffix // Eventually this streaming injection could be replaced with: @@ -96,7 +96,7 @@ function logStreamDisconnectWarning (remoteLabel, err) { } function shouldInjectWeb3 () { - return doctypeCheck() && suffixCheck() + return doctypeCheck() && suffixCheck() && documentElementCheck() && !blacklistedDomainCheck() } -- cgit