aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2016-07-22 02:30:57 +0800
committerKevin Serrano <kevgagser@gmail.com>2016-07-22 02:30:57 +0800
commit7b85802a0fede74217dd702ddda9bea1154517eb (patch)
tree055d903420fb1e04bc01d8bc542b389581ca4b41 /app/scripts/lib
parent4a9d5b1c258912acedd6f1e89fb632526d9c910b (diff)
parent6658bea8d444281491718f8eee7bc3ae42f91b69 (diff)
downloadtangerine-wallet-browser-7b85802a0fede74217dd702ddda9bea1154517eb.tar
tangerine-wallet-browser-7b85802a0fede74217dd702ddda9bea1154517eb.tar.gz
tangerine-wallet-browser-7b85802a0fede74217dd702ddda9bea1154517eb.tar.bz2
tangerine-wallet-browser-7b85802a0fede74217dd702ddda9bea1154517eb.tar.lz
tangerine-wallet-browser-7b85802a0fede74217dd702ddda9bea1154517eb.tar.xz
tangerine-wallet-browser-7b85802a0fede74217dd702ddda9bea1154517eb.tar.zst
tangerine-wallet-browser-7b85802a0fede74217dd702ddda9bea1154517eb.zip
Merge branch 'master' into usd-conversion
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/extension-instance.js38
-rw-r--r--app/scripts/lib/extension.js14
-rw-r--r--app/scripts/lib/inpage-provider.js10
-rw-r--r--app/scripts/lib/notifications.js31
4 files changed, 77 insertions, 16 deletions
diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js
new file mode 100644
index 000000000..eeab6c6d0
--- /dev/null
+++ b/app/scripts/lib/extension-instance.js
@@ -0,0 +1,38 @@
+const apis = [
+ 'alarms',
+ 'bookmarks',
+ 'browserAction',
+ 'commands',
+ 'contextMenus',
+ 'cookies',
+ 'downloads',
+ 'events',
+ 'extension',
+ 'extensionTypes',
+ 'history',
+ 'i18n',
+ 'idle',
+ 'notifications',
+ 'pageAction',
+ 'runtime',
+ 'storage',
+ 'tabs',
+ 'webNavigation',
+ 'webRequest',
+ 'windows',
+]
+
+function Extension () {
+ const _this = this
+ let global = window
+
+ if (window.chrome) {
+ global = window.chrome
+ }
+
+ apis.forEach(function (api) {
+ _this[api] = global[api]
+ })
+}
+
+module.exports = Extension
diff --git a/app/scripts/lib/extension.js b/app/scripts/lib/extension.js
new file mode 100644
index 000000000..4b670490f
--- /dev/null
+++ b/app/scripts/lib/extension.js
@@ -0,0 +1,14 @@
+/* Extension.js
+ *
+ * A module for unifying browser differences in the WebExtension API.
+ *
+ * Initially implemented because Chrome hides all of their WebExtension API
+ * behind a global `chrome` variable, but we'd like to start grooming
+ * the code-base for cross-browser extension support.
+ *
+ * You can read more about the WebExtension API here:
+ * https://developer.mozilla.org/en-US/Add-ons/WebExtensions
+ */
+
+const Extension = require('./extension-instance')
+module.exports = new Extension()
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index 3b6ec154f..e387be895 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -107,7 +107,15 @@ function createSyncProvider (providerConfig) {
syncProviderUrl = MetamaskConfig.network.default
}
}
- return new HttpProvider(syncProviderUrl)
+
+ const provider = new HttpProvider(syncProviderUrl)
+ // Stubbing out the send method to throw on sync methods:
+ provider.send = function() {
+ var message = 'The MetaMask Web3 object does not support synchronous methods. See https://github.com/MetaMask/faq#all-async---think-of-metamask-as-a-light-client for details.'
+ throw new Error(message)
+ }
+
+ return provider
}
function remoteStoreWithLocalStorageCache (storageKey) {
diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js
index b6590b0e5..6c1601df1 100644
--- a/app/scripts/lib/notifications.js
+++ b/app/scripts/lib/notifications.js
@@ -7,6 +7,7 @@ const h = require('react-hyperscript')
const PendingTxDetails = require('../../../ui/app/components/pending-tx-details')
const PendingMsgDetails = require('../../../ui/app/components/pending-msg-details')
const MetaMaskUiCss = require('../../../ui/css')
+const extension = require('./extension')
var notificationHandlers = {}
const notifications = {
@@ -20,34 +21,34 @@ window.METAMASK_NOTIFIER = notifications
setupListeners()
function setupListeners () {
- // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
- if (!chrome.notifications) return console.error('Chrome notifications API missing...')
+ // guard for extension bug https://github.com/MetaMask/metamask-plugin/issues/236
+ if (!extension.notifications) return console.error('Chrome notifications API missing...')
// notification button press
- chrome.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) {
+ extension.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) {
var handlers = notificationHandlers[notificationId]
if (buttonIndex === 0) {
handlers.confirm()
} else {
handlers.cancel()
}
- chrome.notifications.clear(notificationId)
+ extension.notifications.clear(notificationId)
})
// notification teardown
- chrome.notifications.onClosed.addListener(function (notificationId) {
+ extension.notifications.onClosed.addListener(function (notificationId) {
delete notificationHandlers[notificationId]
})
}
// creation helper
function createUnlockRequestNotification (opts) {
- // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
- if (!chrome.notifications) return console.error('Chrome notifications API missing...')
+ // guard for extension bug https://github.com/MetaMask/metamask-plugin/issues/236
+ if (!extension.notifications) return console.error('Chrome notifications API missing...')
var message = 'An Ethereum app has requested a signature. Please unlock your account.'
var id = createId()
- chrome.notifications.create(id, {
+ extension.notifications.create(id, {
type: 'basic',
iconUrl: '/images/icon-128.png',
title: opts.title,
@@ -56,8 +57,8 @@ function createUnlockRequestNotification (opts) {
}
function createTxNotification (state) {
- // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
- if (!chrome.notifications) return console.error('Chrome notifications API missing...')
+ // guard for extension bug https://github.com/MetaMask/metamask-plugin/issues/236
+ if (!extension.notifications) return console.error('Chrome notifications API missing...')
renderTxNotificationSVG(state, function (err, notificationSvgSource) {
if (err) throw err
@@ -70,8 +71,8 @@ function createTxNotification (state) {
}
function createMsgNotification (state) {
- // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
- if (!chrome.notifications) return console.error('Chrome notifications API missing...')
+ // guard for extension bug https://github.com/MetaMask/metamask-plugin/issues/236
+ if (!extension.notifications) return console.error('Chrome notifications API missing...')
renderMsgNotificationSVG(state, function (err, notificationSvgSource) {
if (err) throw err
@@ -84,11 +85,11 @@ function createMsgNotification (state) {
}
function showNotification (state) {
- // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
- if (!chrome.notifications) return console.error('Chrome notifications API missing...')
+ // guard for extension bug https://github.com/MetaMask/metamask-plugin/issues/236
+ if (!extension.notifications) return console.error('Chrome notifications API missing...')
var id = createId()
- chrome.notifications.create(id, {
+ extension.notifications.create(id, {
type: 'image',
requireInteraction: true,
iconUrl: '/images/icon-128.png',