diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-08-17 07:46:44 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-08-17 07:46:44 +0800 |
commit | 030bdec27a95390207b9147c95b810893756db6d (patch) | |
tree | 459f0411c7f57b7ae86dce77a8dc71c55fef257b | |
parent | 4ba90969ee8fa9b9e21e88f5c6f0d646874049a3 (diff) | |
download | tangerine-wallet-browser-030bdec27a95390207b9147c95b810893756db6d.tar tangerine-wallet-browser-030bdec27a95390207b9147c95b810893756db6d.tar.gz tangerine-wallet-browser-030bdec27a95390207b9147c95b810893756db6d.tar.bz2 tangerine-wallet-browser-030bdec27a95390207b9147c95b810893756db6d.tar.lz tangerine-wallet-browser-030bdec27a95390207b9147c95b810893756db6d.tar.xz tangerine-wallet-browser-030bdec27a95390207b9147c95b810893756db6d.tar.zst tangerine-wallet-browser-030bdec27a95390207b9147c95b810893756db6d.zip |
Unify notification and popup ui files
-rw-r--r-- | app/notification.html | 7 | ||||
-rw-r--r-- | app/scripts/lib/extension-instance.js | 6 | ||||
-rw-r--r-- | app/scripts/lib/is-popup-or-notification.js | 8 | ||||
-rw-r--r-- | app/scripts/lib/notifications.js | 2 | ||||
-rw-r--r-- | app/scripts/popup.js | 7 | ||||
-rw-r--r-- | gulpfile.js | 5 | ||||
-rw-r--r-- | ui/notification.js | 52 |
7 files changed, 29 insertions, 58 deletions
diff --git a/app/notification.html b/app/notification.html index 927f1634c..cc485da7f 100644 --- a/app/notification.html +++ b/app/notification.html @@ -3,9 +3,14 @@ <head> <meta charset="utf-8"> <title>MetaMask Notification</title> + <style> + body { + overflow: hidden; + } + </style> </head> <body> <div id="app-content"></div> - <script src="./scripts/notification.js" type="text/javascript" charset="utf-8"></script> + <script src="./scripts/popup.js" type="text/javascript" charset="utf-8"></script> </body> </html> diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js index eb3b8a1e9..d284895bc 100644 --- a/app/scripts/lib/extension-instance.js +++ b/app/scripts/lib/extension-instance.js @@ -42,6 +42,12 @@ function Extension () { } catch (e) {} try { + if (browser[api]) { + _this[api] = browser[api] + } + } + + try { _this.api = browser.extension[api] } catch (e) {} diff --git a/app/scripts/lib/is-popup-or-notification.js b/app/scripts/lib/is-popup-or-notification.js new file mode 100644 index 000000000..5c38ac823 --- /dev/null +++ b/app/scripts/lib/is-popup-or-notification.js @@ -0,0 +1,8 @@ +module.exports = function isPopupOrNotification() { + const url = window.location.href + if (url.match(/popup.html$/)) { + return 'popup' + } else { + return 'notification' + } +} diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js index 75fb60dd0..e6bdeff09 100644 --- a/app/scripts/lib/notifications.js +++ b/app/scripts/lib/notifications.js @@ -31,7 +31,7 @@ function createMsgNotification (state) { } function showNotification() { - chrome.windows.create({ + extension.windows.create({ url:"notification.html", type:"panel", width:360, diff --git a/app/scripts/popup.js b/app/scripts/popup.js index 20be15df7..4c729e227 100644 --- a/app/scripts/popup.js +++ b/app/scripts/popup.js @@ -9,6 +9,7 @@ const injectCss = require('inject-css') const PortStream = require('./lib/port-stream.js') const StreamProvider = require('web3-stream-provider') const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex +const isPopupOrNotification = require('./lib/is-popup-or-notification') const extension = require('./lib/extension') // setup app @@ -22,7 +23,10 @@ async.parallel({ function connectToAccountManager (cb) { // setup communication with background - var pluginPort = extension.runtime.connect({name: 'popup'}) + + var name = isPopupOrNotification() + window.METAMASK_UI_TYPE = name + var pluginPort = extension.runtime.connect({ name }) var portStream = new PortStream(pluginPort) // setup multiplexing var mx = setupMultiplex(portStream) @@ -93,3 +97,4 @@ function setupApp (err, opts) { networkVersion: opts.networkVersion, }) } + diff --git a/gulpfile.js b/gulpfile.js index 48f30835b..aeaf3e674 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -108,7 +108,6 @@ const jsFiles = [ 'contentscript', 'background', 'popup', - 'notification', ] jsFiles.forEach((jsFile) => { @@ -116,9 +115,9 @@ jsFiles.forEach((jsFile) => { gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, filename: `${jsFile}.js` })) }) -gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup', 'dev:js:notification')) +gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup')) -gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup', 'dev:js:notification')) +gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup')) // clean dist diff --git a/ui/notification.js b/ui/notification.js deleted file mode 100644 index 8cf74f6ee..000000000 --- a/ui/notification.js +++ /dev/null @@ -1,52 +0,0 @@ -const render = require('react-dom').render -const h = require('react-hyperscript') -const Root = require('./app/root') -const actions = require('./app/actions') -const configureStore = require('./app/store') - -module.exports = launchApp - -function launchApp (opts) { - var accountManager = opts.accountManager - actions._setAccountManager(accountManager) - - // check if we are unlocked first - accountManager.getState(function (err, metamaskState) { - if (err) throw err - startApp(metamaskState, accountManager, opts) - }) -} - -function startApp (metamaskState, accountManager, opts) { - // parse opts - var store = configureStore({ - - // metamaskState represents the cross-tab state - metamask: metamaskState, - - // appState represents the current tab's popup state - appState: { - currentDomain: opts.currentDomain, - }, - - // Which blockchain we are using: - networkVersion: opts.networkVersion, - }) - - // if unconfirmed txs, start on txConf page - if (Object.keys(metamaskState.unconfTxs || {}).length) { - store.dispatch(actions.showConfTxPage()) - } - - accountManager.on('update', function (metamaskState) { - store.dispatch(actions.updateMetamaskState(metamaskState)) - }) - - // start app - render( - h(Root, { - // inject initial state - store: store, - } - ), opts.container) -} |