aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-10-21 11:48:10 +0800
committerGitHub <noreply@github.com>2018-10-21 11:48:10 +0800
commit3b46478024f87bd237b507e5fb18068febf02de9 (patch)
tree1b70c2e7f431e7e3eb638c7630a2d220fa3dd030 /app/scripts
parent600f755dbf8d4cfdc152e3d521b537ee9a046a35 (diff)
parentba3617b685b9dcd8a62e0009ee2015c5997fead3 (diff)
downloadtangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.gz
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.bz2
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.lz
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.xz
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.zst
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.zip
Merge branch 'develop' into develop
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/background.js3
-rw-r--r--app/scripts/contentscript.js19
-rw-r--r--app/scripts/controllers/preferences.js81
-rw-r--r--app/scripts/controllers/transactions/index.js39
-rw-r--r--app/scripts/controllers/transactions/tx-state-manager.js5
-rw-r--r--app/scripts/inpage.js2
-rw-r--r--app/scripts/lib/setupFetchDebugging.js34
-rw-r--r--app/scripts/metamask-controller.js13
-rw-r--r--app/scripts/phishing-detect.js2
9 files changed, 160 insertions, 38 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 0343e134c..509a0001d 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/contentscript.js b/app/scripts/contentscript.js
index d870741d6..33523eb46 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -135,17 +135,22 @@ function doctypeCheck () {
}
/**
- * Checks the current document extension
+ * Returns whether or not the extension (suffix) of the current document is prohibited
*
- * @returns {boolean} {@code true} if the current extension is not prohibited
+ * This checks {@code window.location.pathname} against a set of file extensions
+ * that should not have web3 injected into them. This check is indifferent of query parameters
+ * in the location.
+ *
+ * @returns {boolean} whether or not the extension of the current document is prohibited
*/
function suffixCheck () {
- var prohibitedTypes = ['xml', 'pdf']
- var currentUrl = window.location.href
- var currentRegex
+ const prohibitedTypes = [
+ /\.xml$/,
+ /\.pdf$/,
+ ]
+ const currentUrl = window.location.pathname
for (let i = 0; i < prohibitedTypes.length; i++) {
- currentRegex = new RegExp(`\\.${prohibitedTypes[i]}$`)
- if (currentRegex.test(currentUrl)) {
+ if (prohibitedTypes[i].test(currentUrl)) {
return false
}
}
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index fd6a4866d..689506a7a 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
@@ -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/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index ebd49f882..9f2290924 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -166,6 +166,10 @@ class TransactionController extends EventEmitter {
async addUnapprovedTransaction (txParams) {
// validate
const normalizedTxParams = txUtils.normalizeTxParams(txParams)
+ // Assert the from address is the selected address
+ if (normalizedTxParams.from !== this.getSelectedAddress()) {
+ throw new Error(`Transaction from address isn't valid for this account`)
+ }
txUtils.validateTxParams(normalizedTxParams)
// construct txMeta
let txMeta = this.txStateManager.generateTxMeta({
@@ -362,7 +366,40 @@ class TransactionController extends EventEmitter {
this.txStateManager.setTxStatusSubmitted(txId)
}
- confirmTransaction (txId) {
+ /**
+ * Sets the status of the transaction to confirmed and sets the status of nonce duplicates as
+ * dropped if the txParams have data it will fetch the txReceipt
+ * @param {number} txId - The tx's ID
+ * @returns {Promise<void>}
+ */
+ async confirmTransaction (txId) {
+ // get the txReceipt before marking the transaction confirmed
+ // to ensure the receipt is gotten before the ui revives the tx
+ const txMeta = this.txStateManager.getTx(txId)
+
+ if (!txMeta) {
+ return
+ }
+
+ try {
+ const txReceipt = await this.query.getTransactionReceipt(txMeta.hash)
+
+ // It seems that sometimes the numerical values being returned from
+ // this.query.getTransactionReceipt are BN instances and not strings.
+ const gasUsed = typeof txReceipt.gasUsed !== 'string'
+ ? txReceipt.gasUsed.toString(16)
+ : txReceipt.gasUsed
+
+ txMeta.txReceipt = {
+ ...txReceipt,
+ gasUsed,
+ }
+
+ this.txStateManager.updateTx(txMeta, 'transactions#confirmTransaction - add txReceipt')
+ } catch (err) {
+ log.error(err)
+ }
+
this.txStateManager.setTxStatusConfirmed(txId)
this._markNonceDuplicatesDropped(txId)
}
diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js
index daa6cc388..58c48e34e 100644
--- a/app/scripts/controllers/transactions/tx-state-manager.js
+++ b/app/scripts/controllers/transactions/tx-state-manager.js
@@ -400,6 +400,11 @@ class TransactionStateManager extends EventEmitter {
*/
_setTxStatus (txId, status) {
const txMeta = this.getTx(txId)
+
+ if (!txMeta) {
+ return
+ }
+
txMeta.status = status
setTimeout(() => {
try {
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)
}
/**
diff --git a/app/scripts/phishing-detect.js b/app/scripts/phishing-detect.js
index 6baf868c0..0889c831e 100644
--- a/app/scripts/phishing-detect.js
+++ b/app/scripts/phishing-detect.js
@@ -1,4 +1,4 @@
-window.onload = function() {
+window.onload = function () {
if (window.location.pathname === '/phishing.html') {
const {hostname} = parseHash()
document.getElementById('esdbLink').innerHTML = '<b>To read more about this scam, navigate to: <a href="https://etherscamdb.info/domain/' + hostname + '"> https://etherscamdb.info/domain/' + hostname + '</a></b>'