aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
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/lib
parent9c6dd9ef4953f6e421feb6e6684ef43da26f6b75 (diff)
parentc48b60d7a6f14d2d2348be8d9a63965ca1267433 (diff)
downloadtangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar.gz
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.tar.zst
tangerine-wallet-browser-ba1edc429b948962fe0f03ef43588f7945cea3f2.zip
Merge branch 'master' into buyForm
Diffstat (limited to 'app/scripts/lib')
-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
6 files changed, 110 insertions, 17 deletions
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',