aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorbrunobar79 <brunobar79@gmail.com>2018-10-21 13:59:53 +0800
committerbrunobar79 <brunobar79@gmail.com>2018-10-21 13:59:53 +0800
commit9c1b2108f69334884473eb95758e2d1c02c984d6 (patch)
tree93f5255399307a28cb9380dc23c275b406403929 /app/scripts
parent13820b6cc1801a420f39cdfecd7ccb5309dc597b (diff)
parentb0c649a4e3c68293e08e764bbf4d53939df88e2d (diff)
downloadtangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar
tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar.gz
tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar.bz2
tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar.lz
tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar.xz
tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar.zst
tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.zip
fix merge conflicts
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/background.js3
-rw-r--r--app/scripts/controllers/preferences.js83
-rw-r--r--app/scripts/inpage.js2
-rw-r--r--app/scripts/lib/setupFetchDebugging.js34
-rw-r--r--app/scripts/metamask-controller.js13
5 files changed, 105 insertions, 30 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index b91021c6e..d20ffe6e3 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -2,6 +2,9 @@
* @file The entry point for the web extension singleton process.
*/
+// this needs to run before anything else
+require('./lib/setupFetchDebugging')()
+
const urlUtil = require('url')
const endOfStream = require('end-of-stream')
const pump = require('pump')
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index fd6a4866d..20b13398c 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -38,6 +38,9 @@ class PreferencesController {
lostIdentities: {},
seedWords: null,
forgottenPassword: false,
+ preferences: {
+ useETHAsPrimaryCurrency: true,
+ },
}, opts.initState)
this.diagnostics = opts.diagnostics
@@ -101,7 +104,7 @@ class PreferencesController {
* @param {Function} - end
*/
async requestWatchAsset (req, res, next, end) {
- if (req.method === 'metamask_watchAsset') {
+ if (req.method === 'metamask_watchAsset' || req.method === 'wallet_watchAsset') {
const { type, options } = req.params
switch (type) {
case 'ERC20':
@@ -372,22 +375,6 @@ class PreferencesController {
}
/**
- * Gets an updated rpc list from this.addToFrequentRpcList() and sets the `frequentRpcList` to this update list.
- *
- * @param {string} _url The the new rpc url to add to the updated list
- * @param {bool} remove Remove selected url
- * @returns {Promise<void>} Promise resolves with undefined
- *
- */
- updateFrequentRpcList (_url, remove = false) {
- return this.addToFrequentRpcList(_url, remove)
- .then((rpcList) => {
- this.store.updateState({ frequentRpcList: rpcList })
- return Promise.resolve()
- })
- }
-
- /**
* Setter for the `currentAccountTab` property
*
* @param {string} currentAccountTab Specifies the new tab to be marked as current
@@ -402,24 +389,39 @@ class PreferencesController {
}
/**
- * Returns an updated rpcList based on the passed url and the current list.
- * The returned list will have a max length of 3. If the _url currently exists it the list, it will be moved to the
- * end of the list. The current list is modified and returned as a promise.
+ * Adds custom RPC url to state.
*
- * @param {string} _url The rpc url to add to the frequentRpcList.
- * @param {bool} remove Remove selected url
- * @returns {Promise<array>} The updated frequentRpcList.
+ * @param {string} url The RPC url to add to frequentRpcList.
+ * @returns {Promise<array>} Promise resolving to updated frequentRpcList.
*
*/
- addToFrequentRpcList (_url, remove = false) {
+ addToFrequentRpcList (url) {
const rpcList = this.getFrequentRpcList()
- const index = rpcList.findIndex((element) => { return element === _url })
+ const index = rpcList.findIndex((element) => { return element === url })
if (index !== -1) {
rpcList.splice(index, 1)
}
- if (!remove && _url !== 'http://localhost:8545') {
- rpcList.push(_url)
+ if (url !== 'http://localhost:8545') {
+ rpcList.push(url)
}
+ this.store.updateState({ frequentRpcList: rpcList })
+ return Promise.resolve(rpcList)
+ }
+
+ /**
+ * Removes custom RPC url from state.
+ *
+ * @param {string} url The RPC url to remove from frequentRpcList.
+ * @returns {Promise<array>} Promise resolving to updated frequentRpcList.
+ *
+ */
+ removeFromFrequentRpcList (url) {
+ const rpcList = this.getFrequentRpcList()
+ const index = rpcList.findIndex((element) => { return element === url })
+ if (index !== -1) {
+ rpcList.splice(index, 1)
+ }
+ this.store.updateState({ frequentRpcList: rpcList })
return Promise.resolve(rpcList)
}
@@ -463,6 +465,33 @@ class PreferencesController {
getFeatureFlags () {
return this.store.getState().featureFlags
}
+
+ /**
+ * Updates the `preferences` property, which is an object. These are user-controlled features
+ * found in the settings page.
+ * @param {string} preference The preference to enable or disable.
+ * @param {boolean} value Indicates whether or not the preference should be enabled or disabled.
+ * @returns {Promise<object>} Promises a new object; the updated preferences object.
+ */
+ setPreference (preference, value) {
+ const currentPreferences = this.getPreferences()
+ const updatedPreferences = {
+ ...currentPreferences,
+ [preference]: value,
+ }
+
+ this.store.updateState({ preferences: updatedPreferences })
+ return Promise.resolve(updatedPreferences)
+ }
+
+ /**
+ * A getter for the `preferences` property
+ * @returns {object} A key-boolean map of user-selected preferences.
+ */
+ getPreferences () {
+ return this.store.getState().preferences
+ }
+
//
// PRIVATE METHODS
//
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 431702d63..b885a7e05 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -27,6 +27,8 @@ var metamaskStream = new LocalMessageDuplexStream({
// compose the inpage provider
var inpageProvider = new MetamaskInpageProvider(metamaskStream)
+// set a high max listener count to avoid unnecesary warnings
+inpageProvider.setMaxListeners(100)
// Augment the provider with its enable method
inpageProvider.enable = function (options = {}) {
diff --git a/app/scripts/lib/setupFetchDebugging.js b/app/scripts/lib/setupFetchDebugging.js
new file mode 100644
index 000000000..dd87b65a6
--- /dev/null
+++ b/app/scripts/lib/setupFetchDebugging.js
@@ -0,0 +1,34 @@
+module.exports = setupFetchDebugging
+
+//
+// This is a utility to help resolve cases where `window.fetch` throws a
+// `TypeError: Failed to Fetch` without any stack or context for the request
+// https://github.com/getsentry/sentry-javascript/pull/1293
+//
+
+function setupFetchDebugging() {
+ if (!global.fetch) return
+ const originalFetch = global.fetch
+
+ global.fetch = wrappedFetch
+
+ async function wrappedFetch(...args) {
+ const initialStack = getCurrentStack()
+ try {
+ return await originalFetch.call(window, ...args)
+ } catch (err) {
+ console.warn('FetchDebugger - fetch encountered an Error', err)
+ console.warn('FetchDebugger - overriding stack to point of original call')
+ err.stack = initialStack
+ throw err
+ }
+ }
+}
+
+function getCurrentStack() {
+ try {
+ throw new Error('Fake error for generating stack trace')
+ } catch (err) {
+ return err.stack
+ }
+}
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 493877345..7913662d4 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -129,6 +129,7 @@ module.exports = class MetamaskController extends EventEmitter {
provider: this.provider,
blockTracker: this.blockTracker,
})
+
// start and stop polling for balances based on activeControllerConnections
this.on('controllerConnectionChanged', (activeControllerConnections) => {
if (activeControllerConnections > 0) {
@@ -137,7 +138,12 @@ module.exports = class MetamaskController extends EventEmitter {
this.accountTracker.stop()
}
})
-
+
+ // ensure accountTracker updates balances after network change
+ this.networkController.on('networkDidChange', () => {
+ this.accountTracker._updateAccounts()
+ })
+
// key mgmt
const additionalKeyrings = [TrezorKeyring, LedgerBridgeKeyring]
this.keyringController = new KeyringController({
@@ -387,6 +393,7 @@ module.exports = class MetamaskController extends EventEmitter {
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController),
setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController),
setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController),
+ setPreference: nodeify(preferencesController.setPreference, preferencesController),
// BlacklistController
whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),
@@ -1451,7 +1458,7 @@ module.exports = class MetamaskController extends EventEmitter {
*/
async setCustomRpc (rpcTarget) {
this.networkController.setRpcTarget(rpcTarget)
- await this.preferencesController.updateFrequentRpcList(rpcTarget)
+ await this.preferencesController.addToFrequentRpcList(rpcTarget)
return rpcTarget
}
@@ -1460,7 +1467,7 @@ module.exports = class MetamaskController extends EventEmitter {
* @param {string} rpcTarget - A RPC URL to delete.
*/
async delCustomRpc (rpcTarget) {
- await this.preferencesController.updateFrequentRpcList(rpcTarget, true)
+ await this.preferencesController.removeFromFrequentRpcList(rpcTarget)
}
/**