diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-07-20 00:41:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 00:41:28 +0800 |
commit | 3784a7e2c852974315cfe17a68673938cf24a7fa (patch) | |
tree | 383bd6f3d2910a5114a94039e4554a23c5ce4b1a /app | |
parent | ae811628d96f3f678eb592221256b1f5770b7111 (diff) | |
parent | d85fc246c561972baf938c9f6cf41d2922f8a17a (diff) | |
download | tangerine-wallet-browser-3784a7e2c852974315cfe17a68673938cf24a7fa.tar tangerine-wallet-browser-3784a7e2c852974315cfe17a68673938cf24a7fa.tar.gz tangerine-wallet-browser-3784a7e2c852974315cfe17a68673938cf24a7fa.tar.bz2 tangerine-wallet-browser-3784a7e2c852974315cfe17a68673938cf24a7fa.tar.lz tangerine-wallet-browser-3784a7e2c852974315cfe17a68673938cf24a7fa.tar.xz tangerine-wallet-browser-3784a7e2c852974315cfe17a68673938cf24a7fa.tar.zst tangerine-wallet-browser-3784a7e2c852974315cfe17a68673938cf24a7fa.zip |
Merge pull request #4656 from MetaMask/portal-metamask-ens-test
Add support for .test ENS domains
Diffstat (limited to 'app')
-rw-r--r-- | app/manifest.json | 3 | ||||
-rw-r--r-- | app/scripts/background.js | 7 | ||||
-rw-r--r-- | app/scripts/lib/ipfsContent.js | 70 | ||||
-rw-r--r-- | app/scripts/lib/resolver.js | 4 |
4 files changed, 47 insertions, 37 deletions
diff --git a/app/manifest.json b/app/manifest.json index a226adfb0..b67cef025 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -62,7 +62,8 @@ "https://*.infura.io/", "activeTab", "webRequest", - "*://*.eth/" + "*://*.eth/", + "*://*.test/" ], "web_accessible_resources": [ "inpage.js" diff --git a/app/scripts/background.js b/app/scripts/background.js index e07b6b38a..7eb7b1255 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -53,6 +53,7 @@ const isIE = !!document.documentMode // Edge 20+ const isEdge = !isIE && !!window.StyleMedia +let ipfsHandle let popupIsOpen = false let notificationIsOpen = false const openMetamaskTabsIDs = {} @@ -158,7 +159,7 @@ async function initialize () { const initLangCode = await getFirstPreferredLangCode() await setupController(initState, initLangCode) log.debug('MetaMask initialization complete.') - ipfsContent(initState.NetworkController.provider) + ipfsHandle = ipfsContent(initState.NetworkController.provider) } // @@ -262,6 +263,10 @@ function setupController (initState, initLangCode) { }) global.metamaskController = controller + controller.networkController.on('networkDidChange', () => { + ipfsHandle && ipfsHandle.remove() + ipfsHandle = ipfsContent(controller.networkController.providerStore.getState()) + }) // report failed transactions to Sentry controller.txController.on(`tx:status-update`, (txId, status) => { diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index a6b99b2f9..5222151ea 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -2,39 +2,43 @@ const extension = require('extensionizer') const resolver = require('./resolver.js') module.exports = function (provider) { - extension.webRequest.onBeforeRequest.addListener(details => { - const urlhttpreplace = details.url.replace(/\w+?:\/\//, '') - const url = urlhttpreplace.replace(/[\\/].*/g, '') // eslint-disable-line no-useless-escape - let domainhtml = urlhttpreplace.match(/[\\/].*/g) // eslint-disable-line no-useless-escape - let clearTime = null - const name = url.replace(/\/$/g, '') - if (domainhtml === null) domainhtml = [''] - extension.tabs.getSelected(null, tab => { - extension.tabs.update(tab.id, { url: 'loading.html' }) + function ipfsContent (details) { + const name = details.url.substring(7, details.url.length - 1) + let clearTime = null + extension.tabs.getSelected(null, tab => { + extension.tabs.update(tab.id, { url: 'loading.html' }) - clearTime = setTimeout(() => { - return extension.tabs.update(tab.id, { url: '404.html' }) - }, 60000) + clearTime = setTimeout(() => { + return extension.tabs.update(tab.id, { url: '404.html' }) + }, 60000) - resolver.resolve(name, provider).then(ipfsHash => { - clearTimeout(clearTime) - let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] - return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { - if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) - extension.tabs.update(tab.id, { url: url }) - }) - .catch(err => { - url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] - extension.tabs.update(tab.id, {url: url}) - return err - }) - }) - .catch(err => { - clearTimeout(clearTime) - const url = err === 'unsupport' ? 'unsupport' : 'error' - extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) - }) - }) - return { cancel: true } - }, {urls: ['*://*.eth/', '*://*.eth/*']}) + resolver.resolve(name, provider).then(ipfsHash => { + clearTimeout(clearTime) + let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { + if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) + extension.tabs.update(tab.id, { url: url }) + }) + .catch(err => { + url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + extension.tabs.update(tab.id, {url: url}) + return err + }) + }) + .catch(err => { + clearTimeout(clearTime) + const url = err === 'unsupport' ? 'unsupport' : 'error' + extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) + }) + }) + return { cancel: true } + } + + extension.webRequest.onBeforeRequest.addListener(ipfsContent, {urls: ['*://*.eth/', '*://*.test/']}) + + return { + remove () { + extension.webRequest.onBeforeRequest.removeListener(ipfsContent) + }, + } } diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js index 6786929d8..ff0fed161 100644 --- a/app/scripts/lib/resolver.js +++ b/app/scripts/lib/resolver.js @@ -60,8 +60,8 @@ function getRegistrar (type) { module.exports.resolve = function (name, provider) { const path = name.split('.') - const tld = path[path.length - 1] - if (tld === 'eth') { + const topLevelDomain = path[path.length - 1] + if (topLevelDomain === 'eth' || topLevelDomain === 'test') { return ens(name, provider) } else { return new Promise((resolve, reject) => { |