aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorFrankie <frankie.pangilinan@consensys.net>2016-08-11 04:48:34 +0800
committerFrankie <frankie.pangilinan@consensys.net>2016-08-11 04:48:34 +0800
commitba1edc429b948962fe0f03ef43588f7945cea3f2 (patch)
treeeda1b54a424c2fc06ef151763b5cb57d2e838116 /app/scripts
parent9c6dd9ef4953f6e421feb6e6684ef43da26f6b75 (diff)
parentc48b60d7a6f14d2d2348be8d9a63965ca1267433 (diff)
downloadtangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar.gz
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar.bz2
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar.lz
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar.xz
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar.zst
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.zip
Merge branch 'master' into buyForm
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/background.js7
-rw-r--r--app/scripts/chromereload.js2
-rw-r--r--app/scripts/config.js2
-rw-r--r--app/scripts/contentscript.js38
-rw-r--r--app/scripts/inpage.js12
-rw-r--r--app/scripts/lib/config-manager.js18
-rw-r--r--app/scripts/lib/extension-instance.js51
-rw-r--r--app/scripts/lib/extension.js14
-rw-r--r--app/scripts/lib/idStore.js3
-rw-r--r--app/scripts/lib/inpage-provider.js10
-rw-r--r--app/scripts/lib/notifications.js31
-rw-r--r--app/scripts/metamask-controller.js2
-rw-r--r--app/scripts/popup.js11
13 files changed, 162 insertions, 39 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 801dc95cf..34c994ab7 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -9,6 +9,7 @@ const createMsgNotification = require('./lib/notifications.js').createMsgNotific
const messageManager = require('./lib/message-manager')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const MetamaskController = require('./metamask-controller')
+const extension = require('./lib/extension')
const STORAGE_KEY = 'metamask-config'
@@ -65,7 +66,7 @@ function showUnconfirmedTx (txParams, txData, onTxDoneCb) {
// connect to other contexts
//
-chrome.runtime.onConnect.addListener(connectRemote)
+extension.runtime.onConnect.addListener(connectRemote)
function connectRemote (remotePort) {
var isMetaMaskInternalProcess = (remotePort.name === 'popup')
var portStream = new PortStream(remotePort)
@@ -133,8 +134,8 @@ function updateBadge (state) {
if (count) {
label = String(count)
}
- chrome.browserAction.setBadgeText({ text: label })
- chrome.browserAction.setBadgeBackgroundColor({ color: '#506F8B' })
+ extension.browserAction.setBadgeText({ text: label })
+ extension.browserAction.setBadgeBackgroundColor({ color: '#506F8B' })
}
function loadData () {
diff --git a/app/scripts/chromereload.js b/app/scripts/chromereload.js
index 283a131f1..88333ba8a 100644
--- a/app/scripts/chromereload.js
+++ b/app/scripts/chromereload.js
@@ -25,7 +25,7 @@
// if (e.data) {
// var data = JSON.parse(e.data);
// if (data && data.command === 'reload') {
-// chrome.runtime.reload();
+// extension.runtime.reload();
// }
// }
// };
diff --git a/app/scripts/config.js b/app/scripts/config.js
index f26e6778d..5f6ffd936 100644
--- a/app/scripts/config.js
+++ b/app/scripts/config.js
@@ -1,12 +1,14 @@
const MAINET_RPC_URL = 'https://mainnet.infura.io/'
const TESTNET_RPC_URL = 'https://morden.infura.io/'
const DEFAULT_RPC_URL = TESTNET_RPC_URL
+const CLASSIC_RPC_URL = 'https://mainnet-nf.infura.io/'
module.exports = {
network: {
default: DEFAULT_RPC_URL,
mainnet: MAINET_RPC_URL,
testnet: TESTNET_RPC_URL,
+ classic: CLASSIC_RPC_URL,
},
}
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 60b37284e..1eb04059d 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -1,6 +1,18 @@
const LocalMessageDuplexStream = require('./lib/local-message-stream.js')
const PortStream = require('./lib/port-stream.js')
const ObjectMultiplex = require('./lib/obj-multiplex')
+const extension = require('./lib/extension')
+
+const fs = require('fs')
+const path = require('path')
+const inpageText = fs.readFileSync(path.join(__dirname + '/inpage.js')).toString()
+
+// Eventually this streaming injection could be replaced with:
+// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction
+//
+// But for now that is only Firefox
+// If we create a FireFox-only code path using that API,
+// MetaMask will be much faster loading and performant on Firefox.
if (shouldInjectWeb3()) {
setupInjection()
@@ -8,13 +20,20 @@ if (shouldInjectWeb3()) {
}
function setupInjection(){
- // inject in-page script
- var scriptTag = document.createElement('script')
- scriptTag.src = chrome.extension.getURL('scripts/inpage.js')
- scriptTag.onload = function () { this.parentNode.removeChild(this) }
- var container = document.head || document.documentElement
- // append as first child
- container.insertBefore(scriptTag, container.children[0])
+ try {
+
+ // inject in-page script
+ var scriptTag = document.createElement('script')
+ scriptTag.src = extension.extension.getURL('scripts/inpage.js')
+ scriptTag.textContent = inpageText
+ scriptTag.onload = function () { this.parentNode.removeChild(this) }
+ var container = document.head || document.documentElement
+ // append as first child
+ container.insertBefore(scriptTag, container.children[0])
+
+ } catch (e) {
+ console.error('Metamask injection failed.', e)
+ }
}
function setupStreams(){
@@ -25,7 +44,7 @@ function setupStreams(){
target: 'inpage',
})
pageStream.on('error', console.error.bind(console))
- var pluginPort = chrome.runtime.connect({name: 'contentscript'})
+ var pluginPort = extension.runtime.connect({name: 'contentscript'})
var pluginStream = new PortStream(pluginPort)
pluginStream.on('error', console.error.bind(console))
@@ -43,10 +62,9 @@ function setupStreams(){
pluginStream.on('close', function () {
reloadStream.write({ method: 'reset' })
})
-
}
function shouldInjectWeb3(){
var shouldInject = (window.location.href.indexOf('.pdf') === -1)
return shouldInject
-} \ No newline at end of file
+}
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index f5e54cd7b..055235671 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -53,9 +53,17 @@ var __define
function cleanContextForImports () {
__define = global.define
- delete global.define
+ try {
+ delete global.define
+ } catch (_) {
+ console.warn('MetaMask - global.define could not be deleted.')
+ }
}
function restoreContextAfterImports () {
- global.define = __define
+ try {
+ global.define = __define
+ } catch (_) {
+ console.warn('MetaMask - global.define could not be overwritten.')
+ }
}
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index caaae8a75..3d84edfd0 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -4,6 +4,7 @@ const migrations = require('./migrations')
const TESTNET_RPC = MetamaskConfig.network.testnet
const MAINNET_RPC = MetamaskConfig.network.mainnet
+const CLASSIC_RPC = MetamaskConfig.network.classic
/* The config-manager is a convenience object
* wrapping a pojo-migrator.
@@ -144,6 +145,9 @@ ConfigManager.prototype.getCurrentRpcAddress = function () {
case 'testnet':
return TESTNET_RPC
+ case 'classic':
+ return CLASSIC_RPC
+
default:
return provider && provider.rpcTarget ? provider.rpcTarget : TESTNET_RPC
}
@@ -270,3 +274,17 @@ ConfigManager.prototype.getConfirmed = function () {
return ('isConfirmed' in data) && data.isConfirmed
}
+ConfigManager.prototype.setShouldntShowWarning = function () {
+ var data = this.getData()
+ if (data.isEthConfirmed) {
+ data.isEthConfirmed = !data.isEthConfirmed
+ } else {
+ data.isEthConfirmed = true
+ }
+ this.setData(data)
+}
+
+ConfigManager.prototype.getShouldntShowWarning = function () {
+ var data = this.getData()
+ return ('isEthConfirmed' in data) && data.isEthConfirmed
+}
diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js
new file mode 100644
index 000000000..eb3b8a1e9
--- /dev/null
+++ b/app/scripts/lib/extension-instance.js
@@ -0,0 +1,51 @@
+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
+
+ apis.forEach(function (api) {
+
+ _this[api] = null
+
+ try {
+ if (chrome[api]) {
+ _this[api] = chrome[api]
+ }
+ } catch (e) {}
+
+ try {
+ if (window[api]) {
+ _this[api] = window[api]
+ }
+ } catch (e) {}
+
+ try {
+ _this.api = browser.extension[api]
+ } catch (e) {}
+
+ })
+}
+
+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/idStore.js b/app/scripts/lib/idStore.js
index 2c8e9108b..c6ac55a03 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -94,6 +94,7 @@ IdentityStore.prototype.getState = function () {
isUnlocked: this._isUnlocked(),
seedWords: seedWords,
isConfirmed: configManager.getConfirmed(),
+ isEthConfirmed: configManager.getShouldntShowWarning(),
unconfTxs: configManager.unconfirmedTxs(),
transactions: configManager.getTxList(),
unconfMsgs: messageManager.unconfirmedMsgs(),
@@ -199,7 +200,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
time: time,
status: 'unconfirmed',
}
-
+
console.log('addUnconfirmedTransaction:', txData)
// keep the onTxDoneCb around for after approval/denial (requires user interaction)
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',
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index dd43ac2fc..e7e96a472 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -243,7 +243,7 @@ module.exports = class MetamaskController {
agreeToEthWarning (cb) {
try {
- this.configManager.setShouldntShowWarning(true)
+ this.configManager.setShouldntShowWarning()
cb()
} catch (e) {
cb(e)
diff --git a/app/scripts/popup.js b/app/scripts/popup.js
index 2e5b98896..20be15df7 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 extension = require('./lib/extension')
// setup app
var css = MetaMaskUiCss()
@@ -21,7 +22,7 @@ async.parallel({
function connectToAccountManager (cb) {
// setup communication with background
- var pluginPort = chrome.runtime.connect({name: 'popup'})
+ var pluginPort = extension.runtime.connect({name: 'popup'})
var portStream = new PortStream(pluginPort)
// setup multiplexing
var mx = setupMultiplex(portStream)
@@ -55,8 +56,8 @@ function setupControllerConnection (stream, cb) {
function getCurrentDomain (cb) {
const unknown = '<unknown>'
- if (!chrome.tabs) return cb(null, unknown)
- chrome.tabs.query({active: true, currentWindow: true}, function (results) {
+ if (!extension.tabs) return cb(null, unknown)
+ extension.tabs.query({active: true, currentWindow: true}, function (results) {
var activeTab = results[0]
var currentUrl = activeTab && activeTab.url
var currentDomain = url.parse(currentUrl).host
@@ -68,9 +69,9 @@ function getCurrentDomain (cb) {
}
function clearNotifications(){
- chrome.notifications.getAll(function (object) {
+ extension.notifications.getAll(function (object) {
for (let notification in object){
- chrome.notifications.clear(notification)
+ extension.notifications.clear(notification)
}
})
}