diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/manifest.json | 2 | ||||
-rw-r--r-- | app/scripts/controllers/network/createInfuraClient.js | 2 | ||||
-rw-r--r-- | app/scripts/controllers/transactions/index.js | 2 | ||||
-rw-r--r-- | app/scripts/controllers/transactions/pending-tx-tracker.js | 2 | ||||
-rw-r--r-- | app/scripts/controllers/transactions/tx-state-manager.js | 4 | ||||
-rw-r--r-- | app/scripts/inpage.js | 16 | ||||
-rw-r--r-- | app/scripts/lib/ens-ipfs/resolver.js | 2 | ||||
-rw-r--r-- | app/scripts/lib/ens-ipfs/setup.js | 6 | ||||
-rw-r--r-- | app/scripts/lib/setupFetchDebugging.js | 8 | ||||
-rw-r--r-- | app/scripts/lib/setupSentry.js | 2 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 4 | ||||
-rw-r--r-- | app/scripts/migrations/029.js | 27 | ||||
-rw-r--r-- | app/scripts/migrations/fail-tx.js | 41 | ||||
-rw-r--r-- | app/scripts/migrations/index.js | 1 | ||||
-rw-r--r-- | app/scripts/ui.js | 2 |
15 files changed, 97 insertions, 24 deletions
diff --git a/app/manifest.json b/app/manifest.json index 89a843ffa..a95688789 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_appName__", "short_name": "__MSG_appName__", - "version": "5.0.2", + "version": "5.0.3", "manifest_version": 2, "author": "https://metamask.io", "description": "__MSG_appDescription__", diff --git a/app/scripts/controllers/network/createInfuraClient.js b/app/scripts/controllers/network/createInfuraClient.js index c70fa9e38..f01927bca 100644 --- a/app/scripts/controllers/network/createInfuraClient.js +++ b/app/scripts/controllers/network/createInfuraClient.js @@ -28,7 +28,7 @@ function createInfuraClient ({ network }) { return { networkMiddleware, blockTracker } } -function createNetworkAndChainIdMiddleware({ network }) { +function createNetworkAndChainIdMiddleware ({ network }) { let chainId let netId diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 9cf822d34..b44f66f14 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -1,4 +1,4 @@ -const EventEmitter = require('events') +const EventEmitter = require('safe-event-emitter') const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const Transaction = require('ethereumjs-tx') diff --git a/app/scripts/controllers/transactions/pending-tx-tracker.js b/app/scripts/controllers/transactions/pending-tx-tracker.js index 44a50a589..4bf40b1db 100644 --- a/app/scripts/controllers/transactions/pending-tx-tracker.js +++ b/app/scripts/controllers/transactions/pending-tx-tracker.js @@ -1,4 +1,4 @@ -const EventEmitter = require('events') +const EventEmitter = require('safe-event-emitter') const log = require('loglevel') const EthQuery = require('ethjs-query') diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index 62319507d..151082452 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -1,5 +1,5 @@ const extend = require('xtend') -const EventEmitter = require('events') +const EventEmitter = require('safe-event-emitter') const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const log = require('loglevel') @@ -86,7 +86,7 @@ class TransactionStateManager extends EventEmitter { @returns {array} the tx list whos status is approved if no address is provide returns all txMetas who's status is approved for the current network */ - getApprovedTransactions(address) { + getApprovedTransactions (address) { const opts = { status: 'approved' } if (address) opts.from = address return this.getFilteredTxList(opts) diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 83392761e..f8c6cf573 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -29,7 +29,7 @@ console.warn('ATTENTION: In an effort to improve user privacy, MetaMask ' + * @param {Function} handler - event handler * @param {boolean} remove - removes this handler after being triggered */ -function onMessage(messageType, handler, remove) { +function onMessage (messageType, handler, remove) { window.addEventListener('message', function ({ data }) { if (!data || data.type !== messageType) { return } remove && window.removeEventListener('message', handler) @@ -59,7 +59,9 @@ onMessage('metamasksetlocked', () => { isEnabled = false }) // set up a listener for privacy mode responses onMessage('ethereumproviderlegacy', ({ data: { selectedAddress } }) => { isEnabled = true - inpageProvider.publicConfigStore.updateState({ selectedAddress }) + setTimeout(() => { + inpageProvider.publicConfigStore.updateState({ selectedAddress }) + }, 0) }, true) // augment the provider with its enable method @@ -70,7 +72,9 @@ inpageProvider.enable = function ({ force } = {}) { reject(error) } else { window.removeEventListener('message', providerHandle) - inpageProvider.publicConfigStore.updateState({ selectedAddress }) + setTimeout(() => { + inpageProvider.publicConfigStore.updateState({ selectedAddress }) + }, 0) // wait for the background to update with an account inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { @@ -104,7 +108,7 @@ inpageProvider._metamask = new Proxy({ * * @returns {Promise<boolean>} - Promise resolving to true if this domain has been previously approved */ - isApproved: function() { + isApproved: function () { return new Promise((resolve) => { isApprovedHandle = ({ data: { caching, isApproved } }) => { if (caching) { @@ -133,7 +137,7 @@ inpageProvider._metamask = new Proxy({ }) }, }, { - get: function(obj, prop) { + get: function (obj, prop) { !warned && console.warn('Heads up! ethereum._metamask exposes methods that have ' + 'not been standardized yet. This means that these methods may not be implemented ' + 'in other dapp browsers and may be removed from MetaMask in the future.') @@ -153,7 +157,7 @@ const proxiedInpageProvider = new Proxy(inpageProvider, { window.ethereum = proxiedInpageProvider // detect eth_requestAccounts and pipe to enable for now -function detectAccountRequest(method) { +function detectAccountRequest (method) { const originalMethod = inpageProvider[method] inpageProvider[method] = function ({ method }) { if (method === 'eth_requestAccounts') { diff --git a/app/scripts/lib/ens-ipfs/resolver.js b/app/scripts/lib/ens-ipfs/resolver.js index fe2dc1134..b98566190 100644 --- a/app/scripts/lib/ens-ipfs/resolver.js +++ b/app/scripts/lib/ens-ipfs/resolver.js @@ -38,7 +38,7 @@ async function resolveEnsToIpfsContentId ({ provider, name }) { return contentId } -function hexValueIsEmpty(value) { +function hexValueIsEmpty (value) { return [undefined, null, '0x', '0x0', '0x0000000000000000000000000000000000000000000000000000000000000000'].includes(value) } diff --git a/app/scripts/lib/ens-ipfs/setup.js b/app/scripts/lib/ens-ipfs/setup.js index 45eb1ce14..df756d0f7 100644 --- a/app/scripts/lib/ens-ipfs/setup.js +++ b/app/scripts/lib/ens-ipfs/setup.js @@ -6,7 +6,7 @@ const supportedTopLevelDomains = ['eth'] module.exports = setupEnsIpfsResolver -function setupEnsIpfsResolver({ provider }) { +function setupEnsIpfsResolver ({ provider }) { // install listener const urlPatterns = supportedTopLevelDomains.map(tld => `*://*.${tld}/*`) @@ -35,11 +35,11 @@ function setupEnsIpfsResolver({ provider }) { attemptResolve({ tabId, name, path, search }) } - async function attemptResolve({ tabId, name, path, search }) { + async function attemptResolve ({ tabId, name, path, search }) { extension.tabs.update(tabId, { url: `loading.html` }) try { const ipfsContentId = await resolveEnsToIpfsContentId({ provider, name }) - let url = `https://gateway.ipfs.io/ipfs/${ipfsContentId}${path}${search || ''}` + const url = `https://gateway.ipfs.io/ipfs/${ipfsContentId}${path}${search || ''}` try { // check if ipfs gateway has result const response = await fetch(url, { method: 'HEAD' }) diff --git a/app/scripts/lib/setupFetchDebugging.js b/app/scripts/lib/setupFetchDebugging.js index c1ef22d21..431340e2b 100644 --- a/app/scripts/lib/setupFetchDebugging.js +++ b/app/scripts/lib/setupFetchDebugging.js @@ -6,13 +6,13 @@ module.exports = setupFetchDebugging // https://github.com/getsentry/sentry-javascript/pull/1293 // -function setupFetchDebugging() { +function setupFetchDebugging () { if (!global.fetch) return const originalFetch = global.fetch global.fetch = wrappedFetch - async function wrappedFetch(...args) { + async function wrappedFetch (...args) { const initialStack = getCurrentStack() try { return await originalFetch.call(window, ...args) @@ -20,14 +20,14 @@ function setupFetchDebugging() { if (!err.stack) { console.warn('FetchDebugger - fetch encountered an Error without a stack', err) console.warn('FetchDebugger - overriding stack to point of original call') - err.stack = initialStack + err.stack = initialStack } throw err } } } -function getCurrentStack() { +function getCurrentStack () { try { throw new Error('Fake error for generating stack trace') } catch (err) { diff --git a/app/scripts/lib/setupSentry.js b/app/scripts/lib/setupSentry.js index 69042bc19..ba0e17df0 100644 --- a/app/scripts/lib/setupSentry.js +++ b/app/scripts/lib/setupSentry.js @@ -32,7 +32,7 @@ function setupSentry (opts) { scope.setExtra('isBrave', isBrave) }) - function rewriteReport(report) { + function rewriteReport (report) { try { // simplify certain complex error messages (e.g. Ethjs) simplifyErrorMessages(report) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 641a7ef3f..f3cd078b8 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -200,7 +200,7 @@ module.exports = class MetamaskController extends EventEmitter { this.networkController.on('networkDidChange', () => { this.balancesController.updateAllBalances() var currentCurrency = this.currencyController.getCurrentCurrency() - this.setCurrentCurrency(currentCurrency, function() {}) + this.setCurrentCurrency(currentCurrency, function () {}) }) this.balancesController.updateAllBalances() @@ -1581,7 +1581,7 @@ module.exports = class MetamaskController extends EventEmitter { /** * Locks MetaMask */ - setLocked() { + setLocked () { this.providerApprovalController.setLocked() return this.keyringController.setLocked() } diff --git a/app/scripts/migrations/029.js b/app/scripts/migrations/029.js new file mode 100644 index 000000000..e17479ccc --- /dev/null +++ b/app/scripts/migrations/029.js @@ -0,0 +1,27 @@ +// next version number +const version = 29 +const failTxsThat = require('./fail-tx') + +// time +const seconds = 1000 +const minutes = 60 * seconds +const hours = 60 * minutes +const unacceptableDelay = 12 * hours + +/* + +normalizes txParams on unconfirmed txs + +*/ + +module.exports = { + version, + + migrate: failTxsThat(version, 'Stuck in approved state for too long.', (txMeta) => { + const isApproved = txMeta.status === 'approved' + const createdTime = txMeta.submittedTime + const now = Date.now() + return isApproved && now - createdTime > unacceptableDelay + }), +} + diff --git a/app/scripts/migrations/fail-tx.js b/app/scripts/migrations/fail-tx.js new file mode 100644 index 000000000..98e3ffddb --- /dev/null +++ b/app/scripts/migrations/fail-tx.js @@ -0,0 +1,41 @@ +const clone = require('clone') + +module.exports = function (version, reason, condition) { + return function (originalVersionedData) { + const versionedData = clone(originalVersionedData) + versionedData.meta.version = version + try { + const state = versionedData.data + const newState = transformState(state, condition, reason) + versionedData.data = newState + } catch (err) { + console.warn(`MetaMask Migration #${version}` + err.stack) + } + return Promise.resolve(versionedData) + + } +} + +function transformState (state, condition, reason) { + const newState = state + const { TransactionController } = newState + if (TransactionController && TransactionController.transactions) { + const transactions = TransactionController.transactions + + newState.TransactionController.transactions = transactions.map((txMeta) => { + if (!condition(txMeta)) { + return txMeta + } + + txMeta.status = 'failed' + txMeta.err = { + message: reason, + note: `Tx automatically failed by migration because ${reason}`, + } + + return txMeta + }) + } + return newState +} + diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index 3b512715e..9344b77ed 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -39,4 +39,5 @@ module.exports = [ require('./026'), require('./027'), require('./028'), + require('./029'), ] diff --git a/app/scripts/ui.js b/app/scripts/ui.js index c4f6615db..444097f14 100644 --- a/app/scripts/ui.js +++ b/app/scripts/ui.js @@ -23,7 +23,7 @@ async function start () { const release = global.platform.getVersion() setupSentry({ release, getState }) // provide app state to append to error logs - function getState() { + function getState () { // get app state const state = window.getCleanAppState() // remove unnecessary data |