diff options
author | Thomas <thomas.b.huang@gmail.com> | 2018-08-15 01:44:42 +0800 |
---|---|---|
committer | Thomas <thomas.b.huang@gmail.com> | 2018-08-15 01:44:42 +0800 |
commit | 96d789d2cffa91da9d65be0de75d2e864d309305 (patch) | |
tree | b3cea0eb6a4638244fd99bf64509c69b0b720a7a /app/scripts | |
parent | 7918240833871648dea6f9787519ba20f1e51899 (diff) | |
parent | 742aa8bb11c1273151ad907171061d4c5e4d1dca (diff) | |
download | tangerine-wallet-browser-96d789d2cffa91da9d65be0de75d2e864d309305.tar tangerine-wallet-browser-96d789d2cffa91da9d65be0de75d2e864d309305.tar.gz tangerine-wallet-browser-96d789d2cffa91da9d65be0de75d2e864d309305.tar.bz2 tangerine-wallet-browser-96d789d2cffa91da9d65be0de75d2e864d309305.tar.lz tangerine-wallet-browser-96d789d2cffa91da9d65be0de75d2e864d309305.tar.xz tangerine-wallet-browser-96d789d2cffa91da9d65be0de75d2e864d309305.tar.zst tangerine-wallet-browser-96d789d2cffa91da9d65be0de75d2e864d309305.zip |
Merge branch 'develop' into network-remove-provider-engine
Override package-lock and fix merge conflicts
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/background.js | 4 | ||||
-rw-r--r-- | app/scripts/contentscript.js | 2 | ||||
-rw-r--r-- | app/scripts/controllers/detect-tokens.js | 2 | ||||
-rw-r--r-- | app/scripts/controllers/preferences.js | 94 | ||||
-rw-r--r-- | app/scripts/lib/enums.js | 11 | ||||
-rw-r--r-- | app/scripts/lib/ipfsContent.js | 6 | ||||
-rw-r--r-- | app/scripts/lib/setupRaven.js | 4 | ||||
-rw-r--r-- | app/scripts/lib/util.js | 29 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 3 | ||||
-rw-r--r-- | app/scripts/migrations/028.js | 40 | ||||
-rw-r--r-- | app/scripts/migrations/index.js | 1 | ||||
-rw-r--r-- | app/scripts/platforms/extension.js | 7 |
12 files changed, 176 insertions, 27 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 4cd6dac4c..c7395c810 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -47,8 +47,8 @@ const notificationManager = new NotificationManager() global.METAMASK_NOTIFIER = notificationManager // setup sentry error reporting -const releaseVersion = platform.getVersion() -const raven = setupRaven({ releaseVersion }) +const release = platform.getVersion() +const raven = setupRaven({ release }) // browser check if it is Edge - https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser // Internet Explorer 6-11 diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index b7496f318..e0a2b0061 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -198,6 +198,6 @@ function blacklistedDomainCheck () { */ function redirectToPhishingWarning () { console.log('MetaMask - routing to Phishing Warning component') - let extensionURL = extension.runtime.getURL('phishing.html') + const extensionURL = extension.runtime.getURL('phishing.html') window.location.href = extensionURL } diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js index 195ec918a..62e639795 100644 --- a/app/scripts/controllers/detect-tokens.js +++ b/app/scripts/controllers/detect-tokens.js @@ -85,7 +85,7 @@ class DetectTokensController { set preferences (preferences) { if (!preferences) { return } this._preferences = preferences - preferences.store.subscribe(({ tokens }) => { this.tokenAddresses = tokens.map((obj) => { return obj.address }) }) + preferences.store.subscribe(({ tokens = [] }) => { this.tokenAddresses = tokens.map((obj) => { return obj.address }) }) preferences.store.subscribe(({ selectedAddress }) => { if (this.selectedAddress !== selectedAddress) { this.selectedAddress = selectedAddress diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index f6250dc16..707fd7de9 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -13,6 +13,7 @@ class PreferencesController { * @property {array} store.frequentRpcList A list of custom rpcs to provide the user * @property {string} store.currentAccountTab Indicates the selected tab in the ui * @property {array} store.tokens The tokens the user wants display in their token lists + * @property {object} store.accountTokens The tokens stored per account and then per network type * @property {boolean} store.useBlockie The users preference for blockie identicons within the UI * @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the * user wishes to see that feature @@ -24,6 +25,7 @@ class PreferencesController { const initState = extend({ frequentRpcList: [], currentAccountTab: 'history', + accountTokens: {}, tokens: [], useBlockie: false, featureFlags: {}, @@ -33,8 +35,9 @@ class PreferencesController { }, opts.initState) this.diagnostics = opts.diagnostics - + this.network = opts.network this.store = new ObservableStore(initState) + this._subscribeProviderType() } // PUBLIC METHODS @@ -77,12 +80,19 @@ class PreferencesController { */ setAddresses (addresses) { const oldIdentities = this.store.getState().identities + const oldAccountTokens = this.store.getState().accountTokens + const identities = addresses.reduce((ids, address, index) => { const oldId = oldIdentities[address] || {} ids[address] = {name: `Account ${index + 1}`, address, ...oldId} return ids }, {}) - this.store.updateState({ identities }) + const accountTokens = addresses.reduce((tokens, address) => { + const oldTokens = oldAccountTokens[address] || {} + tokens[address] = oldTokens + return tokens + }, {}) + this.store.updateState({ identities, accountTokens }) } /** @@ -93,11 +103,13 @@ class PreferencesController { */ removeAddress (address) { const identities = this.store.getState().identities + const accountTokens = this.store.getState().accountTokens if (!identities[address]) { throw new Error(`${address} can't be deleted cause it was not found`) } delete identities[address] - this.store.updateState({ identities }) + delete accountTokens[address] + this.store.updateState({ identities, accountTokens }) // If the selected account is no longer valid, // select an arbitrary other account: @@ -117,14 +129,17 @@ class PreferencesController { */ addAddresses (addresses) { const identities = this.store.getState().identities + const accountTokens = this.store.getState().accountTokens addresses.forEach((address) => { // skip if already exists if (identities[address]) return // add missing identity const identityCount = Object.keys(identities).length + + accountTokens[address] = {} identities[address] = { name: `Account ${identityCount + 1}`, address } }) - this.store.updateState({ identities }) + this.store.updateState({ identities, accountTokens }) } /* @@ -175,15 +190,15 @@ class PreferencesController { * Setter for the `selectedAddress` property * * @param {string} _address A new hex address for an account - * @returns {Promise<void>} Promise resolves with undefined + * @returns {Promise<void>} Promise resolves with tokens * */ setSelectedAddress (_address) { - return new Promise((resolve, reject) => { - const address = normalizeAddress(_address) - this.store.updateState({ selectedAddress: address }) - resolve() - }) + const address = normalizeAddress(_address) + this._updateTokens(address) + this.store.updateState({ selectedAddress: address }) + const tokens = this.store.getState().tokens + return Promise.resolve(tokens) } /** @@ -232,9 +247,7 @@ class PreferencesController { } else { tokens.push(newEntry) } - - this.store.updateState({ tokens }) - + this._updateAccountTokens(tokens) return Promise.resolve(tokens) } @@ -247,10 +260,8 @@ class PreferencesController { */ removeToken (rawAddress) { const tokens = this.store.getState().tokens - const updatedTokens = tokens.filter(token => token.address !== rawAddress) - - this.store.updateState({ tokens: updatedTokens }) + this._updateAccountTokens(updatedTokens) return Promise.resolve(updatedTokens) } @@ -376,6 +387,57 @@ class PreferencesController { // // PRIVATE METHODS // + /** + * Subscription to network provider type. + * + * + */ + _subscribeProviderType () { + this.network.providerStore.subscribe(() => { + const { tokens } = this._getTokenRelatedStates() + this.store.updateState({ tokens }) + }) + } + + /** + * Updates `accountTokens` and `tokens` of current account and network according to it. + * + * @param {array} tokens Array of tokens to be updated. + * + */ + _updateAccountTokens (tokens) { + const { accountTokens, providerType, selectedAddress } = this._getTokenRelatedStates() + accountTokens[selectedAddress][providerType] = tokens + this.store.updateState({ accountTokens, tokens }) + } + + /** + * Updates `tokens` of current account and network. + * + * @param {string} selectedAddress Account address to be updated with. + * + */ + _updateTokens (selectedAddress) { + const { tokens } = this._getTokenRelatedStates(selectedAddress) + this.store.updateState({ tokens }) + } + + /** + * A getter for `tokens` and `accountTokens` related states. + * + * @param {string} selectedAddress A new hex address for an account + * @returns {Object.<array, object, string, string>} States to interact with tokens in `accountTokens` + * + */ + _getTokenRelatedStates (selectedAddress) { + const accountTokens = this.store.getState().accountTokens + if (!selectedAddress) selectedAddress = this.store.getState().selectedAddress + const providerType = this.network.providerStore.getState().type + if (!(selectedAddress in accountTokens)) accountTokens[selectedAddress] = {} + if (!(providerType in accountTokens[selectedAddress])) accountTokens[selectedAddress][providerType] = [] + const tokens = accountTokens[selectedAddress][providerType] + return { tokens, accountTokens, providerType, selectedAddress } + } } module.exports = PreferencesController diff --git a/app/scripts/lib/enums.js b/app/scripts/lib/enums.js index 0a3afca47..c6d57a1bc 100644 --- a/app/scripts/lib/enums.js +++ b/app/scripts/lib/enums.js @@ -2,8 +2,19 @@ const ENVIRONMENT_TYPE_POPUP = 'popup' const ENVIRONMENT_TYPE_NOTIFICATION = 'notification' const ENVIRONMENT_TYPE_FULLSCREEN = 'fullscreen' +const PLATFORM_BRAVE = 'Brave' +const PLATFORM_CHROME = 'Chrome' +const PLATFORM_EDGE = 'Edge' +const PLATFORM_FIREFOX = 'Firefox' +const PLATFORM_OPERA = 'Opera' + module.exports = { ENVIRONMENT_TYPE_POPUP, ENVIRONMENT_TYPE_NOTIFICATION, ENVIRONMENT_TYPE_FULLSCREEN, + PLATFORM_BRAVE, + PLATFORM_CHROME, + PLATFORM_EDGE, + PLATFORM_FIREFOX, + PLATFORM_OPERA, } diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index 5222151ea..5db63f47d 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -5,7 +5,7 @@ module.exports = function (provider) { function ipfsContent (details) { const name = details.url.substring(7, details.url.length - 1) let clearTime = null - extension.tabs.getSelected(null, tab => { + extension.tabs.query({active: true}, tab => { extension.tabs.update(tab.id, { url: 'loading.html' }) clearTime = setTimeout(() => { @@ -34,11 +34,11 @@ module.exports = function (provider) { return { cancel: true } } - extension.webRequest.onBeforeRequest.addListener(ipfsContent, {urls: ['*://*.eth/', '*://*.test/']}) + extension.webRequest.onErrorOccurred.addListener(ipfsContent, {urls: ['*://*.eth/', '*://*.test/']}) return { remove () { - extension.webRequest.onBeforeRequest.removeListener(ipfsContent) + extension.webRequest.onErrorOccurred.removeListener(ipfsContent) }, } } diff --git a/app/scripts/lib/setupRaven.js b/app/scripts/lib/setupRaven.js index 9aa2dec0a..e6e511640 100644 --- a/app/scripts/lib/setupRaven.js +++ b/app/scripts/lib/setupRaven.js @@ -8,7 +8,7 @@ module.exports = setupRaven // Setup raven / sentry remote error reporting function setupRaven (opts) { - const { releaseVersion } = opts + const { release } = opts let ravenTarget // detect brave const isBrave = Boolean(window.chrome.ipcRenderer) @@ -22,7 +22,7 @@ function setupRaven (opts) { } const client = Raven.config(ravenTarget, { - releaseVersion, + release, transport: function (opts) { opts.data.extra.isBrave = isBrave const report = opts.data diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index 2b3fe3d6e..ea13b26be 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -5,6 +5,11 @@ const { ENVIRONMENT_TYPE_POPUP, ENVIRONMENT_TYPE_NOTIFICATION, ENVIRONMENT_TYPE_FULLSCREEN, + PLATFORM_FIREFOX, + PLATFORM_OPERA, + PLATFORM_CHROME, + PLATFORM_EDGE, + PLATFORM_BRAVE, } = require('./enums') /** @@ -38,6 +43,29 @@ const getEnvironmentType = (url = window.location.href) => { } /** + * Returns the platform (browser) where the extension is running. + * + * @returns {string} the platform ENUM + * + */ +const getPlatform = _ => { + const ua = navigator.userAgent + if (ua.search('Firefox') !== -1) { + return PLATFORM_FIREFOX + } else { + if (window && window.chrome && window.chrome.ipcRenderer) { + return PLATFORM_BRAVE + } else if (ua.search('Edge') !== -1) { + return PLATFORM_EDGE + } else if (ua.search('OPR') !== -1) { + return PLATFORM_OPERA + } else { + return PLATFORM_CHROME + } + } +} + +/** * Checks whether a given balance of ETH, represented as a hex string, is sufficient to pay a value plus a gas fee * * @param {object} txParams Contains data about a transaction @@ -114,6 +142,7 @@ function removeListeners (listeners, emitter) { module.exports = { removeListeners, applyListeners, + getPlatform, getStack, getEnvironmentType, sufficientBalance, diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 12daf1603..81bb080ab 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -86,6 +86,7 @@ module.exports = class MetamaskController extends EventEmitter { this.preferencesController = new PreferencesController({ initState: initState.PreferencesController, initLangCode: opts.initLangCode, + network: this.networkController, }) // currency controller @@ -1405,7 +1406,7 @@ module.exports = class MetamaskController extends EventEmitter { } /** - * A method for activating the retrieval of price data and auto detect tokens, + * A method for activating the retrieval of price data, * which should only be fetched when the UI is visible. * @private * @param {boolean} active - True if price data should be getting fetched. diff --git a/app/scripts/migrations/028.js b/app/scripts/migrations/028.js new file mode 100644 index 000000000..9e995ee1a --- /dev/null +++ b/app/scripts/migrations/028.js @@ -0,0 +1,40 @@ +// next version number +const version = 28 + +/* + +normalizes txParams on unconfirmed txs + +*/ +const clone = require('clone') + +module.exports = { + version, + + migrate: async function (originalVersionedData) { + const versionedData = clone(originalVersionedData) + versionedData.meta.version = version + const state = versionedData.data + const newState = transformState(state) + versionedData.data = newState + return versionedData + }, +} + +function transformState (state) { + const newState = state + + if (newState.PreferencesController) { + if (newState.PreferencesController.tokens && newState.PreferencesController.identities) { + const identities = newState.PreferencesController.identities + const tokens = newState.PreferencesController.tokens + newState.PreferencesController.accountTokens = {} + for (const identity in identities) { + newState.PreferencesController.accountTokens[identity] = {'mainnet': tokens} + } + newState.PreferencesController.tokens = [] + } + } + + return newState +} diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index bd0005221..3b512715e 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -38,4 +38,5 @@ module.exports = [ require('./025'), require('./026'), require('./027'), + require('./028'), ] diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index 0803164e8..71b162dd0 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -24,8 +24,13 @@ class ExtensionPlatform { return extension.runtime.getManifest().version } - openExtensionInBrowser (route = null) { + openExtensionInBrowser (route = null, queryString = null) { let extensionURL = extension.runtime.getURL('home.html') + + if (queryString) { + extensionURL += `?${queryString}` + } + if (route) { extensionURL += `#${route}` } |